/** * Test to check whether the IPs given overlap or not at all * * @param flowIntersect - the current potential intersection * @param maskShift - the shift value (ie. either for a src_ip or a dst_ip). * @param masklenX - the netmask for the first ip. * @param masklenY - the netmask for the second ip. * @param x - the first ip * @param y - the second ip. * @return the smallest intersection of this ip space. */ private int testIP( FlowIntersect flowIntersect, int maskShift, int masklenX, int masklenY, int x, int y) { int min = Math.min(masklenX, masklenY); // get the less specific address int max = Math.max(masklenX, masklenY); // get the more specific address int min_encoded = 32 - min; // because OpenFlow does it backwards... grr int max_encoded = 32 - max; // because OpenFlow does it backwards... grr if (max_encoded >= 32) // set all the bits if this is in fact fully max_encoded = 63; // wildcarded; if only for wireshark's sake int mask; if (min == 0) mask = 0; // nasty work around for stupid signed ints else mask = ~((1 << min_encoded) - 1); // min < 32, so no signed issues // int mask = (1 << min) - 1; if ((x & mask) != (y & mask)) // if these are not in the same CIDR block flowIntersect.setMatchType(MatchType.NONE); // else there is some overlap OFMatch interMatch = flowIntersect.getMatch(); int wildCards = interMatch.getWildcards(); // turn off all bits for this match and then turn on the used ones // use MAX not MIN, because we want the most specific intersection // split into two ops, so we can see intermediate step in debugger // assumes SRC mask == DST mask // turn off all bits for this match (making it an exact match) wildCards = wildCards & ~(((1 << OFMatch.OFPFW_NW_SRC_BITS) - 1) << maskShift); // turn on the bits for the intersection wildCards = wildCards | max_encoded << maskShift; interMatch.setWildcards(wildCards); if (masklenX < masklenY) { flowIntersect.maybeSubset = false; return y; } else if (masklenX > masklenY) { flowIntersect.maybeSuperset = false; return x; } // note that b/c of how CIDR addressing works, there is no overlap that // is not a SUB or SUPERSET return x; // x == y; doesn't matter }