@Test public void syncFlows_endpointGroupsOnly() { Endpoint endpoint = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1).build(); EndpointBuilder endpointBuilder = new EndpointBuilder(endpoint); endpointBuilder.setEndpointGroup(ENDPOINT_GROUP_0); List<EndpointGroupId> endpointGroupIds = new ArrayList<>(); endpointGroupIds.add(ENDPOINT_GROUP_1); endpointGroupIds.add(ENDPOINT_GROUP_2); endpointBuilder.setEndpointGroups(endpointGroupIds); SourceMapper sourceMapper = new SourceMapper(ctx, tableId); when(ctx.getPolicyManager()).thenReturn(policyManager); when(ctx.getSwitchManager()).thenReturn(switchManager); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant()); when(policyManager.getTABLEID_DESTINATION_MAPPER()).thenReturn((short) 3); SourceMapperFlows flows = mock(SourceMapperFlows.class); sourceMapper.syncFlows(flows, endpointBuilder.build(), NODE_ID, ofWriter); verify(ctx, times(4)).getTenant(Mockito.any(TenantId.class)); verify(ctx.getPolicyManager(), times(1)).getTABLEID_DESTINATION_MAPPER(); verify(ctx.getSwitchManager(), times(1)).getTunnelPort(NODE_ID, TunnelTypeVxlan.class); InOrder order = inOrder(ctx, flows); order.verify(flows, atLeastOnce()).dropFlow(Mockito.anyInt(), Mockito.anyLong(), eq(ofWriter)); order.verify(ctx, times(1)).getPolicyManager(); order.verify(ctx, times(1)).getSwitchManager(); order.verify(ctx, times(3)).getTenant(Mockito.any(TenantId.class)); order.verify(ctx, times(1)).getEndpointManager(); order.verify(ctx, times(1)).getCurrentPolicy(); order.verify(flows, atLeastOnce()).synchronizeEp(Mockito.anyShort(), Mockito.anyInt(), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.any(MacAddress.class), Mockito.any(NodeConnectorId.class), eq(ofWriter)); }
@VisibleForTesting void syncFlows(SourceMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_ALL, null, ofWriter); short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); NodeConnectorId tunnelPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunnelPort != null) { Set<EgKey> endpointGroups = getEndpointGroups(endpoint); for (EgKey endpointGroup : endpointGroups) { Set<EgKey> peers = Sets.union(Collections.singleton(endpointGroup), ctx.getCurrentPolicy().getPeers(endpointGroup)); for (EgKey peer : peers) { Collection<Endpoint> peerEgEndpoints = ctx.getEndpointManager().getEndpointsForGroup(peer); for (Endpoint peerEgEndpoint : peerEgEndpoints) { OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, peerEgEndpoint); flows.createTunnelFlow(destinationMapperId, TUNNEL_FLOW, tunnelPort, ordinals, ofWriter); flows.createBroadcastFlow(destinationMapperId, BROADCAST_FLOW, tunnelPort, ordinals, ofWriter); } } } } if (endpoint.getEndpointGroup() == null && endpoint.getEndpointGroups() == null || endpoint.getTenant() == null) { return; } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); MacAddress macAddress = endpoint.getMacAddress(); if (endpointFwdCtxOrdinals != null) { OfOverlayContext ofOverlayContext = endpoint.getAugmentation(OfOverlayContext.class); if (ofOverlayContext != null && ofOverlayContext.getNodeConnectorId() != null && (EndpointManager.isInternal(endpoint, tenant.getExternalImplicitGroups()))) { flows.synchronizeEp(destinationMapperId, SYNCHRONIZE_EP, endpointFwdCtxOrdinals, macAddress, ofOverlayContext.getNodeConnectorId(), ofWriter); } } }
SourceMapper extends FlowTable { @VisibleForTesting void syncFlows(SourceMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_ALL, null, ofWriter); short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); NodeConnectorId tunnelPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunnelPort != null) { Set<EgKey> endpointGroups = getEndpointGroups(endpoint); for (EgKey endpointGroup : endpointGroups) { Set<EgKey> peers = Sets.union(Collections.singleton(endpointGroup), ctx.getCurrentPolicy().getPeers(endpointGroup)); for (EgKey peer : peers) { Collection<Endpoint> peerEgEndpoints = ctx.getEndpointManager().getEndpointsForGroup(peer); for (Endpoint peerEgEndpoint : peerEgEndpoints) { OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, peerEgEndpoint); flows.createTunnelFlow(destinationMapperId, TUNNEL_FLOW, tunnelPort, ordinals, ofWriter); flows.createBroadcastFlow(destinationMapperId, BROADCAST_FLOW, tunnelPort, ordinals, ofWriter); } } } } if (endpoint.getEndpointGroup() == null && endpoint.getEndpointGroups() == null || endpoint.getTenant() == null) { return; } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); MacAddress macAddress = endpoint.getMacAddress(); if (endpointFwdCtxOrdinals != null) { OfOverlayContext ofOverlayContext = endpoint.getAugmentation(OfOverlayContext.class); if (ofOverlayContext != null && ofOverlayContext.getNodeConnectorId() != null && (EndpointManager.isInternal(endpoint, tenant.getExternalImplicitGroups()))) { flows.synchronizeEp(destinationMapperId, SYNCHRONIZE_EP, endpointFwdCtxOrdinals, macAddress, ofOverlayContext.getNodeConnectorId(), ofWriter); } } } }
SourceMapper extends FlowTable { @VisibleForTesting void syncFlows(SourceMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_ALL, null, ofWriter); short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); NodeConnectorId tunnelPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunnelPort != null) { Set<EgKey> endpointGroups = getEndpointGroups(endpoint); for (EgKey endpointGroup : endpointGroups) { Set<EgKey> peers = Sets.union(Collections.singleton(endpointGroup), ctx.getCurrentPolicy().getPeers(endpointGroup)); for (EgKey peer : peers) { Collection<Endpoint> peerEgEndpoints = ctx.getEndpointManager().getEndpointsForGroup(peer); for (Endpoint peerEgEndpoint : peerEgEndpoints) { OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, peerEgEndpoint); flows.createTunnelFlow(destinationMapperId, TUNNEL_FLOW, tunnelPort, ordinals, ofWriter); flows.createBroadcastFlow(destinationMapperId, BROADCAST_FLOW, tunnelPort, ordinals, ofWriter); } } } } if (endpoint.getEndpointGroup() == null && endpoint.getEndpointGroups() == null || endpoint.getTenant() == null) { return; } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); MacAddress macAddress = endpoint.getMacAddress(); if (endpointFwdCtxOrdinals != null) { OfOverlayContext ofOverlayContext = endpoint.getAugmentation(OfOverlayContext.class); if (ofOverlayContext != null && ofOverlayContext.getNodeConnectorId() != null && (EndpointManager.isInternal(endpoint, tenant.getExternalImplicitGroups()))) { flows.synchronizeEp(destinationMapperId, SYNCHRONIZE_EP, endpointFwdCtxOrdinals, macAddress, ofOverlayContext.getNodeConnectorId(), ofWriter); } } } SourceMapper(OfContext ctx, short tableId); }
SourceMapper extends FlowTable { @VisibleForTesting void syncFlows(SourceMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_ALL, null, ofWriter); short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); NodeConnectorId tunnelPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunnelPort != null) { Set<EgKey> endpointGroups = getEndpointGroups(endpoint); for (EgKey endpointGroup : endpointGroups) { Set<EgKey> peers = Sets.union(Collections.singleton(endpointGroup), ctx.getCurrentPolicy().getPeers(endpointGroup)); for (EgKey peer : peers) { Collection<Endpoint> peerEgEndpoints = ctx.getEndpointManager().getEndpointsForGroup(peer); for (Endpoint peerEgEndpoint : peerEgEndpoints) { OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, peerEgEndpoint); flows.createTunnelFlow(destinationMapperId, TUNNEL_FLOW, tunnelPort, ordinals, ofWriter); flows.createBroadcastFlow(destinationMapperId, BROADCAST_FLOW, tunnelPort, ordinals, ofWriter); } } } } if (endpoint.getEndpointGroup() == null && endpoint.getEndpointGroups() == null || endpoint.getTenant() == null) { return; } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); MacAddress macAddress = endpoint.getMacAddress(); if (endpointFwdCtxOrdinals != null) { OfOverlayContext ofOverlayContext = endpoint.getAugmentation(OfOverlayContext.class); if (ofOverlayContext != null && ofOverlayContext.getNodeConnectorId() != null && (EndpointManager.isInternal(endpoint, tenant.getExternalImplicitGroups()))) { flows.synchronizeEp(destinationMapperId, SYNCHRONIZE_EP, endpointFwdCtxOrdinals, macAddress, ofOverlayContext.getNodeConnectorId(), ofWriter); } } } SourceMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); }
SourceMapper extends FlowTable { @VisibleForTesting void syncFlows(SourceMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) { flows.dropFlow(DROP_ALL, null, ofWriter); short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER(); NodeConnectorId tunnelPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunnelPort != null) { Set<EgKey> endpointGroups = getEndpointGroups(endpoint); for (EgKey endpointGroup : endpointGroups) { Set<EgKey> peers = Sets.union(Collections.singleton(endpointGroup), ctx.getCurrentPolicy().getPeers(endpointGroup)); for (EgKey peer : peers) { Collection<Endpoint> peerEgEndpoints = ctx.getEndpointManager().getEndpointsForGroup(peer); for (Endpoint peerEgEndpoint : peerEgEndpoints) { OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, peerEgEndpoint); flows.createTunnelFlow(destinationMapperId, TUNNEL_FLOW, tunnelPort, ordinals, ofWriter); flows.createBroadcastFlow(destinationMapperId, BROADCAST_FLOW, tunnelPort, ordinals, ofWriter); } } } } if (endpoint.getEndpointGroup() == null && endpoint.getEndpointGroups() == null || endpoint.getTenant() == null) { return; } IndexedTenant tenant = ctx.getTenant(endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); MacAddress macAddress = endpoint.getMacAddress(); if (endpointFwdCtxOrdinals != null) { OfOverlayContext ofOverlayContext = endpoint.getAugmentation(OfOverlayContext.class); if (ofOverlayContext != null && ofOverlayContext.getNodeConnectorId() != null && (EndpointManager.isInternal(endpoint, tenant.getExternalImplicitGroups()))) { flows.synchronizeEp(destinationMapperId, SYNCHRONIZE_EP, endpointFwdCtxOrdinals, macAddress, ofOverlayContext.getNodeConnectorId(), ofWriter); } } } SourceMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter);  }