@Test public void testSyncFlows() throws Exception { Endpoint endpoint = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0).build(); List<Endpoint> endpoints = new ArrayList<>(); endpoints.add(endpoint); EndpointL3 endpointL3 = buildL3Endpoint(IPV4_0, IPV4_1, MAC_0, L2).build(); List<EndpointL3> endpointsL3 = new ArrayList<>(); endpointsL3.add(endpointL3); Set<EgKey> egKeys = new HashSet<>(); egKeys.add(new EgKey(TENANT_ID, ENDPOINT_GROUP_1)); when(ctx.getPolicyManager()).thenReturn(policyManager); when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant()); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(endpointManager.getL3EndpointsWithNat()).thenReturn(endpointsL3); when(endpointManager.getEndpoint(Mockito.any(EpKey.class))).thenReturn(endpoint); when(endpointManager.getEgKeysForEndpoint(Mockito.any(Endpoint.class))).thenReturn(egKeys); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); when(endpointManager.getExtEpsNoLocForGroup(Mockito.any(EgKey.class))).thenReturn(endpoints); IngressNatMapperFlows flows = mock(IngressNatMapperFlows.class); IngressNatMapper ingressNatMapper = new IngressNatMapper(ctx, tableId); ingressNatMapper.syncFlows(flows, endpoint, ofWriter); verify(flows, times(1)).baseFlow(Mockito.anyShort(), Mockito.anyInt(), eq(ofWriter)); verify(flows, times(1)).createNatFlow(Mockito.anyShort(), Mockito.any(EndpointL3.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.anyInt(), eq(ofWriter)); verify(flows, times(1)).createArpFlow(Mockito.any(IndexedTenant.class), Mockito.any(EndpointL3.class), Mockito.anyInt(), eq(ofWriter)); verify(flows, times(1)).createIngressExternalNatFlows(Mockito.anyShort(), Mockito.any(Endpoint.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.anyInt(), eq(ofWriter)); verify(flows, times(1)).createIngressExternalArpFlows(Mockito.anyShort(), Mockito.any(Endpoint.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.anyInt(), eq(ofWriter)); InOrder order = inOrder(ctx, flows); order.verify(ctx, times(1)).getPolicyManager(); order.verify(flows, times(1)).baseFlow(Mockito.anyShort(), Mockito.anyInt(), eq(ofWriter)); order.verify(flows, times(1)).createNatFlow(Mockito.anyShort(), Mockito.any(EndpointL3.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.anyInt(), eq(ofWriter)); order.verify(ctx, times(1)).getTenant(Mockito.any(TenantId.class)); order.verify(flows, times(1)).createArpFlow(Mockito.any(IndexedTenant.class), Mockito.any(EndpointL3.class), Mockito.anyInt(), eq(ofWriter)); order.verify(ctx, times(1)).getCurrentPolicy(); order.verify(ctx, times(1)).getEndpointManager(); order.verify(flows, times(1)).createIngressExternalNatFlows(Mockito.anyShort(), Mockito.any(Endpoint.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.anyInt(), eq(ofWriter)); order.verify(flows, times(1)).createIngressExternalArpFlows(Mockito.anyShort(), Mockito.any(Endpoint.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.anyInt(), eq(ofWriter)); }
void syncFlows(IngressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); flows.baseFlow(destinationMapperId, BASE, ofWriter); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); OrdinalFactory.EndpointFwdCtxOrdinals epFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); 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())) { if (epFwdCtxOrdinals != null) { flows.createNatFlow(destinationMapperId, l3Endpoint, epFwdCtxOrdinals, NAT, ofWriter); } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); if (tenant != null) { flows.createArpFlow(tenant, l3Endpoint, ARP, ofWriter); } break; } } } for (EgKey endpointGroupKey : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey peer : Sets.union(Collections.singleton(endpointGroupKey), ctx.getCurrentPolicy().getPeers(endpointGroupKey))) { for (Endpoint externalEndpoint : ctx.getEndpointManager().getExtEpsNoLocForGroup(peer)) { if (epFwdCtxOrdinals != null) { flows.createIngressExternalNatFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, NAT_EXTERNAL, ofWriter); flows.createIngressExternalArpFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, ARP_EXTERNAL, ofWriter); } } } } }
IngressNatMapper extends FlowTable { void syncFlows(IngressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); flows.baseFlow(destinationMapperId, BASE, ofWriter); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); OrdinalFactory.EndpointFwdCtxOrdinals epFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); 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())) { if (epFwdCtxOrdinals != null) { flows.createNatFlow(destinationMapperId, l3Endpoint, epFwdCtxOrdinals, NAT, ofWriter); } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); if (tenant != null) { flows.createArpFlow(tenant, l3Endpoint, ARP, ofWriter); } break; } } } for (EgKey endpointGroupKey : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey peer : Sets.union(Collections.singleton(endpointGroupKey), ctx.getCurrentPolicy().getPeers(endpointGroupKey))) { for (Endpoint externalEndpoint : ctx.getEndpointManager().getExtEpsNoLocForGroup(peer)) { if (epFwdCtxOrdinals != null) { flows.createIngressExternalNatFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, NAT_EXTERNAL, ofWriter); flows.createIngressExternalArpFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, ARP_EXTERNAL, ofWriter); } } } } } }
IngressNatMapper extends FlowTable { void syncFlows(IngressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); flows.baseFlow(destinationMapperId, BASE, ofWriter); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); OrdinalFactory.EndpointFwdCtxOrdinals epFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); 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())) { if (epFwdCtxOrdinals != null) { flows.createNatFlow(destinationMapperId, l3Endpoint, epFwdCtxOrdinals, NAT, ofWriter); } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); if (tenant != null) { flows.createArpFlow(tenant, l3Endpoint, ARP, ofWriter); } break; } } } for (EgKey endpointGroupKey : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey peer : Sets.union(Collections.singleton(endpointGroupKey), ctx.getCurrentPolicy().getPeers(endpointGroupKey))) { for (Endpoint externalEndpoint : ctx.getEndpointManager().getExtEpsNoLocForGroup(peer)) { if (epFwdCtxOrdinals != null) { flows.createIngressExternalNatFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, NAT_EXTERNAL, ofWriter); flows.createIngressExternalArpFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, ARP_EXTERNAL, ofWriter); } } } } } IngressNatMapper(OfContext ctx, short tableId); }
IngressNatMapper extends FlowTable { void syncFlows(IngressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); flows.baseFlow(destinationMapperId, BASE, ofWriter); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); OrdinalFactory.EndpointFwdCtxOrdinals epFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); 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())) { if (epFwdCtxOrdinals != null) { flows.createNatFlow(destinationMapperId, l3Endpoint, epFwdCtxOrdinals, NAT, ofWriter); } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); if (tenant != null) { flows.createArpFlow(tenant, l3Endpoint, ARP, ofWriter); } break; } } } for (EgKey endpointGroupKey : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey peer : Sets.union(Collections.singleton(endpointGroupKey), ctx.getCurrentPolicy().getPeers(endpointGroupKey))) { for (Endpoint externalEndpoint : ctx.getEndpointManager().getExtEpsNoLocForGroup(peer)) { if (epFwdCtxOrdinals != null) { flows.createIngressExternalNatFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, NAT_EXTERNAL, ofWriter); flows.createIngressExternalArpFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, ARP_EXTERNAL, ofWriter); } } } } } IngressNatMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); }
IngressNatMapper extends FlowTable { void syncFlows(IngressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) { short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); flows.baseFlow(destinationMapperId, BASE, ofWriter); Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); OrdinalFactory.EndpointFwdCtxOrdinals epFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); 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())) { if (epFwdCtxOrdinals != null) { flows.createNatFlow(destinationMapperId, l3Endpoint, epFwdCtxOrdinals, NAT, ofWriter); } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); if (tenant != null) { flows.createArpFlow(tenant, l3Endpoint, ARP, ofWriter); } break; } } } for (EgKey endpointGroupKey : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey peer : Sets.union(Collections.singleton(endpointGroupKey), ctx.getCurrentPolicy().getPeers(endpointGroupKey))) { for (Endpoint externalEndpoint : ctx.getEndpointManager().getExtEpsNoLocForGroup(peer)) { if (epFwdCtxOrdinals != null) { flows.createIngressExternalNatFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, NAT_EXTERNAL, ofWriter); flows.createIngressExternalArpFlows(destinationMapperId, externalEndpoint, epFwdCtxOrdinals, ARP_EXTERNAL, ofWriter); } } } } } IngressNatMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter);  }