@Test public void testComputeArpTrueEdge() { IpSpace nextHopIpSpace = new MockIpSpace(1); IpSpace dstIpSpace = new MockIpSpace(2); Edge e1 = Edge.of("c1", "i1", "c2", "i2"); _arpTrueEdgeDestIp = ImmutableMap.of(e1, dstIpSpace); _arpTrueEdgeNextHopIp = ImmutableMap.of(e1, nextHopIpSpace); ForwardingAnalysisImpl forwardingAnalysisImpl = initForwardingAnalysisImpl(); Map<Edge, IpSpace> result = forwardingAnalysisImpl.computeArpTrueEdge(); assertThat( result, hasEntry( equalTo(e1), isAclIpSpaceThat( hasLines( containsInAnyOrder( AclIpSpaceLine.permit(nextHopIpSpace), AclIpSpaceLine.permit(dstIpSpace)))))); }
@Test public void testComputeRouteMatchConditions() { Set<AbstractRoute> routes = ImmutableSet.of(new ConnectedRoute(P1, INTERFACE1), new ConnectedRoute(P2, INTERFACE2)); MockRib rib = MockRib.builder().setMatchingIps(ImmutableMap.of(P1, IPSPACE1, P2, IPSPACE2)).build(); /* Resulting IP space should permit matching IPs */ assertThat( ForwardingAnalysisImpl.computeRouteMatchConditions(routes, rib.getMatchingIps()), isAclIpSpaceThat( hasLines( containsInAnyOrder( AclIpSpaceLine.permit(IPSPACE1), AclIpSpaceLine.permit(IPSPACE2))))); }
@Test public void testVisitAclIpSpace() { IpSpace lineIpSpace = UniverseIpSpace.INSTANCE; String lineIpSpaceName = "lineIpSpace"; IpSpaceMetadata lineIpSpaceMetadata = new IpSpaceMetadata("line_space_name", "line_space_type"); IpSpace ipSpace = AclIpSpace.of(AclIpSpaceLine.permit(lineIpSpace)); IpSpaceDescriber describerWithMetadata = new IpSpaceDescriber( new AclTracer( _flow, null, ImmutableMap.of(), ImmutableMap.of(TEST_NAME, ipSpace), ImmutableMap.of(TEST_NAME, TEST_METADATA))); IpSpaceDescriber describerWithLineMetadata = new IpSpaceDescriber( new AclTracer( _flow, null, ImmutableMap.of(), ImmutableMap.of(lineIpSpaceName, lineIpSpace), ImmutableMap.of(lineIpSpaceName, lineIpSpaceMetadata))); assertThat(ipSpace.accept(_describerNoNamesNorMetadata), equalTo("[0: universe]")); assertThat( ipSpace.accept(describerWithLineMetadata), equalTo("[0: 'line_space_type' named 'line_space_name']")); assertThat(ipSpace.accept(describerWithMetadata), equalTo(TEST_METADATA_DESCRIPTION)); }
@Test public void testWithAclIpSpaceWithGoodRefs() { // ACL contains an AclIpSpace that references the same valid named IpSpace twice _aclb .setLines( ImmutableList.of( acceptingHeaderSpace( HeaderSpace.builder() .setSrcIps( AclIpSpace.of( AclIpSpaceLine.permit(new IpSpaceReference("ipSpace")), AclIpSpaceLine.permit(new IpSpaceReference("ipSpace")))) .build()))) .build(); List<AclSpecs> aclSpecs = getAclSpecs(ImmutableSet.of("c1")); // The sanitized version of the acl should have correctly dereferenced "ipSpace" assertThat(aclSpecs, hasSize(1)); AclSpecs spec = aclSpecs.get(0); assertThat( spec.acl.getSanitizedAcl().getLines(), equalTo( ImmutableList.of( acceptingHeaderSpace( HeaderSpace.builder() .setSrcIps( AclIpSpace.of( AclIpSpaceLine.permit(Ip.parse("1.2.3.4").toIpSpace()), AclIpSpaceLine.permit(Ip.parse("1.2.3.4").toIpSpace()))) .build())))); }
@Test public void testWithAclIpSpaceWithCircularRef() { // Named IP spaces includes AclIpSpace "aclIpSpace". // "aclIpSpace" contains an IpSpaceReference to itself. Rip _c1.setIpSpaces( ImmutableSortedMap.of( "aclIpSpace", AclIpSpace.of(AclIpSpaceLine.permit(new IpSpaceReference("aclIpSpace"))))); _aclb .setLines( ImmutableList.of( IpAccessListLine.accepting() .setMatchCondition( new MatchHeaderSpace( HeaderSpace.builder() .setSrcIps(new IpSpaceReference("aclIpSpace")) .build())) .build())) .build(); List<AclSpecs> aclSpecs = getAclSpecs(ImmutableSet.of("c1")); // The sanitized version of the acl should have one unmatchable line assertThat(aclSpecs, hasSize(1)); AclSpecs spec = aclSpecs.get(0); assertThat(spec.acl.getSanitizedAcl().getLines(), equalTo(ImmutableList.of(UNMATCHABLE))); }