use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method handlePacketToExternalNetwork.
private void handlePacketToExternalNetwork(Uuid vpnInstanceNameUuid, String routerId, byte[] dstIp, long elanTag) throws UnknownHostException {
Routers externalRouter = VpnUtil.getExternalRouter(dataBroker, routerId);
if (externalRouter == null) {
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.debug("{} handlePacketToExternalNetwork: Can't find external router with id {}", LOGGING_PREFIX, routerId);
return;
}
List<ExternalIps> externalIps = externalRouter.getExternalIps();
if (externalIps == null || externalIps.isEmpty()) {
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have any external ips.", LOGGING_PREFIX, externalRouter.getRouterName());
return;
}
java.util.Optional<ExternalIps> externalIp = externalRouter.getExternalIps().stream().filter(eip -> vpnInstanceNameUuid.equals(eip.getSubnetId())).findFirst();
if (!externalIp.isPresent()) {
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have an external ip for subnet id {}.", LOGGING_PREFIX, externalRouter.getRouterName(), vpnInstanceNameUuid);
return;
}
BigInteger dpnId = centralizedSwitchProvider.getPrimarySwitchForRouter(externalRouter.getRouterName());
if (BigInteger.ZERO.equals(dpnId)) {
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.debug("{} handlePacketToExternalNetwork: Could not find primary switch for router {}.", LOGGING_PREFIX, externalRouter.getRouterName());
return;
}
transmitArpPacket(dpnId, externalIp.get().getIpAddress(), externalRouter.getExtGwMacAddress(), dstIp, elanTag);
return;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class CentralizedSwitchChangeListener method setupRouterGwFlows.
private void setupRouterGwFlows(RouterToNaptSwitch routerToNaptSwitch, WriteTransaction writeTx, int addOrRemove) {
Routers router = VpnUtil.getExternalRouter(dataBroker, routerToNaptSwitch.getRouterName());
if (router == null) {
LOG.warn("No router data found for router id {}", routerToNaptSwitch.getRouterName());
return;
}
BigInteger primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
Uuid extNetworkId = router.getNetworkId();
String extGwMacAddress = router.getExtGwMacAddress();
String routerName = router.getRouterName();
List<ExternalIps> externalIps = router.getExternalIps();
if (externalIps.isEmpty()) {
LOG.error("CentralizedSwitchChangeListener: setupRouterGwFlows no externalIP present");
return;
}
Uuid subnetVpnName = externalIps.get(0).getSubnetId();
if (addOrRemove == NwConstants.ADD_FLOW) {
vpnManager.addRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId, subnetVpnName.getValue(), writeTx);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), extGwMacAddress, primarySwitchId, extNetworkId, writeTx);
} else {
vpnManager.removeRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId, subnetVpnName.getValue(), writeTx);
vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), extGwMacAddress, primarySwitchId, extNetworkId);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method removeSnatEntries.
private void removeSnatEntries(Networks original, Uuid networkUuid, WriteTransaction writeFlowInvTx) {
List<Uuid> routerUuids = original.getRouterIds();
for (Uuid routerUuid : routerUuids) {
Long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntries : Invalid routerId returned for routerName {}", routerUuid.getValue());
return;
}
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
if (natMode == NatMode.Controller) {
externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId, networkUuid, externalIps, original.getVpnid().getValue(), writeFlowInvTx);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class ExternalRoutersListener method handleDisableSnatInternetVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleDisableSnatInternetVpn(String routerName, long routerId, Uuid networkUuid, @Nonnull Collection<String> externalIps, String vpnId, WriteTransaction writeFlowInvTx) {
LOG.debug("handleDisableSnatInternetVpn: Started to process handle disable snat for router {} " + "with internet vpn {}", routerName, vpnId);
try {
BigInteger naptSwitchDpnId = null;
InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerName);
Optional<RouterToNaptSwitch> rtrToNapt = read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
if (rtrToNapt.isPresent()) {
naptSwitchDpnId = rtrToNapt.get().getPrimarySwitchId();
}
LOG.debug("handleDisableSnatInternetVpn : got primarySwitch as dpnId{} ", naptSwitchDpnId);
removeNaptFlowsFromActiveSwitchInternetVpn(routerId, routerName, naptSwitchDpnId, networkUuid, vpnId, writeFlowInvTx);
try {
String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (extGwMacAddress != null) {
LOG.debug("handleDisableSnatInternetVpn : External Gateway MAC address {} found for " + "External Router ID {}", extGwMacAddress, routerId);
} else {
LOG.error("handleDisableSnatInternetVpn : No External Gateway MAC address found for " + "External Router ID {}", routerId);
return;
}
clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, vpnId, extGwMacAddress, writeFlowInvTx);
} catch (Exception ex) {
LOG.error("handleDisableSnatInternetVpn : Failed to remove fib entries for routerId {} " + "in naptSwitchDpnId {}", routerId, naptSwitchDpnId, ex);
}
NatOverVxlanUtil.releaseVNI(vpnId, idManager);
} catch (Exception ex) {
LOG.error("handleDisableSnatInternetVpn: Exception while handling disableSNATInternetVpn for router {} " + "with internet vpn {}", routerName, vpnId, ex);
}
LOG.debug("handleDisableSnatInternetVpn: Processed handle disable snat for router {} with internet vpn {}", routerName, vpnId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps 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");
}
Aggregations