@Override protected Ip featureValueOf(Flow flow) { return flow.getDstIp(); } }
/** * Does a basic validation of input to {@link * TracerouteEngineImplContext#buildTracesAndReturnFlows()} * * @param configurations {@link Map} of {@link Configuration}s * @param flow {@link Flow} for which input validation is to be done */ static void validateInputs(Map<String, Configuration> configurations, Flow flow) { String ingressNodeName = flow.getIngressNode(); checkArgument( ingressNodeName != null, "Cannot construct flow trace since ingressNode is not specified"); Configuration ingressNode = configurations.get(ingressNodeName); checkArgument( ingressNode != null, "Node %s is not in the network, cannot perform traceroute", ingressNodeName); String ingressIfaceName = flow.getIngressInterface(); if (ingressIfaceName != null) { checkArgument( ingressNode.getAllInterfaces().get(ingressIfaceName) != null, "%s interface does not exist on the node %s", ingressIfaceName, ingressNodeName); } checkArgument( flow.getDstIp() != null, "Cannot construct flow trace since dstIp is not specified"); }
@Nullable private static Transformation sessionTransformation(Flow inputFlow, Flow currentFlow) { ImmutableList.Builder<TransformationStep> transformationStepsBuilder = ImmutableList.builder(); Ip origDstIp = inputFlow.getDstIp(); if (!origDstIp.equals(currentFlow.getDstIp())) { transformationStepsBuilder.add(assignSourceIp(origDstIp, origDstIp)); } Ip origSrcIp = inputFlow.getSrcIp(); if (!origSrcIp.equals(currentFlow.getSrcIp())) { transformationStepsBuilder.add(TransformationStep.assignDestinationIp(origSrcIp, origSrcIp)); } List<TransformationStep> transformationSteps = transformationStepsBuilder.build(); return transformationSteps.isEmpty() ? null : always().apply(transformationSteps).build(); }
Prefix buildPrefix(SymbolicRoute symbolicRoute, Flow flow) { Integer pfxLen = intVal(symbolicRoute.getPrefixLength()); return Prefix.create(flow.getDstIp(), pfxLen); }
"Cannot construct flow trace since ingressNode is not specified"); Ip dstIp = flow.getDstIp(); if (dstIp == null) { throw new BatfishException(
currentNodeName, outgoingInterfaceName, transmissionContext._transformedFlow.getDstIp()); buildArpFailureTrace(outgoingInterface, disposition, transmissionContext, steps); return false;
/** Compute the differences between two flows */ public static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2) { if (flow1 == null || flow2 == null || flow1.equals(flow2)) { return ImmutableSortedSet.of(); } checkArgument( flow1 .toBuilder() .setDstIp(flow2.getDstIp()) .setSrcIp(flow2.getSrcIp()) .build() .equals(flow2), "flowDiff only supports differences of src or dst Ip"); ImmutableSortedSet.Builder<FlowDiff> diffs = ImmutableSortedSet.naturalOrder(); if (!flow1.getDstIp().equals(flow2.getDstIp())) { diffs.add( new FlowDiff(PROP_DST_IP, flow1.getDstIp().toString(), flow2.getDstIp().toString())); } if (!flow1.getSrcIp().equals(flow2.getSrcIp())) { diffs.add( new FlowDiff(PROP_SRC_IP, flow1.getSrcIp().toString(), flow2.getSrcIp().toString())); } return diffs.build(); }
/** * Creates a return {@link Flow} for the input {@param forwardFlow}. Swaps the source/destination * IPs/ports, and sets the ingress node/vrf/interface. */ static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .build(); }
fb.setSrcIp(forwardFlow.getDstIp()); fb.setDstIp(forwardFlow.getSrcIp()); fb.setSrcPort(forwardFlow.getDstPort());
Flow originalFlow, Flow transformedFlow) { Ip dstIp = transformedFlow.getDstIp(); Configuration currentConfiguration = _configurations.get(currentNodeName); if (currentConfiguration == null) {
Ip dstIp = currentFlow.getDstIp(); .getOrDefault(currentFlow.getDstIp(), ImmutableMap.of()) .getOrDefault(currentConfiguration.getHostname(), ImmutableSet.of()) .contains(vrfName)) { firewallSessionInterfaceInfo.getSessionInterfaces(), match5Tuple( newTransformedFlow.getDstIp(), newTransformedFlow.getDstPort(), newTransformedFlow.getSrcIp(), currentNodeName, outgoingInterface.getName(), transmissionContext._transformedFlow.getDstIp());
Interface interf = graphEdge.getStart(); Ip ip = interf.getAddress().getIp(); if (ip.equals(flow.getDstIp())) { FlowTrace ft = new FlowTrace(FlowDisposition.ACCEPTED, hops, "ACCEPTED"); return new Tuple<>(flow, ft);