X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Ftopologymanager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ftopologymanager%2Finternal%2FTopologyManagerImpl.java;h=f9574b993ca709d769a48562f5f03cd5ea5e72aa;hb=ff1b4a79cca00743a00c3b0b1100bd0ab2b2fb31;hp=e8d0d416e5dd6dd4764a2b7e7e19bc73ca4fdd1c;hpb=fbfab4661220d56543ceabbcba5a40b335be1e07;p=controller.git diff --git a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java index e8d0d416e5..f9574b993c 100644 --- a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java +++ b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java @@ -66,16 +66,17 @@ import org.slf4j.LoggerFactory; * topology database and notifies all the listeners of topology changes. */ public class TopologyManagerImpl implements ITopologyManager, - IConfigurationContainerAware, IListenTopoUpdates, IObjectReader, - CommandProvider { +IConfigurationContainerAware, IListenTopoUpdates, IObjectReader, +CommandProvider { private static final Logger log = LoggerFactory .getLogger(TopologyManagerImpl.class); private ITopologyService topoService = null; private IClusterContainerServices clusterContainerService = null; // DB of all the Edges with properties which constitute our topology private ConcurrentMap> edgesDB = null; - // DB of all NodeConnector which are part of Edges, meaning they - // are connected to another NodeConnector on the other side + // DB of all NodeConnector which are part of ISL Edges, meaning they + // are connected to another NodeConnector on the other side of an ISL link. + // NodeConnector of a Production Edge is not part of this DB. private ConcurrentMap> nodeConnectorsDB = null; // DB of all the NodeConnectors with an Host attached to it private ConcurrentMap>> hostsDB = null; @@ -135,7 +136,7 @@ public class TopologyManagerImpl implements ITopologyManager, /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ void init(Component c) { String containerName = null; @@ -203,7 +204,7 @@ public class TopologyManagerImpl implements ITopologyManager, /** * Function called after the topology manager has registered the service in * OSGi service registry. - * + * */ void started() { // SollicitRefresh MUST be called here else if called at init @@ -216,7 +217,7 @@ public class TopologyManagerImpl implements ITopologyManager, * Function called by the dependency manager when at least one dependency * become unsatisfied or when the component is shutting down because for * example bundle is being stopped. - * + * */ void destroy() { if (this.clusterContainerService == null) { @@ -231,7 +232,7 @@ public class TopologyManagerImpl implements ITopologyManager, this.clusterContainerService.destroyCache("topologymanager.hostsDB"); this.hostsDB = null; this.clusterContainerService - .destroyCache("topologymanager.nodeConnectorDB"); + .destroyCache("topologymanager.nodeConnectorDB"); this.nodeConnectorsDB = null; log.debug("Topology Manager DB Deallocated"); } @@ -256,7 +257,7 @@ public class TopologyManagerImpl implements ITopologyManager, // Publish the save config event to the cluster nodes /** * Get the CLUSTERING SERVICES WORKING BEFORE TRYING THIS - * + * * configSaveEvent.put(new Date().getTime(), SAVE); */ return saveConfigInternal(); @@ -324,10 +325,35 @@ public class TopologyManagerImpl implements ITopologyManager, return (this.nodeConnectorsDB.get(p) != null); } + /** + * This method returns true if the edge is an ISL link. + * + * @param e + * The edge + * @return true if it is an ISL link + */ + public boolean isISLink(Edge e) { + return (!isProductionLink(e)); + } + + /** + * This method returns true if the edge is a production link. + * + * @param e + * The edge + * @return true if it is a production link + */ + public boolean isProductionLink(Edge e) { + return (e.getHeadNodeConnector().getType() + .equals(NodeConnector.NodeConnectorIDType.PRODUCTION) || e + .getTailNodeConnector().getType() + .equals(NodeConnector.NodeConnectorIDType.PRODUCTION)); + } + /** * The Map returned is a copy of the current topology hence if the topology * changes the copy doesn't - * + * * @return A Map representing the current topology expressed as edges of the * network */ @@ -469,12 +495,15 @@ public class TopologyManagerImpl implements ITopologyManager, this.edgesDB.put(e, props); // Now populate the DB of NodeConnectors - // NOTE WELL: properties are empy sets, not really needed + // NOTE WELL: properties are empty sets, not really needed // for now. - this.nodeConnectorsDB.put(e.getHeadNodeConnector(), - new HashSet()); - this.nodeConnectorsDB.put(e.getTailNodeConnector(), - new HashSet()); + // The DB only contains ISL ports + if (isISLink(e)) { + this.nodeConnectorsDB.put(e.getHeadNodeConnector(), + new HashSet()); + this.nodeConnectorsDB.put(e.getTailNodeConnector(), + new HashSet()); + } log.trace("Edge {} {}", e.toString(), type.name()); break; case REMOVED: @@ -567,82 +596,21 @@ public class TopologyManagerImpl implements ITopologyManager, private Edge getReverseLinkTuple(TopologyUserLinkConfig link) { TopologyUserLinkConfig rLink = new TopologyUserLinkConfig( - link.getName(), link.getDstNodeIDType(), link.getDstSwitchId(), - link.getDstNodeConnectorIDType(), link.getDstPort(), - link.getSrcNodeIDType(), link.getSrcSwitchId(), - link.getSrcNodeConnectorIDType(), link.getSrcPort()); + link.getName(), link.getDstNodeConnector(), link.getSrcNodeConnector()); return getLinkTuple(rLink); } + private Edge getLinkTuple(TopologyUserLinkConfig link) { Edge linkTuple = null; - - // if atleast 1 link exists for the srcPort and atleast 1 link exists - // for the dstPort - // that makes it ineligible for the Manual link addition - // This is just an extra protection to avoid mis-programming. - boolean srcLinkExists = false; - boolean dstLinkExists = false; - // TODO check a way to validate the port with inventory services - // if (srcSw.getPorts().contains(srcPort) && - // dstSw.getPorts().contains(srcPort) && - if (!srcLinkExists && !dstLinkExists) { - Node sNode = null; - Node dNode = null; - NodeConnector sPort = null; - NodeConnector dPort = null; - linkTuple = null; - String srcNodeIDType = link.getSrcNodeIDType(); - String srcNodeConnectorIDType = link.getSrcNodeConnectorIDType(); - String dstNodeIDType = link.getDstNodeIDType(); - String dstNodeConnectorIDType = link.getDstNodeConnectorIDType(); - try { - if (srcNodeIDType.equals(NodeIDType.OPENFLOW)) { - sNode = new Node(srcNodeIDType, link.getSrcSwitchIDLong()); - } else { - sNode = new Node(srcNodeIDType, link.getSrcSwitchId()); - } - - if (dstNodeIDType.equals(NodeIDType.OPENFLOW)) { - dNode = new Node(dstNodeIDType, link.getDstSwitchIDLong()); - } else { - dNode = new Node(dstNodeIDType, link.getDstSwitchId()); - } - - if (srcNodeConnectorIDType.equals(NodeConnectorIDType.OPENFLOW)) { - Short srcPort = Short.valueOf((short) 0); - if (!link.isSrcPortByName()) { - srcPort = Short.parseShort(link.getSrcPort()); - } - sPort = new NodeConnector(srcNodeConnectorIDType, srcPort, - sNode); - } else { - sPort = new NodeConnector(srcNodeConnectorIDType, - link.getSrcPort(), sNode); - } - - if (dstNodeConnectorIDType.equals(NodeConnectorIDType.OPENFLOW)) { - Short dstPort = Short.valueOf((short) 0); - if (!link.isDstPortByName()) { - dstPort = Short.parseShort(link.getDstPort()); - } - dPort = new NodeConnector(dstNodeConnectorIDType, dstPort, - dNode); - } else { - dPort = new NodeConnector(dstNodeConnectorIDType, - link.getDstPort(), dNode); - } - linkTuple = new Edge(sPort, dPort); - } catch (ConstructionException cex) { - log.warn("Caught exception ", cex); - } - return linkTuple; - } - - if (srcLinkExists && dstLinkExists) { - link.setStatus(TopologyUserLinkConfig.STATUS.INCORRECT); + NodeConnector srcNodeConnector = NodeConnector.fromString(link.getSrcNodeConnector()); + NodeConnector dstNodeConnector = NodeConnector.fromString(link.getDstNodeConnector()); + if (srcNodeConnector == null || dstNodeConnector == null) return null; + try { + linkTuple = new Edge(srcNodeConnector, dstNodeConnector); + } catch (Exception e) { } - return null; + return linkTuple; } @Override @@ -670,13 +638,16 @@ public class TopologyManagerImpl implements ITopologyManager, Edge linkTuple = getLinkTuple(link); if (linkTuple != null) { - try { - linkTuple = getReverseLinkTuple(link); + if (!isProductionLink(linkTuple)) { + edgeUpdate(linkTuple, UpdateType.ADDED, new HashSet()); + } + + linkTuple = getReverseLinkTuple(link); + if (linkTuple != null) { link.setStatus(TopologyUserLinkConfig.STATUS.SUCCESS); - } catch (Exception e) { - return new Status(StatusCode.INTERNALERROR, - "Exception while adding custom link : " - + e.getMessage()); + if (!isProductionLink(linkTuple)) { + edgeUpdate(linkTuple, UpdateType.ADDED, new HashSet()); + } } } return new Status(StatusCode.SUCCESS, null); @@ -694,20 +665,13 @@ public class TopologyManagerImpl implements ITopologyManager, Edge linkTuple = getLinkTuple(link); userLinks.remove(linkName); if (linkTuple != null) { - try { - // oneTopology.deleteUserConfiguredLink(linkTuple); - } catch (Exception e) { - log.warn( - "Harmless : Exception while Deleting User Configured link {} {}", - link, e.toString()); + if (!isProductionLink(linkTuple)) { + edgeUpdate(linkTuple, UpdateType.REMOVED, null); } + linkTuple = getReverseLinkTuple(link); - try { - // oneTopology.deleteUserConfiguredLink(linkTuple); - } catch (Exception e) { - log.warn( - "Harmless : Exception while Deleting User Configured Reverse link {} {}", - link, e.toString()); + if ((linkTuple != null) && !isProductionLink(linkTuple)) { + edgeUpdate(linkTuple, UpdateType.REMOVED, null); } } return new Status(StatusCode.SUCCESS, null); @@ -724,14 +688,14 @@ public class TopologyManagerImpl implements ITopologyManager, public String getHelp() { StringBuffer help = new StringBuffer(); help.append("---Topology Manager---\n"); - help.append("\t addTopo name \n"); - help.append("\t delTopo name\n"); - help.append("\t printTopo\n"); + help.append("\t addUserLink \n"); + help.append("\t deleteUserLink \n"); + help.append("\t printUserLink\n"); help.append("\t printNodeEdges\n"); return help.toString(); } - public void _printTopo(CommandInterpreter ci) { + public void _printUserLink(CommandInterpreter ci) { for (String name : this.userLinks.keySet()) { TopologyUserLinkConfig linkConfig = userLinks.get(name); ci.println("Name : " + name); @@ -741,67 +705,40 @@ public class TopologyManagerImpl implements ITopologyManager, } } - public void _addTopo(CommandInterpreter ci) { + public void _addUserLink(CommandInterpreter ci) { String name = ci.nextArgument(); if ((name == null)) { ci.println("Please enter a valid Name"); return; } - String srcNodeIDType = ci.nextArgument(); - if (srcNodeIDType == null) { - ci.println("Null source node ID Type. Example: OF or PR"); + String ncStr1 = ci.nextArgument(); + if (ncStr1 == null) { + ci.println("Please enter two node connector strings"); return; } - - String dpid = ci.nextArgument(); - if (dpid == null) { - ci.println("Null source node id"); + String ncStr2 = ci.nextArgument(); + if (ncStr2 == null) { + ci.println("Please enter second node connector string"); return; } - String srcNodeConnectorIDType = ci.nextArgument(); - if (srcNodeConnectorIDType == null) { - ci.println("Null source node connector ID Type. Example: OF or PR"); + NodeConnector nc1 = NodeConnector.fromString(ncStr1); + if (nc1 == null) { + ci.println("Invalid input node connector 1 string: " + ncStr1); return; } - - String port = ci.nextArgument(); - if (port == null) { - ci.println("Null source port number"); + NodeConnector nc2 = NodeConnector.fromString(ncStr2); + if (nc2 == null) { + ci.println("Invalid input node connector 2 string: " + ncStr2); return; } - String dstNodeIDType = ci.nextArgument(); - if (dstNodeIDType == null) { - ci.println("Null destination node ID Type. Example: OF or PR"); - return; - } - - String ddpid = ci.nextArgument(); - if (ddpid == null) { - ci.println("Null destination node ID"); - return; - } - - String dstNodeConnectorIDType = ci.nextArgument(); - if (dstNodeConnectorIDType == null) { - ci.println("Null destination node connector ID Type. Example: OF or PR"); - return; - } - - String dport = ci.nextArgument(); - if (dport == null) { - ci.println("Null destination port number"); - return; - } - TopologyUserLinkConfig config = new TopologyUserLinkConfig(name, - srcNodeIDType, dpid, srcNodeConnectorIDType, port, - dstNodeIDType, ddpid, dstNodeConnectorIDType, dport); + TopologyUserLinkConfig config = new TopologyUserLinkConfig(name, ncStr1, ncStr2); ci.println(this.addUserLink(config)); } - public void _delTopo(CommandInterpreter ci) { + public void _deleteUserLink(CommandInterpreter ci) { String name = ci.nextArgument(); if ((name == null)) { ci.println("Please enter a valid Name");