/** * @param other another IpWildcard * @return whether the set of IPs matched by this intersects the set of those matched by other. */ public boolean intersects(IpWildcard other) { long differentIpBits = getIp().asLong() ^ other.getIp().asLong(); long canDiffer = getWildcard().asLong() | other.getWildcard().asLong(); /* * All IP bits that different must be wild in either this or other. */ return (differentIpBits & canDiffer) == differentIpBits; }
public boolean containsIp(@Nonnull Ip ip) { long wildcardIpAsLong = getIp().asLong(); long wildcardMask = getWildcard().asLong(); long ipAsLong = ip.asLong(); long maskedIpAsLong = ipAsLong | wildcardMask; long maskedWildcard = wildcardIpAsLong | wildcardMask; return maskedIpAsLong == maskedWildcard; }
/** * @param other another IpWildcard * @return whether the set of IPs matched by this is a superset of those matched by other. */ public boolean supersetOf(IpWildcard other) { long wildToThis = getWildcard().asLong(); long wildToOther = other.getWildcard().asLong(); long differentIpBits = getIp().asLong() ^ other.getIp().asLong(); /* * 1. Any bits wild in other must be wild in this (i.e. other's wild bits must be a subset * of this' wild bits). * 2. Any IP bits that differ must be wild in this. */ return (wildToThis & wildToOther) == wildToOther && (wildToThis & differentIpBits) == differentIpBits; }
public static BooleanExpr matchIpWildcard(IpWildcard ipWildcard, IntExpr ipField) { if (ipWildcard.isPrefix()) { return matchPrefix(ipWildcard.toPrefix(), ipField); } long ip = ipWildcard.getIp().asLong(); long wildcard = ipWildcard.getWildcard().asLong(); ImmutableList.Builder<BooleanExpr> matchIp = ImmutableList.builder(); for (int currentBitIndex = 0; currentBitIndex < Prefix.MAX_PREFIX_LENGTH; currentBitIndex++) { long mask = 1L << currentBitIndex; long currentWildcardBit = mask & wildcard; boolean useBit = currentWildcardBit == 0; if (useBit) { IntExpr extractIp = ExtractExpr.newExtractExpr(ipField, currentBitIndex, currentBitIndex); LitIntExpr srcIpMatchLit = new LitIntExpr(ip, currentBitIndex, currentBitIndex); EqExpr matchIpBit = new EqExpr(extractIp, srcIpMatchLit); matchIp.add(matchIpBit); } } return new AndExpr(matchIp.build()); }
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)); }
public void computeNetworks(Collection<Interface> interfaces) { for (Interface i : interfaces) { InterfaceAddress address = i.getAddress(); if (address == null) { continue; } for (IpWildcard wn : _wildcardNetworks) { // Check if the interface IP address matches the eigrp network // when the wildcard is ORed to both long wildcardLong = wn.getWildcard().asLong(); long eigrpNetworkLong = wn.getIp().asLong(); long intIpLong = address.getIp().asLong(); long wildcardedNetworkLong = eigrpNetworkLong | wildcardLong; long wildcardedIntIpLong = intIpLong | wildcardLong; if (wildcardedNetworkLong == wildcardedIntIpLong) { // since we have a match, we add the INTERFACE network, ignoring // the wildcard stuff from before _networks.add(address.getPrefix()); break; } } } }
private BoolExpr toBoolExpr(IpWildcard ipWildcard) { BitVecExpr ip = _context.mkBV(ipWildcard.getIp().asLong(), 32); BitVecExpr mask = _context.mkBV(~ipWildcard.getWildcard().asLong(), 32); return _context.mkEq(_context.mkBVAND(_var, mask), _context.mkBVAND(ip, mask)); }
public BDD toBDD(IpWildcard ipWildcard) { long ip = ipWildcard.getIp().asLong(); long wildcard = ipWildcard.getWildcard().asLong(); BDD acc = _factory.one(); BDD[] bitBDDs = _bddInteger.getBitvec(); for (int i = 0; i < Prefix.MAX_PREFIX_LENGTH; i++) { boolean significant = !Ip.getBitAtPosition(wildcard, i); if (significant) { boolean bitValue = Ip.getBitAtPosition(ip, i); if (bitValue) { acc = acc.and(bitBDDs[i]); } else { acc = acc.and(bitBDDs[i].not()); } } } return acc; }