Bug 7700: create-l3vpn (REST/CLI) should not allow another VPN to use the same VPNID 74/51174/2
authorAbhinav Gupta <abhinav.gupta@ericsson.com>
Mon, 30 Jan 2017 07:51:10 +0000 (13:21 +0530)
committerVivekanandan Narasimhan <n.vivekanandan@ericsson.com>
Tue, 31 Jan 2017 05:09:15 +0000 (05:09 +0000)
Change-Id: I4481db51b17e92b2df7afab18b41bcb4e1a23df0
Signed-off-by: Abhinav Gupta <abhinav.gupta@ericsson.com>
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java

index d0f4406b66631ad70d896a26b83790040cd9ad9a..c6e32a7abbc54510bb60c9b8f3b77217c552095a 100644 (file)
@@ -826,9 +826,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
         List<L3vpn> vpns = input.getL3vpn();
         for (L3vpn vpn : vpns) {
-            List<String> existingRDs = NeutronvpnUtils.getExistingRDs(dataBroker);
             RpcError error = null;
             String msg;
+            if (NeutronvpnUtils.doesVpnExist(dataBroker, vpn.getId())) {
+                msg = String.format("Creation of L3VPN failed for VPN %s due to VPN with the same ID already present",
+                                vpn.getId().getValue());
+                LOG.warn(msg);
+                error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
+                errorList.add(error);
+                warningcount++;
+                continue;
+            }
             if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
                 msg = String.format("Creation of L3VPN failed for VPN %s due to absence of RD/iRT/eRT input",
                         vpn.getId().getValue());
@@ -847,6 +855,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 warningcount++;
                 continue;
             }
+            List<String> existingRDs = NeutronvpnUtils.getExistingRDs(dataBroker);
             if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
                 msg = String.format("Creation of L3VPN failed for VPN %s as another VPN with the same RD %s is already configured",
                         vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0));
index 0a97528627070dee7251e5216b84de7705b75100..f40bd7a139def18a383c403110111b231fb01823 100644 (file)
@@ -331,7 +331,7 @@ public class NeutronvpnUtils {
      * @param port the port
      * @return port_security_enabled status
      */
-    protected static Boolean getPortSecurityEnabled(Port port) {
+    protected static boolean getPortSecurityEnabled(Port port) {
         String deviceOwner = port.getDeviceOwner();
         if (deviceOwner != null && deviceOwner.startsWith("network:")) {
             // port with device owner of network:xxx is created by
@@ -1180,4 +1180,14 @@ public class NeutronvpnUtils {
         return existingRDs;
     }
 
+    protected static boolean doesVpnExist(DataBroker broker, Uuid vpnId) {
+        InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
+                new VpnMapKey(vpnId)).build();
+        Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+        if (optionalVpnMap.isPresent()) {
+            return true;
+        }
+        return false;
+    }
+
 }