예제 #1
0
  /**
   * Determine the highest supported version of OpenFlow in common between both our OFVersion bitmap
   * and the switch's.
   *
   * @param theirs, the version bitmaps of the switch
   * @return the highest OFVersion in common b/t the two
   */
  private OFVersion computeOFVersionFromBitmap(List<U32> theirs) {
    Iterator<U32> theirsItr = theirs.iterator();
    Iterator<U32> oursItr = ofBitmaps.iterator();
    OFVersion version = null;
    int pos = 0;
    int size = 32;
    while (theirsItr.hasNext() && oursItr.hasNext()) {
      int t = theirsItr.next().getRaw();
      int o = oursItr.next().getRaw();

      int common = t & o; /* Narrow down the results to the common bits */
      for (int i = 0; i < size; i++) {
          /* Iterate over and locate the 1's */
        int tmp = common & (1 << i); /* Select the bit of interest, 0-31 */
        if (tmp != 0) {
            /* Is the version of this bit in common? */
          for (OFVersion v : OFVersion.values()) {
              /* Which version does this bit represent? */
            if (v.getWireVersion() == i + (size * pos)) {
              version = v;
            }
          }
        }
      }
      pos++; /* OFVersion position. 1-31 = 1, 32 - 63 = 2, etc. Inc at end so it starts at 0. */
    }
    return version;
  }