@Test public void test_Conditions() throws Exception { Condition cond1 = new ConditionBuilder().setName(new ConditionName("cond1")).build(); Condition cond2 = new ConditionBuilder().setName(new ConditionName("cond2")).build(); EndpointBuilder ep1Builder = buildEndpoint(IPV4_0, MAC_0, nodeConnector); ep1Builder.setEndpointGroup(ENDPOINT_GROUP_0); ep1Builder.setL2Context(L2BD_ID); ep1Builder.setCondition(ImmutableList.of(cond1.getName())).build(); Endpoint ep1 = ep1Builder.build(); endpointManagerMock.addEndpoint(ep1); EndpointBuilder ep2Builder = buildEndpoint(IPV4_1, MAC_1, nodeConnector); ep2Builder.setEndpointGroup(ENDPOINT_GROUP_1); ep2Builder.setL2Context(L2BD_ID); ep2Builder.setCondition(ImmutableList.of(cond1.getName(), cond2.getName())).build(); Endpoint ep2 = ep2Builder.build(); endpointManagerMock.addEndpoint(ep2); TenantBuilder tb = buildTenant().setPolicy(new PolicyBuilder(buildTenant().getPolicy()) .setContract(ImmutableList.of(new ContractBuilder().setId(CONTRACT_ID) .setSubject(ImmutableList.of(baseSubject(Direction.Out).build())) .setClause(ImmutableList.of(new ClauseBuilder().setName(new ClauseName("test")) .setSubjectRefs(ImmutableList.of(new SubjectName("s1"))) .setConsumerMatchers(new ConsumerMatchersBuilder().setConditionMatcher( ImmutableList.of(new ConditionMatcherBuilder().setName(new ConditionMatcherName("m1")) .setCondition(ImmutableList.of(cond1, cond2)) .setMatchType(MatchType.Any) .build())) .build()) .setProviderMatchers(new ProviderMatchersBuilder() .setConditionMatcher( ImmutableList.of(new ConditionMatcherBuilder().setName(new ConditionMatcherName("m2")) .setCondition(ImmutableList.of(cond1, cond2)) .setMatchType(MatchType.All) .build())) .build()) .build())) .build())) .build()); ctxMock.addTenant(tb.build()); PolicyInfo policy = ctxMock.getCurrentPolicy(); List<ConditionName> ep1c = endpointManagerMock.getConditionsForEndpoint(ep1); ConditionGroup cg1 = policy.getEgCondGroup(new EgKey(tb.getId(), ep1.getEndpointGroup()), ep1c); List<ConditionName> ep2c = endpointManagerMock.getConditionsForEndpoint(ep2); ConditionGroup cg2 = policy.getEgCondGroup(new EgKey(tb.getId(), ep2.getEndpointGroup()), ep2c); int cg1Id = OrdinalFactory.getCondGroupOrdinal(cg1); int cg2Id = OrdinalFactory.getCondGroupOrdinal(cg2); int eg1Id = OrdinalFactory.getContextOrdinal(ep1.getTenant(), ep1.getEndpointGroup()); int eg2Id = OrdinalFactory.getContextOrdinal(ep1.getTenant(), ep2.getEndpointGroup()); assertNotEquals(cg1Id, cg2Id); MatchBuilder mb = new MatchBuilder(); FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, (long) eg1Id), RegMatch.of(NxmNxReg1.class, (long) cg1Id), RegMatch.of(NxmNxReg2.class, (long) eg2Id), RegMatch.of(NxmNxReg3.class, (long) cg2Id)); int count = 0; ofWriter = new OfWriter(); table.sync(ep1, ofWriter); int dropAllFlow = 1; int arpFlows = 1; int totalFlows = sameEpgFlows + allowTunnelFlows + layer4flowsIPv4 + layer4flowsIPv6 + arpFlows + dropAllFlow; assertEquals(totalFlows, ofWriter .getTableForNode(NODE_ID, ctxMock.getPolicyManager().getTABLEID_POLICY_ENFORCER()).getFlow().size()); for (Flow f : ofWriter.getTableForNode(NODE_ID, ctxMock.getPolicyManager().getTABLEID_POLICY_ENFORCER()) .getFlow()) { if (f.getMatch() != null && f.getMatch().getEthernetMatch() != null) { count++; } } totalFlows = layer4flowsIPv4 + layer4flowsIPv6 + arpFlows; assertEquals(totalFlows, count); }
@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);  }