use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.
the class NatUtil method removePreDnatToSnatTableEntry.
public static void removePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, BigInteger naptDpnId, WriteTransaction removeFlowInvTx) {
LOG.debug("removePreDnatToSnatTableEntry : Remove Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ", NwConstants.PDNAT_TABLE, NwConstants.INBOUND_NAPT_TABLE, naptDpnId);
String flowRef = getFlowRefPreDnatToSnat(naptDpnId, NwConstants.PDNAT_TABLE, "PreDNATToSNAT");
Flow preDnatToSnatTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.PDNAT_TABLE, flowRef, 5, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, null, null);
mdsalManager.removeFlowToTx(naptDpnId, preDnatToSnatTableFlowEntity, removeFlowInvTx);
LOG.debug("removePreDnatToSnatTableEntry: Successfully removed Pre-DNAT flow {} on NAPT DpnId = {}", preDnatToSnatTableFlowEntity, naptDpnId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.
the class RouterDpnChangeListener method removeSNATFromDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId, Uuid extNetworkId, WriteTransaction removeFlowInvTx) {
// irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
// remove miss entry to NAPT switch
// if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
if (extNwProvType == null) {
return;
}
// Get the external IP labels other than VXLAN provider type. Since label is not applicable for VXLAN
Map<String, Long> externalIpLabel;
if (extNwProvType == ProviderTypes.VXLAN) {
externalIpLabel = null;
} else {
externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
}
BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
return;
}
try {
boolean naptStatus = naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, removeFlowInvTx);
if (!naptStatus) {
LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}", dpnId, routerName);
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
FlowEntity flowEntity = null;
try {
flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.DEL_FLOW);
if (flowEntity == null) {
LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} " + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
return;
}
LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
// remove group
GroupEntity groupEntity = null;
try {
groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
mdsalManager.removeGroup(groupEntity);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}", dpnId, routerName);
} else {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch, externalIpLabel, removeFlowInvTx);
// remove table 26 flow ppointing to table46
FlowEntity flowEntity = null;
try {
flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.DEL_FLOW);
if (flowEntity == null) {
LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with " + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
// best effort to check IntExt model
naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, removeFlowInvTx);
}
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.
the class FloatingIPListener method removeNATFlowEntries.
void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId, WriteTransaction removeFlowInvTx) {
String internalIp = mapping.getInternalIp();
String externalIp = mapping.getExternalIp();
// Get the DPN on which this interface resides
if (dpnId == null) {
dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.warn("removeNATFlowEntries: Abort processing Floating ip configuration. No DPN for port: {}", interfaceName);
return;
}
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeNATFlowEntries : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
return;
}
// Delete the DNAT and SNAT table entries
removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
if (extNwId == null) {
LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
return;
}
long vpnId = getVpnId(extNwId, mapping.getExternalId());
if (vpnId < 0) {
LOG.error("removeNATFlowEntries : No VPN associated with ext nw {}. Unable to delete SNAT table " + "entry for fixed ip {}", extNwId, internalIp);
return;
}
removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
// Remove the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
if (!isSnatEnabled) {
addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, removeFlowInvTx, false);
}
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
if (provType == null) {
LOG.error("removeNATFlowEntries : External Network Provider Type missing");
return;
}
if (provType == ProviderTypes.VXLAN) {
floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, NatConstants.DEFAULT_L3VNI_VALUE, removeFlowInvTx);
removeOperationalDS(routerName, interfaceName, internalIp);
return;
}
long label = getOperationalIpMapping(routerName, interfaceName, internalIp);
if (label < 0) {
LOG.error("removeNATFlowEntries : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
return;
}
floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, (int) label, removeFlowInvTx);
removeOperationalDS(routerName, interfaceName, internalIp);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.
the class FloatingIPListener method createNATFlowEntries.
void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, final InstanceIdentifier<RouterPorts> portIid, final String routerName, WriteTransaction writeFlowInvTx) {
if (!validateIpMapping(mapping)) {
LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
return;
}
// Get the DPN on which this interface resides
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.warn("createNATFlowEntries : No DPN for interface {}. NAT flow entries for ip mapping {} will " + "not be installed", interfaceName, mapping);
return;
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("createNATFlowEntries : Could not retrieve router id for {} to create NAT Flow entries", routerName);
return;
}
// Check if the router to vpn association is present
// long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
long associatedVpnId = NatConstants.INVALID_ID;
if (associatedVpn == null) {
LOG.debug("createNATFlowEntries : Router {} is not assicated with any BGP VPN instance", routerName);
} else {
LOG.debug("createNATFlowEntries : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
LOG.debug("createNATFlowEntries : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
// routerId = associatedVpnId;
}
Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.CONFIGURATION);
if (extNwId == null) {
LOG.error("createNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
return;
}
long vpnId = getVpnId(extNwId, mapping.getExternalId());
if (vpnId < 0) {
LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
return;
}
// Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
if (!isSnatEnabled) {
addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, writeFlowInvTx, true);
}
// Create the DNAT and SNAT table entries
createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, writeFlowInvTx);
createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, writeFlowInvTx);
floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, writeFlowInvTx);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.
the class InterfaceStateEventListener method removeSnatEntriesForPort.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void removeSnatEntriesForPort(String interfaceName, String routerName) {
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntriesForPort : routerId not found for routername {}", routerName);
return;
}
BigInteger naptSwitch = getNaptSwitchforRouter(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
LOG.error("removeSnatEntriesForPort : NaptSwitch is not elected for router {} with Id {}", routerName, routerId);
return;
}
// getInternalIp for port
List<String> fixedIps = getFixedIpsForPort(interfaceName);
if (fixedIps == null) {
LOG.warn("removeSnatEntriesForPort : Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
return;
}
for (String internalIp : fixedIps) {
LOG.debug("removeSnatEntriesForPort : Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
IpPort ipPort = NatUtil.getInternalIpPortInfo(dataBroker, routerId, internalIp);
if (ipPort == null) {
LOG.debug("removeSnatEntriesForPort : no snatint-ip-port-map found for ip:{}", internalIp);
continue;
}
for (IntIpProtoType protoType : ipPort.getIntIpProtoType()) {
ProtocolTypes protocol = protoType.getProtocol();
for (Integer portnum : protoType.getPorts()) {
// build and remove the flow in outbound table
try {
removeNatFlow(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum);
} catch (Exception ex) {
LOG.error("removeSnatEntriesForPort : Failed to remove snat flow for internalIP {} with " + "Port {} protocol {} for routerId {} in OUTBOUNDTABLE of NaptSwitch {}", internalIp, portnum, protocol, routerId, naptSwitch, ex);
}
// Get the external IP address and the port from the model
NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum), proto);
if (ipPortExternal == null) {
LOG.error("removeSnatEntriesForPort : Mapping for internalIp {} with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
return;
}
String externalIpAddress = ipPortExternal.getIpAddress();
Integer portNumber = ipPortExternal.getPortNum();
// build and remove the flow in inboundtable
try {
removeNatFlow(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, externalIpAddress, portNumber);
} catch (Exception ex) {
LOG.error("removeSnatEntriesForPort : Failed to remove snat flow internalIP {} with " + "Port {} protocol {} for routerId {} in INBOUNDTABLE of naptSwitch {}", externalIpAddress, portNumber, protocol, routerId, naptSwitch, ex);
}
String internalIpPort = internalIp + ":" + portnum;
// delete the entry from IntExtIpPortMap DS
try {
naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
naptManager.removePortFromPool(internalIpPort, externalIpAddress);
} catch (Exception ex) {
LOG.error("removeSnatEntriesForPort : releaseIpExtPortMapping failed, Removal of " + "ipportmap {} for router {} failed", internalIpPort, routerId, ex);
}
}
}
// delete the entry from SnatIntIpPortMap DS
LOG.debug("removeSnatEntriesForPort : Removing InternalIp:{} on router {}", internalIp, routerId);
naptManager.removeFromSnatIpPortDS(routerId, internalIp);
}
}
Aggregations