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 NatUtil method removePseudoPortFromElanDpn.
public static void removePseudoPortFromElanDpn(String elanInstanceName, String pseudoPortId, Uint64 dpnId, DataBroker dataBroker) {
InstanceIdentifier<DpnInterfaces> elanDpnInterfaceId = getElanDpnInterfaceOperationalDataPath(elanInstanceName, dpnId);
// FIXME: separate this out?
final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanInstanceName);
lock.lock();
try {
Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
if (!dpnInElanInterfaces.isPresent()) {
LOG.info("No interface in any dpn for {}", elanInstanceName);
return;
}
dpnInterface = dpnInElanInterfaces.get();
elanInterfaceList = dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty() ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
if (!elanInterfaceList.contains(pseudoPortId)) {
LOG.info("Router port not present in DPN {} for VPN {}", dpnId, elanInstanceName);
return;
}
elanInterfaceList.remove(pseudoPortId);
dpnInterface = new DpnInterfacesBuilder().setDpId(dpnId).setInterfaces(elanInterfaceList).withKey(new DpnInterfacesKey(dpnId)).build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId, dpnInterface);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed to read elanDpnInterface with error {}", e.getMessage());
} catch (TransactionCommitFailedException e) {
LOG.warn("Failed to remove elanDpnInterface with error {}", e.getMessage());
} finally {
lock.unlock();
}
}
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 NatUtil method getExternalSubnetForRouterExternalIp.
@Nullable
protected static Uuid getExternalSubnetForRouterExternalIp(String externalIpAddress, Routers router) {
externalIpAddress = validateAndAddNetworkMask(externalIpAddress);
for (ExternalIps extIp : router.nonnullExternalIps().values()) {
String extIpString = validateAndAddNetworkMask(extIp.getIpAddress());
if (extIpString.equals(externalIpAddress)) {
return extIp.getSubnetId();
}
}
LOG.warn("getExternalSubnetForRouterExternalIp : Missing External Subnet for Ip:{}", externalIpAddress);
return null;
}
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 RouterDpnChangeListener method add.
@Override
public void add(final InstanceIdentifier<DpnVpninterfacesList> identifier, final DpnVpninterfacesList dpnInfo) {
LOG.trace("add : key: {}, value: {}", dpnInfo.key(), dpnInfo);
final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
Uint64 dpnId = dpnInfo.getDpnId();
// check router is associated to external network
InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (routerData.isPresent()) {
Routers router = routerData.get();
Uuid networkId = router.getNetworkId();
if (networkId != null) {
if (natMode == NatMode.Conntrack) {
Uint64 naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
LOG.warn("add : NAPT switch is not selected.");
return;
}
// If it is for NAPT switch skip as the flows would be already programmed.
if (naptSwitch.equals(dpnId)) {
LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
return;
}
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
natServiceManager.notify(confTx, router, null, naptSwitch, dpnId, SnatServiceManager.Action.CNT_ROUTER_ENBL);
if (router.isEnableSnat()) {
natServiceManager.notify(confTx, router, null, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
}
}), LOG, "Error notifying NAT service manager");
} else {
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerUuid);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid routerId returned for routerName {}", routerUuid);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (extNwProvType == ProviderTypes.FLAT || extNwProvType == ProviderTypes.VLAN) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + networkId, () -> {
extNetGroupInstaller.installExtNetGroupEntries(networkId, dpnId);
installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(new ArrayList<ExternalIps>(router.nonnullExternalIps().values())));
return Collections.emptyList();
});
}
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.getRouterName(), () -> {
LOG.debug("add : Router {} is associated with ext nw {}", routerUuid, networkId);
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
Uint32 vpnId;
if (vpnName == null) {
LOG.debug("add : Internal vpn associated to router {}", routerUuid);
vpnId = routerId;
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
return;
}
LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Install default entry in FIB to SNAT table
LOG.info("add : Installing default route in FIB on dpn {} for router {} with vpn {}", dpnId, routerUuid, vpnId);
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, confTx);
} else {
LOG.debug("add : External BGP vpn associated to router {}", routerUuid);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
return;
}
LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Install default entry in FIB to SNAT table
LOG.debug("add : Installing default route in FIB on dpn {} for routerId {} with " + "vpnId {}...", dpnId, routerUuid, vpnId);
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
}
/* install V6 internet default fallback rule in FIB_TABLE if router
* is having V6 subnet
*/
Uuid internetVpnId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
if (internetVpnId != null) {
nvpnManager.programV6InternetFallbackFlow(new Uuid(routerUuid), internetVpnId, NwConstants.ADD_FLOW);
}
if (router.isEnableSnat()) {
LOG.info("add : SNAT enabled for router {}", routerUuid);
if (extNwProvType == null) {
LOG.error("add : External Network Provider Type missing");
return;
}
NatUtil.handleSNATForDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, dpnId, router, routerId, vpnId, confTx, extNwProvType, upgradeState);
} else {
LOG.info("add : SNAT is not enabled for router {} to handle addDPN event {}", routerUuid, dpnId);
}
}));
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
// end of controller based SNAT
}
} else {
LOG.debug("add : Router {} is not associated with External network", routerUuid);
}
}
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 RouterDpnChangeListener method installDefaultNatRouteForRouterExternalSubnets.
private void installDefaultNatRouteForRouterExternalSubnets(Uint64 dpnId, Collection<Uuid> externalSubnetIds) {
if (externalSubnetIds == null) {
LOG.error("installDefaultNatRouteForRouterExternalSubnets : No external subnets for router");
return;
}
for (Uuid subnetId : externalSubnetIds) {
Uint32 vpnIdForSubnet = NatUtil.getExternalSubnetVpnId(dataBroker, subnetId);
if (vpnIdForSubnet != NatConstants.INVALID_ID) {
LOG.info("installDefaultNatRouteForRouterExternalSubnets : Installing default routes in FIB on dpn {} " + "for subnetId {} with vpnId {}", dpnId, subnetId, vpnIdForSubnet);
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnIdForSubnet, subnetId.getValue());
} else {
LOG.debug("installDefaultNatRouteForRouterExternalSubnets : No vpnID for subnet {} found", subnetId);
}
}
}
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 NatRouterInterfaceListener method add.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void add(InstanceIdentifier<Interfaces> identifier, Interfaces interfaceInfo) {
LOG.trace("add : Add event - key: {}, value: {}", interfaceInfo.key(), interfaceInfo);
final String routerId = identifier.firstKeyOf(RouterInterfaces.class).getRouterId().getValue();
final String interfaceName = interfaceInfo.getInterfaceId();
if (NatUtil.isRouterInterfacePort(dataBroker, interfaceName)) {
LOG.info("ADD: Ignoring Router Interface Port {} for processing of router {}", interfaceName, routerId);
return;
}
try {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, NatUtil.getRouterInterfaceId(interfaceName), getRouterInterface(interfaceName, routerId));
} catch (Exception e) {
LOG.error("add: Unable to write data in RouterInterface model", e);
}
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = NatUtil.getInterfaceStateFromOperDS(dataBroker, interfaceName);
if (interfaceState != null) {
Uint64 dpId = NatUtil.getDpIdFromInterface(interfaceState);
if (dpId.equals(Uint64.ZERO)) {
LOG.warn("ADD : Could not retrieve dp id for interface {} to handle router {} association model", interfaceName, routerId);
return;
}
final ReentrantLock lock = NatUtil.lockForNat(dpId);
lock.lock();
try {
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
NatUtil.addToNeutronRouterDpnsMap(routerId, interfaceName, dpId, operTx);
NatUtil.addToDpnRoutersMap(routerId, interfaceName, dpId, operTx);
}), LOG, "Error processing NAT router interface addition");
} finally {
lock.unlock();
}
LOG.info("ADD: Added neutron-router-dpns mapping for interface {} of router {}", interfaceName, routerId);
} else {
LOG.info("add : Interface {} not yet operational to handle router interface add event in router {}", interfaceName, routerId);
}
}
Aggregations