use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class FloatingIPListener method removeNATFlowEntries.
void removeNATFlowEntries(BigInteger dpnId, String interfaceName, String vpnName, String routerName, InternalToExternalPortMap mapping, WriteTransaction removeFlowInvTx) {
String internalIp = mapping.getInternalIp();
String externalIp = mapping.getExternalIp();
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;
}
long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
if (vpnId == NatConstants.INVALID_ID) {
LOG.warn("removeNATFlowEntries : VPN Id not found for {} to remove NAT flow entries {}", vpnName, internalIp);
}
// Delete the DNAT and SNAT table entries
removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
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);
}
Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
if (provType == null) {
LOG.error("removeNATFlowEntries : External Network Provider Type Missing");
return;
}
if (provType == ProviderTypes.VXLAN) {
floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, NatConstants.DEFAULT_L3VNI_VALUE, removeFlowInvTx, provType);
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.cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
removeOperationalDS(routerName, interfaceName, internalIp);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes 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.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class ExternalRoutersListener method removeNaptFlowsFromActiveSwitch.
public void removeNaptFlowsFromActiveSwitch(long routerId, String routerName, BigInteger dpnId, Uuid networkId, String vpnName, @Nonnull Collection<String> externalIps, Collection<Uuid> externalSubnetList, WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
// Remove the PSNAT entry which forwards the packet to Outbound NAPT Table (For the
// traffic which comes from the VMs of the NAPT switches)
String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, routerName);
FlowEntity preSnatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} " + "and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
mdsalManager.removeFlowToTx(preSnatFlowEntity, removeFlowInvTx);
// Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table (For the
// traffic which comes from the VMs of the non NAPT switches)
long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
String tsFlowRef = getFlowRefTs(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tunnelId);
FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} " + "and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, dpnId, routerId);
mdsalManager.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
// Remove the flow table 25->44 from NAPT Switch
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
}
// Remove the Outbound flow entry which forwards the packet to FIB Table
String outboundNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
FlowEntity outboundNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, outboundNatFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {}" + " and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
mdsalManager.removeFlowToTx(outboundNatFlowEntity, removeFlowInvTx);
removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, removeFlowInvTx);
// External Subnet Vpn Id.
for (Uuid externalSubnetId : externalSubnetList) {
long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
if (subnetVpnId != -1) {
String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibSubnetFlowRef);
mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
LOG.debug("removeNaptFlowsFromActiveSwitch : Removed the flow in table {} with external subnet " + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE, subnetVpnId, dpnId);
}
}
// Remove the NAPT PFIB TABLE which forwards the incoming packet to FIB Table matching on the router ID.
String natPfibFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId);
FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} " + "and router ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId);
mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
// Long vpnId = NatUtil.getVpnId(dataBroker, routerId);
// - This does not work since ext-routers is deleted already - no network info
// Get the VPN ID from the ExternalNetworks model
long vpnId = -1;
if (vpnName == null || vpnName.isEmpty()) {
// ie called from router delete cases
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
LOG.debug("removeNaptFlowsFromActiveSwitch : vpnUuid is {}", vpnUuid);
if (vpnUuid != null) {
vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId {} for external network {} router delete or " + "disableSNAT scenario", vpnId, networkId);
}
} else {
// ie called from disassociate vpn case
LOG.debug("removeNaptFlowsFromActiveSwitch : This is disassociate nw with vpn case with vpnName {}", vpnName);
vpnId = NatUtil.getVpnId(dataBroker, vpnName);
LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId for disassociate nw with vpn scenario {}", vpnId);
}
if (vpnId != NatConstants.INVALID_ID) {
// Remove the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the VPN ID.
String natPfibVpnFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, vpnId);
FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in {} for the active switch with the DPN ID {} " + "and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
mdsalManager.removeFlowToTx(natPfibVpnFlowEntity, removeFlowInvTx);
}
// For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
if (ipPortMapping == null) {
LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the IpPortMapping");
return;
}
List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
for (IpPortMap ipPortMap : ipPortMaps) {
String ipPortInternal = ipPortMap.getIpPortInternal();
String[] ipPortParts = ipPortInternal.split(":");
if (ipPortParts.length != 2) {
LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the Internal IP and port");
return;
}
String internalIp = ipPortParts[0];
String internalPort = ipPortParts[1];
// Build the flow for the outbound NAPT table
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + internalIp + NatConstants.COLON_SEPARATOR + internalPort);
String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort));
FlowEntity outboundNaptFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch " + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
mdsalManager.removeFlowToTx(outboundNaptFlowEntity, removeFlowInvTx);
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
String externalIp = ipPortExternal.getIpAddress();
int externalPort = ipPortExternal.getPortNum();
// Build the flow for the inbound NAPT table
switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId), externalIp, externalPort);
FlowEntity inboundNaptFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active active switch " + "with the DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
mdsalManager.removeFlowToTx(inboundNaptFlowEntity, removeFlowInvTx);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class ExternalRoutersListener method makeTunnelTableEntry.
private void makeTunnelTableEntry(BigInteger dpnId, long serviceId, long l3Vni, List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
List<MatchInfo> mkMatches = new ArrayList<>();
LOG.debug("makeTunnelTableEntry : DpnId = {} and serviceId = {} and actions = {}", dpnId, serviceId, customInstructions);
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
mkMatches.add(new MatchTunnelId(BigInteger.valueOf(l3Vni)));
} else {
mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
}
Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE, getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), 5, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class ExternalRoutersListener method changeBgpVpnIdToLocalVpnId.
/**
* router disassociation from vpn.
*
* @param routerName - Name of router
* @param routerId - router id
* @param bgpVpnName BGP VPN name
*/
public void changeBgpVpnIdToLocalVpnId(String routerName, long routerId, String bgpVpnName, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("changeBgpVpnIdToLocalVpnId : Router dissociated from BGP VPN");
if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
LOG.debug("changeBgpVpnIdToLocalVpnId : BGP VPN ID value {} ", bgpVpnId);
// Get the allocated Primary NAPT Switch for this router
LOG.debug("changeBgpVpnIdToLocalVpnId : Router ID value {} ", routerId);
LOG.debug("changeBgpVpnIdToLocalVpnId : Update the BGP VPN ID {} to the Router ID {}", bgpVpnId, routerId);
addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, NatConstants.INVALID_ID, true, writeFlowInvTx);
// Get the group ID
createGroupId(getGroupIdKey(routerName));
BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, NatConstants.INVALID_ID, routerId, true, writeFlowInvTx, extNwProvType);
}
}
Aggregations