@Override public String getName() { return _ip.toString(); }
@Override public String getId() { return _publicIp.toString(); }
public String networkString(int prefixLength) { return toString() + "/" + prefixLength; }
public String networkString(Ip mask) { return toString() + "/" + mask.numSubnetBits(); }
private static String getTextDesc(Ip ip, Vrf v) { return String.format("BGP neighbor %s in vrf %s", ip.toString(), v.getName()); }
@VisibleForTesting public static Set<String> getIps(Map<String, Configuration> configurations) { ImmutableSet.Builder<String> ips = ImmutableSet.builder(); configurations .values() .forEach( configuration -> configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllAddresses().stream() .map(interfaceAddress -> interfaceAddress.getIp().toString()) .forEach(ips::add))); return ips.build(); }
@Override public String visitIpIpSpace(IpIpSpace ipIpSpace) { String metadataDescription = computeMetadataDescription(ipIpSpace); if (metadataDescription != null) { return metadataDescription; } return ipIpSpace.getIp().toString(); }
@Override public String toString() { String originatorIp = _originatorIp.equals(UNSET_ORIGINATOR_IP) ? "N/A" : _originatorIp.toString(); return "BgpAdvert<" + _type
@JsonValue @Override public String toString() { if (_second.equals(Ip.ZERO)) { return _first.toString(); } else if (isPrefix()) { return toPrefix().toString(); } else { return _first + ":" + _second; } } }
String buildRoute(Prefix pfx, Protocol proto, GraphEdge graphEdge) { String type; String nextHopIP; String nextHopInt; if (proto.isConnected()) { type = "ConnectedRoute"; nextHopIP = "AUTO/NONE(-1l)"; nextHopInt = graphEdge.getStart().getName(); } else { type = StringUtils.capitalize(proto.name().toLowerCase()) + "Route"; nextHopIP = graphEdge.getStart().getAddress().getIp().toString(); nextHopInt = "dynamic"; } return String.format("%s<%s,nhip:%s,nhint:%s>", type, pfx, nextHopIP, nextHopInt); }
nhip = "N/A"; nhip = nextHopIp != null ? nextHopIp.toString() : "N/A"; String vrf = getVrf(); String net = getNetwork().toString();
/** 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(); }
@Test public void testFlowDiffs() { Ip dst1 = Ip.parse("1.1.1.1"); Ip src1 = Ip.parse("2.2.2.2"); Ip dst2 = Ip.parse("3.3.3.3"); Ip src2 = Ip.parse("4.4.4.4"); Flow orig = Flow.builder() .setIngressNode("ingressNode") .setTag("tag") .setDstIp(dst1) .setSrcIp(src1) .build(); Flow newDst = orig.toBuilder().setDstIp(dst2).build(); Flow newSrc = orig.toBuilder().setSrcIp(src2).build(); Flow newDstAndSrc = newDst.toBuilder().setSrcIp(src2).build(); assertThat(flowDiffs(null, orig), empty()); assertThat(flowDiffs(orig, null), empty()); assertThat(flowDiffs(orig, orig), empty()); FlowDiff dstDiff = new FlowDiff(PROP_DST_IP, dst1.toString(), dst2.toString()); FlowDiff srcDiff = new FlowDiff(PROP_SRC_IP, src1.toString(), src2.toString()); assertThat(flowDiffs(orig, newDst), contains(dstDiff)); assertThat(flowDiffs(orig, newSrc), contains(srcDiff)); assertThat(flowDiffs(orig, newDstAndSrc), containsInAnyOrder(dstDiff, srcDiff)); }
.setHeaderConstraints( PacketHeaderConstraints.builder() .setDstIp(NODE1_LOOPBACK_IP.toString()) .build()) .setInvertSearch(true)
@Test public void testOneFailure_notDstIp() { final ReachabilityQuestion question = new ReachabilityQuestion(); question.setIngressNodeRegex(_srcNode.getHostname()); question.setFinalNodeRegex(_dstNode.getHostname()); question.setNotDstIps(ImmutableSet.of(new IpWildcard(_dstIp))); question.setFailures(1); final AnswerElement answer = _batfish.smtReachability(question); assertThat(answer, instanceOf(SmtReachabilityAnswerElement.class)); final SmtReachabilityAnswerElement smtAnswer = (SmtReachabilityAnswerElement) answer; assertThat( smtAnswer, hasVerificationResult( allOf( hasIsVerified(false), /* * For some reason, when we use setNotDstIps we get a packetModel, whereas if we * use setDstIps we don't. */ hasPacketModel( hasEntry( equalTo("dstIp"), allOf(in(DST_IP_STRINGS), not(equalTo(_dstIp.toString()))))), hasFailures(singleton(_failureDesc))))); } }
address = "null"; } else { address = n.getPeerAddress().toString();
/** * Verify that with no failures, source can reach each dest IP. This time, we negate the check and * get a counterexample. */ @Test public void testNoFailures_negate() { final ReachabilityQuestion question = new ReachabilityQuestion(); question.setIngressNodeRegex(_srcNode.getHostname()); question.setFinalNodeRegex(_dstNode.getHostname()); // verify unreachability, which is false (we'll get a counterexample). question.setNegate(true); question.setDstIps(ImmutableSet.of(new IpWildcard(_dstIp))); final AnswerElement answer = _batfish.smtReachability(question); assertThat(answer, instanceOf(SmtReachabilityAnswerElement.class)); final SmtReachabilityAnswerElement smtAnswer = (SmtReachabilityAnswerElement) answer; assertThat( smtAnswer, hasVerificationResult( allOf( hasIsVerified(false), hasFailures(hasSize(0)), hasPacketModel(hasEntry("dstIp", _dstIp.toString()))))); }
setDefaultProperty(ARG_QUEUE_INCOMPLETE_WORK, "batfishincompletework"); setDefaultProperty(ARG_QUEUE_TYPE, WorkQueue.Type.memory.toString()); setDefaultProperty(ARG_POOL_BIND_HOST, Ip.ZERO.toString()); setDefaultProperty(ARG_SERVICE_POOL_PORT, CoordConsts.SVC_CFG_POOL_PORT); setDefaultProperty(ARG_WORK_BIND_HOST, Ip.ZERO.toString()); setDefaultProperty(ARG_SERVICE_NAME, "coordinator-service"); setDefaultProperty(ARG_SERVICE_WORK_PORT, CoordConsts.SVC_CFG_WORK_PORT);