@Override public IpSpace toIpSpace() { return _host.toIpSpace(); } }
@Override public String getName() { return _ip.toString(); }
/** * See {@link #getBitAtPosition(long, int)}. Equivalent to {@code getBitAtPosition(ip.asLong(), * position)} */ public static boolean getBitAtPosition(Ip ip, int position) { return getBitAtPosition(ip.asLong(), position); }
public String networkString(Ip mask) { return toString() + "/" + mask.numSubnetBits(); }
@Test public void testContains() { IpSpace ipWildcard = new IpWildcard(Ip.create(0x01010001L), Ip.create(0x0000FF00L)).toIpSpace(); assertThat(ipWildcard, containsIp(Ip.parse("1.1.1.1"))); assertThat(ipWildcard, containsIp(Ip.parse("1.1.255.1"))); assertThat(ipWildcard, not(containsIp(Ip.parse("1.1.0.0")))); }
private static RouteFilterLine toRouteFilterLine(ExtendedAccessListLine fromLine) { LineAction action = fromLine.getAction(); IpWildcard srcIpWildcard = ((WildcardAddressSpecifier) fromLine.getSourceAddressSpecifier()).getIpWildcard(); Ip ip = srcIpWildcard.getIp(); IpWildcard dstIpWildcard = ((WildcardAddressSpecifier) fromLine.getDestinationAddressSpecifier()).getIpWildcard(); long minSubnet = dstIpWildcard.getIp().asLong(); long maxSubnet = minSubnet | dstIpWildcard.getWildcard().asLong(); int minPrefixLength = dstIpWildcard.getIp().numSubnetBits(); int maxPrefixLength = Ip.create(maxSubnet).numSubnetBits(); int statedPrefixLength = srcIpWildcard.getWildcard().inverted().numSubnetBits(); int prefixLength = Math.min(statedPrefixLength, minPrefixLength); Prefix prefix = Prefix.create(ip, prefixLength); return new RouteFilterLine( action, new IpWildcard(prefix), new SubRange(minPrefixLength, maxPrefixLength)); }
private static Ip parseMask(String str) { if (str.contains(":")) { String[] parts = str.split(":"); if (parts.length != 2) { throw new BatfishException("Invalid IpWildcard string: '" + str + "'"); } else { return Ip.parse(parts[1]); } } else if (str.contains("/")) { String[] parts = str.split("/"); if (parts.length != 2) { throw new BatfishException("Invalid IpWildcard string: '" + str + "'"); } else { int prefixLength = Integer.parseInt(parts[1]); return Ip.numSubnetBitsToSubnetMask(prefixLength).inverted(); } } else { return Ip.ZERO; } }
public IpWildcard(Ip address, Ip wildcardMask) { // Canonicalize the address before passing it to parent, so that #equals works. super(Ip.create(address.asLong() & ~wildcardMask.asLong()), wildcardMask); if (!wildcardMask.valid()) { throw new BatfishException("Invalid wildcard: " + wildcardMask); } }
@Test public void testIntersects() { /* * The second Ip of an IpWildcard indicates which bits of the first Ip * are significant (i.e. not wild). In this example, since the significant bits of * wc1 and wc2 don't overlap, they should intersect (i.e. their bitwise OR is included in each). */ IpWildcard wc1 = new IpWildcard(Ip.create(0x00b0000aL), Ip.create(0x00FF00FFL).inverted()); IpWildcard wc2 = new IpWildcard(Ip.create(0x000cd000L), Ip.create(0x0000FF00L).inverted()); assertThat("wildcards should overlap", wc1.intersects(wc2)); }
@Override public void exitRo_network(Ro_networkContext ctx) { Ip address; Ip wildcard; if (ctx.prefix != null) { Prefix prefix = Prefix.parse(ctx.prefix.getText()); address = prefix.getStartIp(); wildcard = prefix.getPrefixWildcard(); } else { address = toIp(ctx.ip); wildcard = toIp(ctx.wildcard); } if (_format == CISCO_ASA) { wildcard = wildcard.inverted(); } long area; if (ctx.area_int != null) { area = toLong(ctx.area_int); } else if (ctx.area_ip != null) { area = toIp(ctx.area_ip).asLong(); } else { throw new BatfishException("bad area"); } OspfWildcardNetwork network = new OspfWildcardNetwork(address, wildcard, area); _currentOspfProcess.getWildcardNetworks().add(network); }
private static EraseAndSet assignIpFromPool(BDDInteger var, Ip poolStart, Ip poolEnd) { BDD erase = Arrays.stream(var.getBitvec()).reduce(var.getFactory().one(), BDD::and); BDD setValue = poolStart.equals(poolEnd) ? var.value(poolStart.asLong()) : var.geq(poolStart.asLong()).and(var.leq(poolEnd.asLong())); return new EraseAndSet(erase, setValue); }