@Test public void syncLocalEndpointFlows() { DestinationMapperFlows flows = mock(DestinationMapperFlows.class); EndpointBuilder endpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1); endpointBuilder.setNetworkContainment(SUBNET_0); EndpointBuilder peerEndpointBuilder = buildEndpoint(IPV4_2, MAC_0, CONNECTOR_0); peerEndpointBuilder.setNetworkContainment(new NetworkDomainId(SUBNET_0)); List<L3Context> l3Contexts = new ArrayList<>(); L3ContextBuilder l3ContextBuilder = new L3ContextBuilder(); l3ContextBuilder.setId(L3C_ID); l3Contexts.add(l3ContextBuilder.build()); List<L2BridgeDomain> l2BDomains = new ArrayList<>(); L2BridgeDomainBuilder l2bdBuilder = new L2BridgeDomainBuilder(); l2bdBuilder.setId(L2BD_ID); l2bdBuilder.setParent(L3C_ID); l2BDomains.add(l2bdBuilder.build()); List<L2FloodDomain> l2FDomains = new ArrayList<>(); L2FloodDomainBuilder l2fdBuilder = new L2FloodDomainBuilder(); l2fdBuilder.setId(L2FD_ID); l2fdBuilder.setParent(L2BD_ID); l2FDomains.add(l2fdBuilder.build()); List<Subnet> subnets = new ArrayList<>(); SubnetBuilder subnetBuilder = new SubnetBuilder(); subnetBuilder.setId(SUBNET_0); subnetBuilder.setParent(L2FD_ID); subnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_2)); subnets.add(subnetBuilder.build()); ForwardingContextBuilder forwardingContextBuilder = new ForwardingContextBuilder(); forwardingContextBuilder.setSubnet(subnets); forwardingContextBuilder.setL3Context(l3Contexts); forwardingContextBuilder.setL2BridgeDomain(l2BDomains); forwardingContextBuilder.setL2FloodDomain(l2FDomains); TenantBuilder peerTenantBuilder = new TenantBuilder(getTestIndexedTenant().getTenant()); peerTenantBuilder.setForwardingContext(buildTenant().getForwardingContext()); Tenant peerTenant = peerTenantBuilder.build(); Endpoint peerEndpoint = peerEndpointBuilder.build(); Collection<Endpoint> peerEndpoints = new ArrayList<>(); peerEndpoints.add(peerEndpoint); when(ctx.getTenant(any(TenantId.class))).thenReturn(new IndexedTenant(peerTenant)); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(ctx.getPolicyManager()).thenReturn(policyManager); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); when(endpointManager.getEndpointsForGroup(any(EgKey.class))).thenReturn(peerEndpoints); when(endpointManager.getEndpointsForNode(any(NodeId.class))).thenReturn(peerEndpoints); destinationMapper.syncFlows(flows, endpointBuilder.build(), NODE_ID, ofWriter); verify(ctx, times(24)).getTenant(any(TenantId.class)); verify(ctx, times(9)).getEndpointManager(); verify(ctx, times(2)).getPolicyManager(); verify(ctx, times(4)).getCurrentPolicy(); InOrder order = inOrder(flows); order.verify(flows, times(1)).createLocalL2Flow(anyShort(), anyInt(), any(Endpoint.class), eq(ofWriter)); order.verify(flows, times(1)).createLocalL3RoutedFlow(anyShort(), anyInt(), any(Endpoint.class), any(L3Address.class), any(Subnet.class), any(Subnet.class), eq(ofWriter)); }
@VisibleForTesting void syncFlows(DestinationMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_FLOW, null, ofWriter); List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { syncLocalFlows(flows, endpoint, localSubnets, ofWriter); syncEndpointFlows(flows, nodeId, endpoint, ofWriter); } TenantId tenantId = endpoint.getTenant(); syncArpFlow(flows, tenantId, ofWriter); EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (ordinals != null) { flows.createBroadcastFlow(BROADCAST, ordinals, MULTICAST_MAC, ofWriter); } Collection<EndpointL3Prefix> prefixes = ctx.getEndpointManager().getEndpointsL3PrefixForTenant(tenantId); if (prefixes != null) { LOG.trace("DestinationMapper - Processing L3PrefixEndpoint"); syncL3PrefixFlow(flows, prefixes, tenantId, nodeId, ofWriter); } }
DestinationMapper extends FlowTable { @VisibleForTesting void syncFlows(DestinationMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_FLOW, null, ofWriter); List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { syncLocalFlows(flows, endpoint, localSubnets, ofWriter); syncEndpointFlows(flows, nodeId, endpoint, ofWriter); } TenantId tenantId = endpoint.getTenant(); syncArpFlow(flows, tenantId, ofWriter); EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (ordinals != null) { flows.createBroadcastFlow(BROADCAST, ordinals, MULTICAST_MAC, ofWriter); } Collection<EndpointL3Prefix> prefixes = ctx.getEndpointManager().getEndpointsL3PrefixForTenant(tenantId); if (prefixes != null) { LOG.trace("DestinationMapper - Processing L3PrefixEndpoint"); syncL3PrefixFlow(flows, prefixes, tenantId, nodeId, ofWriter); } } }
DestinationMapper extends FlowTable { @VisibleForTesting void syncFlows(DestinationMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_FLOW, null, ofWriter); List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { syncLocalFlows(flows, endpoint, localSubnets, ofWriter); syncEndpointFlows(flows, nodeId, endpoint, ofWriter); } TenantId tenantId = endpoint.getTenant(); syncArpFlow(flows, tenantId, ofWriter); EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (ordinals != null) { flows.createBroadcastFlow(BROADCAST, ordinals, MULTICAST_MAC, ofWriter); } Collection<EndpointL3Prefix> prefixes = ctx.getEndpointManager().getEndpointsL3PrefixForTenant(tenantId); if (prefixes != null) { LOG.trace("DestinationMapper - Processing L3PrefixEndpoint"); syncL3PrefixFlow(flows, prefixes, tenantId, nodeId, ofWriter); } } DestinationMapper(OfContext ctx, short tableId); }
DestinationMapper extends FlowTable { @VisibleForTesting void syncFlows(DestinationMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_FLOW, null, ofWriter); List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { syncLocalFlows(flows, endpoint, localSubnets, ofWriter); syncEndpointFlows(flows, nodeId, endpoint, ofWriter); } TenantId tenantId = endpoint.getTenant(); syncArpFlow(flows, tenantId, ofWriter); EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (ordinals != null) { flows.createBroadcastFlow(BROADCAST, ordinals, MULTICAST_MAC, ofWriter); } Collection<EndpointL3Prefix> prefixes = ctx.getEndpointManager().getEndpointsL3PrefixForTenant(tenantId); if (prefixes != null) { LOG.trace("DestinationMapper - Processing L3PrefixEndpoint"); syncL3PrefixFlow(flows, prefixes, tenantId, nodeId, ofWriter); } } DestinationMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); }
DestinationMapper extends FlowTable { @VisibleForTesting void syncFlows(DestinationMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_FLOW, null, ofWriter); List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { syncLocalFlows(flows, endpoint, localSubnets, ofWriter); syncEndpointFlows(flows, nodeId, endpoint, ofWriter); } TenantId tenantId = endpoint.getTenant(); syncArpFlow(flows, tenantId, ofWriter); EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (ordinals != null) { flows.createBroadcastFlow(BROADCAST, ordinals, MULTICAST_MAC, ofWriter); } Collection<EndpointL3Prefix> prefixes = ctx.getEndpointManager().getEndpointsL3PrefixForTenant(tenantId); if (prefixes != null) { LOG.trace("DestinationMapper - Processing L3PrefixEndpoint"); syncL3PrefixFlow(flows, prefixes, tenantId, nodeId, ofWriter); } } DestinationMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); static final MacAddress ROUTER_MAC; }