use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.
the class VpnInterfaceOpListener method postProcessVpnInterfaceRemoval.
private void postProcessVpnInterfaceRemoval(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, VpnInterfaceOpDataEntry del, WriteTransaction writeOperTxn) {
final VpnInterfaceOpDataEntryKey key = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class, VpnInterfaceOpDataEntryKey.class);
String interfaceName = key.getName();
String vpnName = del.getVpnInstanceName();
LOG.info("postProcessVpnInterfaceRemoval: interface name {} vpnName {} dpn {}", interfaceName, vpnName, del.getDpnId());
// decrement the vpn interface count in Vpn Instance Op Data
Optional<VpnInstance> vpnInstance = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName));
if (vpnInstance.isPresent()) {
String rd = null;
rd = vpnInstance.get().getVrfId();
VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
AdjacenciesOp adjs = del.getAugmentation(AdjacenciesOp.class);
List<Adjacency> adjList = adjs != null ? adjs.getAdjacency() : null;
if (vpnInstOp != null && adjList != null && adjList.size() > 0) {
/*
* When a VPN Interface is removed by FibManager (aka VrfEntryListener and its cohorts),
* one adjacency for that VPN Interface will be hanging around along with that
* VPN Interface. That adjacency could be primary (or) non-primary.
* If its a primary adjacency, then a prefix-to-interface entry will be available for the
* same. If its a non-primary adjacency, then a prefix-to-interface entry will not be
* available for the same, instead we will have vpn-to-extraroutes filled in for them.
*
* Here we try to remove prefix-to-interface entry for pending adjacency in the deleted
* vpnInterface. More importantly, we also update the vpnInstanceOpData by removing this
* vpnInterface from it.
*/
List<Prefixes> prefixToInterface = new ArrayList<>();
for (Adjacency adjacency : adjs.getAdjacency()) {
List<Prefixes> prefixToInterfaceLocal = new ArrayList<>();
Optional<Prefixes> prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(adjacency.getIpAddress())));
if (prefix.isPresent()) {
prefixToInterfaceLocal.add(prefix.get());
}
if (prefixToInterfaceLocal.isEmpty()) {
for (String nh : adjacency.getNextHopIpList()) {
prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(nh)));
if (prefix.isPresent()) {
prefixToInterfaceLocal.add(prefix.get());
}
}
}
if (!prefixToInterfaceLocal.isEmpty()) {
prefixToInterface.addAll(prefixToInterfaceLocal);
}
}
/*
* In VPN Migration scenarios, there is a race condition where we use the new DPNID
* for the migrated VM instead of old DPNID because when we read prefix-to-interface to cleanup
* old DPNID, we actually get the new DPNID.
*
* More dangerously, we tend to alter the new prefix-to-interface which should be retained intac
* for the migration to succeed in L3VPN. As a workaround, here we are going to use the dpnId in
* the deleted vpnInterface itself instead of tinkering with the prefix-to-interface. Further we
* will tinker prefix-to-interface only when are damn sure if its value matches our
* deleted vpnInterface.
*
*/
for (Prefixes pref : prefixToInterface) {
if (isMatchedPrefixToInterface(pref, del)) {
if (writeOperTxn != null) {
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()));
} else {
VpnUtil.delete(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()), VpnUtil.DEFAULT_CALLBACK);
}
}
}
}
if (del.getDpnId() != null) {
vpnFootprintService.updateVpnToDpnMapping(del.getDpnId(), del.getVpnInstanceName(), rd, interfaceName, null, /*ipAddressSourceValuePair*/
false);
}
LOG.info("postProcessVpnInterfaceRemoval: Removed vpn operational data and updated vpn footprint" + " for interface {} on dpn {} vpn {}", interfaceName, del.getDpnId(), vpnName);
} else {
LOG.error("postProcessVpnInterfaceRemoval: rd not retrievable as vpninstancetovpnid for vpn {} is absent," + " trying rd as {}. interface {} dpn {}", vpnName, vpnName, interfaceName, del.getDpnId());
}
notifyTaskIfRequired(interfaceName);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method handleStaticRoutes.
@Override
public void handleStaticRoutes(InterVpnLinkDataComposite ivpnLink) {
/*
* Checks if there are any static routes pointing to any of both
* InterVpnLink's endpoints. Goes through all routers checking if they have
* a route whose nexthop is an InterVpnLink endpoint
*/
// Map that corresponds a routerId with the L3VPN that it's been assigned to.
Map<String, String> routerXL3VpnMap = buildRouterXL3VPNMap();
// Retrieving all Routers
InstanceIdentifier<Routers> routersIid = InstanceIdentifier.builder(Neutron.class).child(Routers.class).build();
Optional<Routers> routerOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIid);
if (!routerOpData.isPresent()) {
return;
}
List<Router> routers = routerOpData.get().getRouter();
for (Router router : routers) {
String vpnId = routerXL3VpnMap.get(router.getUuid().getValue());
if (vpnId == null) {
LOG.warn("Could not find suitable VPN for router {}", router.getUuid());
// with next router
continue;
}
List<Routes> routerRoutes = router.getRoutes();
if (routerRoutes != null) {
for (Routes route : routerRoutes) {
handleStaticRoute(vpnId, route, ivpnLink);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.
the class VpnToElanFallbackNodeListener method add.
@Override
protected void add(InstanceIdentifier<Node> identifier, Node add) {
BigInteger dpnId = getDpnIdFromNodeId(add.getNodeId());
if (dpnId == null) {
return;
}
LOG.debug("Installing L3VPN to ELAN default Fallback flow in LPortDispatcher table on Dpn {}", add.getNodeId());
List<MatchInfo> matches = Collections.singletonList(new MatchMetadata(MetaDataUtil.getServiceIndexMetaData(ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants.L3VPN_SERVICE_INDEX)), MetaDataUtil.METADATA_MASK_SERVICE_INDEX));
BigInteger metadataToWrite = MetaDataUtil.getServiceIndexMetaData(ServiceIndex.getIndex(NwConstants.ELAN_SERVICE_NAME, NwConstants.ELAN_SERVICE_INDEX));
int instructionKey = 0;
List<Instruction> instructions = Arrays.asList(MDSALUtil.buildAndGetWriteMetadaInstruction(metadataToWrite, MetaDataUtil.METADATA_MASK_SERVICE_INDEX, ++instructionKey), MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_INTERFACE_TABLE, ++instructionKey));
Flow flow = MDSALUtil.buildFlowNew(NwConstants.LPORT_DISPATCHER_TABLE, L3_TO_L2_DEFAULT_FLOW_REF, NwConstants.TABLE_MISS_PRIORITY, L3_TO_L2_DEFAULT_FLOW_REF, 0, 0, CloudServiceChainConstants.COOKIE_L3_BASE, matches, instructions);
mdsalMgr.installFlow(dpnId, flow);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.
the class VpnToElanFallbackNodeListener method remove.
@Override
protected void remove(InstanceIdentifier<Node> identifier, Node del) {
BigInteger dpnId = getDpnIdFromNodeId(del.getNodeId());
if (dpnId == null) {
return;
}
LOG.debug("Removing L3VPN to ELAN default Fallback flow in LPortDispatcher table from Dpn {}", del.getNodeId());
Flow flowToRemove = new FlowBuilder().setFlowName(L3_TO_L2_DEFAULT_FLOW_REF).setId(new FlowId(L3_TO_L2_DEFAULT_FLOW_REF)).setTableId(NwConstants.LPORT_DISPATCHER_TABLE).build();
mdsalMgr.removeFlow(dpnId, flowToRemove);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.
the class VpnServiceChainUtils method programLPortDispatcherFlowForScfToVpn.
/**
* Installs/removes a flow in LPortDispatcher table that is in charge of
* handling packets that falls back from SCF Pipeline to L3Vpn.
*
* @param mdsalManager MDSAL Util API accessor
* @param vpnId Dataplane identifier of the VPN, the Vrf Tag.
* @param dpId The DPN where the flow must be installed/removed
* @param vpnPseudoLportTag Dataplane identifier for the VpnPseudoPort
* @param addOrRemove States if the flow must be created or removed
*/
public static void programLPortDispatcherFlowForScfToVpn(IMdsalApiManager mdsalManager, long vpnId, BigInteger dpId, Integer vpnPseudoLportTag, int addOrRemove) {
LOG.trace("programLPortDispatcherFlowForScfToVpn: vpnId={} dpId={}, vpnPseudoLportTag={} addOrRemove={}", vpnId, dpId, vpnPseudoLportTag, addOrRemove);
Flow flow = buildLPortDispFromScfToL3VpnFlow(vpnId, dpId, vpnPseudoLportTag, addOrRemove);
if (addOrRemove == NwConstants.ADD_FLOW) {
mdsalManager.installFlow(dpId, flow);
} else {
mdsalManager.removeFlow(dpId, flow);
}
}
Aggregations