private static Ip6 toIp6(Token t) { return new Ip6(t.getText()); }
public Ip6 getPrefixWildcard() { int numWildcardBits = MAX_PREFIX_LENGTH - _prefixLength; BigInteger wildcardBigInteger = numWildcardBitsToWildcardBigInteger(numWildcardBits); return new Ip6(wildcardBigInteger); }
public Ip6 inverted() { BigInteger mask = new BigInteger("+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16); BigInteger invertedBigInteger = mask.andNot(_ip6); return new Ip6(invertedBigInteger); }
public static Ip6 numSubnetBitsToSubnetMask(int numBits) { BigInteger mask = numSubnetBitsToSubnetBigInteger(numBits); return new Ip6(mask); }
public Ip6 getNetworkAddress(int subnetBits) { BigInteger mask = numSubnetBitsToSubnetBigInteger(subnetBits); return new Ip6(_ip6.and(mask)); }
private static Ip6 toIp6(TerminalNode t) { return new Ip6(t.getText()); }
private static Ip6 parseAddress(String str) { if (str.contains(";")) { String[] parts = str.split(";"); if (parts.length != 2) { throw new BatfishException("Invalid Ip6Wildcard string: '" + str + "'"); } else { return new Ip6(parts[0]); } } else if (str.contains("/")) { String[] parts = str.split("/"); if (parts.length != 2) { throw new BatfishException("Invalid Ip6Wildcard string: '" + str + "'"); } else { return new Ip6(parts[0]); } } else { return new Ip6(str); } }
@JsonCreator public Prefix6(String text) { String[] parts = text.split("/"); if (parts.length != 2) { throw new BatfishException("Invalid Prefix6 string: \"" + text + "\""); } _address = new Ip6(parts[0]); try { _prefixLength = Integer.parseInt(parts[1]); } catch (NumberFormatException e) { throw new BatfishException("Invalid Prefix6 length: \"" + parts[1] + "\"", e); } }
public Ip6 getEndAddress() { return new Ip6(getNetworkEnd(_address.asBigInteger(), _prefixLength)); }
private static Ip6 parseMask(String str) { if (str.contains(";")) { String[] parts = str.split(";"); if (parts.length != 2) { throw new BatfishException("Invalid Ip6Wildcard string: '" + str + "'"); } else { return new Ip6(parts[1]); } } else if (str.contains("/")) { String[] parts = str.split("/"); if (parts.length != 2) { throw new BatfishException("Invalid Ip6Wildcard string: '" + str + "'"); } else { int prefixLength = Integer.parseInt(parts[1]); return Ip6.numSubnetBitsToSubnetMask(prefixLength).inverted(); } } else { return Ip6.ZERO; } }
@Override public void exitPopsfrf_address_mask(Popsfrf_address_maskContext ctx) { if (_currentRouteFilterPrefix != null) { // ipv4 if (ctx.IP_ADDRESS() != null) { Route4FilterLine line = new Route4FilterLineAddressMask( _currentRouteFilterPrefix, Ip.parse(ctx.IP_ADDRESS().getText()).inverted()); _currentRouteFilterLine = _currentRouteFilter.insertLine(line, Route4FilterLine.class); } else { _w.redFlag( String.format( "Route filter mask does not match version for prefix %s", _currentRouteFilterPrefix)); } } else if (_currentRoute6FilterPrefix != null) { // ipv6 if (ctx.IPV6_ADDRESS() != null) { Route6FilterLine line = new Route6FilterLineAddressMask( _currentRoute6FilterPrefix, new Ip6(ctx.IPV6_ADDRESS().getText()).inverted()); _currentRoute6FilterLine = _currentRouteFilter.insertLine(line, Route6FilterLine.class); } else { _w.redFlag( String.format( "Route filter mask does not match version for prefix %s", _currentRouteFilterPrefix)); } } }
private static Route6FilterLine toRoute6FilterLine(ExtendedIpv6AccessListLine fromLine) { LineAction action = fromLine.getAction(); Ip6 ip = fromLine.getSourceIpWildcard().getIp(); BigInteger minSubnet = fromLine.getDestinationIpWildcard().getIp().asBigInteger(); BigInteger maxSubnet = minSubnet.or(fromLine.getDestinationIpWildcard().getWildcard().asBigInteger()); int minPrefixLength = fromLine.getDestinationIpWildcard().getIp().numSubnetBits(); int maxPrefixLength = new Ip6(maxSubnet).numSubnetBits(); int statedPrefixLength = fromLine.getSourceIpWildcard().getWildcard().inverted().numSubnetBits(); int prefixLength = Math.min(statedPrefixLength, minPrefixLength); Prefix6 prefix = new Prefix6(ip, prefixLength); return new Route6FilterLine(action, prefix, new SubRange(minPrefixLength, maxPrefixLength)); }