@Test public void syncL3PrefixFlow() { DestinationMapperFlows flows = mock(DestinationMapperFlows.class); 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()); HashSet<Subnet> subnets = new HashSet<>(); 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.setL3Context(l3Contexts); forwardingContextBuilder.setSubnet(new ArrayList<>(subnets)); forwardingContextBuilder.setL2BridgeDomain(l2BDomains); forwardingContextBuilder.setL2FloodDomain(l2FDomains); TenantBuilder tenantBuilder = buildTenant(); tenantBuilder.setForwardingContext(forwardingContextBuilder.build()); Tenant tenant = tenantBuilder.build(); Collection<Endpoint> endpoints = new ArrayList<>(); EndpointBuilder endpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1); endpointBuilder.setNetworkContainment(SUBNET_0); Endpoint endpoint = endpointBuilder.build(); endpoints.add(endpoint); ArrayList<EndpointL3Prefix> l3Prefixes = new ArrayList<>(); EndpointL3PrefixBuilder prefixBuilder = new EndpointL3PrefixBuilder(); List<EndpointL3Gateways> endpointL3GatewaysList = new ArrayList<>(); EndpointL3GatewaysBuilder endpointL3GatewaysBuilder = new EndpointL3GatewaysBuilder(); endpointL3GatewaysBuilder.setIpAddress(new IpAddress(new Ipv4Address(IPV4_1))); endpointL3GatewaysBuilder.setL3Context(L3C_ID); endpointL3GatewaysList.add(endpointL3GatewaysBuilder.build()); prefixBuilder.setEndpointL3Gateways(endpointL3GatewaysList); l3Prefixes.add(prefixBuilder.build()); EndpointL3 endpointL3 = buildL3Endpoint(IPV4_0, IPV4_2, MAC_2, L2).build(); when(ctx.getTenant(any(TenantId.class))).thenReturn(new IndexedTenant(tenant)); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(ctx.getSwitchManager()).thenReturn(switchManager); when(ctx.getPolicyManager()).thenReturn(policyManager); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); when(endpointManager.getEndpointsForNode(any(NodeId.class))).thenReturn(endpoints); when(endpointManager.getL3Endpoint(any(L3ContextId.class), any(IpAddress.class), any(TenantId.class))) .thenReturn(endpointL3); when(endpointManager.getL2EndpointFromL3(any(EndpointL3.class))).thenReturn(endpoint); destinationMapper.syncL3PrefixFlow(flows, l3Prefixes, null, NODE_ID, ofWriter); verify(ctx, times(6)).getTenant(any(TenantId.class)); verify(ctx, times(4)).getEndpointManager(); verify(ctx, times(1)).getSwitchManager(); verify(ctx, times(1)).getPolicyManager(); verify(ctx, times(1)).getCurrentPolicy(); verify(flows, times(1)).createL3PrefixFlow(anyShort(), anyInt(), any(Endpoint.class), any(EndpointL3Prefix.class), any(IndexedTenant.class), any(Subnet.class), anySetOf(NodeConnectorId.class), eq(ofWriter)); }
@VisibleForTesting void syncL3PrefixFlow(DestinationMapperFlows flows, Collection<EndpointL3Prefix> l3Prefixes, TenantId tenantId, NodeId nodeId, OfWriter ofWriter) { short policyEnforcerTableId = ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(); for (EndpointL3Prefix l3Prefix : l3Prefixes) { List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { for (Subnet localSubnet : localSubnets) { for (EndpointL3Gateways l3Gateway : l3Prefix.getEndpointL3Gateways()) { if (l3Gateway != null && l3Gateway.getL3Context() != null && l3Gateway.getIpAddress() != null) { EndpointL3 endpointL3 = ctx.getEndpointManager().getL3Endpoint(l3Gateway.getL3Context(), l3Gateway.getIpAddress(), tenantId); Endpoint endpointL2 = ctx.getEndpointManager().getL2EndpointFromL3(endpointL3); IndexedTenant tenant = ctx.getTenant(l3Prefix.getTenant()); Set<NodeConnectorId> externalPorts = ctx.getSwitchManager().getExternalPorts(nodeId); if (endpointL3 != null && endpointL2 != null && tenant != null && externalPorts != null) { L3Context l3Context = utils.getL3ContextForSubnet(tenant, localSubnet); if (l3Context == null || l3Context.getId() == null) { LOG.error("No L3 Context found associated with subnet {}", localSubnet.getId()); continue; } EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpointL2); if (ordinals == null) { LOG.error("No Fwd Ctx ordinals found in endpoint ", endpointL2); continue; } flows.createL3PrefixFlow(policyEnforcerTableId, L3_PREFIX, endpointL2, l3Prefix, tenant, localSubnet, externalPorts, ofWriter); } } } } } } }
DestinationMapper extends FlowTable { @VisibleForTesting void syncL3PrefixFlow(DestinationMapperFlows flows, Collection<EndpointL3Prefix> l3Prefixes, TenantId tenantId, NodeId nodeId, OfWriter ofWriter) { short policyEnforcerTableId = ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(); for (EndpointL3Prefix l3Prefix : l3Prefixes) { List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { for (Subnet localSubnet : localSubnets) { for (EndpointL3Gateways l3Gateway : l3Prefix.getEndpointL3Gateways()) { if (l3Gateway != null && l3Gateway.getL3Context() != null && l3Gateway.getIpAddress() != null) { EndpointL3 endpointL3 = ctx.getEndpointManager().getL3Endpoint(l3Gateway.getL3Context(), l3Gateway.getIpAddress(), tenantId); Endpoint endpointL2 = ctx.getEndpointManager().getL2EndpointFromL3(endpointL3); IndexedTenant tenant = ctx.getTenant(l3Prefix.getTenant()); Set<NodeConnectorId> externalPorts = ctx.getSwitchManager().getExternalPorts(nodeId); if (endpointL3 != null && endpointL2 != null && tenant != null && externalPorts != null) { L3Context l3Context = utils.getL3ContextForSubnet(tenant, localSubnet); if (l3Context == null || l3Context.getId() == null) { LOG.error("No L3 Context found associated with subnet {}", localSubnet.getId()); continue; } EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpointL2); if (ordinals == null) { LOG.error("No Fwd Ctx ordinals found in endpoint ", endpointL2); continue; } flows.createL3PrefixFlow(policyEnforcerTableId, L3_PREFIX, endpointL2, l3Prefix, tenant, localSubnet, externalPorts, ofWriter); } } } } } } } }
DestinationMapper extends FlowTable { @VisibleForTesting void syncL3PrefixFlow(DestinationMapperFlows flows, Collection<EndpointL3Prefix> l3Prefixes, TenantId tenantId, NodeId nodeId, OfWriter ofWriter) { short policyEnforcerTableId = ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(); for (EndpointL3Prefix l3Prefix : l3Prefixes) { List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { for (Subnet localSubnet : localSubnets) { for (EndpointL3Gateways l3Gateway : l3Prefix.getEndpointL3Gateways()) { if (l3Gateway != null && l3Gateway.getL3Context() != null && l3Gateway.getIpAddress() != null) { EndpointL3 endpointL3 = ctx.getEndpointManager().getL3Endpoint(l3Gateway.getL3Context(), l3Gateway.getIpAddress(), tenantId); Endpoint endpointL2 = ctx.getEndpointManager().getL2EndpointFromL3(endpointL3); IndexedTenant tenant = ctx.getTenant(l3Prefix.getTenant()); Set<NodeConnectorId> externalPorts = ctx.getSwitchManager().getExternalPorts(nodeId); if (endpointL3 != null && endpointL2 != null && tenant != null && externalPorts != null) { L3Context l3Context = utils.getL3ContextForSubnet(tenant, localSubnet); if (l3Context == null || l3Context.getId() == null) { LOG.error("No L3 Context found associated with subnet {}", localSubnet.getId()); continue; } EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpointL2); if (ordinals == null) { LOG.error("No Fwd Ctx ordinals found in endpoint ", endpointL2); continue; } flows.createL3PrefixFlow(policyEnforcerTableId, L3_PREFIX, endpointL2, l3Prefix, tenant, localSubnet, externalPorts, ofWriter); } } } } } } } DestinationMapper(OfContext ctx, short tableId); }
DestinationMapper extends FlowTable { @VisibleForTesting void syncL3PrefixFlow(DestinationMapperFlows flows, Collection<EndpointL3Prefix> l3Prefixes, TenantId tenantId, NodeId nodeId, OfWriter ofWriter) { short policyEnforcerTableId = ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(); for (EndpointL3Prefix l3Prefix : l3Prefixes) { List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { for (Subnet localSubnet : localSubnets) { for (EndpointL3Gateways l3Gateway : l3Prefix.getEndpointL3Gateways()) { if (l3Gateway != null && l3Gateway.getL3Context() != null && l3Gateway.getIpAddress() != null) { EndpointL3 endpointL3 = ctx.getEndpointManager().getL3Endpoint(l3Gateway.getL3Context(), l3Gateway.getIpAddress(), tenantId); Endpoint endpointL2 = ctx.getEndpointManager().getL2EndpointFromL3(endpointL3); IndexedTenant tenant = ctx.getTenant(l3Prefix.getTenant()); Set<NodeConnectorId> externalPorts = ctx.getSwitchManager().getExternalPorts(nodeId); if (endpointL3 != null && endpointL2 != null && tenant != null && externalPorts != null) { L3Context l3Context = utils.getL3ContextForSubnet(tenant, localSubnet); if (l3Context == null || l3Context.getId() == null) { LOG.error("No L3 Context found associated with subnet {}", localSubnet.getId()); continue; } EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpointL2); if (ordinals == null) { LOG.error("No Fwd Ctx ordinals found in endpoint ", endpointL2); continue; } flows.createL3PrefixFlow(policyEnforcerTableId, L3_PREFIX, endpointL2, l3Prefix, tenant, localSubnet, externalPorts, ofWriter); } } } } } } } DestinationMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); }
DestinationMapper extends FlowTable { @VisibleForTesting void syncL3PrefixFlow(DestinationMapperFlows flows, Collection<EndpointL3Prefix> l3Prefixes, TenantId tenantId, NodeId nodeId, OfWriter ofWriter) { short policyEnforcerTableId = ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(); for (EndpointL3Prefix l3Prefix : l3Prefixes) { List<Subnet> localSubnets = utils.getLocalSubnets(nodeId); if (localSubnets != null) { for (Subnet localSubnet : localSubnets) { for (EndpointL3Gateways l3Gateway : l3Prefix.getEndpointL3Gateways()) { if (l3Gateway != null && l3Gateway.getL3Context() != null && l3Gateway.getIpAddress() != null) { EndpointL3 endpointL3 = ctx.getEndpointManager().getL3Endpoint(l3Gateway.getL3Context(), l3Gateway.getIpAddress(), tenantId); Endpoint endpointL2 = ctx.getEndpointManager().getL2EndpointFromL3(endpointL3); IndexedTenant tenant = ctx.getTenant(l3Prefix.getTenant()); Set<NodeConnectorId> externalPorts = ctx.getSwitchManager().getExternalPorts(nodeId); if (endpointL3 != null && endpointL2 != null && tenant != null && externalPorts != null) { L3Context l3Context = utils.getL3ContextForSubnet(tenant, localSubnet); if (l3Context == null || l3Context.getId() == null) { LOG.error("No L3 Context found associated with subnet {}", localSubnet.getId()); continue; } EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpointL2); if (ordinals == null) { LOG.error("No Fwd Ctx ordinals found in endpoint ", endpointL2); continue; } flows.createL3PrefixFlow(policyEnforcerTableId, L3_PREFIX, endpointL2, l3Prefix, tenant, localSubnet, externalPorts, ofWriter); } } } } } } } DestinationMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); static final MacAddress ROUTER_MAC; }