use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.
the class InterfaceStateEventListener method processInterfaceAdded.
private void processInterfaceAdded(String portName, String routerId, List<ListenableFuture<Void>> futures) {
LOG.trace("processInterfaceAdded : Processing Interface Add Event for interface {}", portName);
List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
if (intExtPortMapList == null || intExtPortMapList.isEmpty()) {
LOG.debug("processInterfaceAdded : Ip Mapping list is empty/null for portname {}", portName);
return;
}
InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
WriteTransaction installFlowInvTx = dataBroker.newWriteOnlyTransaction();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
floatingIPListener.createNATFlowEntries(portName, intExtPortMap, portIid, routerId, installFlowInvTx);
}
// final submit call for installFlowInvTx
futures.add(NatUtil.waitForTransactionToComplete(installFlowInvTx));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.
the class VpnFloatingIpHandler method onAddFloatingIp.
@Override
public void onAddFloatingIp(final BigInteger dpnId, final String routerUuid, final long routerId, final Uuid networkId, final String interfaceName, final InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
String externalIp = mapping.getExternalIp();
String internalIp = mapping.getInternalIp();
Uuid floatingIpId = mapping.getExternalId();
Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("onAddFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for " + "router {} to handle floatingIp {}", floatingIpId, routerUuid, externalIp);
return;
}
Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() : NatUtil.getAssociatedVPN(dataBroker, networkId);
final String subnetVpnName = externalSubnet.isPresent() ? subnetId.getValue() : null;
if (vpnName == null) {
LOG.error("onAddFloatingIp: No VPN is associated with ext nw {} to handle add floating ip {} configuration " + "for router {}", networkId, externalIp, routerId);
return;
}
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (rd == null) {
LOG.error("onAddFloatingIp: Unable to retrieve external (internet) VPN RD from external VPN {} for " + "router {} to handle floatingIp {}", vpnName, routerId, externalIp);
return;
}
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (provType == null) {
return;
}
/*
* For external network of type GRE, it is required to use "Internet VPN VNI" for intra-DC
* communication, but we still require "MPLS labels" to reach SNAT/DNAT VMs from external
* entities via MPLSOverGRE.
*
* MPLSOverGRE based external networks, the ``opendaylight-vni-ranges`` pool will be
* used to carve out a unique VNI per Internet VPN (GRE-provider-type) to be used in the
* datapath for traffic forwarding for ``SNAT-to-DNAT`` and ``DNAT-to-DNAT`` cases within the
* DataCenter.
*/
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager, NatConstants.ODL_VNI_POOL_NAME);
}
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
LOG.debug("onAddFloatingIp: Nexthop ip for prefix {} is {}", externalIp, nextHopIp);
if (provType == ProviderTypes.VXLAN) {
Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
evpnDnatFlowProgrammer.onAddFloatingIp(dpnId, routerUuid, routerId, vpnName, internalIp, externalIp, networkId, interfaceName, floatingIpInterface.getValue(), floatingIpPortMacAddress, rd, nextHopIp, writeFlowInvTx);
return;
}
/*
* MPLS label will be used to advertise prefixes and in "L3_LFIB_TABLE" (table 20) taking the packet
* to "INBOUND_NAPT_TABLE" (table 44) and "PDNAT_TABLE" (table 25).
*/
GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);
ListenableFuture<RpcResult<Void>> future = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(labelFuture), (AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>) result -> {
if (result.isSuccessful()) {
GenerateVpnLabelOutput output = result.getResult();
long label = output.getLabel();
LOG.debug("onAddFloatingIp : Generated label {} for prefix {}", label, externalIp);
FloatingIPListener.updateOperationalDS(dataBroker, routerUuid, interfaceName, label, internalIp, externalIp);
long l3vni = 0;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, subnetId, fibExternalIp, nextHopIp, networkId.getValue(), floatingIpPortMacAddress, label, l3vni, RouteOrigin.STATIC, dpnId);
List<Instruction> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
makeTunnelTableEntry(vpnName, dpnId, label, instructions, writeFlowInvTx, provType);
List<ActionInfo> actionInfoFib = new ArrayList<>();
List<Instruction> customInstructions = new ArrayList<>();
actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
customInstructions.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE, writeFlowInvTx);
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(customInstructions).build();
Future<RpcResult<Void>> future1 = fibService.createFibEntry(input);
LOG.debug("onAddFloatingIp : Add Floating Ip {} , found associated to fixed port {}", externalIp, interfaceName);
String networkVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
vpnManager.addSubnetMacIntoVpnInstance(networkVpnName, subnetVpnName, floatingIpPortMacAddress, dpnId, tx);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerUuid, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId, tx);
});
return JdkFutureAdapters.listenInPoolThread(future1);
} else {
String errMsg = String.format("onAddFloatingIp : Could not retrieve the label for prefix %s " + "in VPN %s, %s", externalIp, vpnName, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
}, MoreExecutors.directExecutor());
Futures.addCallback(future, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("onAddFloatingIp : Error in generate label or fib install process", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for prefix {}", externalIp);
} else {
LOG.error("onAddFloatingIp : Error in rpc call to create custom Fib entries for prefix {} " + "in DPN {}, {}", externalIp, dpnId, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
// Handle GARP transmission
final IpAddress extrenalAddress = IpAddressBuilder.getDefaultInstance(externalIp);
sendGarpOnInterface(dpnId, networkId, extrenalAddress, floatingIpPortMacAddress);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.
the class NatRpcServiceImpl method constructNatInformation.
private List<RouterNat> constructNatInformation(Uuid routerUuid, long routerId) {
String neutronRouterName = NatUtil.getNeutronRouterNamebyUuid(dataBroker, routerUuid);
RouterNatBuilder natRouterBuilder = new RouterNatBuilder();
natRouterBuilder.setRouterUuid(routerUuid);
natRouterBuilder.setRouterName(neutronRouterName);
IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
if (ipPortMapping == null) {
LOG.warn("constructNatInformation : No SNAT IP Mapping found for router-uuid {}", routerUuid.getValue());
} else {
// Capturing SNAT information
List<SnatIpMapping> snatIpMapping = new ArrayList<SnatIpMapping>();
for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
String[] internalPortMap = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
SnatIpMappingBuilder natIpMappingBuilder = new SnatIpMappingBuilder().setInternalIp(internalPortMap[0]).setInternalPort(internalPortMap[1]).setExternalIp(ipPortMap.getIpPortExternal().getIpAddress()).setExternalPort(ipPortMap.getIpPortExternal().getPortNum().toString()).setProtocol(protocolType.getProtocol().getName());
snatIpMapping.add(natIpMappingBuilder.build());
}
}
natRouterBuilder.setSnatIpMapping(snatIpMapping);
}
// Capturing DNAT information
List<DnatIpMapping> dnatIpMapping = new ArrayList<DnatIpMapping>();
List<Ports> fipPorts = NatUtil.getFloatingIpPortsForRouter(dataBroker, routerUuid);
if (fipPorts.isEmpty()) {
LOG.warn("constructNatInformation : No DNAT IP Mapping found for router-uuid {}", routerUuid.getValue());
} else {
for (Ports fipPort : fipPorts) {
List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
for (InternalToExternalPortMap fipMap : ipMapping) {
DnatIpMappingBuilder natIpMappingBuilder = new DnatIpMappingBuilder().setExternalIp(fipMap.getExternalIp()).setInternalIp(fipMap.getInternalIp());
dnatIpMapping.add(natIpMappingBuilder.build());
}
}
natRouterBuilder.setDnatIpMapping(dnatIpMapping);
}
List<RouterNat> natRouterList = new ArrayList<RouterNat>();
natRouterList.add(natRouterBuilder.build());
return natRouterList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method clearFromFloatingIpInfo.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void clearFromFloatingIpInfo(String routerName, String fixedNeutronPortName, String fixedIpAddress) {
boolean isLockAcquired = false;
InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName));
try {
Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
if (optionalRouterPorts.isPresent()) {
RouterPorts routerPorts = optionalRouterPorts.get();
List<Ports> portsList = routerPorts.getPorts();
List<InternalToExternalPortMap> intExtPortMap = new ArrayList<>();
for (Ports ports : portsList) {
if (ports.getPortName().equals(fixedNeutronPortName)) {
intExtPortMap = ports.getInternalToExternalPortMap();
break;
}
}
if (intExtPortMap.size() == 1) {
removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, portsList, fixedNeutronPortName, isLockAcquired);
} else {
for (InternalToExternalPortMap intToExtMap : intExtPortMap) {
if (intToExtMap.getInternalIp().equals(fixedIpAddress)) {
InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(fixedIpAddress)).build();
try {
// remove particular internal-to-external-port-map
isLockAcquired = routerLock.tryLock(fixedIpAddress, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("removing particular internal-to-external-port-map {}", intExtPortMap);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intExtPortMapIdentifier);
} catch (Exception e) {
LOG.error("Failure in deletion of internal-to-external-port-map {}", intExtPortMap, e);
} finally {
if (isLockAcquired) {
routerLock.unlock(fixedIpAddress);
}
}
}
}
}
LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
} else {
LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
}
} catch (RuntimeException | ReadFailedException e) {
LOG.error("Failed to delete internal-to-external-port-map from FloatingIpInfo DS for fixed Ip {}", fixedIpAddress, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method addToFloatingIpInfo.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addToFloatingIpInfo(String routerName, Uuid extNetworkId, String fixedNeutronPortName, String fixedIpAddress, String floatingIpAddress, Uuid floatingIpId) {
RouterPortsBuilder routerPortsBuilder;
boolean isLockAcquired = false;
InstanceIdentifier<RouterPorts> routerPortsIdentifier = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName)).build();
try {
Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier);
if (optionalRouterPorts.isPresent()) {
LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
} else {
LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
routerPortsBuilder = new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName);
}
if (extNetworkId != null) {
routerPortsBuilder.setExternalNetworkId(extNetworkId);
}
if (fixedNeutronPortName != null) {
List<Ports> portsList = routerPortsBuilder.getPorts();
if (portsList == null) {
portsList = new ArrayList<>();
}
PortsBuilder fixedNeutronPortBuilder = null;
for (Ports neutronPort : portsList) {
if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
fixedNeutronPortBuilder = new PortsBuilder(neutronPort);
break;
}
}
if (fixedNeutronPortBuilder == null) {
fixedNeutronPortBuilder = new PortsBuilder().setKey(new PortsKey(fixedNeutronPortName)).setPortName(fixedNeutronPortName);
}
if (fixedIpAddress != null) {
List<InternalToExternalPortMap> intExtPortMapList = fixedNeutronPortBuilder.getInternalToExternalPortMap();
if (intExtPortMapList == null) {
intExtPortMapList = new ArrayList<>();
}
InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().setKey(new InternalToExternalPortMapKey(fixedIpAddress)).setInternalIp(fixedIpAddress).setExternalIp(floatingIpAddress).setExternalId(floatingIpId).setLabel(null).build();
intExtPortMapList.add(intExtPortMap);
fixedNeutronPortBuilder.setInternalToExternalPortMap(intExtPortMapList);
}
portsList.add(fixedNeutronPortBuilder.build());
routerPortsBuilder.setPorts(portsList);
}
isLockAcquired = routerLock.tryLock(routerName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier, routerPortsBuilder.build());
LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
} catch (ReadFailedException | RuntimeException e) {
LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress, e);
} finally {
if (isLockAcquired) {
routerLock.unlock(routerName);
}
}
}
Aggregations