Fixed EVC create 02/29402/1
authorGabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Fri, 6 Nov 2015 23:59:19 +0000 (18:59 -0500)
committerGabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Sat, 7 Nov 2015 00:42:31 +0000 (19:42 -0500)
Change-Id: I267a4508d3fc5966fad4bb114cdc8f7f7425f582
Signed-off-by: Gabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
impl/src/main/java/org/opendaylight/unimgr/command/EvcCreateCommand.java
impl/src/main/java/org/opendaylight/unimgr/command/EvcDeleteCommand.java
impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java
impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java
impl/src/main/java/org/opendaylight/unimgr/command/UniUpdateCommand.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrDataChangeListener.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java

index 295f338f1ad29e3fb07288374a64cf4544ef4df4..c5bf7ea5192b83160b66054ce98cd5c4615aa53a 100644 (file)
@@ -35,13 +35,12 @@ public class EvcCreateCommand extends AbstractCreateCommand {
         super.changes = changes;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public void execute() {
         for (Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
             if (created.getValue() != null && created.getValue() instanceof EvcAugmentation) {
                 EvcAugmentation evc = (EvcAugmentation) created.getValue();
-                LOG.info("New EVC created, source IP: {} destination IP {}.",
+                LOG.trace("New EVC created, source IP: {} destination IP {}.",
                         evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
                         evc.getUniDest().iterator().next().getIpAddress().getIpv4Address());
                 // For now, we assume that there is 1 uni per source/destination
@@ -56,17 +55,19 @@ public class EvcCreateCommand extends AbstractCreateCommand {
                 InstanceIdentifier<Node> sourceUniIid;
                 InstanceIdentifier<Node> destinationUniIid;
                 if (evc.getUniSource().iterator().next().getUni() != null) {
-                    sourceUniIid = (InstanceIdentifier<Node>) evc.getUniSource().iterator().next().getUni();
+                    sourceUniIid = evc.getUniSource().iterator().next().getUni().firstIdentifierOf(Node.class);
                 } else {
-                    sourceUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniSource().iterator().next().getIpAddress());
+                    sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
+                                                          evc.getUniSource().iterator().next().getIpAddress(),
+                                                          LogicalDatastoreType.OPERATIONAL);
                 }
                 if (evc.getUniDest().iterator().next().getUni() != null) {
-                    destinationUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniDest().iterator().next().getIpAddress());;
+                    destinationUniIid = evc.getUniDest().iterator().next().getUni().firstIdentifierOf(Node.class);
                 } else {
-                    destinationUniIid = (InstanceIdentifier<Node>) evc.getUniDest().iterator().next().getUni();
+                    destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
+                                                               evc.getUniDest().iterator().next().getIpAddress(),
+                                                               LogicalDatastoreType.OPERATIONAL);
                 }
-                // The user has specified the instance identifier of the
-                // uni source and uni destination
                 Optional<Node> optionalUniSource = UnimgrUtils.readNode(dataBroker,
                                                                         LogicalDatastoreType.CONFIGURATION,
                                                                         sourceUniIid);
@@ -76,56 +77,73 @@ public class EvcCreateCommand extends AbstractCreateCommand {
                 Node uniSource;
                 Node uniDestination;
                 // Retrieve the source and destination Unis
-                if (!optionalUniSource.isPresent() || !optionalUniDestination.isPresent()) {
-                    LOG.info("Unable to retrieve the Source and/or Destination Unis.");
-                    break;
-                } else {
+                if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
                     uniSource = optionalUniSource.get();
                     uniDestination = optionalUniDestination.get();
-                }
-                // Set source and destination
-                InstanceIdentifier<Node> sourceBridgeIid =
-                        UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(),
-                                                           UnimgrConstants.DEFAULT_BRIDGE_NAME);
-                Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
-                                                                       LogicalDatastoreType.CONFIGURATION,
-                                                                       sourceBridgeIid);
-                InstanceIdentifier<Node> destinationBridgeIid =
-                        UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(),
-                                                           UnimgrConstants.DEFAULT_BRIDGE_NAME);
-                Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
-                                                                            LogicalDatastoreType.CONFIGURATION,
-                                                                            destinationBridgeIid);
-                if (!optionalSourceBr.isPresent() || !optionalDestinationBr.isPresent()) {
-                    LOG.info("Unable to retrieve the source and/or destination bridge.");
-                    break;
+                    // Set source and destination
+                    UniAugmentation sourceUniAugmentation =
+                                        uniSource.getAugmentation(UniAugmentation.class);
+                    UniAugmentation destinationUniAugmentation =
+                                        uniDestination.getAugmentation(UniAugmentation.class);
+                    Optional<Node> optionalSourceOvsdbNode =
+                                       UnimgrUtils.readNode(dataBroker,
+                                                            LogicalDatastoreType.OPERATIONAL,
+                                                            sourceUniAugmentation
+                                                                .getOvsdbNodeRef()
+                                                                .getValue());
+                    Optional<Node> optionalDestinationOvsdbNode =
+                                       UnimgrUtils.readNode(dataBroker,
+                                                            LogicalDatastoreType.OPERATIONAL,
+                                                            destinationUniAugmentation
+                                                                .getOvsdbNodeRef()
+                                                                .getValue());
+                    if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
+                        InstanceIdentifier<Node> sourceBridgeIid =
+                                UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
+                        Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
+                                                                               LogicalDatastoreType.OPERATIONAL,
+                                                                               sourceBridgeIid);
+                        InstanceIdentifier<Node> destinationBridgeIid =
+                                UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
+                        Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
+                                                                                    LogicalDatastoreType.OPERATIONAL,
+                                                                                    destinationBridgeIid);
+                        Node sourceBr;
+                        Node destinationBr;
+                        if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
+                            sourceBr = optionalSourceBr.get();
+                            destinationBr = optionalDestinationBr.get();
+                            UnimgrUtils.createTerminationPointNode(dataBroker,
+                                                                   uniSource.getAugmentation(UniAugmentation.class),
+                                                                   sourceBr,
+                                                                   UnimgrConstants.DEFAULT_BRIDGE_NAME,
+                                                                   UnimgrConstants.DEFAULT_TUNNEL_IFACE,
+                                                                   UnimgrConstants.DEFAULT_GRE_NAME);
+                            UnimgrUtils.createGreTunnel(dataBroker,
+                                                        uniSource.getAugmentation(UniAugmentation.class),
+                                                        uniDestination.getAugmentation(UniAugmentation.class),
+                                                        sourceBr,
+                                                        UnimgrConstants.DEFAULT_BRIDGE_NAME,
+                                                        "gre0");
+                            UnimgrUtils.createTerminationPointNode(dataBroker, 
+                                                                   uniSource.getAugmentation(UniAugmentation.class),
+                                                                   destinationBr,
+                                                                   UnimgrConstants.DEFAULT_BRIDGE_NAME,
+                                                                   UnimgrConstants.DEFAULT_TUNNEL_IFACE,
+                                                                   UnimgrConstants.DEFAULT_GRE_NAME);
+                            UnimgrUtils.createGreTunnel(dataBroker,
+                                                        uniDestination.getAugmentation(UniAugmentation.class),
+                                                        uniSource.getAugmentation(UniAugmentation.class), destinationBr,
+                                                        UnimgrConstants.DEFAULT_BRIDGE_NAME,
+                                                        "gre0");
+                        } else {
+                            LOG.info("Unable to retrieve the source and/or destination bridge.");
+                        }
+                    } else {
+                        LOG.info("Uname to retrieve the source and/or destination ovsdbNode.");
+                    }
                 } else {
-                    Node sourceBr = optionalSourceBr.get();
-                    Node destinationBr = optionalDestinationBr.get();
-                    UnimgrUtils.createTerminationPointNode(dataBroker,
-                                                           uniSource.getAugmentation(UniAugmentation.class),
-                                                           sourceBr,
-                                                           UnimgrConstants.DEFAULT_BRIDGE_NAME,
-                                                           UnimgrConstants.DEFAULT_TUNNEL_IFACE,
-                                                           UnimgrConstants.DEFAULT_GRE_NAME);
-                    UnimgrUtils.createGreTunnel(dataBroker,
-                                                uniSource.getAugmentation(UniAugmentation.class),
-                                                uniDestination.getAugmentation(UniAugmentation.class),
-                                                sourceBr,
-                                                UnimgrConstants.DEFAULT_BRIDGE_NAME,
-                                                "gre0");
-                    UnimgrUtils.createTerminationPointNode(dataBroker,
-                                                           uniSource.getAugmentation(UniAugmentation.class),
-                                                           destinationBr,
-                                                           UnimgrConstants.DEFAULT_BRIDGE_NAME,
-                                                           UnimgrConstants.DEFAULT_TUNNEL_IFACE,
-                                                           UnimgrConstants.DEFAULT_GRE_NAME);
-                    UnimgrUtils.createGreTunnel(dataBroker,
-                                                uniDestination.getAugmentation(UniAugmentation.class),
-                                                uniSource.getAugmentation(UniAugmentation.class),
-                                                destinationBr,
-                                                UnimgrConstants.DEFAULT_BRIDGE_NAME,
-                                                "gre0");
+                    LOG.info("Unable to retrieve the source and/or destination Uni.");
                 }
             }
         }
index c02449e6ba27b8b672574cd02be846fb3f3a7428..3a862e3e04bf755b7eef75d285db4e0d25855983 100644 (file)
@@ -48,13 +48,13 @@ public class EvcDeleteCommand extends AbstractDeleteCommand {
     @Override
     public void execute() {
         Map<InstanceIdentifier<Evc>, Evc> originalEvcs = UnimgrUtils.extractOriginal(changes, Evc.class);
-        Set<InstanceIdentifier<Evc>> removedEvcs = UnimgrUtils.extractRemoved(changes, Evc.class);
+        //Set<InstanceIdentifier<Evc>> removedEvcs = UnimgrUtils.extractRemoved(changes, Evc.class);
 
         Set<InstanceIdentifier<?>> removedPaths = changes.getRemovedPaths();
         if (!removedPaths.isEmpty()) {
             for (InstanceIdentifier<?> removedPath: removedPaths) {
                 Class<?> type = removedPath.getTargetType();
-                LOG.info("Removed paths instance identifier {}", type);
+                LOG.trace("Removed paths instance identifier {}", type);
                 if (type.equals(Evc.class)) {
                     LOG.info("Removed paths instance identifier {}", type);
                     for (Entry<InstanceIdentifier<Evc>, Evc> evc: originalEvcs.entrySet()) {
@@ -63,20 +63,32 @@ public class EvcDeleteCommand extends AbstractDeleteCommand {
                             List<UniSource> uniSourceLst = data.getUniSource();
                             for (UniSource uniSource : uniSourceLst) {
                                 InstanceIdentifier<?> iidUni = uniSource.getUni();
-                                Node ovsdbNd = getUniOvsdbNode(iidUni);
-                                List<TerminationPoint> termPointList = ovsdbNd.getTerminationPoint();
-                                for(TerminationPoint termPoint : termPointList) {
-                                    deleteTerminationPoint(termPoint, ovsdbNd);
+                                Optional<Node> optionalOvsdbNode =
+                                                   UnimgrUtils.readNode(dataBroker,
+                                                   LogicalDatastoreType.OPERATIONAL,
+                                                   iidUni);
+                                if (optionalOvsdbNode.isPresent()) {
+                                    Node ovsdbNode = optionalOvsdbNode.get();
+                                    List<TerminationPoint> termPointList = ovsdbNode.getTerminationPoint();
+                                    for(TerminationPoint termPoint : termPointList) {
+                                        deleteTerminationPoint(termPoint, ovsdbNode);
+                                    }
                                 }
                             }
                             LOG.info("Removed EVC Source {}", data.getUniSource());
                             List<UniDest> uniDestLst = data.getUniDest();
                             for (UniDest uniDest : uniDestLst) {
                                 InstanceIdentifier<?> iidUni = uniDest.getUni();
-                                Node ovsdbNd = getUniOvsdbNode(iidUni);
-                                List<TerminationPoint> termPointList = ovsdbNd.getTerminationPoint();
-                                for(TerminationPoint termPoint : termPointList) {
-                                    deleteTerminationPoint(termPoint, ovsdbNd);
+                                Optional<Node> optionalOvsdbNode =
+                                                   UnimgrUtils.readNode(dataBroker,
+                                                           LogicalDatastoreType.OPERATIONAL,
+                                                           iidUni);
+                                if (optionalOvsdbNode.isPresent()) {
+                                    Node ovsdbNode = optionalOvsdbNode.get();
+                                    List<TerminationPoint> termPointList = ovsdbNode.getTerminationPoint();
+                                    for(TerminationPoint termPoint : termPointList) {
+                                        deleteTerminationPoint(termPoint, ovsdbNode);
+                                    }
                                 }
                             }
                             LOG.info("Removed EVC Destination {}", data.getUniDest());
@@ -87,14 +99,6 @@ public class EvcDeleteCommand extends AbstractDeleteCommand {
         }
     }
 
-    private Node getUniOvsdbNode(InstanceIdentifier<?> iidUni) {
-        Optional<Node> nodeOpt = UnimgrUtils.readNode(dataBroker, iidUni);
-        if (nodeOpt.isPresent()) {
-            return  nodeOpt.get();
-        }
-        return null;
-    }
-
     private boolean deleteTerminationPoint(TerminationPoint termPoint, Node ovsdbNode) {
         boolean result = false;
         InstanceIdentifier<TerminationPoint> terminationPointPath = InstanceIdentifier
index b41975c78df68ade59b53e2a9cf51c618d15c3ff..0ffa5d4b5687564245dcf178b211b53f44460dea 100644 (file)
@@ -43,7 +43,7 @@ public class UniCreateCommand extends AbstractCreateCommand {
             if (created.getValue() != null && created.getValue() instanceof UniAugmentation) {
                 UniAugmentation uni = (UniAugmentation) created.getValue();
                 InstanceIdentifier<?> uniKey = created.getKey();
-                LOG.info("New UNI created {}.", uni.getIpAddress().getIpv4Address());
+                LOG.trace("New UNI created {}.", uni.getIpAddress().getIpv4Address());
                 /* We assume that when the user specifies the
                  * ovsdb-node-ref that the node already exists in
                  * the controller and that the OVS instance is in
index 6522c56276b5cf5679af06ebe4bd043ae298b1c5..9d06ba27efaea441b24f841e943f4fddf9877f1e 100644 (file)
@@ -14,7 +14,6 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.unimgr.impl.UnimgrConstants;
 import org.opendaylight.unimgr.impl.UnimgrMapper;
 import org.opendaylight.unimgr.impl.UnimgrUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
@@ -46,17 +45,17 @@ public class UniDeleteCommand extends AbstractDeleteCommand {
             for (InstanceIdentifier<UniAugmentation> removedUniIid: removedUnis) {
                 UniAugmentation uniAug = UnimgrUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, removedUniIid);
                 if(uniAug != null){
-                    LOG.info("Uni Augmentation present.");
-                    OvsdbNodeRef ovsNdRef = uniAug.getOvsdbNodeRef();
-                    InstanceIdentifier<Node> iidNode = (InstanceIdentifier<Node>) ovsNdRef.getValue();
-                    Optional<Node> optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, iidNode);
+                    LOG.trace("Uni Augmentation present.");
+                    OvsdbNodeRef ovsdbNodeRef = uniAug.getOvsdbNodeRef();
+                    InstanceIdentifier<Node> ovsdbIid = ovsdbNodeRef.getValue().firstIdentifierOf(Node.class);
+                    Optional<Node> optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, ovsdbIid);
                     if (optNode.isPresent()) {
                         Node ovsdbNode = optNode.get();
-                        InstanceIdentifier<Node> iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(), UnimgrConstants.DEFAULT_BRIDGE_NAME);
+                        InstanceIdentifier<Node> iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode);
                         deleteNode(iidBridgeNode);
                         LOG.info("Received a request to remove a UNI BridgeNode ", iidBridgeNode);
                     }
-                    deleteNode(iidNode);
+                    deleteNode(ovsdbIid);
                     LOG.info("Received a request to remove an UNI ", removedUniIid);
                 }
             }
@@ -68,7 +67,7 @@ public class UniDeleteCommand extends AbstractDeleteCommand {
                 Optional<Node> optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, iidNode);
                 if (optNode.isPresent()) {
                     Node ovsdbNode = optNode.get();
-                    InstanceIdentifier<Node> iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(), UnimgrConstants.DEFAULT_BRIDGE_NAME);
+                    InstanceIdentifier<Node> iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode);
                     deleteNode(iidBridgeNode);
                     LOG.info("Received a request to remove a BridgeNode ", iidBridgeNode);
                 }
index 351a93074f62a309a1bda4b213c6ab5baf27e0e9..607625019b0ac767279445a7d2274bd540e146fa 100644 (file)
@@ -38,13 +38,13 @@ public class UniUpdateCommand extends AbstractUpdateCommand {
                 OvsdbNodeAugmentation ovsdbNodeAugmentation = (OvsdbNodeAugmentation) created
                         .getValue();
                 if (ovsdbNodeAugmentation != null) {
-                    LOG.info("Received an OVSDB node create {}",
+                    LOG.trace("Received an OVSDB node create {}",
                             ovsdbNodeAugmentation.getConnectionInfo()
                                     .getRemoteIp().getIpv4Address().getValue());
                     final List<ManagedNodeEntry> managedNodeEntries = ovsdbNodeAugmentation.getManagedNodeEntry();
                     if (managedNodeEntries != null) {
                         for (ManagedNodeEntry managedNodeEntry : managedNodeEntries) {
-                            LOG.info("Received an update from an OVSDB node {}.", managedNodeEntry.getKey());
+                            LOG.trace("Received an update from an OVSDB node {}.", managedNodeEntry.getKey());
                             // We received a node update from the southbound plugin
                             // so we have to check if it belongs to the UNI
                         }
index 9441ed8f72c30f517b7d0bd1037bcfcf6ead17b2..299b3cdc6c8c698d096b032d8eb5e7e927d05586 100644 (file)
@@ -71,8 +71,10 @@ public class UnimgrDataChangeListener  implements IUnimgrDataChangeListener {
                        DataObject> changes) {
         if (changes != null) {
             List<Command> commands = new ArrayList<Command>();
-            commands.add(new UniCreateCommand(dataBroker, changes));
-            commands.add(new EvcCreateCommand(dataBroker, changes));
+            Command uniCreate = new UniCreateCommand(dataBroker, changes);
+            Command evcCreate = new EvcCreateCommand(dataBroker, changes);
+            commands.add(uniCreate);
+            commands.add(evcCreate);
             invoker.setCommands(commands);
             invoker.invoke();
         }
@@ -83,8 +85,10 @@ public class UnimgrDataChangeListener  implements IUnimgrDataChangeListener {
                        DataObject> changes) {
         if (changes != null) {
             List<Command> commands = new ArrayList<Command>();
-            commands.add(new UniUpdateCommand(dataBroker, changes));
-            commands.add(new EvcUpdateCommand(dataBroker, changes));
+            Command uniUpdate = new UniUpdateCommand(dataBroker, changes);
+            Command evcUpdate = new EvcUpdateCommand(dataBroker, changes);
+            commands.add(uniUpdate);
+            commands.add(evcUpdate);
             invoker.setCommands(commands);
             invoker.invoke();
         }
@@ -95,8 +99,10 @@ public class UnimgrDataChangeListener  implements IUnimgrDataChangeListener {
                        DataObject> changes) {
         if (changes != null) {
             List<Command> commands = new ArrayList<Command>();
-            commands.add(new UniDeleteCommand(dataBroker, changes));
-            commands.add(new EvcDeleteCommand(dataBroker, changes));
+            Command uniDelete = new UniDeleteCommand(dataBroker, changes);
+            Command evcDelete = new EvcDeleteCommand(dataBroker, changes);
+            commands.add(uniDelete);
+            commands.add(evcDelete);
             invoker.setCommands(commands);
             invoker.invoke();
         }
index 5223f1ab28efd0fbad83f0b6108f76c85db9be79..dc94694f48c6b539ab62a9198d035794239cc7be 100755 (executable)
@@ -12,6 +12,7 @@ import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -29,7 +30,21 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class UnimgrMapper {
 
-    public static InstanceIdentifier<Link> getEvcLinkIID(LinkId id) {
+    public static InstanceIdentifier<Node> createOvsdbBridgeNodeIid(Node ovsdbNode,
+                                                                    String bridgeName) {
+        String bridgeNodeName = ovsdbNode.getNodeId().getValue()
+                            + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
+                            + bridgeName;
+        NodeId bridgeNodeId = new NodeId(bridgeNodeName);
+        InstanceIdentifier<Node> bridgeNodePath = InstanceIdentifier
+                                                      .create(NetworkTopology.class)
+                                                      .child(Topology.class,
+                                                              new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+                                                      .child(Node.class, new NodeKey(bridgeNodeId));
+        return bridgeNodePath;
+    }
+
+    public static InstanceIdentifier<Link> getEvcLinkIid(LinkId id) {
         InstanceIdentifier<Link> linkPath = InstanceIdentifier
                                                 .create(NetworkTopology.class)
                                                 .child(Topology.class,
@@ -56,18 +71,15 @@ public class UnimgrMapper {
         return nodePath;
     }
 
-    public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(NodeId ovsdbNode,
-                                                                 String bridgeName) {
-        String ovsdbNodeId = ovsdbNode.getValue();
-        NodeId bridgeNodeId = new NodeId(ovsdbNodeId
-                                       + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
-                                       + bridgeName);
-        InstanceIdentifier<Node> nodePath = InstanceIdentifier
-                                                .create(NetworkTopology.class)
-                                                .child(Topology.class,
-                                                        new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
-                                                .child(Node.class,
-                                                        new NodeKey(bridgeNodeId));
+    public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(Node ovsdbNode) {
+        OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+        InstanceIdentifier<Node> nodePath = ovsdbNodeAugmentation
+                                                .getManagedNodeEntry()
+                                                .iterator()
+                                                .next()
+                                                .getBridgeRef()
+                                                .getValue()
+                                                .firstIdentifierOf(Node.class);
         return nodePath;
     }
 
index 78f3efbbea6715a9ed874c564564b6f7b648944f..09c49a26cce415448dab14d0d7843c94030f74f1 100644 (file)
@@ -77,52 +77,16 @@ public class UnimgrUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(UnimgrUtils.class);
 
-    @Deprecated
-    public static void createBridgeNode(DataBroker dataBroker,
-                                        NodeId ovsdbNodeId,
-                                        Uni uni,
-                                        String bridgeName) {
-        LOG.info("Creating a bridge on node {}", ovsdbNodeId);
-        InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper
-                                                    .getOvsdbNodeIid(uni.getIpAddress());
-        ConnectionInfo connectionInfo = UnimgrUtils.getConnectionInfo(dataBroker, ovsdbNodeId);
-        if (connectionInfo != null) {
-            NodeBuilder bridgeNodeBuilder = new NodeBuilder();
-            InstanceIdentifier<Node> bridgeIid = UnimgrMapper
-                                                    .getOvsdbBridgeNodeIid(ovsdbNodeId, bridgeName);
-            NodeId bridgeNodeId = new NodeId(ovsdbNodeId
-                                             + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
-                                             + bridgeName);
-            bridgeNodeBuilder.setNodeId(bridgeNodeId);
-            OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
-            ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
-            ovsdbBridgeAugmentationBuilder.setProtocolEntry(UnimgrUtils
-                                                                .createMdsalProtocols());
-            OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
-            ovsdbBridgeAugmentationBuilder.setManagedBy(ovsdbNodeRef);
-            bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class,
-                                              ovsdbBridgeAugmentationBuilder.build());
-            WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-            transaction.put(LogicalDatastoreType.CONFIGURATION,
-                            bridgeIid,
-                            bridgeNodeBuilder.build());
-            transaction.submit();
-        } else {
-            LOG.error("The OVSDB node is not connected {}", ovsdbNodeId);
-        }
-    }
-
     public static void createBridgeNode(DataBroker dataBroker,
                                         Node ovsdbNode,
                                         UniAugmentation uni,
                                         String bridgeName) {
-        LOG.info("Creating a bridge on node {}", ovsdbNode.getNodeId());
-        @SuppressWarnings("unchecked")
-        InstanceIdentifier<Node> ovsdbNodeIid = (InstanceIdentifier<Node>) uni.getOvsdbNodeRef().getValue();
+        LOG.info("Creating a bridge on node {}", ovsdbNode.getNodeId().getValue());
+        InstanceIdentifier<Node> ovsdbNodeIid = uni.getOvsdbNodeRef().getValue().firstIdentifierOf(Node.class);
         if (ovsdbNodeIid != null) {
             NodeBuilder bridgeNodeBuilder = new NodeBuilder();
-            InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(),
-                                                                                    bridgeName);
+            InstanceIdentifier<Node> bridgeIid = UnimgrMapper.createOvsdbBridgeNodeIid(ovsdbNode,
+                                                                                       bridgeName);
             NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId()
                                            + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
                                            + bridgeName);
@@ -153,8 +117,8 @@ public class UnimgrUtils {
                                                                     ovsdbNodeIid);
             if (optionalOvsdbNode.isPresent()) {
                 Node ovsdbNode = optionalOvsdbNode.get();
-                InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(),
-                                                                                        bridgeName);
+                InstanceIdentifier<Node> bridgeIid = UnimgrMapper.createOvsdbBridgeNodeIid(ovsdbNode,
+                                                                                           bridgeName);
                 NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId().getValue()
                                                + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
                                                + bridgeName);