private void updateUnpickedMaps(Trace t) { _pickedTraces.add(t); _unpickedDispositions.remove(t.getDisposition()); t.getHops().stream().map(hop -> hop.getNode().getName()).forEach(_unpickedNodes::remove); } }
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()); }
/** * 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); }
@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)); }
private static void buildAcceptTrace( TransmissionContext transmissionContext, List<Step<?>> steps, Flow currentFlow, String vrfName) { InboundStep inboundStep = InboundStep.builder() .setAction(StepAction.ACCEPTED) .setDetail(new InboundStepDetail()) .build(); steps.add(inboundStep); transmissionContext._hopsSoFar.add( new Hop(transmissionContext._currentNode, ImmutableList.copyOf(steps))); Trace trace = new Trace(FlowDisposition.ACCEPTED, transmissionContext._hopsSoFar); Flow returnFlow = returnFlow(currentFlow, transmissionContext._currentNode.getName(), vrfName, null); transmissionContext._flowTraces.add( new TraceAndReverseFlow(trace, returnFlow, transmissionContext._newSessions)); }
/** * Returns true if local node, remote node, and session type in row match the question's filters */ protected static boolean matchesNodesAndType( Row row, Set<String> nodes, Set<String> remoteNodes, BgpSessionQuestion question) { if (!question.getNodes().equals(NodesSpecifier.ALL)) { Node node = (Node) row.get(COL_NODE, Schema.NODE); if (node == null || !nodes.contains(node.getName())) { return false; } } if (!question.getRemoteNodes().equals(NodesSpecifier.ALL)) { Node remoteNode = (Node) row.get(COL_REMOTE_NODE, Schema.NODE); if (remoteNode == null || !remoteNodes.contains(remoteNode.getName())) { return false; } } String typeName = (String) row.get(COL_SESSION_TYPE, Schema.STRING); SessionType type = typeName == null ? null : SessionType.valueOf(typeName); if (!question.matchesType(type)) { return false; } return true; }
@Test public void constructorBasic() throws IOException { String nodeStr = "{\"name\" : \"nodeName\"}"; Node node = BatfishObjectMapper.mapper().readValue(nodeStr, Node.class); assertThat(node.getId(), equalTo("node-nodeName")); assertThat(node.getName(), equalTo("nodeName")); }
@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")); }
propertyDescriptor.getSchema(), property, node.getName(), vrfName, peer,
@Nonnull private static ExitOutputIfaceStep buildExitOutputIfaceStep( String outputIface, TransmissionContext transmissionContext, StepAction action) { return ExitOutputIfaceStep.builder() .setDetail( ExitOutputIfaceStepDetail.builder() .setOutputInterface( new NodeInterfacePair(transmissionContext._currentNode.getName(), outputIface)) .setTransformedFlow( hopFlow( transmissionContext._originalFlow, transmissionContext._transformedFlow)) .build()) .setAction(action) .build(); }
Flow inputFlow, Stack<Breadcrumb> breadcrumbs) { String currentNodeName = transmissionContext._currentNode.getName(); Configuration currentConfiguration = _configurations.get(currentNodeName); if (currentConfiguration == null) {
assertThat(((Node) row.get(COL_NODE, Schema.NODE)).getName(), equalTo(c1.getHostname()));