use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class EvpnDnatFlowProgrammer method onAddFloatingIp.
public void onAddFloatingIp(final BigInteger dpnId, final String routerName, final long routerId, final String vpnName, final String internalIp, final String externalIp, final Uuid networkId, final String interfaceName, final String floatingIpInterface, final String floatingIpPortMacAddress, final String rd, final String nextHopIp, final WriteTransaction writeFlowInvTx) {
/*
* 1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
* responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
*
* 2) Install the flow L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25) (FIP VM1 to FIP VM2
* Traffic on Same Hypervisor) {DNAT to DNAT on Same Hypervisor}
*
* 3) Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
* (DC-GW is responding back to FIP VM) {DNAT Reverse traffic})
*
*/
long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("onAddFloatingIp : Invalid Vpn Id is found for Vpn Name {}", vpnName);
return;
}
long l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("onAddFloatingIp : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue with installing " + "DNAT flows for FloatingIp {}", vpnName, rd, externalIp);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
FloatingIPListener.updateOperationalDS(dataBroker, routerName, interfaceName, NatConstants.DEFAULT_LABEL_VALUE, internalIp, externalIp);
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
// Inform to FIB and BGP
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp, nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress, writeFlowInvTx, RouteOrigin.STATIC, dpnId);
/* Install the flow table L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
* (SNAT to DNAT reverse traffic: If the DPN has both SNAT and DNAT configured )
*/
List<ActionInfo> actionInfoFib = new ArrayList<>();
actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
List<Instruction> instructionsFib = new ArrayList<>();
instructionsFib.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
instructionsFib.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(l3Vni).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(instructionsFib).build();
Future<RpcResult<Void>> future1 = fibService.createFibEntry(input);
ListenableFuture<RpcResult<Void>> futureVxlan = JdkFutureAdapters.listenInPoolThread(future1);
LOG.debug("onAddFloatingIp : Add Floating Ip {} , found associated to fixed port {}", externalIp, interfaceName);
if (floatingIpPortMacAddress != null) {
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
vpnManager.addSubnetMacIntoVpnInstance(vpnName, null, floatingIpPortMacAddress, dpnId, writeTx);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId, writeTx);
writeTx.submit();
}
final long finalL3Vni = l3Vni;
Futures.addCallback(futureVxlan, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("onAddFloatingIp : Error {} in custom fib routes install process for Floating " + "IP Prefix {} on DPN {}", error, externalIp, dpnId);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating " + "IP Prefix {} on DPN {}", externalIp, dpnId);
List<Instruction> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
List<Instruction> customInstructions = new ArrayList<>();
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
/* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not call for
* installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with same tunnel_id
* again and again.
*/
if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
makeTunnelTableEntry(dpnId, finalL3Vni, instructions, writeFlowInvTx);
}
/* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
* (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward traffic))
*/
NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, customInstructions, mdsalManager, writeFlowInvTx);
NatUtil.waitForTransactionToComplete(writeFlowInvTx);
} else {
LOG.error("onAddFloatingIp : Error {} in rpc call to create custom Fib entries for Floating " + "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
}
}
}, MoreExecutors.directExecutor());
// Read the FIP vpn-interface details from Configuration l3vpn:vpn-interfaces model and write into Operational DS
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NatUtil.getVpnInterfaceIdentifier(floatingIpInterface);
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
VpnInterfaceOpDataEntryBuilder vpnIfOpDataEntryBuilder = new VpnInterfaceOpDataEntryBuilder();
vpnIfOpDataEntryBuilder.setKey(new VpnInterfaceOpDataEntryKey(interfaceName, vpnName));
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
List<Adjacency> adjacencyListToImport = new ArrayList<>();
for (Adjacency adj : adjacencyList) {
Subnetmap sn = VpnHelper.getSubnetmapFromItsUuid(dataBroker, adj.getSubnetId());
if (!VpnHelper.isSubnetPartOfVpn(sn, vpnName)) {
continue;
}
adjacencyListToImport.add(adj);
}
AdjacenciesOp adjacenciesOp = new AdjacenciesOpBuilder().setAdjacency(adjacencyListToImport).build();
vpnIfOpDataEntryBuilder.addAugmentation(AdjacenciesOp.class, adjacenciesOp);
LOG.debug("onAddFloatingIp : Add vpnInterface {} to Operational l3vpn:vpn-interfaces-op-data ", floatingIpInterface);
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnIfIdentifierOpDataEntry = NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
writeOperTxn.put(LogicalDatastoreType.OPERATIONAL, vpnIfIdentifierOpDataEntry, vpnIfOpDataEntryBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
break;
}
ListenableFuture<Void> futures = writeOperTxn.submit();
String errorText = "onAddFloatingIp : Could not write Interface " + interfaceName + " vpnName " + vpnName;
ListenableFutures.addErrorLogging(futures, LOG, errorText);
} else {
LOG.debug("onAddFloatingIp : No vpnInterface {} found in Configuration l3vpn:vpn-interfaces ", floatingIpInterface);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class FibUtil method updateUsedRdAndVpnToExtraRoute.
public void updateUsedRdAndVpnToExtraRoute(WriteTransaction writeOperTxn, String tunnelIpRemoved, String primaryRd, String prefix) {
Optional<VpnInstanceOpDataEntry> optVpnInstance = getVpnInstanceOpData(primaryRd);
if (!optVpnInstance.isPresent()) {
return;
}
VpnInstanceOpDataEntry vpnInstance = optVpnInstance.get();
String vpnName = vpnInstance.getVpnInstanceName();
long vpnId = vpnInstance.getVpnId();
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, prefix);
// which rd is allocated for the particular OVS.
for (String usedRd : usedRds) {
Optional<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRd, prefix);
if (vpnExtraRoutes.isPresent()) {
// Since all the nexthops under one OVS will be present under one rd, only 1 nexthop is read
// to identify the OVS
String nextHopRemoved = vpnExtraRoutes.get().getNexthopIpList().get(0);
Prefixes prefixToInterface = getPrefixToInterface(vpnId, getIpPrefix(nextHopRemoved));
if (prefixToInterface != null && tunnelIpRemoved.equals(getEndpointIpAddressForDPN(prefixToInterface.getDpnId()))) {
InstanceIdentifier<Adjacency> adjId = getAdjacencyIdentifier(prefixToInterface.getVpnInterfaceName(), prefix);
Interface ifState = getInterfaceStateFromOperDS(prefixToInterface.getVpnInterfaceName());
// Delete datastore only if extra route is deleted or VM interface is deleted/down
if (!MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, adjId).isPresent() || ifState == null || ifState.getOperStatus() == OperStatus.Down) {
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, getAdjacencyIdentifier(prefixToInterface.getVpnInterfaceName(), prefix));
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, VpnExtraRouteHelper.getVpnToExtrarouteVrfIdIdentifier(vpnName, usedRd, prefix));
writeOperTxn.delete(LogicalDatastoreType.CONFIGURATION, VpnExtraRouteHelper.getUsedRdsIdentifier(vpnId, prefix, nextHopRemoved));
break;
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpExternalRoutesOnDpn.
public void cleanUpExternalRoutesOnDpn(final BigInteger dpnId, final long vpnId, final String rd, final String localNextHopIp, final String remoteNextHopIp) {
LOG.trace("cleanUpExternalRoutesOnDpn : cleanup remote routes on dpn {} for vpn {}, rd {}, " + " localNexthopIp {} , remoteNexhtHopIp {}", dpnId, vpnId, rd, localNextHopIp, remoteNextHopIp);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
List<SubTransaction> txnObjects = new ArrayList<>();
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (vrfTable.isPresent()) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
WriteTransaction writeCfgTxn = dataBroker.newWriteOnlyTransaction();
vrfTable.get().getVrfEntry().stream().filter(vrfEntry -> RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP).forEach(bgpRouteVrfEntryHandler.getConsumerForDeletingRemoteFib(dpnId, vpnId, remoteNextHopIp, vrfTable, writeCfgTxn, txnObjects));
futures.add(writeCfgTxn.submit());
}
return futures;
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VrfEntryListener method populateFibOnNewDpn.
public void populateFibOnNewDpn(final BigInteger dpnId, final long vpnId, final String rd, final FutureCallback<List<Void>> callback) {
LOG.trace("New dpn {} for vpn {} : populateFibOnNewDpn", dpnId, rd);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
List<SubTransaction> txnObjects = new ArrayList<>();
if (!vrfTable.isPresent()) {
LOG.info("populateFibOnNewDpn: dpn: {}: VRF Table not yet available for RD {}", dpnId, rd);
if (callback != null) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
return;
}
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
futures.add(retryingTxRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
for (final VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) {
SubnetRoute subnetRoute = vrfEntry.getAugmentation(SubnetRoute.class);
if (subnetRoute != null) {
long elanTag = subnetRoute.getElantag();
installSubnetRouteInFib(dpnId, elanTag, rd, vpnId, vrfEntry, tx);
installSubnetBroadcastAddrDropRule(dpnId, rd, vpnId, vrfEntry, NwConstants.ADD_FLOW, tx);
continue;
}
RouterInterface routerInt = vrfEntry.getAugmentation(RouterInterface.class);
if (routerInt != null) {
LOG.trace("Router augmented vrfentry found rd:{}, uuid:{}, ip:{}, mac:{}", rd, routerInt.getUuid(), routerInt.getIpAddress(), routerInt.getMacAddress());
routerInterfaceVrfEntryHandler.installRouterFibEntry(vrfEntry, dpnId, vpnId, routerInt.getIpAddress(), new MacAddress(routerInt.getMacAddress()), NwConstants.ADD_FLOW);
continue;
}
// Handle local flow creation for imports
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.SELF_IMPORTED) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
List<String> nextHopList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(optionalLabel.get());
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopList, lri)) {
if (lri.getDpnId().equals(dpnId)) {
createLocalFibEntry(vpnId, rd, vrfEntry);
continue;
}
}
}
}
boolean shouldCreateRemoteFibEntry = shouldCreateFibEntryForVrfAndVpnIdOnDpn(vpnId, vrfEntry, dpnId);
if (shouldCreateRemoteFibEntry) {
LOG.trace("Will create remote FIB entry for vrfEntry {} on DPN {}", vrfEntry, dpnId);
if (RouteOrigin.BGP.getValue().equals(vrfEntry.getOrigin())) {
bgpRouteVrfEntryHandler.createRemoteFibEntry(dpnId, vpnId, vrfTable.get().getRouteDistinguisher(), vrfEntry, tx, txnObjects);
} else {
createRemoteFibEntry(dpnId, vpnId, vrfTable.get().getRouteDistinguisher(), vrfEntry, tx);
}
}
}
}));
if (callback != null) {
ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
}
return futures;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VrfEntryListener method populateExternalRoutesOnDpn.
public void populateExternalRoutesOnDpn(final BigInteger dpnId, final long vpnId, final String rd, final String localNextHopIp, final String remoteNextHopIp) {
LOG.trace("populateExternalRoutesOnDpn : dpn {}, vpn {}, rd {}, localNexthopIp {} , remoteNextHopIp {} ", dpnId, vpnId, rd, localNextHopIp, remoteNextHopIp);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
List<SubTransaction> txnObjects = new ArrayList<>();
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (vrfTable.isPresent()) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
WriteTransaction writeCfgTxn = dataBroker.newWriteOnlyTransaction();
vrfTable.get().getVrfEntry().stream().filter(vrfEntry -> RouteOrigin.BGP == RouteOrigin.value(vrfEntry.getOrigin())).forEach(bgpRouteVrfEntryHandler.getConsumerForCreatingRemoteFib(dpnId, vpnId, rd, remoteNextHopIp, vrfTable, writeCfgTxn, txnObjects));
futures.add(writeCfgTxn.submit());
}
return futures;
});
}
}
Aggregations