use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping in project netvirt by opendaylight.
the class FloatingIPListener method buildSNATFlowEntity.
private FlowEntity buildSNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long vpnId, Uuid externalNetworkId) {
String internalIp = mapping.getInternalIp();
LOG.debug("buildSNATFlowEntity : Building SNAT Flow entity for ip {} ", internalIp);
ProviderTypes provType = NatUtil.getProviderTypefromNetworkId(dataBroker, externalNetworkId);
if (provType == null) {
LOG.error("buildSNATFlowEntity : Unable to get Network Provider Type for network {}", externalNetworkId);
return null;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(MatchEthernetType.IPV4);
String externalIp = mapping.getExternalIp();
matches.add(new MatchIpv4Source(externalIp, "32"));
List<ActionInfo> actionsInfo = new ArrayList<>();
Uuid floatingIpId = mapping.getExternalId();
String macAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (macAddress != null) {
actionsInfo.add(new ActionSetFieldEthernetSource(new MacAddress(macAddress)));
} else {
LOG.warn("buildSNATFlowEntity : No MAC address found for floating IP {}", externalIp);
}
LOG.trace("buildSNATFlowEntity : External Network Provider Type is {}, resubmit to FIB", provType.toString());
actionsInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfo));
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.SNAT_TABLE, vpnId, externalIp);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.SNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
return flowEntity;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping in project netvirt by opendaylight.
the class InterfaceStateEventListener method processInterfaceRemoved.
private void processInterfaceRemoved(String portName, BigInteger dpnId, String routerId, List<ListenableFuture<Void>> futures) {
LOG.trace("processInterfaceRemoved : Processing Interface Removed Event for interface {} on DPN ID {}", portName, dpnId);
List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
if (intExtPortMapList == null || intExtPortMapList.isEmpty()) {
LOG.debug("processInterfaceRemoved : Ip Mapping list is empty/null for portName {}", portName);
return;
}
InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
LOG.trace("processInterfaceRemoved : Removing DNAT Flow entries for dpnId {} ", dpnId);
floatingIPListener.removeNATFlowEntries(portName, intExtPortMap, portIid, routerId, dpnId, removeFlowInvTx);
}
// final submit call for removeFlowInvTx
futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping in project netvirt by opendaylight.
the class ExternalRoutersListener method allocateExternalIp.
private void allocateExternalIp(BigInteger dpnId, Routers router, long routerId, String routerName, Uuid networkId, String subnetIp, WriteTransaction writeFlowInvTx) {
String[] subnetIpParts = NatUtil.getSubnetIpAndPrefix(subnetIp);
try {
InetAddress address = InetAddress.getByName(subnetIpParts[0]);
if (address instanceof Inet6Address) {
LOG.debug("allocateExternalIp : Skipping ipv6 address {} for the router {}.", address, routerName);
return;
}
} catch (UnknownHostException e) {
LOG.error("allocateExternalIp : Invalid ip address {}", subnetIpParts[0], e);
return;
}
String leastLoadedExtIpAddr = NatUtil.getLeastLoadedExternalIp(dataBroker, routerId);
if (leastLoadedExtIpAddr != null) {
String[] externalIpParts = NatUtil.getExternalIpAndPrefix(leastLoadedExtIpAddr);
String leastLoadedExtIp = externalIpParts[0];
String leastLoadedExtIpPrefix = externalIpParts[1];
IPAddress externalIpAddr = new IPAddress(leastLoadedExtIp, Integer.parseInt(leastLoadedExtIpPrefix));
subnetIp = subnetIpParts[0];
String subnetIpPrefix = subnetIpParts[1];
IPAddress subnetIpAddr = new IPAddress(subnetIp, Integer.parseInt(subnetIpPrefix));
LOG.debug("allocateExternalIp : Add the IP mapping for the router ID {} and internal " + "IP {} and prefix {} -> external IP {} and prefix {}", routerId, subnetIp, subnetIpPrefix, leastLoadedExtIp, leastLoadedExtIpPrefix);
naptManager.registerMapping(routerId, subnetIpAddr, externalIpAddr);
// Check if external IP is already assigned a route. (i.e. External IP is previously
// allocated to any of the subnets)
// If external IP is already assigned a route, (, do not re-advertise to the BGP
String leastLoadedExtIpAddrStr = leastLoadedExtIp + "/" + leastLoadedExtIpPrefix;
Long label = checkExternalIpLabel(routerId, leastLoadedExtIpAddrStr);
if (label != null) {
// update
String internalIp = subnetIpParts[0] + "/" + subnetIpParts[1];
IpMapKey ipMapKey = new IpMapKey(internalIp);
LOG.debug("allocateExternalIp : Setting label {} for internalIp {} and externalIp {}", label, internalIp, leastLoadedExtIpAddrStr);
IpMap newIpm = new IpMapBuilder().setKey(ipMapKey).setInternalIp(internalIp).setExternalIp(leastLoadedExtIpAddrStr).setLabel(label).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, internalIp), newIpm);
return;
}
// Re-advertise to the BGP for the external IP, which is allocated to the subnet
// for the first time and hence not having a route.
// Get the VPN Name using the network ID
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (vpnName != null) {
LOG.debug("allocateExternalIp : Retrieved vpnName {} for networkId {}", vpnName, networkId);
if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
LOG.debug("allocateExternalIp : Best effort for getting primary napt switch when router i/f are" + "added after gateway-set");
dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
LOG.error("allocateExternalIp : dpnId is null or Zero for the router {}", routerName);
return;
}
}
advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, leastLoadedExtIp + "/" + leastLoadedExtIpPrefix, networkId, router, writeFlowInvTx);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping in project netvirt by opendaylight.
the class ExternalRoutersListener method handleEnableSnat.
public void handleEnableSnat(Routers routers, long routerId, BigInteger primarySwitchId, long bgpVpnId, WriteTransaction writeFlowInvTx) {
String routerName = routers.getRouterName();
LOG.info("handleEnableSnat : Handling SNAT for router {}", routerName);
naptManager.initialiseExternalCounter(routers, routerId);
subnetRegisterMapping(routers, routerId);
LOG.debug("handleEnableSnat:About to create and install outbound miss entry in Primary Switch {} for router {}", primarySwitchId, routerName);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, routers.getNetworkId());
if (extNwProvType == null) {
LOG.error("handleEnableSnat : External Network Provider Type missing");
return;
}
if (bgpVpnId != NatConstants.INVALID_ID) {
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, writeFlowInvTx, extNwProvType);
} else {
// write metadata and punt
installOutboundMissEntry(routerName, routerId, primarySwitchId, writeFlowInvTx);
// Now install entries in SNAT tables to point to Primary for each router
List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
for (BigInteger dpnId : switches) {
// Handle switches and NAPT switches separately
if (!dpnId.equals(primarySwitchId)) {
LOG.debug("handleEnableSnat : Handle Ordinary switch");
handleSwitches(dpnId, routerName, routerId, primarySwitchId);
} else {
LOG.debug("handleEnableSnat : Handle NAPT switch");
handlePrimaryNaptSwitch(dpnId, routerName, routerId, writeFlowInvTx);
}
}
}
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
if (externalIps.isEmpty()) {
LOG.error("handleEnableSnat : Internal External mapping not found for router {}", routerName);
return;
} else {
for (String externalIpAddrPrefix : externalIps) {
LOG.debug("handleEnableSnat : Calling handleSnatReverseTraffic for primarySwitchId {}, " + "routerName {} and externalIpAddPrefix {}", primarySwitchId, routerName, externalIpAddrPrefix);
handleSnatReverseTraffic(primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix, writeFlowInvTx);
}
}
LOG.debug("handleEnableSnat : Exit");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping in project netvirt by opendaylight.
the class ExternalSubnetVpnInstanceListener method add.
@Override
protected void add(InstanceIdentifier<VpnInstance> key, VpnInstance vpnInstance) {
LOG.trace("add : External Subnet VPN Instance OP Data Entry add mapping method - key:{}. value={}", vpnInstance.getKey(), vpnInstance);
String possibleExtSubnetUuid = vpnInstance.getVpnInstanceName();
Optional<Subnets> optionalSubnets = NatUtil.getOptionalExternalSubnets(dataBroker, new Uuid(possibleExtSubnetUuid));
if (optionalSubnets.isPresent()) {
LOG.debug("add : VpnInstance {} for external subnet {}.", possibleExtSubnetUuid, optionalSubnets.get());
addOrDelDefaultFibRouteToSNATFlow(vpnInstance, optionalSubnets.get(), NwConstants.ADD_FLOW);
invokeSubnetAddedToVpn(possibleExtSubnetUuid);
}
}
Aggregations