Fixes for VLAN interfaces creation and DHCP for ELAN datapath 55/36855/1
authorAbhinav Gupta <abhinav.gupta@ericsson.com>
Tue, 22 Mar 2016 07:30:15 +0000 (13:00 +0530)
committerAbhinav Gupta <abhinav.gupta@ericsson.com>
Wed, 30 Mar 2016 05:29:46 +0000 (05:29 +0000)
1. VLAN interfaces created with portuuid
2. DHCP exception handling for tapinterfaces
3. Removes redundant code - mainly for trunkport extensions

Change-Id: I486a535b03a2ed05b4543a8522fcea731e3f28f3
Signed-off-by: Abhinav Gupta <abhinav.gupta@ericsson.com>
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpInterfaceEventListener.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpManager.java
neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronvpnUtils.java

index b7f2629846a00d171a36a9b35ee1dfe9cc4e53a8..5cc245653a097bdf6d4f4ac3b5f59344a06fd34c 100644 (file)
@@ -106,7 +106,7 @@ public class DhcpInterfaceEventListener extends AbstractDataChangeListener<Inter
         List<String> ofportIds = add.getLowerLayerIf();
         NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
         BigInteger dpId = BigInteger.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
-        logger.trace("Received add DCN for interface {}, dpid{}", interfaceName, dpId);
+        logger.trace("Received add DCN for interface {}, dpid {}", interfaceName, dpId);
         installDhcpEntries(interfaceName, dpId);
     }
 
@@ -116,7 +116,7 @@ public class DhcpInterfaceEventListener extends AbstractDataChangeListener<Inter
             logger.trace("Port found in neutron. Interface Name {}, port {}", interfaceName, port);
             return port.getMacAddress();
         }
-        logger.trace("Port not found in neutron. Interface Name {}, vlanId {}", interfaceName);
+        logger.trace("Port not found in neutron. Interface Name {}", interfaceName);
         return null;
     }
 
index 6233d40d8a713c7734a3e4f21a94a29dd2e7cba7..2309defb00a5ad69c9b46bcd792508228718d20a 100644 (file)
@@ -172,7 +172,12 @@ public class DhcpManager implements AutoCloseable {
     }
 
     public Port getNeutronPort(String name) {
-        return neutronVpnService.getNeutronPort(name);
+        try {
+            return neutronVpnService.getNeutronPort(name);
+        } catch (Exception ex) {
+            logger.trace("In getNeutronPort interface name passed {} exception message {}.", name, ex.getMessage());
+            return null;
+        }
     }
 
     public void installDhcpEntries(BigInteger dpnId, String vmMacAddress) {
index 42fcd3cfca439adb7d2f32445c7f23c5dad803d0..f128c5bc17feb89f272c44dbac87cf0459457d1f 100644 (file)
@@ -144,11 +144,6 @@ module neutronvpn {
 
     /* Data models to adhere to restart requirements */
     container neutron-port-data {
-        list port-name-to-port-uuid {
-            key port-name;
-            leaf port-id { type yang:uuid;}
-            leaf port-name { type string;}
-        }
         list port-fixedip-to-port-name {
             key port-fixedip;
             leaf port-name { type string;}
index c4ba484b8ea6a103d6e9bea3ab93ffa9ef0c3e4f..0d98bb57da002270273cc6fc5a8f87d25dbe9d17 100644 (file)
@@ -35,8 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev
 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
-        .PortNameToPortUuidBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -129,11 +127,10 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
 
     private void handleNeutronPortCreated(Port port) {
         LOG.info("Of-port-interface creation");
-        int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
         // Create of-port interface for this neutron port
-        createOfPortInterface(port, portVlanId);
+        String portInterfaceName = createOfPortInterface(port);
         LOG.debug("Creating ELAN Interface");
-        createElanInterface(port);
+        createElanInterface(port, portInterfaceName);
         LOG.debug("Add port to subnet");
         // add port to local Subnets DS
         Uuid vpnId = addPortToSubnets(port);
@@ -156,10 +153,9 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
             LOG.debug("removing VPN Interface");
             nvpnManager.deleteVpnInterface(port);
         }
-        int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
         // Remove of-port interface for this neutron port
         // ELAN interface is also implicitly deleted as part of this operation
-        deleteOfPortInterface(port, portVlanId);
+        deleteOfPortInterface(port);
 
     }
 
@@ -180,40 +176,41 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         }
     }
 
-    private void createOfPortInterface(Port port, int portVlanId) {
-        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-        //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
-        //Network network = NeutronvpnUtils.getNeutronNetwork(broker, port.getNetworkId());
-        //Boolean isVlanTransparent = network.isVlanTransparent();
+    private String createOfPortInterface(Port port) {
+        Interface inf = createInterface(port);
+        String infName = inf.getName();
 
-        LOG.debug("Creating OFPort Interface {}", name);
-        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
+        LOG.debug("Creating OFPort Interface {}", infName);
+        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
         try {
             Optional<Interface> optionalInf = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
                     interfaceIdentifier);
             if (!optionalInf.isPresent()) {
-                // handle these for trunkport extensions : portVlanId, isVlanTransparent
-                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);
+                LOG.error("Interface {} is already present", infName);
             }
         } catch (Exception e) {
-            LOG.error("failed to create interface {} due to the exception {} ", name, e.getMessage());
+            LOG.error("failed to create interface {} due to the exception {} ", infName, e.getMessage());
         }
+        return infName;
+    }
 
-        InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
-        PortNameToPortUuidBuilder builder = new PortNameToPortUuidBuilder().setPortName(name).setPortId(port.getUuid());
-        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier, builder.build());
-        LOG.debug("name-uuid map for port with name: {}, uuid: {} added to NeutronPortData DS", name, port.getUuid());
+    private Interface createInterface(Port port) {
+        String parentRefName = NeutronvpnUtils.uuidToTapPortName(port.getUuid());;
+        String interfaceName = port.getUuid().getValue();
+        IfL2vlan.L2vlanMode l2VlanMode = IfL2vlan.L2vlanMode.Trunk;
+        InterfaceBuilder interfaceBuilder = new InterfaceBuilder();
+        IfL2vlanBuilder ifL2vlanBuilder = new IfL2vlanBuilder();
+        ifL2vlanBuilder.setL2vlanMode(l2VlanMode);
+        ParentRefsBuilder parentRefsBuilder = new ParentRefsBuilder().setParentInterface(parentRefName);
+        interfaceBuilder.setEnabled(true).setName(interfaceName).setType(L2vlan.class).addAugmentation(IfL2vlan
+                .class, ifL2vlanBuilder.build()).addAugmentation(ParentRefs.class, parentRefsBuilder.build());
+        return interfaceBuilder.build();
     }
 
-    private void deleteOfPortInterface(Port port, int portVlanId) {
-        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-        //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
+    private void deleteOfPortInterface(Port port) {
+        String name = port.getUuid().getValue();
         LOG.debug("Removing OFPort Interface {}", name);
         InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
         try {
@@ -227,15 +224,9 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         } catch (Exception e) {
             LOG.error("Failed to delete interface {} due to the exception {}", name, e.getMessage());
         }
-
-        InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
-        MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier);
-        LOG.debug("name-uuid map for port with name: {}, uuid: {} deleted from NeutronPortData DS", name, port
-                .getUuid());
     }
 
-    private void createElanInterface(Port port) {
-        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+    private void createElanInterface(Port port, String name) {
         String elanInstanceName = port.getNetworkId().getValue();
         List<PhysAddress> physAddresses = new ArrayList<>();
         physAddresses.add(new PhysAddress(port.getMacAddress()));
index e6c18b77767f457379bad40f2e0a354d128125b4..8c26eea506fd9b8e48be14914dc7511fcb263dd1 100644 (file)
@@ -49,10 +49,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev15
         .PortFixedipToPortName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
         .PortFixedipToPortNameKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
-        .PortNameToPortUuid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
-        .PortNameToPortUuidKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMap;
@@ -68,10 +64,6 @@ import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.port.ext.rev151125.TrunkportExt;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.port.ext.rev151125.TrunkportTypeBase;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.port.ext.rev151125.TrunkportTypeSubport;
-
 public class NeutronvpnUtils {
 
     private static final Logger logger = LoggerFactory.getLogger(NeutronvpnUtils.class);
@@ -149,15 +141,6 @@ public class NeutronvpnUtils {
         return null;
     }
 
-    protected static Uuid getNeutronPortIdfromPortName(DataBroker broker, String portname) {
-        InstanceIdentifier id = buildPortNameToPortUuidIdentifier(portname);
-        Optional<PortNameToPortUuid> portNameToPortUuidData = read(broker, LogicalDatastoreType.CONFIGURATION, id);
-        if (portNameToPortUuidData.isPresent()) {
-            return portNameToPortUuidData.get().getPortId();
-        }
-        return null;
-    }
-
     protected static String getNeutronPortNamefromPortFixedIp(DataBroker broker, String fixedIp) {
         InstanceIdentifier id = buildFixedIpToPortNameIdentifier(fixedIp);
         Optional<PortFixedipToPortName> portFixedipToPortNameData = read(broker, LogicalDatastoreType.CONFIGURATION,
@@ -177,22 +160,6 @@ public class NeutronvpnUtils {
         return null;
     }
 
-    //TODO
-    //Will be done once integrated with TrunkPort Extensions
-    protected static int getVlanFromNeutronPort(Port port) {
-        int vlanId = 0;
-        /*
-        TrunkportExt trunkportExt = port.getAugmentation(TrunkportExt.class);
-        if (trunkportExt != null) {
-            Class<? extends TrunkportTypeBase> trunkportType = trunkportExt.getType();
-            if (trunkportType != null && trunkportType.isAssignableFrom(TrunkportTypeSubport.class)) {
-                vlanId = trunkportExt.getVid();
-            }
-        }
-        */
-        return vlanId;
-    }
-
     protected static Router getNeutronRouter(DataBroker broker, Uuid routerId) {
 
         InstanceIdentifier<Router> inst = InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router
@@ -318,12 +285,6 @@ public class NeutronvpnUtils {
         return null;
     }
 
-    static InstanceIdentifier<PortNameToPortUuid> buildPortNameToPortUuidIdentifier(String portname) {
-        InstanceIdentifier<PortNameToPortUuid> id = InstanceIdentifier.builder(NeutronPortData.class).child
-                (PortNameToPortUuid.class, new PortNameToPortUuidKey(portname)).build();
-        return id;
-    }
-
     static InstanceIdentifier<PortFixedipToPortName> buildFixedIpToPortNameIdentifier(String fixedIp) {
         InstanceIdentifier<PortFixedipToPortName> id = InstanceIdentifier.builder(NeutronPortData.class).child
                 (PortFixedipToPortName.class, new PortFixedipToPortNameKey(fixedIp)).build();