X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=neutronvpn%2Fneutronvpn-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fneutronvpn%2FNeutronPortChangeListener.java;h=c4ba484b8ea6a103d6e9bea3ab93ffa9ef0c3e4f;hb=0c3fd2f89bcc0ee030ed8edcb007091b59cc665e;hp=3783a61ba6f3ae60c904a4e57b00fa271d63c64f;hpb=391599acb898d5edafd26b5e27f7a374fa99e915;p=vpnservice.git diff --git a/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java b/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java index 3783a61b..c4ba484b 100644 --- a/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java +++ b/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java @@ -19,11 +19,20 @@ import org.opendaylight.vpnservice.mdsalutil.MDSALUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.ElanInterfaces; +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 @@ -123,6 +132,8 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port); // Create of-port interface for this neutron port createOfPortInterface(port, portVlanId); + LOG.debug("Creating ELAN Interface"); + createElanInterface(port); LOG.debug("Add port to subnet"); // add port to local Subnets DS Uuid vpnId = addPortToSubnets(port); @@ -147,20 +158,21 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener } 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); } private void handleNeutronPortUpdated(Port portoriginal, Port portupdate) { LOG.debug("Add port to subnet"); - // add port FixedIPs to local Subnets DS + // add port FixedIP to local Subnets DS Uuid vpnIdup = addPortToSubnets(portupdate); if (vpnIdup != null) { nvpnManager.createVpnInterface(vpnIdup, portupdate); } - // remove port FixedIPs from local Subnets DS + // remove port FixedIP from local Subnets DS Uuid vpnIdor = removePortFromSubnets(portoriginal); if (vpnIdor != null) { @@ -181,7 +193,10 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener 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); @@ -193,8 +208,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener 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 - ()); + LOG.debug("name-uuid map for port with name: {}, uuid: {} added to NeutronPortData DS", name, port.getUuid()); } private void deleteOfPortInterface(Port port, int portVlanId) { @@ -220,29 +234,40 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener .getUuid()); } + private void createElanInterface(Port port) { + String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid()); + String elanInstanceName = port.getNetworkId().getValue(); + List physAddresses = new ArrayList<>(); + physAddresses.add(new PhysAddress(port.getMacAddress())); + + InstanceIdentifier id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface + .class, new ElanInterfaceKey(name)).build(); + ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName) + .setName(name).setStaticMacEntries(physAddresses).setKey(new ElanInterfaceKey(name)).build(); + MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, elanInterface); + LOG.debug("Creating new ELan Interface {}", elanInterface); + } + // adds port to subnet list and creates vpnInterface private Uuid addPortToSubnets(Port port) { Uuid subnetId = null; Uuid vpnId = null; - String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid()); - - // find all subnets to which this port is associated - List ips = port.getFixedIps(); - for (FixedIps ip : ips) { - String ipValue = ip.getIpAddress().getIpv4Address().getValue(); - - InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue); - PortFixedipToPortNameBuilder builder = new PortFixedipToPortNameBuilder().setPortFixedip(ipValue) - .setPortName(name); - MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, builder.build()); - LOG.debug("fixedIp-name map for neutron port with fixedIp: {}, name: {} added to NeutronPortData DS", - ipValue, name); - - subnetId = ip.getSubnetId(); - Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, port.getUuid()); - if (vpnId == null && subnetmap != null) { - vpnId = subnetmap.getVpnId(); - } + Subnetmap subnetmap = null; + String infName = port.getUuid().getValue(); + + // find the subnet to which this port is associated + FixedIps ip = port.getFixedIps().get(0); + String ipValue = ip.getIpAddress().getIpv4Address().getValue(); + InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue); + PortFixedipToPortNameBuilder builder = new PortFixedipToPortNameBuilder().setPortFixedip(ipValue) + .setPortName(infName); + MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, builder.build()); + LOG.debug("fixedIp-name map for neutron port with fixedIp: {}, name: {} added to NeutronPortData DS", + ipValue, infName); + subnetId = ip.getSubnetId(); + subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, null, port.getUuid()); + if (subnetmap != null) { + vpnId = subnetmap.getVpnId(); } return vpnId; } @@ -250,21 +275,18 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener private Uuid removePortFromSubnets(Port port) { Uuid subnetId = null; Uuid vpnId = null; - - // find all Subnets to which this port is associated - List ips = port.getFixedIps(); - for (FixedIps ip : ips) { - String ipValue = ip.getIpAddress().getIpv4Address().getValue(); - - InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue); - MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, id); - LOG.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS", ipValue); - - subnetId = ip.getSubnetId(); - Subnetmap subnetmap = nvpnManager.removeFromSubnetNode(subnetId, null, null, null, port.getUuid()); - if (vpnId == null && subnetmap != null) { - vpnId = subnetmap.getVpnId(); - } + Subnetmap subnetmap = null; + + // find the subnet to which this port is associated + FixedIps ip = port.getFixedIps().get(0); + String ipValue = ip.getIpAddress().getIpv4Address().getValue(); + InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue); + MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, id); + LOG.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS", ipValue); + subnetId = ip.getSubnetId(); + subnetmap = nvpnManager.removeFromSubnetNode(subnetId, null, null, null, port.getUuid()); + if (subnetmap != null) { + vpnId = subnetmap.getVpnId(); } return vpnId; }