@Test public void testSyncFlows() { EgressNatMapperFlows flows = mock(EgressNatMapperFlows.class); EgressNatMapper mapper = new EgressNatMapper(ctx, tableId); Endpoint endpoint = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_1).build(); EndpointL3 endpointL3 = buildL3Endpoint(IPV4_0, IPV4_1, MAC_0, L2).build(); List<EndpointL3> endpointsL3 = new ArrayList<>(); endpointsL3.add(endpointL3); when(ctx.getPolicyManager()).thenReturn(policyManager); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(endpointManager.getL3EndpointsWithNat()).thenReturn(endpointsL3); when(endpointManager.getEndpoint(Mockito.any(EpKey.class))).thenReturn(endpoint); mapper.syncFlows(flows, endpoint, ofWriter); verify(flows, times(1)).dropFlow(Mockito.anyInt(), Mockito.anyLong(), eq(ofWriter)); verify(flows, times(1)).natFlows(Mockito.anyShort(), Mockito.any(EndpointL3.class), Mockito.anyInt(), eq(ofWriter)); InOrder order = inOrder(ctx, flows); order.verify(flows, times(1)).dropFlow(Mockito.anyInt(), Mockito.anyLong(), eq(ofWriter)); order.verify(ctx, times(1)).getPolicyManager(); order.verify(flows, times(1)).natFlows(Mockito.anyShort(), Mockito.any(EndpointL3.class), Mockito.anyInt(), eq(ofWriter)); }
void syncFlows(EgressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { flows.dropFlow(DROP, null, ofWriter); short externalMapperId = ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); EndpointKey endpointKey = endpoint.getKey(); for (EndpointL3 l3Endpoint : l3Endpoints) { L2BridgeDomainId l2Context = l3Endpoint.getL2Context(); MacAddress macAddress = l3Endpoint.getMacAddress(); if (l2Context != null && macAddress != null) { Endpoint l2EpFromL3Ep = ctx.getEndpointManager().getEndpoint(new EpKey(l2Context, macAddress)); if(endpointKey.equals(l2EpFromL3Ep.getKey())) { flows.natFlows(externalMapperId, l3Endpoint, NAT, ofWriter); break; } } } }
EgressNatMapper extends FlowTable { void syncFlows(EgressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { flows.dropFlow(DROP, null, ofWriter); short externalMapperId = ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); EndpointKey endpointKey = endpoint.getKey(); for (EndpointL3 l3Endpoint : l3Endpoints) { L2BridgeDomainId l2Context = l3Endpoint.getL2Context(); MacAddress macAddress = l3Endpoint.getMacAddress(); if (l2Context != null && macAddress != null) { Endpoint l2EpFromL3Ep = ctx.getEndpointManager().getEndpoint(new EpKey(l2Context, macAddress)); if(endpointKey.equals(l2EpFromL3Ep.getKey())) { flows.natFlows(externalMapperId, l3Endpoint, NAT, ofWriter); break; } } } } }
EgressNatMapper extends FlowTable { void syncFlows(EgressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { flows.dropFlow(DROP, null, ofWriter); short externalMapperId = ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); EndpointKey endpointKey = endpoint.getKey(); for (EndpointL3 l3Endpoint : l3Endpoints) { L2BridgeDomainId l2Context = l3Endpoint.getL2Context(); MacAddress macAddress = l3Endpoint.getMacAddress(); if (l2Context != null && macAddress != null) { Endpoint l2EpFromL3Ep = ctx.getEndpointManager().getEndpoint(new EpKey(l2Context, macAddress)); if(endpointKey.equals(l2EpFromL3Ep.getKey())) { flows.natFlows(externalMapperId, l3Endpoint, NAT, ofWriter); break; } } } } EgressNatMapper(OfContext ctx, short tableId); }
EgressNatMapper extends FlowTable { void syncFlows(EgressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { flows.dropFlow(DROP, null, ofWriter); short externalMapperId = ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); EndpointKey endpointKey = endpoint.getKey(); for (EndpointL3 l3Endpoint : l3Endpoints) { L2BridgeDomainId l2Context = l3Endpoint.getL2Context(); MacAddress macAddress = l3Endpoint.getMacAddress(); if (l2Context != null && macAddress != null) { Endpoint l2EpFromL3Ep = ctx.getEndpointManager().getEndpoint(new EpKey(l2Context, macAddress)); if(endpointKey.equals(l2EpFromL3Ep.getKey())) { flows.natFlows(externalMapperId, l3Endpoint, NAT, ofWriter); break; } } } } EgressNatMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); }
EgressNatMapper extends FlowTable { void syncFlows(EgressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { flows.dropFlow(DROP, null, ofWriter); short externalMapperId = ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); EndpointKey endpointKey = endpoint.getKey(); for (EndpointL3 l3Endpoint : l3Endpoints) { L2BridgeDomainId l2Context = l3Endpoint.getL2Context(); MacAddress macAddress = l3Endpoint.getMacAddress(); if (l2Context != null && macAddress != null) { Endpoint l2EpFromL3Ep = ctx.getEndpointManager().getEndpoint(new EpKey(l2Context, macAddress)); if(endpointKey.equals(l2EpFromL3Ep.getKey())) { flows.natFlows(externalMapperId, l3Endpoint, NAT, ofWriter); break; } } } } EgressNatMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter);  }