use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class NatUtil method installRouterGwFlows.
public static void installRouterGwFlows(DataBroker dataBroker, IVpnManager vpnManager, Routers router, BigInteger primarySwitchId, int addOrRemove) {
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
List<ExternalIps> externalIps = router.getExternalIps();
List<String> externalIpsSting = new ArrayList<>();
if (externalIps.isEmpty()) {
LOG.error("installRouterGwFlows: setupRouterGwFlows no externalIP present");
return;
}
for (ExternalIps externalIp : externalIps) {
externalIpsSting.add(externalIp.getIpAddress());
}
Uuid subnetVpnName = externalIps.get(0).getSubnetId();
if (addOrRemove == NwConstants.ADD_FLOW) {
vpnManager.addRouterGwMacFlow(router.getRouterName(), router.getExtGwMacAddress(), primarySwitchId, router.getNetworkId(), subnetVpnName.getValue(), writeTx);
vpnManager.addArpResponderFlowsToExternalNetworkIps(router.getRouterName(), externalIpsSting, router.getExtGwMacAddress(), primarySwitchId, router.getNetworkId(), writeTx);
} else {
vpnManager.removeRouterGwMacFlow(router.getRouterName(), router.getExtGwMacAddress(), primarySwitchId, router.getNetworkId(), subnetVpnName.getValue(), writeTx);
vpnManager.removeArpResponderFlowsToExternalNetworkIps(router.getRouterName(), externalIpsSting, router.getExtGwMacAddress(), primarySwitchId, router.getNetworkId());
}
writeTx.submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class NatUtil method getExternalSubnetForRouterExternalIp.
protected static Uuid getExternalSubnetForRouterExternalIp(String externalIpAddress, Routers router) {
externalIpAddress = validateAndAddNetworkMask(externalIpAddress);
List<ExternalIps> externalIps = router.getExternalIps();
for (ExternalIps extIp : externalIps) {
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.netvirt.natservice.rev160111.ext.routers.Routers 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.netvirt.natservice.rev160111.ext.routers.Routers 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class VxlanGreConntrackBasedSnatService method handleSnat.
@Override
public boolean handleSnat(Routers routers, BigInteger primarySwitchId, BigInteger dpnId, int addOrRemove) {
ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, routers.getNetworkId());
LOG.debug("VxlanGreConntrackBasedSnatService: handleSnat ProviderTypes {}", extNwProviderType);
if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
return false;
}
return super.handleSnat(routers, primarySwitchId, dpnId, addOrRemove);
}
Aggregations