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;
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);
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);
}
}
}
- 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 {
} 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()));
.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;
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);
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,
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
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();