use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class ExternalRoutersListener method changeLocalVpnIdToBgpVpnId.
/**
* router association to vpn.
*
* @param routerName - Name of router
* @param routerId - router id
* @param bgpVpnName BGP VPN name
*/
public void changeLocalVpnIdToBgpVpnId(String routerName, long routerId, String bgpVpnName, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Router associated to BGP VPN");
if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
LOG.debug("changeLocalVpnIdToBgpVpnId : BGP VPN ID value {} ", bgpVpnId);
if (bgpVpnId != NatConstants.INVALID_ID) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Populate the router-id-name container with the " + "mapping BGP VPN-ID {} -> BGP VPN-NAME {}", bgpVpnId, bgpVpnName);
RouterIds rtrs = new RouterIdsBuilder().setKey(new RouterIdsKey(bgpVpnId)).setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getRoutersIdentifier(bgpVpnId), rtrs);
// Get the allocated Primary NAPT Switch for this router
LOG.debug("changeLocalVpnIdToBgpVpnId : Router ID value {} ", routerId);
LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ", routerId, bgpVpnId);
addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, true, writeFlowInvTx);
// Get the group ID
BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
createGroupId(getGroupIdKey(routerName));
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, true, writeFlowInvTx, extNwProvType);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class ExternalRoutersListener method handleDisableSnat.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleDisableSnat(Routers router, Uuid networkUuid, @Nonnull Collection<String> externalIps, boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId, long routerId, WriteTransaction removeFlowInvTx) {
LOG.info("handleDisableSnat : Entry");
String routerName = router.getRouterName();
try {
if (routerFlag) {
removeNaptSwitch(routerName);
} else {
updateNaptSwitch(routerName, BigInteger.ZERO);
}
LOG.debug("handleDisableSnat : Remove the ExternalCounter model for the router ID {}", routerId);
naptManager.removeExternalCounter(routerId);
LOG.debug("handleDisableSnat : got primarySwitch as dpnId {}", naptSwitchDpnId);
if (naptSwitchDpnId == null || naptSwitchDpnId.equals(BigInteger.ZERO)) {
LOG.error("handleDisableSnat : Unable to retrieve the primary NAPT switch for the " + "router ID {} from RouterNaptSwitch model", routerId);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkUuid);
if (extNwProvType == null) {
LOG.error("handleDisableSnat : External Network Provider Type missing");
return;
}
Collection<Uuid> externalSubnetList = NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps());
removeNaptFlowsFromActiveSwitch(routerId, routerName, naptSwitchDpnId, networkUuid, vpnName, externalIps, externalSubnetList, removeFlowInvTx, extNwProvType);
removeFlowsFromNonActiveSwitches(routerId, routerName, naptSwitchDpnId, removeFlowInvTx);
try {
String externalSubnetVpn = null;
for (Uuid externalSubnetId : externalSubnetList) {
Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
// externalSubnet data model will exist for FLAT/VLAN external netowrk UCs.
if (externalSubnet.isPresent()) {
externalSubnetVpn = externalSubnetId.getValue();
clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, externalSubnetVpn, router.getExtGwMacAddress(), removeFlowInvTx);
}
}
if (externalSubnetVpn == null) {
clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, vpnName, router.getExtGwMacAddress(), removeFlowInvTx);
}
} catch (Exception ex) {
LOG.error("handleDisableSnat : Failed to remove fib entries for routerId {} in naptSwitchDpnId {}", routerId, naptSwitchDpnId, ex);
}
// Use the NaptMananager removeMapping API to remove the entire list of IP addresses maintained
// for the router ID.
LOG.debug("handleDisableSnat : Remove the Internal to external IP address maintained for the " + "router ID {} in the DS", routerId);
naptManager.removeMapping(routerId);
} catch (Exception ex) {
LOG.error("handleDisableSnat : Exception while handling disableSNAT for router :{}", routerName, ex);
}
LOG.info("handleDisableSnat : Exit");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class ExternalRoutersListener method advToBgpAndInstallFibAndTsFlows.
public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName, final long routerId, final String routerName, final String externalIp, final Uuid extNetworkId, final Routers router, final WriteTransaction writeFlowInvTx) {
LOG.debug("advToBgpAndInstallFibAndTsFlows : entry for DPN ID {}, tableId {}, vpnname {} " + "and externalIp {}", dpnId, tableId, vpnName, externalIp);
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (rd == null || rd.isEmpty()) {
LOG.error("advToBgpAndInstallFibAndTsFlows : Unable to get RD for VPN Name {}", vpnName);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
if (extNwProvType == null) {
LOG.error("advToBgpAndInstallFibAndTsFlows : External Network Provider Type missing");
return;
}
if (extNwProvType == ProviderTypes.VXLAN) {
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp, vpnName, rd, nextHopIp, writeTx, routerId, routerName, writeFlowInvTx);
return;
}
// Generate VPN label for the external IP
GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);
// On successful generation of the VPN label, advertise the route to the BGP and install the FIB routes.
ListenableFuture<RpcResult<Void>> future = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(labelFuture), (AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>) result -> {
if (result.isSuccessful()) {
LOG.debug("advToBgpAndInstallFibAndTsFlows : inside apply with result success");
GenerateVpnLabelOutput output = result.getResult();
final long label = output.getLabel();
int externalIpInDsFlag = 0;
List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId);
if (dbIpMaps != null) {
for (IpMap dbIpMap : dbIpMaps) {
String dbExternalIp = dbIpMap.getExternalIp();
if (dbExternalIp.contains(externalIp)) {
String dbInternalIp = dbIpMap.getInternalIp();
IpMapKey dbIpMapKey = dbIpMap.getKey();
LOG.debug("advToBgpAndInstallFibAndTsFlows : Setting label {} for internalIp {} " + "and externalIp {}", label, dbInternalIp, externalIp);
IpMap newIpm = new IpMapBuilder().setKey(dbIpMapKey).setInternalIp(dbInternalIp).setExternalIp(dbExternalIp).setLabel(label).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm);
externalIpInDsFlag++;
}
}
if (externalIpInDsFlag <= 0) {
LOG.debug("advToBgpAndInstallFibAndTsFlows : External Ip {} not found in DS, " + "Failed to update label {} for routerId {} in DS", externalIp, label, routerId);
String errMsg = String.format("Failed to update label %s due to external Ip %s not" + " found in DS for router %s", label, externalIp, routerId);
return Futures.immediateFailedFuture(new Exception(errMsg));
}
} else {
LOG.error("advToBgpAndInstallFibAndTsFlows : Failed to write label {} for externalIp {} for" + " routerId {} in DS", label, externalIp, routerId);
}
long l3vni = 0;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
}
Routers extRouter = router != null ? router : NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, extRouter);
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, externalSubnetId, externalIp, nextHopIp, extRouter.getNetworkId().getValue(), null, label, l3vni, RouteOrigin.STATIC, dpnId);
List<Instruction> tunnelTableCustomInstructions = new ArrayList<>();
tunnelTableCustomInstructions.add(new InstructionGotoTable(tableId).buildInstruction(0));
makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions, writeFlowInvTx, extNwProvType);
makeLFibTableEntry(dpnId, label, tableId, writeFlowInvTx);
List<Instruction> fibTableCustomInstructions = createFibTableCustomInstructions(tableId, routerName, externalIp);
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, writeFlowInvTx);
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
String externalVpn = vpnName;
if (externalSubnet.isPresent()) {
externalVpn = externalSubnetId.getValue();
}
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(externalVpn).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(CreateFibEntryInput.IpAddressSource.ExternalFixedIP).setInstruction(fibTableCustomInstructions).build();
Future<RpcResult<Void>> future1 = fibService.createFibEntry(input);
return JdkFutureAdapters.listenInPoolThread(future1);
} else {
LOG.error("advToBgpAndInstallFibAndTsFlows : inside apply with result failed");
String errMsg = String.format("Could not retrieve the label for prefix %s in VPN %s, %s", externalIp, vpnName, result.getErrors());
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
}, MoreExecutors.directExecutor());
Futures.addCallback(future, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("advToBgpAndInstallFibAndTsFlows : Error in generate label or fib install process", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("advToBgpAndInstallFibAndTsFlows : Successfully installed custom FIB routes for prefix {}", externalIp);
} else {
LOG.error("advToBgpAndInstallFibAndTsFlows : Error in rpc call to create custom Fib entries " + "for prefix {} in DPN {}, {}", externalIp, dpnId, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class NatUtil method removeFromDpnRoutersMap.
static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName, BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
/*
1) Get the DpnRoutersList for the DPN.
2) Get the RoutersList identifier for the DPN and router.
3) Get the VPN interfaces for the router (routerList) through which it is connected to the DPN.
4) If the removed VPN interface is the only interface through which the router is connected to the DPN,
then remove RouterList.
*/
LOG.debug("removeFromDpnRoutersMap() : Removing the DPN {} and router {} for the Interface {}" + " in the ODL-L3VPN : DPNRouters map", curDpnId, routerName, vpnInterfaceName);
// Get the dpn-routers-list instance for the current DPN.
InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(curDpnId);
Optional<DpnRoutersList> dpnRoutersListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
if (dpnRoutersListData == null || !dpnRoutersListData.isPresent()) {
LOG.error("removeFromDpnRoutersMap : dpn-routers-list is not present for DPN {} " + "in the ODL-L3VPN:dpn-routers model", curDpnId);
return;
}
// Get the routers-list instance for the router on the current DPN only
InstanceIdentifier<RoutersList> routersListIdentifier = getRoutersList(curDpnId, routerName);
Optional<RoutersList> routersListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
if (routersListData == null || !routersListData.isPresent()) {
LOG.error("removeFromDpnRoutersMap : routers-list is not present for the DPN {} " + "in the ODL-L3VPN:dpn-routers model", curDpnId);
return;
}
LOG.debug("removeFromDpnRoutersMap : Get the interfaces for the router {} " + "from the NeutronVPN - router-interfaces-map", routerName);
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces> routerInterfacesId = getRoutersInterfacesIdentifier(routerName);
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces> routerInterfacesData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
if (routerInterfacesData == null || !routerInterfacesData.isPresent()) {
LOG.debug("removeFromDpnRoutersMap : Unable to get the routers list for the DPN {}. Possibly all subnets " + "removed from router {} OR Router {} has been deleted. Hence DPN router model WILL be cleared ", curDpnId, routerName, routerName);
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
return;
}
// Get the VM interfaces for the router on the current DPN only.
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces> vmInterfaces = routerInterfacesData.get().getInterfaces();
if (vmInterfaces == null) {
LOG.debug("removeFromDpnRoutersMap : VM interfaces are not present for the router {} in the " + "NeutronVPN - router-interfaces-map", routerName);
return;
}
// then remove RouterList.
for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces vmInterface : vmInterfaces) {
String vmInterfaceName = vmInterface.getInterfaceId();
BigInteger vmDpnId = getDpnForInterface(ifaceMgrRpcService, vmInterfaceName);
if (vmDpnId.equals(BigInteger.ZERO) || !vmDpnId.equals(curDpnId)) {
LOG.debug("removeFromDpnRoutersMap : DPN ID {} for the removed interface {} is not the same as that of " + "the DPN ID {} for the checked interface {}", curDpnId, vpnInterfaceName, vmDpnId, vmInterfaceName);
continue;
}
if (!vmInterfaceName.equalsIgnoreCase(vpnInterfaceName)) {
LOG.info("removeFromDpnRoutersMap : Router {} is present in the DPN {} through the other interface {} " + "Hence DPN router model WOULD NOT be cleared", routerName, curDpnId, vmInterfaceName);
return;
}
}
LOG.debug("removeFromDpnRoutersMap : Router {} is present in the DPN {} only through the interface {} " + "Hence DPN router model WILL be cleared. Possibly last VM for the router " + "deleted in the DPN", routerName, curDpnId, vpnInterfaceName);
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class RouterDpnChangeListener method removeSNATFromDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId, Uuid extNetworkId, WriteTransaction removeFlowInvTx) {
// irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
// remove miss entry to NAPT switch
// if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
if (extNwProvType == null) {
return;
}
// Get the external IP labels other than VXLAN provider type. Since label is not applicable for VXLAN
Map<String, Long> externalIpLabel;
if (extNwProvType == ProviderTypes.VXLAN) {
externalIpLabel = null;
} else {
externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
}
BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
return;
}
try {
boolean naptStatus = naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, removeFlowInvTx);
if (!naptStatus) {
LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}", dpnId, routerName);
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
FlowEntity flowEntity = null;
try {
flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.DEL_FLOW);
if (flowEntity == null) {
LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} " + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
return;
}
LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
// remove group
GroupEntity groupEntity = null;
try {
groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
mdsalManager.removeGroup(groupEntity);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}", dpnId, routerName);
} else {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch, externalIpLabel, removeFlowInvTx);
// remove table 26 flow ppointing to table46
FlowEntity flowEntity = null;
try {
flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.DEL_FLOW);
if (flowEntity == null) {
LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with " + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
// best effort to check IntExt model
naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, removeFlowInvTx);
}
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, ex);
}
}
Aggregations