use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NatTunnelInterfaceStateListener method hndlTepAddForDnatInEachRtr.
private void hndlTepAddForDnatInEachRtr(RoutersList router, long routerId, String nextHopIp, BigInteger tepAddedDpnId, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
// DNAT : Advertise the new route to the floating IP having the new TEP IP as the next hop IP
final String routerName = router.getRouter();
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatinIpInfo", routerName);
return;
}
RouterPorts routerPorts = optRouterPorts.get();
Uuid extNwId = routerPorts.getExternalNetworkId();
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
if (vpnName == null) {
LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> No External VPN associated with ext nw {} for router {}", extNwId, routerName);
return;
}
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (extNwProvType == null) {
return;
}
String gwMacAddress = null;
long l3Vni = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
// Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (gwMacAddress != null) {
LOG.debug("hndlTepAddForDnatInEachRtr : External GwMAC address {} found for External Router ID {}", gwMacAddress, routerId);
} else {
LOG.error("hndlTepAddForDnatInEachRtr : No External GwMAC address found for External Router ID {}", routerId);
return;
}
// get l3Vni value for external VPN
l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("hndlTepAddForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
}
List<Ports> interfaces = routerPorts.getPorts();
for (Ports port : interfaces) {
// Get the DPN on which this interface resides
final String interfaceName = port.getPortName();
final BigInteger fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
if (fipCfgdDpnId.equals(BigInteger.ZERO)) {
LOG.info("hndlTepAddForDnatInEachRtr : DNAT->Skip processing Floating ip configuration for the port {}," + "since no DPN present for it", interfaceName);
continue;
}
if (!fipCfgdDpnId.equals(tepAddedDpnId)) {
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> TEP added DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepAddedDpnId, fipCfgdDpnId, interfaceName);
continue;
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
final String internalIp = intExtPortMap.getInternalIp();
final String externalIp = intExtPortMap.getExternalIp();
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertising the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
long serviceId = 0;
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
if (extNwProvType == ProviderTypes.VXLAN) {
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress, writeFlowInvTx, RouteOrigin.STATIC, fipCfgdDpnId);
serviceId = l3Vni;
} else {
long label = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
if (label == NatConstants.INVALID_ID) {
LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Unable to advertise to the DC GW since label " + "is invalid");
return;
}
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
long l3vni = 0;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
}
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, null, fibExternalIp, nextHopIp, null, null, label, l3vni, RouteOrigin.STATIC, fipCfgdDpnId);
serviceId = label;
}
// Install custom FIB routes (Table 21 -> Push MPLS label to Tunnel port
List<Instruction> customInstructions = new ArrayList<>();
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(serviceId).setInstruction(customInstructions).build();
Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Error in generate label or fib install process", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> Successfully installed custom FIB routes " + "for prefix {}", externalIp);
} else {
LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Error in rpc call to create custom Fib " + "entries for prefix {} in DPN {}, {}", externalIp, fipCfgdDpnId, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NatTunnelInterfaceStateListener method hndlTepDelForDnatInEachRtr.
private void hndlTepDelForDnatInEachRtr(RoutersList router, long routerId, BigInteger tepDeletedDpnId, ProviderTypes extNwProvType) {
// DNAT : Withdraw the routes from the BGP
String routerName = router.getRouter();
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Trying to clear routes to the Floating IP " + "associated to the router {}", routerName);
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatingIpInfo", routerName);
return;
}
RouterPorts routerPorts = optRouterPorts.get();
Uuid extNwId = routerPorts.getExternalNetworkId();
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
if (vpnName == null) {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> No External VPN associated with Ext N/W {} for Router {}", extNwId, routerName);
return;
}
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (extNwProvType == null) {
return;
}
long l3Vni = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
// get l3Vni value for external VPN
l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("hndlTepDelForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
}
List<Ports> interfaces = routerPorts.getPorts();
for (Ports port : interfaces) {
// Get the DPN on which this interface resides
String interfaceName = port.getPortName();
BigInteger fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
if (fipCfgdDpnId.equals(BigInteger.ZERO)) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Abort processing Floating ip configuration. " + "No DPN for port : {}", interfaceName);
continue;
}
if (!fipCfgdDpnId.equals(tepDeletedDpnId)) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> TEP deleted DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepDeletedDpnId, fipCfgdDpnId, interfaceName);
continue;
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
String internalIp = intExtPortMap.getInternalIp();
String externalIp = intExtPortMap.getExternalIp();
externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Withdrawing the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName, LOG);
long serviceId = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
serviceId = l3Vni;
} else {
long label = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
if (label == NatConstants.INVALID_ID) {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Unable to remove the table 21 entry pushing the" + " MPLS label to the tunnel since label is invalid");
return;
}
serviceId = label;
}
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp).setServiceId(serviceId).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
Future<RpcResult<Void>> future = fibRpcService.removeFibEntry(input);
ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in removing the table 21 entry pushing " + "the MPLS label to the tunnel since label is invalid ", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Successfully removed the entry pushing the " + "MPLS label to the tunnel");
} else {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in fib rpc call to remove the table " + "21 entry pushing the MPLS label to the tunnnel due to {}", result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class RouterToVpnListener method handleDNATConfigurationForRouterAssociation.
void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork) {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.debug("handleDNATConfigurationForRouterAssociation : Could not read Router Ports data " + "object with id: {} to handle associate vpn {}", routerName, vpnName);
return;
}
Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
RouterPorts routerPorts = optRouterPorts.get();
List<Ports> interfaces = routerPorts.getPorts();
for (Ports port : interfaces) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.warn("handleDNATConfigurationForRouterAssociation : DPN not found for {}, " + "skip handling of router {} association with vpn {}", portName, routerName, vpnName);
continue;
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
// remove all NAT related entries with routerName
// floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, null,
// intExtPortMap.getInternalIp(), externalIp);
// Create NAT entries with VPN Id
LOG.debug("handleDNATConfigurationForRouterAssociation : Updating DNAT flows with VPN metadata {} ", vpnName);
floatingIpListener.createNATOnlyFlowEntries(dpnId, routerName, vpnName, networkId, intExtPortMap);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class RouterToVpnListener method handleDNATConfigurationForRouterDisassociation.
void handleDNATConfigurationForRouterDisassociation(String routerName, String vpnName, String externalNetwork) {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.error("handleDNATConfigurationForRouterDisassociation : Could not read Router Ports " + "data object with id: {} to handle disassociate vpn {}", routerName, vpnName);
return;
}
Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
RouterPorts routerPorts = optRouterPorts.get();
List<Ports> interfaces = routerPorts.getPorts();
for (Ports port : interfaces) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.debug("handleDNATConfigurationForRouterDisassociation : DPN not found for {}, " + "skip handling of router {} association with vpn {}", portName, routerName, vpnName);
continue;
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
// remove all NAT related entries with routerName
// floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, vpnName,
// intExtPortMap.getInternalIp(), externalIp);
// Create NAT entries with VPN Id
floatingIpListener.createNATOnlyFlowEntries(dpnId, routerName, null, networkId, intExtPortMap);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class FloatingIPListener method updateOperationalDS.
static void updateOperationalDS(DataBroker dataBroker, String routerId, String interfaceName, long label, String internalIp, String externalIp) {
LOG.info("updateOperationalDS : Updating operational DS for floating ip config : {} with label {}", internalIp, label);
InstanceIdentifier<Ports> portsId = NatUtil.getPortsIdentifier(routerId, interfaceName);
Optional<Ports> optPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId);
InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().setKey(new InternalToExternalPortMapKey(internalIp)).setInternalIp(internalIp).setExternalIp(externalIp).setLabel(label).build();
if (optPorts.isPresent()) {
LOG.debug("updateOperationalDS : Ports {} entry already present. Updating intExtPortMap for internal ip {}", interfaceName, internalIp);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId.child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(internalIp)), intExtPortMap);
} else {
LOG.debug("updateOperationalDS : Adding Ports entry {} along with intExtPortMap {}", interfaceName, internalIp);
List<InternalToExternalPortMap> intExtPortMapList = new ArrayList<>();
intExtPortMapList.add(intExtPortMap);
Ports ports = new PortsBuilder().setKey(new PortsKey(interfaceName)).setPortName(interfaceName).setInternalToExternalPortMap(intExtPortMapList).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId, ports);
}
}
Aggregations