if (deltaRows == null) { // no matching keys in delta table if (includeOneTableKeys) { RowBuilder diffRowBuilder = Row.builder(diffColumnMap).putAll(baseRow, keyColumns); diffRowValues(diffRowBuilder, baseRow, null, inputMetadata); diffTable.addRow(diffRowBuilder.build()); RowBuilder diffRowBuilder = Row.builder(diffColumnMap).putAll(baseRow, keyColumns); diffRowValues(diffRowBuilder, baseRow, deltaRow, inputMetadata); diffTable.addRow(diffRowBuilder.build()); continue; RowBuilder diffRowBuilder = Row.builder(diffColumnMap).putAll(deltaRow, keyColumns); diffRowValues(diffRowBuilder, null, deltaRow, inputMetadata); diffTable.addRow(diffRowBuilder.build());
.put(COL_INTERFACE, new NodeInterfacePair(nodeName, iface.getName()));
ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": " + acl.getName())) .put(COL_UNREACHABLE_LINE, lineNames.get(1)) .put(COL_UNREACHABLE_LINE_ACTION, PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of(lineNames.get(0))) .put(COL_DIFF_ACTION, true) .put(COL_REASON, BLOCKING_LINES) .build(), Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": " + acl.getName())) .put(COL_UNREACHABLE_LINE, lineNames.get(2)) .put(COL_UNREACHABLE_LINE_ACTION, PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of()) .put(COL_DIFF_ACTION, false) .put(COL_REASON, INDEPENDENTLY_UNMATCHABLE) .build(), Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": " + acl.getName())) .put(COL_UNREACHABLE_LINE, lineNames.get(3)) .put(COL_UNREACHABLE_LINE_ACTION, PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of(lineNames.get(0))) .put(COL_DIFF_ACTION, true) .put(COL_REASON, BLOCKING_LINES) .build());
ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": acl0, acl1, acl2")) .put(COL_UNREACHABLE_LINE, null) .put(COL_UNREACHABLE_LINE_ACTION, null) .put(COL_BLOCKING_LINES, null) .put(COL_DIFF_ACTION, null) .put(COL_REASON, CYCLICAL_REFERENCE) .put( COL_ADDITIONAL_INFO, "Cyclic references in node 'c1': acl0 -> acl1 -> acl2 -> acl0") .build()); assertThat(answer.getRows().getData(), equalTo(expected));
_rows.add( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, flatSources) .put(COL_UNREACHABLE_LINE_ACTION, blockedLine.getAction()) .put(COL_UNREACHABLE_LINE, firstNonNull(blockedLine.getName(), blockedLine.toString())) .put( COL_BLOCKING_LINES, blockingLines.stream() }) .collect(ImmutableList.toImmutableList())) .put(COL_DIFF_ACTION, diffAction) .put(COL_REASON, reason) .build());
ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": " + acl.getName())) .put(COL_UNREACHABLE_LINE, lineNames.get(1)) .put(COL_UNREACHABLE_LINE_ACTION, PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of(lineNames.get(0))) .put(COL_DIFF_ACTION, false) .put(COL_REASON, BLOCKING_LINES) .build());
RowBuilder row = Row.builder(columns).put(COL_STRUCTURE_TYPE, structureType);
ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": " + acl.getName())) .put(COL_UNREACHABLE_LINE, lineNames.get(2)) .put(COL_UNREACHABLE_LINE_ACTION, PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of(lineNames.get(0), lineNames.get(1))) .put(COL_DIFF_ACTION, false) .put(COL_REASON, BLOCKING_LINES) .build());
ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": acl")) .put(COL_UNREACHABLE_LINE, lineNames.get(1)) .put(COL_UNREACHABLE_LINE_ACTION, LineAction.PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of(lineNames.get(0))) .put(COL_DIFF_ACTION, false) .put(COL_REASON, BLOCKING_LINES) .build()); assertThat(answer.getRows().getData(), equalTo(expected));
/** * Gets properties of nodes. * * @param propertySpecifier Specifies which properties to get * @param configurations configuration to use in extractions * @param nodes the set of nodes to focus on * @param columns a map from column name to {@link ColumnMetadata} * @return A multiset of {@link Row}s where each row corresponds to a node and columns correspond * to property values. */ public static Multiset<Row> getProperties( NodePropertySpecifier propertySpecifier, Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columns) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodes) { RowBuilder row = Row.builder(columns).put(COL_NODE, new Node(nodeName)); for (String property : propertySpecifier.getMatchingProperties()) { PropertySpecifier.fillProperty( NodePropertySpecifier.JAVA_MAP.get(property), configurations.get(nodeName), property, row); } rows.add(row.build()); } return rows; }
ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": acl1, acl2")) .put(COL_UNREACHABLE_LINE, null) .put(COL_UNREACHABLE_LINE_ACTION, null) .put(COL_BLOCKING_LINES, null) .put(COL_DIFF_ACTION, null) .put(COL_REASON, CYCLICAL_REFERENCE) .put(COL_ADDITIONAL_INFO, "Cyclic references in node 'c1': acl1 -> acl2 -> acl1") .build()); assertThat(answer.getRows().getData(), equalTo(expected));
@Test public void testWithIcmpType() { // First line accepts IP 1.2.3.4 // Second line accepts same but only ICMP of type 8 List<IpAccessListLine> lines = ImmutableList.of( IpAccessListLine.acceptingHeaderSpace( HeaderSpace.builder().setSrcIps(Ip.parse("1.2.3.4").toIpSpace()).build()), IpAccessListLine.acceptingHeaderSpace( HeaderSpace.builder() .setSrcIps(Ip.parse("1.2.3.4").toIpSpace()) .setIpProtocols(ImmutableSet.of(IpProtocol.ICMP)) .setIcmpTypes(ImmutableList.of(new SubRange(8))) .build())); _aclb.setLines(lines).setName("acl").build(); List<String> lineNames = lines.stream().map(Object::toString).collect(Collectors.toList()); TableAnswerElement answer = answer(new FilterLineReachabilityQuestion()); // Construct the expected result. First line should block second. Multiset<Row> expected = ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": acl")) .put(COL_UNREACHABLE_LINE, lineNames.get(1)) .put(COL_UNREACHABLE_LINE_ACTION, LineAction.PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of(lineNames.get(0))) .put(COL_DIFF_ACTION, false) .put(COL_REASON, BLOCKING_LINES) .build()); assertThat(answer.getRows().getData(), equalTo(expected)); }
private static @Nonnull Row buildActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, SessionType type, SessionStatus status, Map<String, ColumnMetadata> metadataMap, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology, Map<String, Configuration> configurations) { Node remoteNode = null; if (status != NOT_COMPATIBLE) { String remoteNodeName = configuredBgpTopology.adjacentNodes(activeId).iterator().next().getHostname(); remoteNode = new Node(remoteNodeName); } Ip localIp = activePeer.getLocalIp(); NodeInterfacePair localInterface = getInterface(configurations.get(activeId.getHostname()), localIp); return Row.builder(metadataMap) .put(COL_ESTABLISHED_STATUS, status) .put(COL_LOCAL_INTERFACE, localInterface) .put(COL_LOCAL_AS, activePeer.getLocalAs()) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, new SelfDescribingObject(Schema.LONG, activePeer.getRemoteAs())) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, type) .put(COL_VRF, activeId.getVrfName()) .build(); }
private static @Nonnull Row buildActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, SessionType type, ConfiguredSessionStatus status, Map<String, ColumnMetadata> metadataMap, ValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology, Map<String, Configuration> configurations) { Node remoteNode = null; if (status == UNIQUE_MATCH) { String remoteNodeName = bgpTopology.adjacentNodes(activeId).iterator().next().getHostname(); remoteNode = new Node(remoteNodeName); } Ip localIp = activePeer.getLocalIp(); NodeInterfacePair localInterface = getInterface(configurations.get(activeId.getHostname()), localIp); return Row.builder(metadataMap) .put(COL_CONFIGURED_STATUS, status) .put(COL_LOCAL_INTERFACE, localInterface) .put(COL_LOCAL_AS, activePeer.getLocalAs()) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, new SelfDescribingObject(Schema.LONG, activePeer.getRemoteAs())) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, type) .put(COL_VRF, activeId.getVrfName()) .build(); }
Map<String, ColumnMetadata> columnMetadataMap) { return Row.builder(columnMetadataMap) .put(COL_NODE, new Node(hostName)) .put(COL_VRF_NAME, vrfName) .put(COL_NETWORK, bgpRoute.getNetwork()) .put(COL_NEXT_HOP_IP, bgpRoute.getNextHopIp()) .put(COL_PROTOCOL, bgpRoute.getProtocol()) .put(COL_AS_PATH, bgpRoute.getAsPath().getAsPathString()) .put(COL_METRIC, bgpRoute.getMetric()) .put(COL_LOCAL_PREF, bgpRoute.getLocalPreference()) .put( COL_COMMUNITIES, bgpRoute.getCommunities().stream() .map(CommonUtil::longToCommunity) .collect(toImmutableList())) .put(COL_ORIGIN_PROTOCOL, bgpRoute.getSrcProtocol()) .put(COL_TAG, bgpRoute.getTag() == Route.UNSET_ROUTE_TAG ? null : bgpRoute.getTag()) .build();