/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import com.google.common.base.Optional;
import com.google.common.util.concurrent.SettableFuture;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.AdjacenciesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.Adjacency;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.RouterInterfacesMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesKey;
+
import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
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.ports.rev150712.ports.attributes.ports.PortKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.ElanInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.instances.ElanInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.instances.ElanInstanceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.lockmanager.rev150819.LockManagerService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.AssociateNetworksInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.AssociateNetworksOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.AssociateNetworksOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.AssociateRouterInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.CreateL3VPNInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.CreateL3VPNOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.CreateL3VPNOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DeleteL3VPNInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DeleteL3VPNOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DeleteL3VPNOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DissociateNetworksInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DissociateNetworksOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DissociateNetworksOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DissociateRouterInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.GetL3VPNInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.GetL3VPNInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.GetL3VPNOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.GetL3VPNOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.L3vpnInstance;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.NeutronvpnService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.Subnetmaps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.VpnMaps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.createl3vpn.input.L3vpn;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.getl3vpn.output
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMapBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMapKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import java.util.EventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
+public class NeutronvpnManager implements NeutronvpnService, AutoCloseable , EventListener{
private static final Logger logger = LoggerFactory.getLogger(NeutronvpnManager.class);
private final DataBroker broker;
private LockManagerService lockManager;
IMdsalApiManager mdsalUtil;
+ private NotificationPublishService notificationPublishService;
+ private NotificationService notificationService;
+ Boolean isExternalVpn;
/**
* @param db - dataBroker reference
* @param mdsalManager - MDSAL Util API access
*/
- public NeutronvpnManager(final DataBroker db, IMdsalApiManager mdsalManager) {
+ public NeutronvpnManager(final DataBroker db, IMdsalApiManager mdsalManager,NotificationPublishService notiPublishService,
+ NotificationService notiService) {
broker = db;
mdsalUtil = mdsalManager;
+ notificationPublishService = notiPublishService;
+ notificationService = notiService;
}
public void setLockManager(LockManagerService lockManager) {
if (vpnId == null || port == null) {
return;
}
- String portname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+ String infName = port.getUuid().getValue();
List<Adjacency> adjList = new ArrayList<Adjacency>();
- InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(portname);
+ InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
// find router associated to vpn
Uuid routerId = NeutronvpnUtils.getRouterforVpn(broker, vpnId);
// create extra route adjacency
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> routeList = rtr.getRoutes();
- List<Adjacency> erAdjList = addAdjacencyforExtraRoute(routeList, false, portname);
+ List<Adjacency> erAdjList = addAdjacencyforExtraRoute(routeList, false, infName);
if (erAdjList != null && !erAdjList.isEmpty()) {
adjList.addAll(erAdjList);
}
}
// create vpn-interface on this neutron port
Adjacencies adjs = new AdjacenciesBuilder().setAdjacency(adjList).build();
- VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(portname)).
- setName(portname).setVpnInstanceName(vpnId.getValue()).addAugmentation(Adjacencies.class, adjs);
+ VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).
+ setName(infName).setVpnInstanceName(vpnId.getValue()).addAugmentation(Adjacencies.class, adjs);
VpnInterface vpnIf = vpnb.build();
try {
- isLockAcquired = NeutronvpnUtils.lock(lockManager, portname);
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
logger.debug("Creating vpn interface {}", vpnIf);
MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
- logger.error("Creation of vpninterface {} failed due to {}", portname, ex);
+ logger.error("Creation of vpninterface {} failed due to {}", infName, ex);
} finally {
if (isLockAcquired) {
- NeutronvpnUtils.unlock(lockManager, portname);
+ NeutronvpnUtils.unlock(lockManager, infName);
}
}
}
if (port != null) {
boolean isLockAcquired = false;
- String pname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
- InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(pname);
+ String infName = port.getUuid().getValue();
+ InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
- isLockAcquired = NeutronvpnUtils.lock(lockManager, pname);
- logger.debug("Deleting vpn interface {}", pname);
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
+ logger.debug("Deleting vpn interface {}", infName);
MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (Exception ex) {
- logger.error("Deletion of vpninterface {} failed due to {}", pname, ex);
+ logger.error("Deletion of vpninterface {} failed due to {}", infName, ex);
} finally {
if (isLockAcquired) {
- NeutronvpnUtils.unlock(lockManager, pname);
+ NeutronvpnUtils.unlock(lockManager, infName);
}
}
}
return;
}
boolean isLockAcquired = false;
- String portname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
- String ifname = new StringBuilder(portname).append(":0").toString();
- InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(ifname);
+ String infName = port.getUuid().getValue();
+ InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(broker, LogicalDatastoreType
.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
VpnInterface vpnIf = vpnIfBuilder.setVpnInstanceName(vpnId.getValue()).build();
- isLockAcquired = NeutronvpnUtils.lock(lockManager, ifname);
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
logger.debug("Updating vpn interface {}", vpnIf);
MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} else {
- logger.error("VPN Interface {} not found", ifname);
+ logger.error("VPN Interface {} not found", infName);
}
} catch (Exception ex) {
- logger.error("Updation of vpninterface {} failed due to {}", ifname, ex);
+ logger.error("Updation of vpninterface {} failed due to {}", infName, ex);
} finally {
if (isLockAcquired) {
- NeutronvpnUtils.unlock(lockManager, ifname);
+ NeutronvpnUtils.unlock(lockManager, infName);
}
}
}
List<L3vpn> vpns = input.getL3vpn();
for (L3vpn vpn : vpns) {
- RpcError error;
+ RpcError error = null;
String msg;
if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
msg = String.format("Creation of L3VPN failed for VPN %s due to absence of RD/iRT/eRT input",
warningcount++;
continue;
}
+ if (vpn.getRouterId() != null) {
+ if (NeutronvpnUtils.getNeutronRouter(broker, vpn.getRouterId()) == null) {
+ msg = String.format("Creation of L3VPN failed for VPN %s due to router not found %s",
+ vpn.getId().getValue(), vpn.getRouterId().getValue());
+ logger.warn(msg);
+ error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
+ errorList.add(error);
+ warningcount++;
+ continue;
+ }
+ Uuid vpnId = NeutronvpnUtils.getVpnForRouter(broker, vpn.getRouterId(), true);
+ if (vpnId != null) {
+ msg = String.format("Creation of L3VPN failed for VPN %s due to router %s already associated to " +
+ "another VPN %s", vpn.getId().getValue(), vpn.getRouterId().getValue(), vpnId.getValue());
+ logger.warn(msg);
+ error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
+ errorList.add(error);
+ warningcount++;
+ continue;
+ }
+ }
+ if (vpn.getNetworkIds() != null) {
+ for (Uuid nw : vpn.getNetworkIds()) {
+ Network network = NeutronvpnUtils.getNeutronNetwork(broker, nw);
+ Uuid vpnId = NeutronvpnUtils.getVpnForNetwork(broker, nw);
+ if (network == null) {
+ msg = String.format("Creation of L3VPN failed for VPN %s due to network not found %s",
+ vpn.getId().getValue(), nw.getValue());
+ logger.warn(msg);
+ error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
+ errorList.add(error);
+ warningcount++;
+ } else if (vpnId != null) {
+ msg = String.format("Creation of L3VPN failed for VPN %s due to network %s already associated" +
+ " to another VPN %s", vpn.getId().getValue(), nw.getValue(), vpnId.getValue());
+ logger.warn(msg);
+ error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
+ errorList.add(error);
+ warningcount++;
+ }
+ }
+ if (error != null) {
+ continue;
+ }
+ }
try {
createL3Vpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(),
vpn.getImportRT(), vpn.getExportRT(), vpn.getRouterId(), vpn.getNetworkIds());
vpnsIdentifier);
if (optionalVpns.isPresent() && optionalVpns.get().getVpnInstance() != null) {
for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
- vpns.add(vpn);
+ // eliminating internal VPNs from getL3VPN output
+ if (vpn.getIpv4Family().getRouteDistinguisher() != null) {
+ vpns.add(vpn);
+ }
}
} else {
// No VPN present
protected void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
logger.debug("Adding subnet {} to vpn {}", subnet.getValue(), vpnId.getValue());
Subnetmap sn = updateSubnetNode(subnet, null, null, null, null, vpnId, null);
+ boolean isLockAcquired = false;
+ String lockName = vpnId.getValue() + subnet.getValue();
+ String elanInstanceName = sn.getNetworkId().getValue();
+ InstanceIdentifier<ElanInstance>elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
+ Optional<ElanInstance> elanInstance = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId);
+ long elanTag = elanInstance.get().getElanTag();
+ Uuid routerId = NeutronvpnUtils.getVpnMap(broker, vpnId).getRouterId();
+ if (vpnId.equals(routerId)) {
+ isExternalVpn = false;
+ } else {
+ isExternalVpn = true;
+ }
+ try {
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName);
+ checkAndPublishSubnetAddNotification(subnet, sn.getSubnetIp(), vpnId.getValue(), isExternalVpn, elanTag);
+ logger.debug("Subnet added to Vpn notification sent");
+ }catch (Exception e){
+ logger.error("Subnet added to Vpn notification failed",e);
+ }finally {
+ if (isLockAcquired) {
+ NeutronvpnUtils.unlock(lockManager, lockName);
+ }
+ }
// Check if there are ports on this subnet and add corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : sn.getPortList()) {
logger.debug("adding vpn-interface for port {}", port.getValue());
- createVpnInterface(vpnId, getNeutronPort(port));
+ createVpnInterface(vpnId, NeutronvpnUtils.getNeutronPort(broker, port));
}
}
}
- protected void updateVpnForSubnet(Uuid vpnId, Uuid subnet) {
+ protected void updateVpnForSubnet(Uuid vpnId, Uuid subnet, boolean isBeingAssociated) {
logger.debug("Updating VPN {} for subnet {}", vpnId.getValue(), subnet.getValue());
Subnetmap sn = updateSubnetNode(subnet, null, null, null, null, vpnId, null);
+ boolean isLockAcquired = false;
+ String lockName = vpnId.getValue() + subnet.getValue();
+ String elanInstanceName = sn.getNetworkId().getValue();
+ InstanceIdentifier<ElanInstance>elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
+ Optional<ElanInstance> elanInstance = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId);
+ long elanTag = elanInstance.get().getElanTag();
+ try {
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName);
+ checkAndPublishSubnetUpdNotification(subnet, sn.getSubnetIp(), vpnId.getValue(), isBeingAssociated, elanTag);
+ logger.debug("Subnet updated in Vpn notification sent");
+ }catch (Exception e){
+ logger.error("Subnet updated in Vpn notification failed",e);
+ }finally {
+ if (isLockAcquired) {
+ NeutronvpnUtils.unlock(lockManager, lockName);
+ }
+ }
// Check for ports on this subnet and update association of corresponding vpn-interfaces to external vpn
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : sn.getPortList()) {
logger.debug("Updating vpn-interface for port {}", port.getValue());
- updateVpnInterface(vpnId, getNeutronPort(port));
+ updateVpnInterface(vpnId, NeutronvpnUtils.getNeutronPort(broker, port));
+ }
+ }
+ }
+
+
+
+ // router-interfaces-map
+// list router-interfaces {
+// key router-id;
+// leaf router-id { type yang:uuid; }
+// list interfaces {
+// key interface-id;
+// leaf interface-id { type yang:uuid; }
+// }
+// }
+////}
+ InstanceIdentifier<RouterInterfaces> getRouterInterfacesId(Uuid routerId) {
+ return InstanceIdentifier.builder(RouterInterfacesMap.class)
+ .child(RouterInterfaces.class, new RouterInterfacesKey(routerId)).build();
+ }
+ void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
+ InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+ Optional<RouterInterfaces> optRouterInterfaces = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
+ Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
+ if(optRouterInterfaces.isPresent()) {
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
+ } else {
+ RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
+ List<Interfaces> interfaces = new ArrayList<>();
+ interfaces.add(routerInterface);
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId, builder.setInterfaces(interfaces).build());
+ }
+ }
+
+ void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
+ InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+ Optional<RouterInterfaces> optRouterInterfaces = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
+ Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
+ if(optRouterInterfaces.isPresent()) {
+ RouterInterfaces routerInterfaces = optRouterInterfaces.get();
+ List<Interfaces> interfaces = routerInterfaces.getInterfaces();
+ if(interfaces != null && interfaces.remove(routerInterface)) {
+ if(interfaces.isEmpty()) {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
+ } else {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
+ }
}
}
}
String nextHop = String.valueOf(route.getNexthop().getValue());
String destination = String.valueOf(route.getDestination().getValue());
- String tapPortName = NeutronvpnUtils.getNeutronPortNamefromPortFixedIp(broker, nextHop);
- logger.trace("Adding extra route with nexthop {}, destination {}, ifName {}", nextHop,
- destination, tapPortName);
+ String infName = NeutronvpnUtils.getNeutronPortNamefromPortFixedIp(broker, nextHop);
+ logger.trace("Adding extra route with nexthop {}, destination {}, infName {}", nextHop,
+ destination, infName);
Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setNextHopIp(nextHop).setKey
(new AdjacencyKey(destination)).build();
if (rtrUp == false) {
- if (tapPortName.equals(vpnifname)) {
+ if (infName.equals(vpnifname)) {
adjList.add(erAdj);
}
continue;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
- child(VpnInterface.class, new VpnInterfaceKey(tapPortName)).build();
+ child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
try {
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(tapPortName))
+ VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
.addAugmentation(Adjacencies.class, erAdjs).build();
- isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnifname);
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
logger.debug("Adding extra route {}", route);
MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} else {
logger.error("VM adjacency for interface {} not present ; cannot add extra route adjacency",
- tapPortName);
+ infName);
}
} catch (Exception e) {
logger.error("exception in adding extra route: {}" + e);
} finally {
if (isLockAcquired) {
- NeutronvpnUtils.unlock(lockManager, vpnifname);
+ NeutronvpnUtils.unlock(lockManager, infName);
}
}
} else {
String nextHop = String.valueOf(route.getNexthop().getValue());
String destination = String.valueOf(route.getDestination().getValue());
- String tapPortName = NeutronvpnUtils.getNeutronPortNamefromPortFixedIp(broker, nextHop);
- logger.trace("Removing extra route with nexthop {}, destination {}, ifName {}", nextHop,
- destination, tapPortName);
+ String infName = NeutronvpnUtils.getNeutronPortNamefromPortFixedIp(broker, nextHop);
+ logger.trace("Removing extra route with nexthop {}, destination {}, infName {}", nextHop,
+ destination, infName);
InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
- child(VpnInterface.class, new VpnInterfaceKey(tapPortName)).augmentation(Adjacencies.class)
+ child(VpnInterface.class, new VpnInterfaceKey(infName)).augmentation(Adjacencies.class)
.child(Adjacency.class, new AdjacencyKey(destination)).build();
try {
- isLockAcquired = NeutronvpnUtils.lock(lockManager, tapPortName);
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
logger.trace("extra route {} deleted successfully", route);
} catch (Exception e) {
logger.error("exception in deleting extra route: {}" + e);
} finally {
if (isLockAcquired) {
- NeutronvpnUtils.unlock(lockManager, tapPortName);
+ NeutronvpnUtils.unlock(lockManager, infName);
}
}
} else {
}
}
- protected void addPortToVpn(Uuid vpnId, Uuid port) {
- logger.debug("Adding Port to vpn node...");
- createVpnInterface(vpnId, getNeutronPort(port));
- }
-
protected void removeL3Vpn(Uuid id) {
// read VPNMaps
VpnMap vpnMap = NeutronvpnUtils.getVpnMap(broker, id);
deleteVpnInstance(id);
}
- protected void removePortFromVpn(Uuid vpnId, Uuid port) {
- logger.debug("Removing Port from vpn node...");
- deleteVpnInterface(getNeutronPort(port));
- }
-
protected void removeSubnetFromVpn(Uuid vpnId, Uuid subnet) {
logger.debug("Removing subnet {} from vpn {}", subnet.getValue(), vpnId.getValue());
Subnetmap sn = NeutronvpnUtils.getSubnetmap(broker, subnet);
+ boolean isLockAcquired = false;
+ String lockName = vpnId.getValue() + subnet.getValue();
+ String elanInstanceName = sn.getNetworkId().getValue();
+ InstanceIdentifier<ElanInstance>elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
+ Optional<ElanInstance> elanInstance = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId);
+ long elanTag = elanInstance.get().getElanTag();
+ Uuid routerId = NeutronvpnUtils.getVpnMap(broker, vpnId).getRouterId();
+ if (vpnId.equals(routerId)) {
+ isExternalVpn = false;
+ } else {
+ isExternalVpn = true;
+ }
+ try {
+ isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName);
+ checkAndPublishSubnetDelNotification(subnet, sn.getSubnetIp(), vpnId.getValue(), isExternalVpn, elanTag);
+ logger.debug("Subnet removed from Vpn notification sent");
+ }catch (Exception e){
+ logger.error("Subnet removed from Vpn notification failed",e);
+ }finally {
+ if (isLockAcquired) {
+ NeutronvpnUtils.unlock(lockManager, lockName);
+ }
+ }
if (sn != null) {
// Check if there are ports on this subnet; remove corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : sn.getPortList()) {
logger.debug("removing vpn-interface for port {}", port.getValue());
- deleteVpnInterface(getNeutronPort(port));
+ deleteVpnInterface(NeutronvpnUtils.getNeutronPort(broker, port));
+ if (routerId != null) {
+ removeFromNeutronRouterInterfacesMap(routerId, port.getValue());
+ }
}
}
// update subnet-vpn association
logger.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
if (routerSubnets != null) {
for (Uuid subnetId : routerSubnets) {
- updateVpnForSubnet(vpnId, subnetId);
+ updateVpnForSubnet(vpnId, subnetId,true);
}
}
} else {
if (routerSubnets != null) {
for (Uuid subnetId : routerSubnets) {
logger.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
- updateVpnForSubnet(routerId, subnetId);
+ updateVpnForSubnet(routerId, subnetId,false);
}
}
clearFromVpnMaps(vpnId, routerId, null);
return result;
}
+ @Override
+ public Future<RpcResult<GetFixedIPsForNeutronPortOutput>> getFixedIPsForNeutronPort(GetFixedIPsForNeutronPortInput
+ input) {
+ GetFixedIPsForNeutronPortOutputBuilder opBuilder = new GetFixedIPsForNeutronPortOutputBuilder();
+ SettableFuture<RpcResult<GetFixedIPsForNeutronPortOutput>> result = SettableFuture.create();
+ Uuid portId = input.getPortId();
+ StringBuilder returnMsg = new StringBuilder();
+ try {
+ List<String> fixedIPList = new ArrayList<>();
+ Port port = NeutronvpnUtils.getNeutronPort(broker, portId);
+ if (port != null) {
+ List<FixedIps> fixedIPs = port.getFixedIps();
+ for (FixedIps ip : fixedIPs) {
+ fixedIPList.add(ip.getIpAddress().getIpv4Address().getValue());
+ }
+ } else {
+ returnMsg.append("neutron port: ").append(portId.getValue()).append(" not found");
+ }
+ if (returnMsg.length() != 0) {
+ String message = String.format("Retrieval of FixedIPList for neutron port failed due to %s", returnMsg);
+ logger.error(message);
+ result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed().withWarning(ErrorType.PROTOCOL,
+ "invalid-value", message).build());
+ } else {
+ opBuilder.setFixedIPs(fixedIPList);
+ result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().withResult(opBuilder.build())
+ .build());
+ result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().build());
+ }
+ } catch (Exception ex) {
+ String message = String.format("Retrieval of FixedIPList for neutron port %s failed due to %s", portId
+ .getValue(), ex.getMessage());
+ logger.error(message, ex);
+ result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed().withError(ErrorType.APPLICATION,
+ message).build());
+ }
+ 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);
}
protected Port getNeutronPort(String name) {
- Uuid portId = NeutronvpnUtils.getNeutronPortIdfromPortName(broker, name);
- if (portId != null) {
- InstanceIdentifier<Port> pid = InstanceIdentifier.create(Neutron.class).
- child(Ports.class).child(Port.class, new PortKey(portId));
- Optional<Port> optPort = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, pid);
- if (optPort.isPresent()) {
- return optPort.get();
- }
- } else {
- logger.error("Port {} not Found!!", name);
- }
- return null;
+ return NeutronvpnUtils.getNeutronPort(broker, new Uuid(name));
}
protected Port getNeutronPort(Uuid portId) {
- InstanceIdentifier<Port> pid = InstanceIdentifier.create(Neutron.class).
- child(Ports.class).child(Port.class, new PortKey(portId));
- Optional<Port> optPort = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, pid);
- if (optPort.isPresent()) {
- return optPort.get();
- }
- return null;
+ return NeutronvpnUtils.getNeutronPort(broker, portId);
}
protected List<Uuid> getSubnetsforVpn(Uuid vpnid) {
public List<String> showNeutronPortsCLI() {
List<String> result = new ArrayList<String>();
- result.add(String.format(" %-22s %-22s %-22s %-6s ", "PortName", "Mac Address", "IP Address",
+ result.add(String.format(" %-34s %-22s %-22s %-6s ", "PortName", "Mac Address", "IP Address",
"Prefix Length"));
result.add("---------------------------------------------------------------------------------------");
InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
try {
Optional<Ports> ports = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, portidentifier);
- if (ports.isPresent() && ports.get().getPort()!= null) {
+ if (ports.isPresent() && ports.get().getPort() != null) {
List<Port> portList = ports.get().getPort();
for (Port port : portList) {
- result.add(String.format(" %-22s %-22s %-22s %-6s ", NeutronvpnUtils.uuidToTapPortName(port
- .getUuid()), port.getMacAddress(), port.getFixedIps().get(0).getIpAddress().getIpv4Address()
- .getValue(), NeutronvpnUtils.getIPPrefixFromPort(broker, port)));
+ result.add(String.format(" %-34s %-22s %-22s %-6s ", port.getUuid().getValue(), port
+ .getMacAddress(), port.getFixedIps().get(0).getIpAddress().getIpv4Address().getValue(),
+ NeutronvpnUtils.getIPPrefixFromPort(broker, port)));
}
}
} catch (Exception e) {
return help.toString();
}
+ private void checkAndPublishSubnetAddNotification(Uuid subnetId, String subnetIp, String vpnName, Boolean isExternalvpn, Long elanTag)throws InterruptedException{
+ SubnetAddedToVpnBuilder builder = new SubnetAddedToVpnBuilder();
+
+ logger.info("publish notification called");
+
+ builder.setSubnetId(subnetId);
+ builder.setSubnetIp(subnetIp);
+ builder.setVpnName(vpnName);
+ builder.setExternalVpn(isExternalvpn);
+ builder.setElanTag(elanTag);
+
+ notificationPublishService.putNotification(builder.build());
+ }
+
+ private void checkAndPublishSubnetDelNotification(Uuid subnetId, String subnetIp, String vpnName, Boolean isExternalvpn, Long elanTag)throws InterruptedException{
+ SubnetDeletedFromVpnBuilder builder = new SubnetDeletedFromVpnBuilder();
+
+ logger.info("publish notification called");
+
+ builder.setSubnetId(subnetId);
+ builder.setSubnetIp(subnetIp);
+ builder.setVpnName(vpnName);
+ builder.setExternalVpn(isExternalvpn);
+ builder.setElanTag(elanTag);
+
+ notificationPublishService.putNotification(builder.build());
+ }
+
+ private void checkAndPublishSubnetUpdNotification(Uuid subnetId, String subnetIp, String vpnName, Boolean isExternalvpn, Long elanTag)throws InterruptedException{
+ SubnetUpdatedInVpnBuilder builder = new SubnetUpdatedInVpnBuilder();
+
+ logger.info("publish notification called");
+
+ builder.setSubnetId(subnetId);
+ builder.setSubnetIp(subnetIp);
+ builder.setVpnName(vpnName);
+ builder.setExternalVpn(isExternalvpn);
+ builder.setElanTag(elanTag);
+
+ notificationPublishService.putNotification(builder.build());
+ }
+
}