use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class EvpnSnatFlowProgrammer method removeTunnelTableEntry.
public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, WriteTransaction removeFlowInvTx) {
LOG.debug("removeTunnelTableEntry : Remove terminating service table {} --> table {} flow on NAPT DpnId {} " + "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, NwConstants.INBOUND_NAPT_TABLE, dpnId, l3Vni);
List<MatchInfo> mkMatches = new ArrayList<>();
// Matching metadata
mkMatches.add(new MatchTunnelId(BigInteger.valueOf(l3Vni)));
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE, NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.SNAT_FLOW_NAME), 5, String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, null);
mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}", flowEntity, dpnId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class NaptEventHandler method prepareAndSendPacketOut.
private void prepareAndSendPacketOut(NAPTEntryEvent naptEntryEvent, Long routerId) {
// Send Packetout - tcp or udp packets which got punted to controller.
BigInteger metadata = naptEntryEvent.getPacketReceived().getMatch().getMetadata().getMetadata();
byte[] inPayload = naptEntryEvent.getPacketReceived().getPayload();
Ethernet ethPkt = new Ethernet();
if (inPayload != null) {
try {
ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.error("prepareAndSendPacketOut : Failed to decode Packet", e);
return;
}
}
long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
LOG.debug("prepareAndSendPacketOut : portTag from incoming packet is {}", portTag);
String interfaceName = getInterfaceNameFromTag(portTag);
LOG.debug("prepareAndSendPacketOut : interfaceName fetched from portTag is {}", interfaceName);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = null;
int vlanId = 0;
iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
if (iface == null) {
LOG.error("prepareAndSendPacketOut : Unable to read interface {} from config DataStore", interfaceName);
return;
}
List<ActionInfo> actionInfos = new ArrayList<>();
IfL2vlan ifL2vlan = iface.getAugmentation(IfL2vlan.class);
if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
vlanId = ifL2vlan.getVlanId().getValue() == null ? 0 : ifL2vlan.getVlanId().getValue();
}
InterfaceInfo infInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
if (infInfo == null) {
LOG.error("prepareAndSendPacketOut : error in getting interfaceInfo from Operation DS");
return;
}
byte[] pktOut = buildNaptPacketOut(ethPkt);
if (ethPkt.getEtherType() != (short) NwConstants.ETHTYPE_802_1Q) {
// VLAN Access port
LOG.debug("prepareAndSendPacketOut : vlanId is {}", vlanId);
if (vlanId != 0) {
// Push vlan
actionInfos.add(new ActionPushVlan(0));
actionInfos.add(new ActionSetFieldVlanVid(1, vlanId));
} else {
LOG.debug("prepareAndSendPacketOut : No vlanId {}, may be untagged", vlanId);
}
} else {
// VLAN Trunk Port
LOG.debug("prepareAndSendPacketOut : This is VLAN Trunk port case - need not do VLAN tagging again");
}
if (pktOut != null) {
String routerName = NatUtil.getRouterName(dataBroker, routerId);
long tunId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
sendNaptPacketOut(pktOut, infInfo, actionInfos, tunId);
} else {
LOG.warn("prepareAndSendPacketOut : Unable to send Packet Out");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class NaptFlowRemovedEventHandler method onFlowRemoved.
@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
/*
If the removed flow is from the OUTBOUND NAPT table :
1) Get the ActionInfo of the flow.
2) From the ActionInfo of the flow get the internal IP address, port and the protocol.
3) Get the Metadata matching info of the flow.
4) From the Metadata matching info of the flow get router ID.
5) Querry the container intext-ip-port-map using the router ID
and the internal IP address, port to get the external IP address, port
6) Instantiate an NaptEntry event and populate the external IP address, port and the router ID.
7) Place the NaptEntry event to the queue.
*/
short tableId = flowRemoved.getTableId();
RemovedFlowReason removedReasonFlag = flowRemoved.getReason();
if (tableId == NwConstants.OUTBOUND_NAPT_TABLE && RemovedFlowReason.OFPRRIDLETIMEOUT.equals(removedReasonFlag)) {
LOG.info("onFlowRemoved : triggered for table-{} entry", tableId);
// Get the internal internal IP address and the port number from the IPv4 match.
Ipv4Prefix internalIpv4Address = null;
Layer3Match layer3Match = flowRemoved.getMatch().getLayer3Match();
if (layer3Match instanceof Ipv4Match) {
Ipv4Match internalIpv4Match = (Ipv4Match) layer3Match;
internalIpv4Address = internalIpv4Match.getIpv4Source();
}
if (internalIpv4Address == null) {
LOG.error("onFlowRemoved : Matching internal IP is null while retrieving the " + "value from the Outbound NAPT flow");
return;
}
// Get the internal IP as a string
String internalIpv4AddressAsString = internalIpv4Address.getValue();
String[] internalIpv4AddressParts = internalIpv4AddressAsString.split("/");
String internalIpv4HostAddress = null;
if (internalIpv4AddressParts.length >= 1) {
internalIpv4HostAddress = internalIpv4AddressParts[0];
}
// Get the protocol from the layer4 match
NAPTEntryEvent.Protocol protocol = null;
Integer internalPortNumber = null;
Layer4Match layer4Match = flowRemoved.getMatch().getLayer4Match();
if (layer4Match instanceof TcpMatch) {
TcpMatchFields tcpMatchFields = (TcpMatchFields) layer4Match;
internalPortNumber = tcpMatchFields.getTcpSourcePort().getValue();
protocol = NAPTEntryEvent.Protocol.TCP;
} else if (layer4Match instanceof UdpMatch) {
UdpMatchFields udpMatchFields = (UdpMatchFields) layer4Match;
internalPortNumber = udpMatchFields.getUdpSourcePort().getValue();
protocol = NAPTEntryEvent.Protocol.UDP;
}
if (protocol == null) {
LOG.error("onFlowRemoved : Matching protocol is null while retrieving the value " + "from the Outbound NAPT flow");
return;
}
// Get the router ID from the metadata.
Long routerId;
BigInteger metadata = flowRemoved.getMatch().getMetadata().getMetadata();
if (MetaDataUtil.getNatRouterIdFromMetadata(metadata) != 0) {
routerId = MetaDataUtil.getNatRouterIdFromMetadata(metadata);
} else {
LOG.error("onFlowRemoved : Null exception while retrieving routerId");
return;
}
final String internalIpPortKey = routerId + NatConstants.COLON_SEPARATOR + internalIpv4HostAddress + NatConstants.COLON_SEPARATOR + internalPortNumber;
// Get the external IP address and the port from the model
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIpv4HostAddress, internalPortNumber.toString(), protocol);
if (ipPortExternal == null) {
LOG.error("onFlowRemoved : IpPortExternal not found, BGP vpn might be " + "associated with router");
// router must be associated with BGP vpn ID
long bgpVpnId = routerId;
LOG.debug("onFlowRemoved : BGP VPN ID {}", bgpVpnId);
String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
if (routerName == null) {
LOG.error("onFlowRemoved : Unable to find router for VpnName {}", vpnName);
return;
}
routerId = NatUtil.getVpnId(dataBroker, routerName);
LOG.debug("onFlowRemoved : Router ID {}", routerId);
ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIpv4HostAddress, internalPortNumber.toString(), protocol);
if (ipPortExternal == null) {
LOG.error("onFlowRemoved : IpPortExternal is null while queried from the " + "model for routerId {}", routerId);
return;
}
}
String externalIpAddress = ipPortExternal.getIpAddress();
int externalPortNumber = ipPortExternal.getPortNum();
// Create an NAPT event and place it in the queue.
NAPTEntryEvent naptEntryEvent = new NAPTEntryEvent(externalIpAddress, externalPortNumber, routerId, NAPTEntryEvent.Operation.DELETE, protocol, null, false, null);
naptEventdispatcher.addFlowRemovedNaptEvent(naptEntryEvent);
// Get the DPN ID from the Node
InstanceIdentifier<Node> nodeRef = flowRemoved.getNode().getValue().firstIdentifierOf(Node.class);
String dpn = nodeRef.firstKeyOf(Node.class).getId().getValue();
BigInteger dpnId = getDpnId(dpn);
String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, tableId, String.valueOf(routerId), internalIpv4HostAddress, internalPortNumber);
// Inform the MDSAL manager to inform about the flow removal.
LOG.debug("onFlowRemoved : DPN ID {}, Metadata {}, SwitchFlowRef {}, " + "internalIpv4HostAddress{}", dpnId, routerId, switchFlowRef, internalIpv4AddressAsString);
FlowEntity snatFlowEntity = NatUtil.buildFlowEntity(dpnId, tableId, switchFlowRef);
long startTime = System.currentTimeMillis();
mdsalManager.removeFlow(snatFlowEntity);
LOG.debug("onFlowRemoved : Elapsed time fo deleting table-{} flow for snat ({}) session:{}ms", tableId, internalIpPortKey, (System.currentTimeMillis() - startTime));
// Remove the SourceIP:Port key from the Napt packet handler map.
naptPacketInHandler.removeIncomingPacketMap(internalIpPortKey);
// Remove the mapping of internal fixed ip/port to external ip/port from the datastore.
SessionAddress internalSessionAddress = new SessionAddress(internalIpv4HostAddress, internalPortNumber);
naptManager.releaseIpExtPortMapping(routerId, internalSessionAddress, protocol);
LOG.info("onFlowRemoved : exit");
} else {
LOG.debug("onFlowRemoved : Received flow removed notification due to flowdelete from switch for flowref");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class NaptSwitchHA method removeSnatFlowsInOldNaptSwitch.
/* This method checks the switch that gone down is a NaptSwitch for a router.
If it is a NaptSwitch
1) selects new NAPT switch
2) installs nat flows in new NAPT switch
table 21(FIB)->26(PSNAT)->group(resubmit/napttunnel)->36(Terminating)->46(outbound)->47(resubmit)->21
3) modify the group and miss entry flow in other vSwitches pointing to newNaptSwitch
4) Remove nat flows in oldNaptSwitch
*/
/*public void handleNaptSwitchDown(BigInteger dpnId){
LOG.debug("handleNaptSwitchDown method is called with dpnId {}",dpnId);
BigInteger naptSwitch;
try {
NaptSwitches naptSwitches = NatUtil.getNaptSwitch(dataBroker);
if (naptSwitches == null || naptSwitches.getRouterToNaptSwitch() == null
|| naptSwitches.getRouterToNaptSwitch().isEmpty()) {
LOG.debug("NaptSwitchDown: NaptSwitch is not allocated for none of the routers");
return;
}
for (RouterToNaptSwitch routerToNaptSwitch : naptSwitches.getRouterToNaptSwitch()) {
String routerName = routerToNaptSwitch.getRouterName();
naptSwitch = routerToNaptSwitch.getPrimarySwitchId();
boolean naptStatus = isNaptSwitchDown(routerName,dpnId,naptSwitch);
if (!naptStatus) {
LOG.debug("NaptSwitchDown: Switch with DpnId {} is not naptSwitch for router {}",
dpnId, routerName);
} else {
removeSnatFlowsInOldNaptSwitch(routerName,naptSwitch);
return;
}
}
} catch (Exception ex) {
LOG.error("Exception in handleNaptSwitchDown method {}",ex);
}
}*/
protected void removeSnatFlowsInOldNaptSwitch(String routerName, Long routerId, BigInteger naptSwitch, Map<String, Long> externalIpmap, WriteTransaction removeFlowInvTx) {
// remove SNAT flows in old NAPT SWITCH
Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
String vpnName = getExtNetworkVpnName(routerName, networkId);
if (vpnName == null) {
LOG.error("removeSnatFlowsInOldNaptSwitch : Vpn is not associated to externalN/w of router {}", routerName);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkId);
if (extNwProvType == null) {
LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the External Network Provider Type " + "for Router {}", routerName);
return;
}
if (extNwProvType == ProviderTypes.VXLAN) {
evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch, removeFlowInvTx);
} else {
// Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table
long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
String tsFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tunnelId);
FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
mdsalManager.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
}
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
// Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
NatUtil.removePreDnatToSnatTableEntry(mdsalManager, naptSwitch, removeFlowInvTx);
}
// Remove the Outbound flow entry which forwards the packet to Outbound NAPT Table
String outboundNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
FlowEntity outboundNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, outboundNatFlowRef);
LOG.info("Remove the flow in table {} for the old napt switch with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
mdsalManager.removeFlowToTx(outboundNatFlowEntity, removeFlowInvTx);
// Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
// External Subnet Vpn Id.
Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker, routerName);
for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
if (subnetVpnId != -1) {
String natPfibSubnetFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, natPfibSubnetFlowRef);
mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Removed the flow in table {} with external subnet " + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE, subnetVpnId, naptSwitch);
}
}
// Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for inbound traffic
// matching on the router ID.
String naptPFibflowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, routerId);
FlowEntity naptPFibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptPFibflowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, routerId);
mdsalManager.removeFlowToTx(naptPFibFlowEntity, removeFlowInvTx);
// Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for outbound traffic
// matching on the vpn ID.
boolean switchSharedByRouters = false;
Uuid extNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
if (extNetworkId != null) {
List<String> routerNamesAssociated = getRouterIdsForExtNetwork(extNetworkId);
for (String routerNameAssociated : routerNamesAssociated) {
if (!routerNameAssociated.equals(routerName)) {
Long routerIdAssociated = NatUtil.getVpnId(dataBroker, routerNameAssociated);
BigInteger naptDpn = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerNameAssociated);
if (naptDpn != null && naptDpn.equals(naptSwitch)) {
LOG.debug("removeSnatFlowsInOldNaptSwitch : Napt switch {} is also acting as primary " + "for router {}", naptSwitch, routerIdAssociated);
switchSharedByRouters = true;
break;
}
}
}
if (!switchSharedByRouters) {
Long vpnId = getVpnIdForRouter(routerId, extNetworkId);
if (vpnId != NatConstants.INVALID_ID) {
String naptFibflowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, vpnId);
FlowEntity naptFibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptFibflowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch" + " with the DPN ID {} and vpnId {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, vpnId);
mdsalManager.removeFlowToTx(naptFibFlowEntity, removeFlowInvTx);
} else {
LOG.error("removeSnatFlowsInOldNaptSwitch : Invalid vpnId retrieved for routerId {}", routerId);
return;
}
}
}
// Remove Fib entries,tables 20->44 ,36-> 44
String gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (externalIpmap != null && !externalIpmap.isEmpty()) {
for (Entry<String, Long> entry : externalIpmap.entrySet()) {
String externalIp = entry.getKey();
Long label = entry.getValue();
externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName, extNetworkId, label, gwMacAddress, true, removeFlowInvTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} " + "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
}
} else {
List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
if (networkId != null) {
externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, networkId, externalIps, null, gwMacAddress, removeFlowInvTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for " + "router {} with networkId {} and externalIps {}", naptSwitch, routerId, networkId, externalIps);
} else {
LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}", routerId);
}
externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId, externalIps, 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 || ipPortMapping.getIntextIpProtocolType() == null || ipPortMapping.getIntextIpProtocolType().isEmpty()) {
LOG.warn("removeSnatFlowsInOldNaptSwitch : No Internal Ip Port mapping associated to router {}, " + "no flows need to be removed in oldNaptSwitch {}", routerId, naptSwitch);
return;
}
BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
if (intextIpProtocolType.getIpPortMap() == null || intextIpProtocolType.getIpPortMap().isEmpty()) {
LOG.debug("removeSnatFlowsInOldNaptSwitch : No {} session associated to router {}," + "no flows need to be removed in oldNaptSwitch {}", intextIpProtocolType.getProtocol(), routerId, naptSwitch);
break;
}
List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
for (IpPortMap ipPortMap : ipPortMaps) {
String ipPortInternal = ipPortMap.getIpPortInternal();
String[] ipPortParts = ipPortInternal.split(":");
if (ipPortParts.length != 2) {
LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the Internal IP and port");
continue;
}
String internalIp = ipPortParts[0];
String internalPort = ipPortParts[1];
// Build and remove flow in outbound NAPT table
String switchFlowRef = NatUtil.getNaptFlowRef(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort));
FlowEntity outboundNaptFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
mdsalManager.removeFlowToTx(outboundNaptFlowEntity, removeFlowInvTx);
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
if (ipPortExternal == null) {
LOG.debug("removeSnatFlowsInOldNaptSwitch : External Ipport mapping not found for internalIp {} " + "with port {} for router {}", internalIp, internalPort, routerId);
continue;
}
String externalIp = ipPortExternal.getIpAddress();
int externalPort = ipPortExternal.getPortNum();
// Build and remove flow in inbound NAPT table
switchFlowRef = NatUtil.getNaptFlowRef(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId), externalIp, externalPort);
FlowEntity inboundNaptFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch with the " + "DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, naptSwitch, routerId);
mdsalManager.removeFlowToTx(inboundNaptFlowEntity, removeFlowInvTx);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class Ipv6PktHandlerTest method testonPacketReceivedRouterSolicitationWithMultipleSubnets.
@Test
public void testonPacketReceivedRouterSolicitationWithMultipleSubnets() throws Exception {
VirtualPort intf = Mockito.mock(VirtualPort.class);
when(intf.getMacAddress()).thenReturn("50:7B:9D:78:54:F3");
when(ifMgrInstance.obtainV6Interface(any())).thenReturn(intf);
when(ifMgrInstance.getInterfaceNameFromTag(anyLong())).thenReturn("ddec9dba-d831-4ad7-84b9-00d7f65f052f");
when(ifMgrInstance.getRouterV6InterfaceForNetwork(any())).thenReturn(intf);
IpAddress gwIpAddress = Mockito.mock(IpAddress.class);
when(gwIpAddress.getIpv4Address()).thenReturn(null);
when(gwIpAddress.getIpv6Address()).thenReturn(new Ipv6Address("2001:db8:1111::1"));
VirtualSubnet v6Subnet1 = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8:1111::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_SLAAC).ipv6RAMode(Ipv6Constants.IPV6_SLAAC).build();
VirtualRouter virtualRouter = VirtualRouter.builder().build();
v6Subnet1.setRouter(virtualRouter);
VirtualSubnet v6Subnet2 = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8:2222::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_DHCPV6_STATELESS).ipv6RAMode(Ipv6Constants.IPV6_DHCPV6_STATELESS).build();
v6Subnet2.setRouter(virtualRouter);
VirtualSubnet v6Subnet3 = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8:3333::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_DHCPV6_STATEFUL).ipv6RAMode(Ipv6Constants.IPV6_DHCPV6_STATEFUL).build();
v6Subnet3.setRouter(virtualRouter);
List<VirtualSubnet> subnetList = new ArrayList<>();
subnetList.add(v6Subnet1);
subnetList.add(v6Subnet2);
subnetList.add(v6Subnet3);
when(intf.getSubnets()).thenReturn(subnetList);
InstanceIdentifier<Node> ncId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1"))).build();
NodeConnectorRef ncRef = new NodeConnectorRef(ncId);
BigInteger mdata = new BigInteger(String.valueOf(0x1000000));
Metadata metadata = new MetadataBuilder().setMetadata(mdata).build();
MatchBuilder matchbuilder = new MatchBuilder().setMetadata(metadata);
pktHandler.onPacketReceived(new PacketReceivedBuilder().setPayload(ipv6TestUtils.buildPacket(// Destination MAC
"33 33 00 00 00 02", // Source MAC
"FA 16 3E 69 2C F3", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 10", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 69 2C F3", // Destination IP
"FF 02 00 00 00 00 00 00 00 00 00 00 00 00 00 02", // ICMPv6 router solicitation
"85", // Code
"00", // Checksum (valid)
"B4 47", // ICMPv6 message body
"00 00 00 00", // ICMPv6 Option: Source Link Layer Address
"01", // Length
"01", // Link Layer Address
"FA 16 3E 69 2C F3")).setIngress(ncRef).setMatch(matchbuilder.build()).build());
// wait on this thread until the async job is completed in the packet handler.
waitForPacketProcessing();
verify(pktProcessService, times(1)).transmitPacket(any(TransmitPacketInput.class));
byte[] expectedPayload = ipv6TestUtils.buildPacket(// Destination MAC
"FA 16 3E 69 2C F3", // Source MAC
"50 7B 9D 78 54 F3", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 78", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 52 7B 9D FF FE 78 54 F3", // Destination IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 69 2C F3", // ICMPv6 router advertisement.
"86", // Code
"00", // Checksum (valid)
"59 41", // Current Hop Limit
"40", // ICMPv6 RA Flags
"C0", // Router Lifetime
"11 94", // Reachable time
"00 01 D4 C0", // Retransmission time.
"00 00 00 00", // Type: Source Link-Layer Option
"01", // Option length
"01", // Source Link layer address
"50 7B 9D 78 54 F3", // Type: Prefix Information
"03", // Option length
"04", // Prefix length
"40", // Prefix flags
"C0", // Valid lifetime
"00 27 8D 00", // Preferred lifetime
"00 09 3A 80", // Reserved
"00 00 00 00", // Prefix
"20 01 0D B8 11 11 00 00 00 00 00 00 00 00 00 00", // Type: Prefix Information
"03", // Option length
"04", // Prefix length
"40", // Prefix flags
"C0", // Valid lifetime
"00 27 8D 00", // Preferred lifetime
"00 09 3A 80", // Reserved
"00 00 00 00", // Prefix
"20 01 0D B8 22 22 00 00 00 00 00 00 00 00 00 00", // Type: Prefix Information
"03", // Option length
"04", // Prefix length
"40", // Prefix flags
"80", // Valid lifetime
"00 27 8D 00", // Preferred lifetime
"00 09 3A 80", // Reserved
"00 00 00 00", // Prefix
"20 01 0D B8 33 33 00 00 00 00 00 00 00 00 00 00");
verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload).setNode(new NodeRef(ncId)).setEgress(ncRef).build());
}
Aggregations