private void addDiscovery() { Map<Long, ISwitch> switches = controller.getSwitches(); Set<Long> sidSet = switches.keySet(); if (sidSet == null) { return; } for (Long sid : sidSet) { Node node = NodeCreator.createOFNode(sid); addDiscovery(node); } }
@Override public void descriptionStatisticsRefreshed(Long switchId, List<OFStatistics> descriptionStats) { Node node = NodeCreator.createOFNode(switchId); Set<Property> properties = new HashSet<Property>(1); OFDescriptionStatistics ofDesc = (OFDescriptionStatistics) descriptionStats.get(0); Description desc = new Description(ofDesc.getDatapathDescription()); properties.add(desc); // Notify all internal and external listeners notifyInventoryShimListener(node, UpdateType.CHANGED, properties); }
@Override public void descriptionStatisticsRefreshed(Long switchId, List<OFStatistics> description) { String container; IReadFilterInternalListener listener; Node node = NodeCreator.createOFNode(switchId); NodeDescription nodeDescription = new DescStatisticsConverter(description).getHwDescription(); for (Map.Entry<String, IReadFilterInternalListener> l : readFilterInternalListeners.entrySet()) { container = l.getKey(); listener = l.getValue(); if (container == GlobalConstants.DEFAULT.toString() || (containerToNode.containsKey(container) && containerToNode.get(container).contains(node))) { listener.nodeDescriptionStatisticsUpdated(node, nodeDescription); } } }
@Override public void tableStatisticsRefreshed(Long switchId, List<OFStatistics> tables) { String container; Node node = NodeCreator.createOFNode(switchId); for (Map.Entry<String, IReadFilterInternalListener> l : readFilterInternalListeners.entrySet()) { container = l.getKey(); // Convert and filter the statistics per container List<OFStatistics> filteredList = filterTableListPerContainer(container, switchId, tables); List<NodeTableStatistics> tableStatsList = new TableStatisticsConverter(switchId, filteredList) .getNodeTableStatsList(); // notify listeners l.getValue().nodeTableStatisticsUpdated(node, tableStatsList); } }
public void _addsw(CommandInterpreter ci) { String val = ci.nextArgument(); Long sid; try { sid = Long.parseLong(val); Node node = NodeCreator.createOFNode(sid); addDiscovery(node); } catch (Exception e) { ci.println("Please enter a valid number"); } return; }
private List<OFStatistics> filterTableListPerContainer( String container, long switchId, List<OFStatistics> list) { if (list == null) { return Collections.emptyList(); } // Create new filtered list of node tables List<OFStatistics> newList = new ArrayList<OFStatistics>(); for (OFStatistics stat : list) { OFTableStatistics target = (OFTableStatistics) stat; NodeTable nt = NodeTableCreator.createOFNodeTable(target.getTableId(), NodeCreator.createOFNode(switchId)); if (containerOwnsNodeTable(container, nt)) { newList.add(target); } } return newList; }
private void removeNode(ISwitch sw) { Node node = NodeCreator.createOFNode(sw.getId()); if(node == null) { return; } removeNodeConnectorProps(node); nodeProps.remove(node); UpdateType type = UpdateType.REMOVED; // Notify all internal and external listeners notifyInventoryShimListener(node, type, null); }
public void _remsw(CommandInterpreter ci) { String val = ci.nextArgument(); Long sid; try { sid = Long.parseLong(val); Node node = NodeCreator.createOFNode(sid); removeDiscovery(node); } catch (Exception e) { ci.println("Please enter a valid number"); } return; }
public List<String> removeContainerEntry(String arg1, String arg2, String arg3) { List<String> result = new ArrayList<String>(); String containerName = arg1; if (containerName == null) { result.add("Container Name not specified"); return result; } String nodeId = arg2; if (nodeId == null) { result.add("Node Id not specified"); return result; } String portId = arg3; if (portId == null) { result.add("Port not specified"); return result; } Node node = NodeCreator.createOFNode(Long.valueOf(nodeId)); Short port = Short.valueOf(portId); NodeConnector nc = NodeConnectorCreator.createOFNodeConnector(port, node); List<String> portList = new ArrayList<String>(1); portList.add(nc.toString()); result.add((this.addRemoveContainerEntries(containerName, portList, true)).toString()); return result; } public List<String> addContainerFlow(String arg1, String arg2, String arg3) {
@Override public void portStatisticsRefreshed(Long switchId, List<OFStatistics> ports) { String container; IReadFilterInternalListener listener; Node node = NodeCreator.createOFNode(switchId); for (Map.Entry<String, IReadFilterInternalListener> l : readFilterInternalListeners.entrySet()) { container = l.getKey(); listener = l.getValue(); // Convert and filter the statistics per container List<OFStatistics> filteredPorts = filterPortListPerContainer(container, switchId, ports); List<NodeConnectorStatistics> ncStatsList = new PortStatisticsConverter(switchId, filteredPorts) .getNodeConnectorStatsList(); // notify listeners listener.nodeConnectorStatisticsUpdated(node, ncStatsList); } }
public List<OFStatistics> filterTableListPerContainer( String container, long switchId, List<OFStatistics> list) { if (list == null) { return null; } // Create new filtered list of node tables List<OFStatistics> newList = new ArrayList<OFStatistics>(); for (OFStatistics stat : list) { OFTableStatistics target = (OFTableStatistics) stat; NodeTable nt = NodeTableCreator.createOFNodeTable( target.getTableId(), NodeCreator.createOFNode(switchId)); if (containerOwnsNodeTable(container, nt)) { newList.add(target); } } return newList; }
@Override public void flowStatisticsRefreshed(Long switchId, List<OFStatistics> flows) { String container; IReadFilterInternalListener listener; Node node = NodeCreator.createOFNode(switchId); for (Map.Entry<String, IReadFilterInternalListener> l : readFilterInternalListeners.entrySet()) { container = l.getKey(); listener = l.getValue(); // Convert and filter the statistics per container List<FlowOnNode> flowOnNodeList = new FlowStatisticsConverter(flows).getFlowOnNodeList(node); flowOnNodeList = filterFlowListPerContainer(container, node, flowOnNodeList); // notify listeners listener.nodeFlowStatisticsUpdated(node, flowOnNodeList); } }
public static Map<NodeConnector, Set<Property>> OFSwitchToProps(ISwitch sw) { Map<NodeConnector, Set<Property>> ncProps = new HashMap<NodeConnector, Set<Property>>(); if (sw == null) { return ncProps; } Node node = NodeCreator.createOFNode(sw.getId()); if (node == null) { return ncProps; } Set<Property> props; NodeConnector nodeConnector; OFPhysicalPort port; Map<Short, OFPhysicalPort> ports = sw.getPhysicalPorts(); for (Map.Entry<Short, OFPhysicalPort> entry : ports.entrySet()) { nodeConnector = PortConverter.toNodeConnector(entry.getKey(), node); port = entry.getValue(); props = InventoryServiceHelper.OFPortToProps(port); ncProps.put(nodeConnector, props); } return ncProps; } }
/** * Filters a list of FlowOnNode elements based on the container * * @param container * @param nodeId * @param list * @return */ public List<OFStatistics> filterPortListPerContainer(String container, long switchId, List<OFStatistics> list) { if (list == null) { return null; } // Create new filtered list of flows List<OFStatistics> newList = new ArrayList<OFStatistics>(); for (OFStatistics stat : list) { OFPortStatisticsReply target = (OFPortStatisticsReply) stat; NodeConnector nc = NodeConnectorCreator.createOFNodeConnector( target.getPortNumber(), NodeCreator.createOFNode(switchId)); if (containerOwnsNodeConnector(container, nc)) { newList.add(target); } } return newList; }
public List<String> createContainer(String arg1, String arg2) { List<String> result = new ArrayList<String>(); String containerName = arg1; if (containerName == null) { result.add("Container Name not specified"); return result; } String staticVlan = arg2; if (staticVlan == null) { result.add("Static Vlan not specified"); return result; } List<String> ports = new ArrayList<String>(); for (long l = 1L; l < 10L; l++) { ports.add(NodeConnectorCreator.createOFNodeConnector((short) 1, NodeCreator.createOFNode(l)).toString()); } List<ContainerFlowConfig> cFlowList = new ArrayList<ContainerFlowConfig>(); cFlowList.add(this.createSampleContainerFlowConfig("tcp", true)); ContainerConfig containerConfig = new ContainerConfig(containerName, staticVlan, ports, cFlowList); result.add((this.addRemoveContainer(containerConfig, false)).toString()); return result; }
public void _createContainer(CommandInterpreter ci) { String containerName = ci.nextArgument(); if (containerName == null) { ci.print("Container Name not specified"); return; } String staticVlan = ci.nextArgument(); if (staticVlan == null) { ci.print("Static Vlan not specified"); return; } List<String> ports = new ArrayList<String>(); for (long l = 1L; l < 10L; l++) { ports.add(NodeConnectorCreator.createOFNodeConnector((short) 1, NodeCreator.createOFNode(l)).toString()); } List<ContainerFlowConfig> cFlowList = new ArrayList<ContainerFlowConfig>(); cFlowList.add(this.createSampleContainerFlowConfig("tcp", true)); ContainerConfig containerConfig = new ContainerConfig(containerName, staticVlan, ports, cFlowList); ci.println(this.addRemoveContainer(containerConfig, false)); }
public void _addContainerEntry(CommandInterpreter ci) { String containerName = ci.nextArgument(); if (containerName == null) { ci.print("Container Name not specified"); return; } String nodeId = ci.nextArgument(); if (nodeId == null) { ci.print("Node Id not specified"); return; } String portId = ci.nextArgument(); if (portId == null) { ci.print("Port not specified"); return; } Node node = NodeCreator.createOFNode(Long.valueOf(nodeId)); Short port = Short.valueOf(portId); NodeConnector nc = NodeConnectorCreator.createOFNodeConnector(port, node); List<String> portList = new ArrayList<String>(1); portList.add(nc.toString()); ci.println(this.addRemoveContainerEntries(containerName, portList, false)); }
public List<NodeTableStatistics> getNodeTableStatsList() { if (this.ofStatsList != null && this.ntStatsList == null) { this.ntStatsList = new ArrayList<NodeTableStatistics>(); OFTableStatistics ofTableStat; Node node = NodeCreator.createOFNode(switchId); for (OFStatistics ofStat : this.ofStatsList) { ofTableStat = (OFTableStatistics) ofStat; NodeTableStatistics ntStat = new NodeTableStatistics(); ntStat.setNodeTable(TableConverter.toNodeTable( ofTableStat.getTableId(), node)); ntStat.setActiveCount(ofTableStat.getActiveCount()); ntStat.setLookupCount(ofTableStat.getLookupCount()); ntStat.setMatchedCount(ofTableStat.getMatchedCount()); this.ntStatsList.add(ntStat); } } log.trace("OFStatistics: {} NodeTableStatistics: {}", ofStatsList, ntStatsList); return this.ntStatsList; } }
protected void handlePortStatusMessage(ISwitch sw, OFPortStatus m) { Node node = NodeCreator.createOFNode(sw.getId()); NodeConnector nodeConnector = PortConverter.toNodeConnector( m.getDesc().getPortNumber(), node); // get node connector properties Set<Property> props = InventoryServiceHelper.OFPortToProps(m.getDesc()); UpdateType type = null; if (m.getReason() == (byte) OFPortReason.OFPPR_ADD.ordinal()) { type = UpdateType.ADDED; nodeConnectorProps.put(nodeConnector, props); } else if (m.getReason() == (byte) OFPortReason.OFPPR_DELETE.ordinal()) { type = UpdateType.REMOVED; nodeConnectorProps.remove(nodeConnector); } else if (m.getReason() == (byte) OFPortReason.OFPPR_MODIFY.ordinal()) { type = UpdateType.CHANGED; nodeConnectorProps.put(nodeConnector, props); } logger.trace("handlePortStatusMessage {} type {}", nodeConnector, type); if (type != null) { notifyInventoryShimListener(nodeConnector, type, props); } }
public List<NodeTableStatistics> getNodeTableStatsList() { if (this.ofStatsList != null && this.ntStatsList == null) { this.ntStatsList = new ArrayList<NodeTableStatistics>(); OFTableStatistics ofTableStat; Node node = NodeCreator.createOFNode(switchId); for (OFStatistics ofStat : this.ofStatsList) { ofTableStat = (OFTableStatistics) ofStat; NodeTableStatistics ntStat = new NodeTableStatistics(); ntStat.setNodeTable(TableConverter.toNodeTable( ofTableStat.getTableId(), node)); ntStat.setActiveCount(ofTableStat.getActiveCount()); ntStat.setLookupCount(ofTableStat.getLookupCount()); ntStat.setMatchedCount(ofTableStat.getMatchedCount()); ntStat.setMaximumEntries(ofTableStat.getMaximumEntries()); this.ntStatsList.add(ntStat); } } log.trace("OFStatistics: {} NodeTableStatistics: {}", ofStatsList, ntStatsList); return this.ntStatsList; } }