add vrf id to vpn operational 94/50294/1
authorDavid Goldberg <gdavid@hpe.com>
Tue, 10 Jan 2017 11:20:09 +0000 (13:20 +0200)
committerDavid Goldberg <gdavid@hpe.com>
Wed, 11 Jan 2017 13:44:09 +0000 (15:44 +0200)
Change-Id: I5a300a4dd192a97250054416a25d65794799677b
Signed-off-by: David Goldberg <gdavid@hpe.com>
legato-api/src/main/yang/mef-services.yang
netvirt/src/main/java/org/opendaylight/unimgr/mef/netvirt/IpvcListener.java
netvirt/src/main/java/org/opendaylight/unimgr/mef/netvirt/MefServicesUtils.java

index d362556aacabcb0793472948ddf5a040c1f90afc..b0237594ff022a76d1222bc65deb5b42a1b63983 100644 (file)
@@ -2032,6 +2032,7 @@ module mef-services {
   augment "/mef-services:mef-services/mef-services:mef-service/mef-services:mef-service-choice/mef-services:ipvc-choice/mef-services:ipvc" {
     ext:augment-identifier "ipvc-vpn";
     leaf vpn-id {type string;}
+    leaf vrf-id {type string;}
     list vpn-elans {
       key "uni-id ip-uni-id";
       leaf uni-id {type  mef-types:identifier45;}
index 79b2a64efb3527fdbea75e3ef31df6cc33f1eb24..021f7a861cdb7356c8959f654d2e6f3d1f66c3b9 100644 (file)
@@ -104,7 +104,7 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
     @Override
     public void connectUni(String uniId) {
         List<RetailSvcIdType> allIpvcs = MefServicesUtils.getAllIpvcsServiceIds(dataBroker);
-        allIpvcs = (allIpvcs != null) ? allIpvcs : Collections.emptyList();
+        allIpvcs = allIpvcs != null ? allIpvcs : Collections.emptyList();
 
         for (RetailSvcIdType ipvcSerId : allIpvcs) {
             InstanceIdentifier<Ipvc> ipvcId = MefServicesUtils.getIpvcInstanceIdentifier(ipvcSerId);
@@ -115,8 +115,8 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
             }
             List<Uni> toConnect = new ArrayList<>();
 
-            List<Uni> unis = (ipvc.getUnis() != null) ? ipvc.getUnis().getUni() : null;
-            unis = (unis != null) ? unis : Collections.emptyList();
+            List<Uni> unis = ipvc.getUnis() != null ? ipvc.getUnis().getUni() : null;
+            unis = unis != null ? unis : Collections.emptyList();
             for (Uni uni : unis) {
                 if (uni.getUniId().getValue().equals(uniId)) {
                     Log.info("Connecting Uni {} to svc id {}", uniId, ipvcSerId);
@@ -146,7 +146,7 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
     public void disconnectUni(String uniId) {
 
         List<RetailSvcIdType> allIpvcs = MefServicesUtils.getAllIpvcsServiceIds(dataBroker);
-        allIpvcs = (allIpvcs != null) ? allIpvcs : Collections.emptyList();
+        allIpvcs = allIpvcs != null ? allIpvcs : Collections.emptyList();
 
         for (RetailSvcIdType ipvcSerId : allIpvcs) {
             InstanceIdentifier<Ipvc> ipvcId = MefServicesUtils.getIpvcInstanceIdentifier(ipvcSerId);
@@ -157,8 +157,8 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
             }
             List<Uni> toRemove = new ArrayList<>();
 
-            List<Uni> unis = (ipvc.getUnis() != null) ? ipvc.getUnis().getUni() : null;
-            unis = (unis != null) ? unis : Collections.emptyList();
+            List<Uni> unis = ipvc.getUnis() != null ? ipvc.getUnis().getUni() : null;
+            unis = unis != null ? unis : Collections.emptyList();
             for (Uni uni : unis) {
                 if (uni.getUniId().getValue().equals(uniId)) {
                     Log.info("Disconnecting Uni {} from svc id {}", uniId, ipvcSerId);
@@ -191,6 +191,8 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
             createVpnInstance(vpnName, ipvcId);
             String rd = waitForRd(vpnName);
 
+            updateOperationalDataStoreWithVrfId(ipvcId, vpnName, rd);
+
             List<Uni> unis = new ArrayList<>();
             if (ipvc.getUnis() != null && ipvc.getUnis() != null) {
                 unis = ipvc.getUnis().getUni();
@@ -203,6 +205,12 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
         }
     }
 
+    private void updateOperationalDataStoreWithVrfId(InstanceIdentifier<Ipvc> ipvcId, String vpnName, String vrfId) {
+        WriteTransaction tx = MdsalUtils.createTransaction(dataBroker);
+        MefServicesUtils.addOperIpvcVpnElan(ipvcId, vpnName, vrfId, tx);
+        MdsalUtils.commitTransaction(tx);
+    }
+
     private void createVpnInstance(final String vpnName, InstanceIdentifier<Ipvc> ipvcId) {
         synchronized (vpnName.intern()) {
             WriteTransaction tx = MdsalUtils.createTransaction(dataBroker);
@@ -306,7 +314,7 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
                 return;
             }
             String vpnName = operIpvcVpn.getVpnId();
-            String rd = (String) waitForRd(vpnName);
+            String rd = waitForRd(vpnName);
             List<Uni> originalUni = origIpvc.getUnis() != null && origIpvc.getUnis().getUni() != null
                     ? origIpvc.getUnis().getUni() : Collections.emptyList();
             List<Uni> updateUni = updateIpvc.getUnis() != null && updateIpvc.getUnis().getUni() != null
@@ -373,14 +381,17 @@ public class IpvcListener extends UnimgrDataTreeChangeListener<Ipvc> implements
     private void waitForInterfaceDpn(String vpnName, String rd, String interfaceName) {
         InstanceIdentifier<VpnInstanceOpDataEntry> vpnId = NetvirtVpnUtils.getVpnInstanceOpDataIdentifier(rd);
         DataWaitGetter<VpnInstanceOpDataEntry> getInterfByName = (vpn) -> {
-            if (vpn.getVpnToDpnList() == null)
+            if (vpn.getVpnToDpnList() == null) {
                 return null;
+            }
             for (VpnToDpnList is : vpn.getVpnToDpnList()) {
-                if (is.getVpnInterfaces() == null)
+                if (is.getVpnInterfaces() == null) {
                     continue;
+                }
                 for (VpnInterfaces i : is.getVpnInterfaces()) {
-                    if (i.getInterfaceName().equals(interfaceName))
+                    if (i.getInterfaceName().equals(interfaceName)) {
                         return interfaceName;
+                    }
                 }
             }
             return null;
index 3c01deac33fd1b9aa571ced76daee27c0b5fe2cf..e58043c8523e0816c77e61210d460419ef288acc 100644 (file)
@@ -129,12 +129,19 @@ public class MefServicesUtils {
     }
 
     public static void addOperIpvcVpnElan(InstanceIdentifier<Ipvc> identifier, String vpnId, WriteTransaction tx) {
+        addOperIpvcVpnElan(identifier, vpnId, null, tx);
+    }
+
+    public static void addOperIpvcVpnElan(InstanceIdentifier<Ipvc> identifier, String vpnId, String vrfId, WriteTransaction tx) {
 
         synchronized (vpnId.intern()) {
             InstanceIdentifier<IpvcVpn> path = identifier.augmentation(IpvcVpn.class);
 
             IpvcVpnBuilder ipvcVpnBuilder = new IpvcVpnBuilder();
             ipvcVpnBuilder.setVpnId(vpnId);
+            if (vrfId != null) {
+                ipvcVpnBuilder.setVrfId(vrfId);
+            }
 
             tx.merge(LogicalDatastoreType.OPERATIONAL, path, ipvcVpnBuilder.build(), true);
         }