@Test public void testNatFlow() throws Exception { EndpointL3 testEndpointL3 = buildL3Endpoint(IPV4_0, IPV4_1, MAC_0, null).build(); Endpoint testEndpoint = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0).build(); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant()); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint); InOrder order = inOrder(ctx); order.verify(ctx, times(1)).getEndpointManager(); order.verify(ctx, times(1)).getCurrentPolicy(); verify(ctx, times(3)).getTenant(TENANT_ID); assertNotNull(ordinals); List<Instruction> instructions = new ArrayList<>(); Action[] ipActions = {FlowUtils.setIpv4DstAction(new Ipv4Address(IPV4_1)), FlowUtils.setDlDstAction(new MacAddress(MAC_0))}; Action[] ordinalsAction = {FlowUtils.nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(1)), FlowUtils.nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0)), FlowUtils.nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(3)), FlowUtils.nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(4)), FlowUtils.nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(5)), FlowUtils.nxLoadTunIdAction(BigInteger.valueOf(ordinals.getTunnelId()), false)}; instructions.add(new InstructionBuilder().setOrder(0) .setInstruction(FlowUtils.applyActionIns(ArrayUtils.addAll(ipActions, ordinalsAction))).build()); instructions.add(new InstructionBuilder().setOrder(1).setInstruction(FlowUtils.gotoTableIns((short) 2)).build()); InstructionsBuilder instructionsBuilder = new InstructionsBuilder(); instructionsBuilder.setInstruction(instructions); MatchBuilder matchBuilder = new MatchBuilder(); matchBuilder.setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build()); matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4)); Flow testFlow = buildFlow(new FlowId("IngressNat" + "|" + new IpAddress(new Ipv4Address(IPV4_0)).toString() + "|" + new IpAddress(new Ipv4Address(IPV4_1)).toString() + "|" + new MacAddress(MAC_0)), tableId, 60, matchBuilder.build(), instructionsBuilder.build()).build(); flows.createNatFlow((short) 2, testEndpointL3, ordinals, 60, ofWriter); verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow); }
void createNatFlow(short goToTable, EndpointL3 l3Ep, OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals, int priority, OfWriter ofWriter) { NatAddress natAugL3Endpoint = l3Ep.getAugmentation(NatAddress.class); if (natAugL3Endpoint == null || natAugL3Endpoint.getNatAddress() == null) { return; } if (l3Ep.getMacAddress() != null || l3Ep.getIpAddress() != null) { Flow flow = buildNatFlow(goToTable, natAugL3Endpoint.getNatAddress(), priority, l3Ep.getIpAddress(), l3Ep.getMacAddress(), endpointFwdCtxOrdinals); if (flow != null) { ofWriter.writeFlow(nodeId, tableId, flow); } } }
IngressNatMapperFlows { void createNatFlow(short goToTable, EndpointL3 l3Ep, OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals, int priority, OfWriter ofWriter) { NatAddress natAugL3Endpoint = l3Ep.getAugmentation(NatAddress.class); if (natAugL3Endpoint == null || natAugL3Endpoint.getNatAddress() == null) { return; } if (l3Ep.getMacAddress() != null || l3Ep.getIpAddress() != null) { Flow flow = buildNatFlow(goToTable, natAugL3Endpoint.getNatAddress(), priority, l3Ep.getIpAddress(), l3Ep.getMacAddress(), endpointFwdCtxOrdinals); if (flow != null) { ofWriter.writeFlow(nodeId, tableId, flow); } } } }
IngressNatMapperFlows { void createNatFlow(short goToTable, EndpointL3 l3Ep, OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals, int priority, OfWriter ofWriter) { NatAddress natAugL3Endpoint = l3Ep.getAugmentation(NatAddress.class); if (natAugL3Endpoint == null || natAugL3Endpoint.getNatAddress() == null) { return; } if (l3Ep.getMacAddress() != null || l3Ep.getIpAddress() != null) { Flow flow = buildNatFlow(goToTable, natAugL3Endpoint.getNatAddress(), priority, l3Ep.getIpAddress(), l3Ep.getMacAddress(), endpointFwdCtxOrdinals); if (flow != null) { ofWriter.writeFlow(nodeId, tableId, flow); } } } IngressNatMapperFlows(NodeId nodeId, short tableId); }
IngressNatMapperFlows { void createNatFlow(short goToTable, EndpointL3 l3Ep, OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals, int priority, OfWriter ofWriter) { NatAddress natAugL3Endpoint = l3Ep.getAugmentation(NatAddress.class); if (natAugL3Endpoint == null || natAugL3Endpoint.getNatAddress() == null) { return; } if (l3Ep.getMacAddress() != null || l3Ep.getIpAddress() != null) { Flow flow = buildNatFlow(goToTable, natAugL3Endpoint.getNatAddress(), priority, l3Ep.getIpAddress(), l3Ep.getMacAddress(), endpointFwdCtxOrdinals); if (flow != null) { ofWriter.writeFlow(nodeId, tableId, flow); } } } IngressNatMapperFlows(NodeId nodeId, short tableId);  }
IngressNatMapperFlows { void createNatFlow(short goToTable, EndpointL3 l3Ep, OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals, int priority, OfWriter ofWriter) { NatAddress natAugL3Endpoint = l3Ep.getAugmentation(NatAddress.class); if (natAugL3Endpoint == null || natAugL3Endpoint.getNatAddress() == null) { return; } if (l3Ep.getMacAddress() != null || l3Ep.getIpAddress() != null) { Flow flow = buildNatFlow(goToTable, natAugL3Endpoint.getNatAddress(), priority, l3Ep.getIpAddress(), l3Ep.getMacAddress(), endpointFwdCtxOrdinals); if (flow != null) { ofWriter.writeFlow(nodeId, tableId, flow); } } } IngressNatMapperFlows(NodeId nodeId, short tableId);   }