Bug 5315 - NPE while creating Neutron Router w/o interface attached to it
[vpnservice.git] / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / vpnservice / neutronvpn / NeutronPortChangeListener.java
index 50dc8ad6f099e2847e85cefe252f37362fe949a0..9a14c570bf505181b97c7c29dff8633dddf8ad07 100644 (file)
@@ -29,6 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.E
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlanBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
         .PortFixedipToPortNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
@@ -129,7 +133,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         // Create of-port interface for this neutron port
         createOfPortInterface(port, portVlanId);
         LOG.debug("Creating ELAN Interface");
-        createElanInterface(port, portVlanId);
+        createElanInterface(port);
         LOG.debug("Add port to subnet");
         // add port to local Subnets DS
         Uuid vpnId = addPortToSubnets(port);
@@ -189,7 +193,10 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     interfaceIdentifier);
             if (!optionalInf.isPresent()) {
                 // handle these for trunkport extensions : portVlanId, isVlanTransparent
-                Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class).build();
+                IfL2vlan l2vlan = new IfL2vlanBuilder().setL2vlanMode(IfL2vlan.L2vlanMode.Trunk).build();
+                ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(name).build();
+                Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class)
+                        .addAugmentation(IfL2vlan.class, l2vlan).addAugmentation(ParentRefs.class, parentRefs).build();
                 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
             } else {
                 LOG.error("Interface {} is already present", name);
@@ -227,18 +234,16 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                 .getUuid());
     }
 
-    private void createElanInterface(Port port, int portVlanId) {
+    private void createElanInterface(Port port) {
         String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-        String interfaceName = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
         String elanInstanceName = port.getNetworkId().getValue();
         List<PhysAddress> physAddresses = new ArrayList<>();
         physAddresses.add(new PhysAddress(port.getMacAddress()));
 
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
-                .class, new ElanInterfaceKey(interfaceName)).build();
+                .class, new ElanInterfaceKey(name)).build();
         ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
-                .setName(interfaceName).setStaticMacEntries(physAddresses).
-                        setKey(new ElanInterfaceKey(interfaceName)).build();
+                .setName(name).setStaticMacEntries(physAddresses).setKey(new ElanInterfaceKey(name)).build();
         MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, elanInterface);
         LOG.debug("Creating new ELan Interface {}", elanInterface);
     }
@@ -262,8 +267,8 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     ipValue, name);
 
             subnetId = ip.getSubnetId();
-            Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, port.getUuid());
-            if (vpnId == null && subnetmap != null) {
+            Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, null, port.getUuid());
+            if (subnetmap != null) {
                 vpnId = subnetmap.getVpnId();
             }
         }