@Test public void testFactory() { assertThat(Edge.of("tail", "tailInt", "head", "headInt"), equalTo(EDGE)); }
private FlowTraceHop buildFlowTraceHop(GraphEdge graphEdge, String route) { String node1 = graphEdge.getRouter(); String int1 = graphEdge.getStart().getName(); String node2 = graphEdge.getPeer() == null ? "(none)" : graphEdge.getPeer(); String int2 = graphEdge.getEnd() == null ? "null_interface" : graphEdge.getEnd().getName(); Edge edge = Edge.of(node1, int1, node2, int2); SortedSet<String> routes = new TreeSet<>(); routes.add(route); return new FlowTraceHop(edge, routes, null, null, null); }
if (ingressInterfaceName != null) { Edge edge = Edge.of( TRACEROUTE_INGRESS_NODE_NAME, TRACEROUTE_INGRESS_NODE_INTERFACE_NAME,
@Test public void testComputeRoutesWithDestIpEdge() { String c1 = "c1"; String c2 = "c2"; String v1 = "v1"; String i1 = "i1"; String i2 = "i2"; AbstractRoute r1 = new ConnectedRoute(P1, i1); _routesWhereDstIpCanBeArpIp = ImmutableMap.of(c1, ImmutableMap.of(v1, ImmutableMap.of(i1, ImmutableSet.of(r1)))); Edge e1 = Edge.of(c1, i1, c2, i2); _arpReplies = ImmutableMap.of(c2, ImmutableMap.of(i2, P2.getStartIp().toIpSpace())); Topology topology = new Topology(ImmutableSortedSet.of(e1)); ForwardingAnalysisImpl forwardingAnalysisImpl = initForwardingAnalysisImpl(); Map<Edge, Set<AbstractRoute>> result = forwardingAnalysisImpl.computeRoutesWithDestIpEdge(topology); assertThat(result, equalTo(ImmutableMap.of(e1, ImmutableSet.of(r1)))); }
/** * Tests that two edges that have the same interface definition but different nodes are not equal. */ @Test public void testEquals() { Interface i1 = new Interface("eth0"); VerboseEdge edge1 = new VerboseEdge(i1, i1, Edge.of("node1", "eth0", "node2", "eth0")); assertEquals(edge1, edge1); VerboseEdge edge2 = new VerboseEdge(i1, i1, Edge.of("node2", "eth0", "node1", "eth0")); assertNotEquals(edge1, edge2); } }
private Edge fromGraphEdge(GraphEdge graphEdge) { String node1 = graphEdge.getRouter(); String int1 = graphEdge.getStart() == null ? "none" : graphEdge.getStart().getName(); String node2 = graphEdge.getPeer(); String int2 = graphEdge.getEnd() == null ? "none" : graphEdge.getEnd().getName(); return Edge.of(node1, int1, node2, int2); }
@Test public void testComputeSomeoneReplies() { String c1 = "c1"; String i1 = "i1"; String c2 = "c2"; String i2 = "i2"; Edge e1 = Edge.of(c1, i1, c2, i2); _arpReplies = ImmutableMap.of(c2, ImmutableMap.of(i2, P1.toIpSpace())); Topology topology = new Topology(ImmutableSortedSet.of(e1)); ForwardingAnalysisImpl forwardingAnalysisImpl = initForwardingAnalysisImpl(); Map<String, Map<String, IpSpace>> result = forwardingAnalysisImpl.computeSomeoneReplies(topology); /* IPs allowed by neighbor should appear */ assertThat(result, hasEntry(equalTo(c1), hasEntry(equalTo(i1), containsIp(P1.getStartIp())))); assertThat(result, hasEntry(equalTo(c1), hasEntry(equalTo(i1), containsIp(P1.getEndIp())))); /* IPs not allowed by neighbor should not appear */ assertThat( result, hasEntry(equalTo(c1), hasEntry(equalTo(i1), not(containsIp(P2.getStartIp()))))); }
@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 testLayer3ToRow() { Map<String, Configuration> configurationMap = ImmutableSortedMap.of("host1", _host1, "host2", _host2); Row row = layer3EdgeToRow(configurationMap, Edge.of("host1", "int1", "host2", "int2")); assertThat( row, allOf( hasColumn( COL_INTERFACE, equalTo(new NodeInterfacePair("host1", "int1")), Schema.INTERFACE), hasColumn( COL_IPS, equalTo(ImmutableSet.of(Ip.parse("1.1.1.1"))), Schema.set(Schema.IP)), hasColumn( COL_REMOTE_INTERFACE, equalTo(new NodeInterfacePair("host2", "int2")), Schema.INTERFACE), hasColumn( COL_REMOTE_IPS, equalTo(ImmutableSet.of(Ip.parse("2.2.2.2"))), Schema.set(Schema.IP)))); }
@Test public void testGetLayer3Edges() { Topology layer3Topology = new Topology(ImmutableSortedSet.of(Edge.of("host1", "int1", "host2", "int2"))); Multiset<Row> rows = getLayer3Edges(_configurations, _includeNodes, _includeRemoteNodes, layer3Topology); assertThat( rows, contains( allOf( hasColumn( COL_INTERFACE, equalTo(new NodeInterfacePair("host1", "int1")), Schema.INTERFACE), hasColumn( COL_IPS, equalTo(ImmutableSet.of(Ip.parse("1.1.1.1"))), Schema.set(Schema.IP)), hasColumn( COL_REMOTE_INTERFACE, equalTo(new NodeInterfacePair("host2", "int2")), Schema.INTERFACE), hasColumn( COL_REMOTE_IPS, equalTo(ImmutableSet.of(Ip.parse("2.2.2.2"))), Schema.set(Schema.IP))))); }
String c2 = "c2"; String i2 = "i2"; Edge e1 = Edge.of(c1, i1, c2, i2); _arpReplies = ImmutableMap.of(c2, ImmutableMap.of(i2, P2.getStartIp().toIpSpace())); Topology topology = new Topology(ImmutableSortedSet.of(e1));
List<Edge> links = ImmutableList.of(Edge.of("n2", "iface2", "n3", "iface3")); List<String> nodes = ImmutableList.of("n4", "n5");
@Test public void testColumnComparatorFlowTrace() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.FLOW_TRACE, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, new FlowTrace(FlowDisposition.ACCEPTED, ImmutableList.of(), "")); Row r2 = Row.of(col, new FlowTrace(FlowDisposition.DELIVERED_TO_SUBNET, ImmutableList.of(), "")); Row r3 = Row.of( col, new FlowTrace( FlowDisposition.ACCEPTED, ImmutableList.of( new FlowTraceHop( Edge.of("a", "a", "b", "b"), ImmutableSortedSet.of(), "a", "a", Flow.builder().setDstIp(Ip.ZERO).setIngressNode("a").setTag("a").build())), "")); assertThat(comparator.compare(r1, r2), lessThan(0)); assertThat(comparator.compare(r1, r3), lessThan(0)); assertThat(comparator.compare(r2, r3), lessThan(0)); }
.build())) .build())); Edge edge = Edge.of(c1.getHostname(), i1.getName(), c2.getHostname(), i2.getName()); _routesWithDestIpEdge = ImmutableMap.of(edge, ImmutableSet.of(new ConnectedRoute(P1, i1.getName())));
.setAddress(new InterfaceAddress(i2Ip, P1.getPrefixLength())) .build(); Edge edge = Edge.of(c1.getHostname(), i1.getName(), c2.getHostname(), i2.getName()); Map<String, Configuration> configurations = ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2);
@Before public void setup() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); _host1 = cb.setHostname("host1").build(); _host1.setInterfaces( ImmutableSortedMap.of( "int1", Interface.builder() .setName("int1") .setAddress(new InterfaceAddress(Ip.parse("1.1.1.1"), 24)) .build())); _host2 = cb.setHostname("host2").build(); _host2.setInterfaces( ImmutableSortedMap.of( "int2", Interface.builder() .setName("int2") .setAddress(new InterfaceAddress(Ip.parse("2.2.2.2"), 24)) .build())); _configurations = ImmutableSortedMap.of("host1", _host1, "host2", _host2); _includeNodes = ImmutableSortedSet.of("host1", "host2"); _includeRemoteNodes = ImmutableSortedSet.of("host1", "host2"); // Sending an edge from host1 to host2 in layer 3 _topology = new Topology(ImmutableSortedSet.of(Edge.of("host1", "int1", "host2", "int2"))); }