use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class NatUtil method getAssociatedExternalNetwork.
static String getAssociatedExternalNetwork(DataBroker dataBroker, String routerId) {
InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerId);
Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (routerData.isPresent()) {
Uuid networkId = routerData.get().getNetworkId();
if (networkId != null) {
return networkId.getValue();
}
}
LOG.info("getAssociatedExternalNetwork : External Network missing for routerid : {}", routerId);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class NatUtil method getExternalIpsLabelForRouter.
@Nonnull
public static Map<String, Long> getExternalIpsLabelForRouter(DataBroker dataBroker, Long routerId) {
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMappingOptional = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getIpMappingBuilder(routerId));
Map<String, Long> externalIpsLabel = new HashMap<>();
if (ipMappingOptional.isPresent()) {
List<IpMap> ipMaps = ipMappingOptional.get().getIpMap();
for (IpMap ipMap : ipMaps) {
externalIpsLabel.put(ipMap.getExternalIp(), ipMap.getLabel());
}
}
return externalIpsLabel;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class NatUtil method getRouterIdfromVpnInstance.
public static String getRouterIdfromVpnInstance(DataBroker broker, String vpnName) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(new Uuid(vpnName))).build();
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
Uuid routerId = optionalVpnMap.get().getRouterId();
if (routerId != null) {
return routerId.getValue();
}
}
LOG.info("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class NatUtil method getExternalIpPortMap.
public static IpPortExternal getExternalIpPortMap(DataBroker broker, Long routerId, String internalIpAddress, String internalPort, NAPTEntryEvent.Protocol protocol) {
ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
InstanceIdentifier<IpPortMap> ipPortMapId = buildIpToPortMapIdentifier(routerId, internalIpAddress, internalPort, protocolType);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, ipPortMapId).toJavaUtil().map(IpPortMap::getIpPortExternal).orElse(null);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class RouterDpnChangeListener method add.
@Override
protected void add(final InstanceIdentifier<DpnVpninterfacesList> identifier, final DpnVpninterfacesList dpnInfo) {
LOG.trace("add : key: {}, value: {}", dpnInfo.getKey(), dpnInfo);
final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
BigInteger 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) {
BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
if (naptSwitch == null || naptSwitch.equals(BigInteger.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;
}
natServiceManager.notify(router, naptSwitch, dpnId, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
} else {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + dpnInfo.getKey(), () -> {
WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
LOG.debug("add : Router {} is associated with ext nw {}", routerUuid, networkId);
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
Long routerId = NatUtil.getVpnId(dataBroker, routerUuid);
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (routerId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid routerId returned for routerName {}", routerUuid);
writeFlowInvTx.cancel();
removeFlowInvTx.cancel();
return futures;
}
extNetGroupInstaller.installExtNetGroupEntries(networkId, dpnId);
Long 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);
writeFlowInvTx.cancel();
removeFlowInvTx.cancel();
return futures;
}
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);
installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps()));
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, writeFlowInvTx);
} 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);
writeFlowInvTx.cancel();
removeFlowInvTx.cancel();
return futures;
}
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);
installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps()));
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, writeFlowInvTx);
}
if (router.isEnableSnat()) {
LOG.info("add : SNAT enabled for router {}", routerUuid);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (extNwProvType == null) {
LOG.error("add : External Network Provider Type missing");
writeFlowInvTx.cancel();
removeFlowInvTx.cancel();
return futures;
}
handleSNATForDPN(dpnId, routerUuid, routerId, vpnId, writeFlowInvTx, removeFlowInvTx, extNwProvType);
} else {
LOG.info("add : SNAT is not enabled for router {} to handle addDPN event {}", routerUuid, dpnId);
}
futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
return futures;
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
// end of controller based SNAT
}
} else {
LOG.debug("add : Router {} is not associated with External network", routerUuid);
}
}
Aggregations