private static TableMetadata createMetadata() { ImmutableList<ColumnMetadata> columnMetadata = ImmutableList.of( new ColumnMetadata(COL_FLOW, Schema.FLOW, "The flow", true, true), new ColumnMetadata( COL_BASE_TRACES, Schema.set(Schema.FLOW_TRACE), "The flow traces in the BASE environment", false, true), new ColumnMetadata( COL_DELTA_TRACES, Schema.set(Schema.FLOW_TRACE), "The flow traces in the DELTA environment", false, true)); return new TableMetadata(columnMetadata, "Flows with reduced reachability"); }
/** * Creates {@link ColumnMetadata}s that the answer should have. * * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata() { return ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata(COL_NODE, Schema.NODE, COL_VLAN_ID, true, false)) .add(new ColumnMetadata(COL_VLAN_ID, Schema.INTEGER, COL_VLAN_ID, true, false)) .add( new ColumnMetadata( COL_INTERFACES, Schema.set(Schema.INTERFACE), "Switched interfaces carrying traffic for this VLAN", false, true)) .add( new ColumnMetadata( COL_VXLAN_VNI, Schema.INTEGER, "VXLAN VNI with which this VLAN is associated", false, true)) .build(); }
public static TableMetadata createMetadata(boolean differential) { List<ColumnMetadata> columnMetadata; if (differential) { columnMetadata = ImmutableList.of( new ColumnMetadata(COL_FLOW, Schema.FLOW, "The flow", true, false), new ColumnMetadata( TableDiff.baseColumnName(COL_TRACES), Schema.set(Schema.FLOW_TRACE), "The flow traces in the BASE environment", false, true), new ColumnMetadata( TableDiff.deltaColumnName(COL_TRACES), Schema.set(Schema.FLOW_TRACE), "The flow traces in the DELTA environment", false, true)); } else { columnMetadata = ImmutableList.of( new ColumnMetadata(COL_FLOW, Schema.FLOW, "The flow", true, false), new ColumnMetadata( COL_TRACES, Schema.set(Schema.FLOW_TRACE), "The flow traces", false, true)); } return new TableMetadata(columnMetadata, String.format("Paths for flow ${%s}", COL_FLOW)); }
@Test public void testTableMetadataLayer3() { List<ColumnMetadata> columnMetadata = getTableMetadata(EdgeType.LAYER3).getColumnMetadata(); assertThat( columnMetadata.stream() .map(ColumnMetadata::getName) .collect(ImmutableList.toImmutableList()), contains(COL_INTERFACE, COL_IPS, COL_REMOTE_INTERFACE, COL_REMOTE_IPS)); assertThat( columnMetadata.stream() .map(ColumnMetadata::getSchema) .collect(ImmutableList.toImmutableList()), contains(Schema.INTERFACE, Schema.set(Schema.IP), Schema.INTERFACE, Schema.set(Schema.IP))); }
@Test public void testHsrpGroupsEmpty() { _ib.build(); String property = InterfacePropertySpecifier.HSRP_GROUPS; assertThat(getActualValue(property, Schema.set(Schema.STRING)), equalTo(ImmutableSet.of())); }
@Test public void isCollection() { assertThat(Schema.INTEGER.isCollection(), equalTo(false)); assertThat(Schema.list(Schema.INTEGER).isCollection(), equalTo(true)); assertThat(Schema.set(Schema.INTEGER).isCollection(), equalTo(true)); assertThat(Schema.set(Schema.list(Schema.INTEGER)).isCollection(), equalTo(true)); } }
@Test public void isIntBased() { assertThat(Schema.INTEGER.isIntBased(), equalTo(true)); assertThat(Schema.list(Schema.INTEGER).isIntBased(), equalTo(true)); assertThat(Schema.set(Schema.INTEGER).isIntBased(), equalTo(true)); assertThat(Schema.set(Schema.list(Schema.INTEGER)).isIntBased(), equalTo(true)); assertThat(Schema.list(Schema.STRING).isIntBased(), equalTo(false)); }
@Test public void testHsrpGroups() { _ib.setHsrpGroups(ImmutableMap.of(1, HsrpGroup.builder().setGroupNumber(1).build())).build(); String property = InterfacePropertySpecifier.HSRP_GROUPS; assertThat(getActualValue(property, Schema.set(Schema.STRING)), equalTo(ImmutableSet.of("1"))); }
@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 constructorTest() { new EqualsTester() .addEqualityGroup(new Schema("Set<List<Integer>>"), Schema.set(Schema.list(Schema.INTEGER))) .addEqualityGroup(new Schema("List<Set<Integer>>"), Schema.list(Schema.set(Schema.INTEGER))) .addEqualityGroup(new Schema("Set<Set<Integer>>"), Schema.set(Schema.set(Schema.INTEGER))) .addEqualityGroup(new Schema("List<Integer>"), Schema.list(Schema.INTEGER)) .addEqualityGroup(new Schema("Set<Integer>"), Schema.set(Schema.INTEGER)) .addEqualityGroup(new Schema("Integer"), Schema.INTEGER) .addEqualityGroup(new Schema("String"), Schema.STRING) .testEquals(); }
@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))))); }
@Test public void testColumnComparatorSet() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.set(Schema.STRING), "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r0 = Row.of(col, null); Row r1 = Row.of(col, ImmutableSet.of()); Row r2 = Row.of(col, ImmutableSet.of("a")); Row r3 = Row.of(col, ImmutableSet.of("b")); Row r4 = Row.of(col, ImmutableSet.of("a", "b")); Row r5 = Row.of(col, ImmutableSet.of("b", "a")); Row r6 = Row.of(col, Collections.singleton(null)); assertThat(comparator.compare(r0, r1), lessThan(0)); assertThat(comparator.compare(r1, r2), lessThan(0)); assertThat(comparator.compare(r1, r3), lessThan(0)); assertThat(comparator.compare(r1, r4), lessThan(0)); assertThat(comparator.compare(r1, r5), lessThan(0)); assertThat(comparator.compare(r2, r3), lessThan(0)); assertThat(comparator.compare(r2, r4), not(equalTo(0))); assertThat(comparator.compare(r2, r5), not(equalTo(0))); assertThat(comparator.compare(r6, r2), lessThan(0)); assertThat(comparator.compare(r3, r4), not(equalTo(0))); assertThat(comparator.compare(r3, r5), not(equalTo(0))); // sets in r4 and r5 might end up in same order, so no guarantee on comparison order }
@Test public void testDeliveredToSubnetVSStaticRoute1() throws IOException { TableAnswerElement answer = testDeliveredToSubnetVSStaticRoute("24"); assertThat(answer.getRows().getData(), hasSize(1)); assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(1))), Schema.set(Schema.FLOW_TRACE)))); assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void testDispositionMultiInterfaces() throws IOException { TableAnswerElement answer = testDispositionMultiInterfaces("25"); assertThat(answer.getRows().getData(), hasSize(2)); // check that packet should reach R1 assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(1))), Schema.set(Schema.FLOW_TRACE)))); assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void testDispositionMultipleRouters2() throws IOException { TableAnswerElement answer = testDispositionMultipleRouters("25"); assertThat(answer.getRows().getData(), hasSize(1)); // check that packet only traverse R1 assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(1))), Schema.set(Schema.FLOW_TRACE)))); // check disposition assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void testMaxTraces_default() throws IOException { Batfish batfish = maxTracesBatfish(); TracerouteQuestion question = new TracerouteQuestion( ".*", PacketHeaderConstraints.builder().setSrcIp("1.1.1.0").setDstIp("1.1.1.1").build(), false, DEFAULT_MAX_TRACES); TracerouteAnswerer answerer = new TracerouteAnswerer(question, batfish); TableAnswerElement answer = (TableAnswerElement) answerer.answer(); assertThat( answer, hasRows( contains( allOf( hasColumn(TracerouteAnswerer.COL_TRACES, hasSize(2), Schema.set(Schema.TRACE)), hasColumn(TracerouteAnswerer.COL_TRACE_COUNT, equalTo(2), Schema.INTEGER))))); }
@Test public void testMaxTraces_limited() throws IOException { Batfish batfish = maxTracesBatfish(); TracerouteQuestion question = new TracerouteQuestion( ".*", PacketHeaderConstraints.builder().setSrcIp("1.1.1.0").setDstIp("1.1.1.1").build(), false, 1); TracerouteAnswerer answerer = new TracerouteAnswerer(question, batfish); TableAnswerElement answer = (TableAnswerElement) answerer.answer(); assertThat( answer, hasRows( contains( allOf( hasColumn(TracerouteAnswerer.COL_TRACES, hasSize(1), Schema.set(Schema.TRACE)), hasColumn(TracerouteAnswerer.COL_TRACE_COUNT, equalTo(2), Schema.INTEGER))))); }
@Test public void testFlowTracesToRowsMaxTraces() { Flow flow = Flow.builder().setTag("tag").setIngressNode("node").setDstIp(Ip.parse("1.1.1.1")).build(); SortedMap<Flow, List<Trace>> flowTraces = ImmutableSortedMap.of( flow, ImmutableList.of( new Trace(FlowDisposition.DENIED_OUT, ImmutableList.of()), new Trace(FlowDisposition.DENIED_IN, ImmutableList.of()))); Multiset<Row> rows = flowTracesToRows(flowTraces, 1); assertThat( rows.iterator().next(), allOf( hasColumn( COL_FLOW, allOf(hasDstIp(Ip.parse("1.1.1.1")), hasIngressNode("node"), hasTag("tag")), Schema.FLOW), hasColumn(COL_TRACES, hasSize(1), Schema.set(Schema.TRACE)), hasColumn(TracerouteAnswerer.COL_TRACE_COUNT, equalTo(2), Schema.INTEGER))); }
@Test public void testDeliveredToSubnetVSStaticRoute2() throws IOException { TableAnswerElement answer = testDeliveredToSubnetVSStaticRoute("26"); assertThat(answer.getRows().getData(), hasSize(1)); assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(2))), Schema.set(Schema.FLOW_TRACE)))); // check packets traverse R2 as the last hop assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasHop(1, hasEdge(hasNode1(equalTo("~Configuration_1~"))))), Schema.set(Schema.FLOW_TRACE)))); assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void testDispositionMultipleRouters1() throws IOException { TableAnswerElement answer = testDispositionMultipleRouters("24"); assertThat(answer.getRows().getData(), hasSize(1)); // check that packet should traverse R1 - R2 - R3 - R2 assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(4))), Schema.set(Schema.FLOW_TRACE)))); assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasHop(3, hasEdge(hasNode1(equalTo("~Configuration_1~"))))), Schema.set(Schema.FLOW_TRACE)))); // check disposition assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.LOOP)), Schema.set(Schema.FLOW_TRACE)))); }