@Test public void test_SameEg() throws Exception { EndpointBuilder ep1Builder = buildEndpoint(IPV4_0, MAC_0, nodeConnector); ep1Builder.setEndpointGroup(ENDPOINT_GROUP_0); ep1Builder.setL2Context(L2BD_ID); Endpoint ep1 = ep1Builder.build(); endpointManagerMock.addEndpoint(ep1); EndpointBuilder ep2Builder = buildEndpoint(IPV4_1, MAC_1, nodeConnector); ep2Builder.setEndpointGroup(ENDPOINT_GROUP_1); ep2Builder.setL2Context(L2BD_ID); Endpoint ep2 = ep2Builder.build(); endpointManagerMock.addEndpoint(ep2); ctxMock.addTenant(buildTenant().setPolicy(new PolicyBuilder(buildTenant().getPolicy()) .setContract(ImmutableList.of(baseContract(null).build())).build()).build()); ofWriter = new OfWriter(); table.sync(ep1, ofWriter); assertTrue(!ofWriter.getTableForNode(NODE_ID, ctxMock.getPolicyManager().getTABLEID_POLICY_ENFORCER()) .getFlow() .isEmpty()); int count = 0; for (Flow f : ofWriter.getTableForNode(NODE_ID, ctxMock.getPolicyManager().getTABLEID_POLICY_ENFORCER()) .getFlow()) { if (isAllowSameEpg(f)) { count++; } } assertEquals(sameEpgFlows, count); int totalFlows = sameEpgFlows + allowTunnelFlows + layer4flowsIPv4 + layer4flowsIPv6; assertEquals(totalFlows, ofWriter .getTableForNode(NODE_ID, ctxMock.getPolicyManager().getTABLEID_POLICY_ENFORCER()).getFlow().size()); }
@Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { Preconditions.checkNotNull(endpoint); Preconditions.checkNotNull(ofWriter); NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID)); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunPort != null) { ofWriter.writeFlow(nodeId, TABLE_ID, allowFromTunnel(tunPort)); } EndpointFwdCtxOrdinals srcEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (srcEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", endpoint); return; } for (EgKey sourceEpg : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey destEpg : ctx.getCurrentPolicy().getPeers(sourceEpg)) { Collection<Endpoint> destinationEndpoints = getEndpointsForGroup(destEpg); for (Endpoint destinationEndpoint : destinationEndpoints) { EndpointFwdCtxOrdinals dstEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, destinationEndpoint); if (dstEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", destinationEndpoint); continue; } NetworkElements netElements = new NetworkElements(endpoint, destinationEndpoint, sourceEpg, destEpg, nodeId, ctx); Policy sourceEpgPolicy = ctx.getCurrentPolicy().getPolicy(destEpg, sourceEpg); Policy destinationEpgPolicy = ctx.getCurrentPolicy().getPolicy(sourceEpg, destEpg); resolveSourceEpgPolicy(ofWriter, netElements, sourceEpgPolicy, destinationEpgPolicy); ofWriter.writeFlow(nodeId, TABLE_ID, createArpFlow(srcEpFwdCxtOrdinals.getFdId())); } } allowSameEpg(sourceEpg, endpoint, nodeId, ofWriter); } }
PolicyEnforcer extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { Preconditions.checkNotNull(endpoint); Preconditions.checkNotNull(ofWriter); NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID)); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunPort != null) { ofWriter.writeFlow(nodeId, TABLE_ID, allowFromTunnel(tunPort)); } EndpointFwdCtxOrdinals srcEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (srcEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", endpoint); return; } for (EgKey sourceEpg : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey destEpg : ctx.getCurrentPolicy().getPeers(sourceEpg)) { Collection<Endpoint> destinationEndpoints = getEndpointsForGroup(destEpg); for (Endpoint destinationEndpoint : destinationEndpoints) { EndpointFwdCtxOrdinals dstEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, destinationEndpoint); if (dstEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", destinationEndpoint); continue; } NetworkElements netElements = new NetworkElements(endpoint, destinationEndpoint, sourceEpg, destEpg, nodeId, ctx); Policy sourceEpgPolicy = ctx.getCurrentPolicy().getPolicy(destEpg, sourceEpg); Policy destinationEpgPolicy = ctx.getCurrentPolicy().getPolicy(sourceEpg, destEpg); resolveSourceEpgPolicy(ofWriter, netElements, sourceEpgPolicy, destinationEpgPolicy); ofWriter.writeFlow(nodeId, TABLE_ID, createArpFlow(srcEpFwdCxtOrdinals.getFdId())); } } allowSameEpg(sourceEpg, endpoint, nodeId, ofWriter); } } }
PolicyEnforcer extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { Preconditions.checkNotNull(endpoint); Preconditions.checkNotNull(ofWriter); NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID)); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunPort != null) { ofWriter.writeFlow(nodeId, TABLE_ID, allowFromTunnel(tunPort)); } EndpointFwdCtxOrdinals srcEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (srcEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", endpoint); return; } for (EgKey sourceEpg : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey destEpg : ctx.getCurrentPolicy().getPeers(sourceEpg)) { Collection<Endpoint> destinationEndpoints = getEndpointsForGroup(destEpg); for (Endpoint destinationEndpoint : destinationEndpoints) { EndpointFwdCtxOrdinals dstEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, destinationEndpoint); if (dstEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", destinationEndpoint); continue; } NetworkElements netElements = new NetworkElements(endpoint, destinationEndpoint, sourceEpg, destEpg, nodeId, ctx); Policy sourceEpgPolicy = ctx.getCurrentPolicy().getPolicy(destEpg, sourceEpg); Policy destinationEpgPolicy = ctx.getCurrentPolicy().getPolicy(sourceEpg, destEpg); resolveSourceEpgPolicy(ofWriter, netElements, sourceEpgPolicy, destinationEpgPolicy); ofWriter.writeFlow(nodeId, TABLE_ID, createArpFlow(srcEpFwdCxtOrdinals.getFdId())); } } allowSameEpg(sourceEpg, endpoint, nodeId, ofWriter); } } PolicyEnforcer(OfContext ctx, short tableId); }
PolicyEnforcer extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { Preconditions.checkNotNull(endpoint); Preconditions.checkNotNull(ofWriter); NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID)); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunPort != null) { ofWriter.writeFlow(nodeId, TABLE_ID, allowFromTunnel(tunPort)); } EndpointFwdCtxOrdinals srcEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (srcEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", endpoint); return; } for (EgKey sourceEpg : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey destEpg : ctx.getCurrentPolicy().getPeers(sourceEpg)) { Collection<Endpoint> destinationEndpoints = getEndpointsForGroup(destEpg); for (Endpoint destinationEndpoint : destinationEndpoints) { EndpointFwdCtxOrdinals dstEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, destinationEndpoint); if (dstEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", destinationEndpoint); continue; } NetworkElements netElements = new NetworkElements(endpoint, destinationEndpoint, sourceEpg, destEpg, nodeId, ctx); Policy sourceEpgPolicy = ctx.getCurrentPolicy().getPolicy(destEpg, sourceEpg); Policy destinationEpgPolicy = ctx.getCurrentPolicy().getPolicy(sourceEpg, destEpg); resolveSourceEpgPolicy(ofWriter, netElements, sourceEpgPolicy, destinationEpgPolicy); ofWriter.writeFlow(nodeId, TABLE_ID, createArpFlow(srcEpFwdCxtOrdinals.getFdId())); } } allowSameEpg(sourceEpg, endpoint, nodeId, ofWriter); } } PolicyEnforcer(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); static Direction reverse(Direction direction); }
PolicyEnforcer extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { Preconditions.checkNotNull(endpoint); Preconditions.checkNotNull(ofWriter); NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID)); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunPort != null) { ofWriter.writeFlow(nodeId, TABLE_ID, allowFromTunnel(tunPort)); } EndpointFwdCtxOrdinals srcEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (srcEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", endpoint); return; } for (EgKey sourceEpg : ctx.getEndpointManager().getEgKeysForEndpoint(endpoint)) { for (EgKey destEpg : ctx.getCurrentPolicy().getPeers(sourceEpg)) { Collection<Endpoint> destinationEndpoints = getEndpointsForGroup(destEpg); for (Endpoint destinationEndpoint : destinationEndpoints) { EndpointFwdCtxOrdinals dstEpFwdCxtOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, destinationEndpoint); if (dstEpFwdCxtOrdinals == null) { LOG.debug("Method getEndpointFwdCtxOrdinals returned null for EP {}", destinationEndpoint); continue; } NetworkElements netElements = new NetworkElements(endpoint, destinationEndpoint, sourceEpg, destEpg, nodeId, ctx); Policy sourceEpgPolicy = ctx.getCurrentPolicy().getPolicy(destEpg, sourceEpg); Policy destinationEpgPolicy = ctx.getCurrentPolicy().getPolicy(sourceEpg, destEpg); resolveSourceEpgPolicy(ofWriter, netElements, sourceEpgPolicy, destinationEpgPolicy); ofWriter.writeFlow(nodeId, TABLE_ID, createArpFlow(srcEpFwdCxtOrdinals.getFdId())); } } allowSameEpg(sourceEpg, endpoint, nodeId, ofWriter); } } PolicyEnforcer(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); static Direction reverse(Direction direction);  }