/** Creates a new TransmissionContext for the specified last-hop node and outgoing interface. */ private TransmissionContext branch( NodeInterfacePair lastHopNodeAndOutgoingInterface, String currentHop) { TransmissionContext transmissionContext = new TransmissionContext( _aclDefinitions, new Node(currentHop), _flowTraces, _hopsSoFar, lastHopNodeAndOutgoingInterface, _newSessions, _namedIpSpaces, _originalFlow, _transformedFlow); return transmissionContext; } }
private void updateUnpickedMaps(Trace t) { _pickedTraces.add(t); _unpickedDispositions.remove(t.getDisposition()); t.getHops().stream().map(hop -> hop.getNode().getName()).forEach(_unpickedNodes::remove); } }
@Test public void constructorProperties() throws IOException { String nodeStr = "{\"name\" : \"nodeName\", \"properties\" : { \"key\": \"value\"}}"; Node node = BatfishObjectMapper.mapper().readValue(nodeStr, Node.class); assertThat(node.getId(), equalTo("node-nodeName")); assertThat(node.getName(), equalTo("nodeName")); assertThat(node.getProperties().size(), equalTo(1)); assertThat(node.getProperties().get("key"), equalTo("value")); }
@Test public void serialization() { Node node = new Node("testnode", "myId", DeviceType.HOST); Map<String, String> properties = new HashMap<>(); properties.put("key", "value"); node.setProperties(properties); JsonNode jsonNode = BatfishObjectMapper.mapper().valueToTree(node); assertThat(jsonNode.get("id").asText(), equalTo("myId")); assertThat(jsonNode.get("name").asText(), equalTo("testnode")); assertThat(jsonNode.get("type").asText(), equalTo("HOST")); assertThat(jsonNode.get("properties").get("key").asText(), equalTo("value")); } }
Flow inputFlow, Stack<Breadcrumb> breadcrumbs) { String currentNodeName = transmissionContext._currentNode.getName(); Configuration currentConfiguration = _configurations.get(currentNodeName); if (currentConfiguration == null) { new TransmissionContext( aclDefinitions, new Node(currentNodeName), transmissionContext._flowTraces, transmissionContext._hopsSoFar,
Node pojoNode = new Node(configuration.getHostname(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Interface pojoInterface = new Interface(pojoNode.getId(), interface1, iface1type); new Link( pojoInterface.getId(), Interface.getId(Node.makeId(edge.getNode2()), interface2), linkType); Aggregate subnetAggregate = pojoTopology.getOrCreateAggregate(subnetId, AggregateType.SUBNET); subnetAggregate.getContents().add(pojoNode.getId()); String vpcId = configuration.getVendorFamily().getAws().getVpcId(); Aggregate vpcAggregate = pojoTopology.getOrCreateAggregate(vpcId, AggregateType.VNET); vpcAggregate.getContents().add(pojoNode.getId()); Aggregate regionAggregate = pojoTopology.getOrCreateAggregate(region, AggregateType.REGION); regionAggregate.getContents().add(pojoNode.getId()); } else { Aggregate awsAggregate = pojoTopology.getOrCreateAggregate("aws", AggregateType.CLOUD); awsAggregate.getContents().add(pojoNode.getId()); Node pojoNode = new Node(configuration.getHostname(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode);
public Node(String name) { this(name, makeId(name), null); }
public Node(String name, DeviceType type) { this(name, makeId(name), type); }
@Nonnull @VisibleForTesting static Row getRow( String filename, ParseStatus status, @Nullable Collection<String> hostsProduced) { Row.TypedRowBuilder builder = Row.builder(TABLE_METADATA.toColumnMap()); builder.put(COL_FILENAME, filename); builder.put(COL_PARSE_STATUS, status.toString()); ImmutableList.Builder<Node> nodesProduced = ImmutableList.builder(); for (String hostname : firstNonNull(hostsProduced, Collections.<String>emptyList())) { nodesProduced.add(new Node(hostname)); } builder.put(COL_NODES, nodesProduced.build()); return builder.build(); }
private TracePruner(List<Trace> traces) { _traces = traces; _dispositionTraces = new HashMap<>(); _nodeTraces = new HashMap<>(); _pickedTraces = Collections.newSetFromMap(new IdentityHashMap<>()); for (Trace trace : traces) { _dispositionTraces .computeIfAbsent(trace.getDisposition(), key -> new ArrayList<>()) .add(trace); for (Hop hop : trace.getHops()) { _nodeTraces.computeIfAbsent(hop.getNode().getName(), key -> new ArrayList<>()).add(trace); } } _unpickedDispositions = new TreeSet<>(_dispositionTraces.keySet()); _unpickedNodes = new TreeSet<>(_nodeTraces.keySet()); }
@JsonCreator public Node( @JsonProperty(PROP_NAME) String name, @JsonProperty(PROP_ID) String id, @JsonProperty(PROP_TYPE) DeviceType type) { super(firstNonNull(id, makeId(name))); _name = name; _type = type; if (name == null) { throw new IllegalArgumentException("Cannot build Node: name is null"); } }
@VisibleForTesting static Row getBgpEdgeRow( String node, @Nullable Ip ip, @Nullable Long asNumber, String remoteNode, @Nullable Ip remoteIp, @Nullable Long remoteAsNumber) { RowBuilder row = Row.builder(); row.put(COL_NODE, new Node(node)) .put(COL_IP, ip) .put(COL_AS_NUMBER, asNumber) .put(COL_REMOTE_NODE, new Node(remoteNode)) .put(COL_REMOTE_IP, remoteIp) .put(COL_REMOTE_AS_NUMBER, remoteAsNumber); return row.build(); }
/** * We can't use {@link TracerouteEngineImplContext#buildArpFailureTrace} for sessions, because * forwarding analysis disposition maps currently include routing conditions, which do not apply * to sessions. * * <p>This ARP failure situation only arises for sessions that have an outgoing interface but no * next hop. This means the user started the trace entering the outgoing interface. For now, just * always call this EXITS_NETWORK. In the future we may want to apply the normal ARP error * disposition logic, which would require factoring out routing-independent disposition maps in * forwarding analysis. */ private void buildSessionArpFailureTrace( String outgoingInterfaceName, TransmissionContext transmissionContext, List<Step<?>> steps) { Interface outgoingInterface = _configurations .get(transmissionContext._currentNode.getName()) .getAllInterfaces() .get(outgoingInterfaceName); buildArpFailureTrace( outgoingInterface, FlowDisposition.EXITS_NETWORK, transmissionContext, steps); }
@VisibleForTesting static Row createRow( Map<String, ColumnMetadata> columns, String node, Integer vlan, Map<Integer, Builder<NodeInterfacePair>> switchedVlanInterfaces, Map<Integer, Integer> vlanVnis) { return Row.builder(columns) .put(COL_NODE, new Node(node)) .put(COL_VLAN_ID, vlan) .put(COL_INTERFACES, switchedVlanInterfaces.get(vlan).build()) .put(COL_VXLAN_VNI, vlanVnis.get(vlan)) .build(); }
@Override protected String featureValueOf(Hop hop) { return hop.getNode().getName(); } }
TransmissionContext transmissionContext, List<Step<?>> steps) { String currentNodeName = transmissionContext._currentNode.getName(); Ip arpIp = finalNextHopIp != null ? finalNextHopIp : dstIp; Configuration c = _configurations.get(currentNodeName); .get(transmissionContext._currentNode.getName()) .get(outgoingInterface.getVrfName()) .get(outgoingInterfaceName)
private static void buildArpFailureTrace( Interface outInterface, FlowDisposition disposition, TransmissionContext transmissionContext, List<Step<?>> steps) { String currentNodeName = transmissionContext._currentNode.getName(); steps.add( buildExitOutputIfaceStep( outInterface.getName(), transmissionContext, getFinalActionForDisposition(disposition))); transmissionContext._hopsSoFar.add(new Hop(transmissionContext._currentNode, steps)); Flow returnFlow = SUCCESS_DISPOSITIONS.contains(disposition) ? returnFlow( transmissionContext._transformedFlow, currentNodeName, null, outInterface.getName()) : null; Trace trace = new Trace(disposition, transmissionContext._hopsSoFar); transmissionContext._flowTraces.add( new TraceAndReverseFlow(trace, returnFlow, transmissionContext._newSessions)); }