return;
}
String portname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
- String name = new StringBuilder(portname).append(":0").toString();
List<Adjacency> adjList = new ArrayList<Adjacency>();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
- child(VpnInterface.class, new VpnInterfaceKey(name)).build();
+ child(VpnInterface.class, new VpnInterfaceKey(portname)).build();
// find router associated to vpn
Uuid routerId = NeutronvpnUtils.getRouterforVpn(broker, vpnId);
Router rtr = null;
// create extra route adjacency
if (rtr != null && rtr.getRoutes() != null) {
List<String> routeList = rtr.getRoutes();
- List<Adjacency> erAdjList = addAdjacencyforExtraRoute(routeList, false, name);
+ List<Adjacency> erAdjList = addAdjacencyforExtraRoute(routeList, false, portname);
if (erAdjList != null) {
adjList.addAll(erAdjList);
}
}
// create vpn-interface on this neutron port
Adjacencies adjs = new AdjacenciesBuilder().setAdjacency(adjList).build();
- VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(name)).
- setName(name).setVpnInstanceName(vpnId.getValue()).addAugmentation(Adjacencies.class, adjs);
+ VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(portname)).
+ setName(portname).setVpnInstanceName(vpnId.getValue()).addAugmentation(Adjacencies.class, adjs);
VpnInterface vpnIf = vpnb.build();
- NeutronvpnUtils.lockVpnInterface(lockManager, name);
+ NeutronvpnUtils.lockVpnInterface(lockManager, portname);
try {
logger.debug("Creating vpn interface {}", vpnIf);
MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
- logger.error("Creation of vpninterface {} failed due to {}", name, ex);
+ logger.error("Creation of vpninterface {} failed due to {}", portname, ex);
} finally {
- NeutronvpnUtils.unlockVpnInterface(lockManager, name);
+ NeutronvpnUtils.unlockVpnInterface(lockManager, portname);
}
}
if (port != null) {
String pname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
- String name = new StringBuilder(pname).append(":0").toString();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
- child(VpnInterface.class, new VpnInterfaceKey(name)).build();
+ child(VpnInterface.class, new VpnInterfaceKey(pname)).build();
- NeutronvpnUtils.lockVpnInterface(lockManager, name);
+ NeutronvpnUtils.lockVpnInterface(lockManager, pname);
try {
- logger.debug("Deleting vpn interface {}", name);
+ logger.debug("Deleting vpn interface {}", pname);
MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (Exception ex) {
- logger.error("Deletion of vpninterface {} failed due to {}", name, ex);
+ logger.error("Deletion of vpninterface {} failed due to {}", pname, ex);
} finally {
- NeutronvpnUtils.unlockVpnInterface(lockManager, name);
+ NeutronvpnUtils.unlockVpnInterface(lockManager, pname);
}
}
}
String destination = parts[1];
String tapPortName = NeutronvpnUtils.getNeutronPortNamefromPortFixedIp(broker, nextHop);
- String ifname = new StringBuilder(tapPortName).append(":0").toString();
logger.trace("Adding extra route with nexthop {}, destination {}, ifName {}", nextHop,
- destination, ifname);
+ destination, tapPortName);
Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setNextHopIp(nextHop).setKey
(new AdjacencyKey(destination)).build();
if (rtrUp == false) {
- if (ifname.equals(vpnifname)) {
+ if (tapPortName.equals(vpnifname)) {
adjList.add(erAdj);
}
continue;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
- child(VpnInterface.class, new VpnInterfaceKey(ifname)).build();
+ child(VpnInterface.class, new VpnInterfaceKey(tapPortName)).build();
Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(broker, LogicalDatastoreType
.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Arrays.asList(erAdj)).build();
- VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(ifname))
+ VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(tapPortName))
.addAugmentation(Adjacencies.class, erAdjs).build();
MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
logger.trace("extra route {} added successfully", route);
} else {
logger.error("VM adjacency for interface {} not present ; cannot add extra route adjacency",
- ifname);
+ tapPortName);
}
} else {
logger.error("Incorrect input received for extra route. {}", parts);
String destination = parts[1];
String tapPortName = NeutronvpnUtils.getNeutronPortNamefromPortFixedIp(broker, nextHop);
- String ifname = new StringBuilder(tapPortName).append(":0").toString();
logger.trace("Removing extra route with nexthop {}, destination {}, ifName {}", nextHop,
- destination, ifname);
+ destination, tapPortName);
InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
- child(VpnInterface.class, new VpnInterfaceKey(ifname)).augmentation(Adjacencies.class)
+ child(VpnInterface.class, new VpnInterfaceKey(tapPortName)).augmentation(Adjacencies.class)
.child(Adjacency.class, new AdjacencyKey(destination)).build();
MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
logger.trace("extra route {} deleted successfully", route);
}
protected void removeL3Vpn(Uuid id) {
- // read VPN networks
+ // read VPNMaps
VpnMap vpnMap = NeutronvpnUtils.getVpnMap(broker, id);
Uuid router = vpnMap.getRouterId();
// dissociate router
}
}
- protected void associateRouterToVpn(Uuid vpn, Uuid router) {
+ protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
- // remove existing Router-VPN
- if (!vpn.equals(router)) {
- removeL3Vpn(router);
- }
- updateVpnMaps(vpn, null, router, null, null);
+ List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(broker, routerId);
- List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(broker, router);
- logger.debug("Adding subnets...");
+ if (!vpnId.equals(routerId)) {
+ logger.debug("Removing subnets from internal vpn {}", routerId.getValue());
+ if (routerSubnets != null) {
+ for (Uuid subnet : routerSubnets) {
+ removeSubnetFromVpn(routerId, subnet);
+ }
+ }
+ }
+ logger.debug("Adding subnets to vpn {}", vpnId.getValue());
for (Uuid subnet : routerSubnets) {
- addSubnetToVpn(vpn, subnet);
+ addSubnetToVpn(vpnId, subnet);
}
+
+ updateVpnMaps(vpnId, null, routerId, null, null);
}
- protected void dissociateRouterFromVpn(Uuid vpn, Uuid router) {
- clearFromVpnMaps(vpn, router, null);
+ protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
- // fetching sn from SubnetmapDS for internal VPN because sn already deleted from RouterIf DS on router deletion
- List<Uuid> routerSubnets = (vpn.equals(router)) ? getSubnetsforVpn(vpn) :
- NeutronvpnUtils.getNeutronRouterSubnetIds(broker, router);
+ // remove existing external vpn interfaces
+ List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(broker, routerId);
- logger.debug("dissociateRouter vpn {} router {} Removing subnets...", vpn.getValue(), router.getValue());
if (routerSubnets != null) {
for (Uuid subnet : routerSubnets) {
- removeSubnetFromVpn(vpn, subnet);
+ logger.debug("Removing subnets from external vpn {}", vpnId.getValue());
+ removeSubnetFromVpn(vpnId, subnet);
+ logger.debug("Adding subnets to internal vpn {}", routerId.getValue());
+ addSubnetToVpn(routerId, subnet);
}
}
- // create Router-VPN for this router
- if (!vpn.equals(router)) {
- logger.debug("Re-creating vpn-router...");
- createL3Vpn(router, null, null, null, null, null, router, null);
- }
+ clearFromVpnMaps(vpnId, routerId, null);
}
protected List<String> associateNetworksToVpn(Uuid vpn, List<Uuid> networks) {
return result;
}
+ protected void handleNeutronRouterDeleted(Uuid routerId, List<Uuid> routerSubnetIds) {
+ // check if the router is associated to some VPN
+ Uuid vpnId = NeutronvpnUtils.getVpnForRouter(broker, routerId, true);
+ if (vpnId != null) {
+ // remove existing external vpn interfaces
+ for (Uuid subnetId : routerSubnetIds) {
+ removeSubnetFromVpn(vpnId, subnetId);
+ }
+ clearFromVpnMaps(vpnId, routerId, null);
+ } else {
+ // remove existing internal vpn interfaces
+ for (Uuid subnetId : routerSubnetIds) {
+ removeSubnetFromVpn(routerId, subnetId);
+ }
+ }
+ // delete entire vpnMaps node for internal VPN
+ deleteVpnMapsNode(routerId);
+
+ // delete vpn-instance for internal VPN
+ deleteVpnInstance(routerId);
+ }
+
protected Subnet getNeutronSubnet(Uuid subnetId) {
InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).
child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));