use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class AbstractSnatService method addCommonEntriesForNaptSwitch.
private void addCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 dpnId) {
String routerName = routers.getRouterName();
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
addDefaultFibRouteForSNAT(confTx, dpnId, routerId);
for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
}
// The logic now handle only one external IP per router, others if present will be ignored.
Uint32 extSubnetId = NatUtil.getExternalSubnetVpnId(dataBroker, externalIp.getSubnetId());
addInboundTerminatingServiceTblEntry(confTx, dpnId, routerId, extSubnetId);
addTerminatingServiceTblEntry(confTx, dpnId, routerId);
break;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class AbstractSnatService method removeMipAdjacencies.
private void removeMipAdjacencies(Routers routers) {
LOG.info("removeMipAdjacencies for router {}", routers.getRouterName());
String externalSubNetId = null;
for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
}
externalSubNetId = externalIp.getSubnetId().getValue();
break;
}
if (externalSubNetId == null) {
LOG.info("removeMipAdjacencies no external Ipv4 address present on router {}", routers.getRouterName());
return;
}
InstanceIdentifier<VpnInterfaces> vpnInterfacesId = InstanceIdentifier.builder(VpnInterfaces.class).build();
try {
VpnInterfaces vpnInterfaces = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId);
List<VpnInterface> updatedVpnInterface = new ArrayList<>();
for (VpnInterface vpnInterface : vpnInterfaces.nonnullVpnInterface().values()) {
List<Adjacency> updatedAdjacencies = new ArrayList<>();
Adjacencies adjacencies = vpnInterface.augmentation(Adjacencies.class);
if (null != adjacencies) {
for (Adjacency adjacency : adjacencies.nonnullAdjacency().values()) {
if (!adjacency.getSubnetId().getValue().equals(externalSubNetId)) {
updatedAdjacencies.add(adjacency);
}
}
}
AdjacenciesBuilder adjacenciesBuilder = new AdjacenciesBuilder();
adjacenciesBuilder.setAdjacency(updatedAdjacencies);
VpnInterfaceBuilder vpnInterfaceBuilder = new VpnInterfaceBuilder(vpnInterface);
vpnInterfaceBuilder.addAugmentation(adjacenciesBuilder.build());
updatedVpnInterface.add(vpnInterfaceBuilder.build());
}
VpnInterfacesBuilder vpnInterfacesBuilder = new VpnInterfacesBuilder();
vpnInterfacesBuilder.setVpnInterface(updatedVpnInterface);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId, vpnInterfacesBuilder.build());
} catch (ExpectedDataObjectNotFoundException e) {
LOG.warn("Failed to read removeMipAdjacencies with error {}", e.getMessage());
} catch (TransactionCommitFailedException e) {
LOG.warn("Failed to remove removeMipAdjacencies with error {}", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class SnatCentralizedSwitchChangeListener method remove.
@Override
public void remove(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
LOG.debug("Deleting {}", routerToNaptSwitch);
if (natMode == NatMode.Controller) {
LOG.info("Do Not Processing this remove() event for (routerName:designatedDpn) {}:{}" + "configured in Controller Mode", routerToNaptSwitch.getRouterName(), routerToNaptSwitch.getPrimarySwitchId());
return;
}
Uint64 primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
Routers router = natDataUtil.getRouter(routerToNaptSwitch.getRouterName());
if (router != null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> snatServiceManger.notify(confTx, router, null, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL)), LOG, "error handling SNAT centralized switch removal");
natDataUtil.removeFromRouterMap(router);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class WeightedCentralizedSwitchScheduler method updateCentralizedSwitch.
@Override
public boolean updateCentralizedSwitch(Routers oldRouter, Routers newRouter) {
LOG.info("updateCentralizedSwitch for router {}", newRouter.getRouterName());
String routerName = newRouter.getRouterName();
List<Uuid> addedSubnetIds = getUpdatedSubnetIds(newRouter.getSubnetIds(), oldRouter.getSubnetIds());
List<Uuid> deletedSubnetIds = getUpdatedSubnetIds(oldRouter.getSubnetIds(), newRouter.getSubnetIds());
Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, newRouter.getRouterName());
addToDpnMaps(routerName, addedSubnetIds, primarySwitchId);
deleteFromDpnMaps(routerName, deletedSubnetIds, primarySwitchId);
try {
InstanceIdentifier<RouterToNaptSwitch> id = NatUtil.buildNaptSwitchIdentifier(routerName);
RouterToNaptSwitch routerToNaptSwitch = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
boolean isSnatEnabled = newRouter.isEnableSnat();
Map<ExternalIpsKey, ExternalIps> updateExternalIpsMap = newRouter.getExternalIps();
if (updateExternalIpsMap == null || updateExternalIpsMap.isEmpty()) {
isSnatEnabled = false;
}
if (isSnatEnabled != routerToNaptSwitch.isEnableSnat()) {
RouterToNaptSwitchBuilder routerToNaptSwitchBuilder = new RouterToNaptSwitchBuilder(routerToNaptSwitch);
routerToNaptSwitchBuilder.setEnableSnat(isSnatEnabled);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName), routerToNaptSwitchBuilder.build());
}
} catch (ExpectedDataObjectNotFoundException e) {
LOG.error("updateCentralizedSwitch ReadFailedException for {}", routerName);
} catch (TransactionCommitFailedException e) {
LOG.error("updateCentralizedSwitch TransactionCommitFailedException for {}", routerName);
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class ExternalRoutersListener method handleSnatReverseTraffic.
public void handleSnatReverseTraffic(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId, Routers router, Uint32 routerId, String routerName, String externalIp) {
LOG.debug("handleSnatReverseTraffic : entry for DPN ID {}, routerId {}, externalIp: {}", dpnId, routerId, externalIp);
Uuid networkId = router.getNetworkId();
if (networkId == null) {
LOG.error("handleSnatReverseTraffic : networkId is null for the router ID {}", routerId);
return;
}
Collection<Uuid> externalSubnetList = NatUtil.getExternalSubnetIdsFromExternalIps(new ArrayList<ExternalIps>(router.nonnullExternalIps().values()));
// FLAT/VLAN case having external-subnet as VPN
String externalSubnetVpn = null;
if (externalSubnetList != null && !externalSubnetList.isEmpty()) {
Boolean isExternalIpsAdvertized = Boolean.FALSE;
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();
advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, externalSubnetVpn, routerId, routerName, externalIp, networkId, router, confTx);
isExternalIpsAdvertized = Boolean.TRUE;
}
}
if (isExternalIpsAdvertized) {
LOG.trace("External Ips {} advertized for Router {}", router.getExternalIps(), routerName);
return;
}
}
// VXVLAN/GRE case having Internet-VPN
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (vpnName == null) {
LOG.error("handleSnatReverseTraffic : No VPN associated with ext nw {} to handle add external ip " + "configuration {} in router {}", networkId, externalIp, routerId);
return;
}
advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, externalIp, networkId, router, confTx);
LOG.debug("handleSnatReverseTraffic : exit for DPN ID {}, routerId {}, externalIp : {}", dpnId, routerId, externalIp);
}
Aggregations