Giant patch of changes to support OpenFlow 1.3

The following people have contributed to this patch:
- Ali Al-Shabibi <alshabibi.ali@gmail.com>
- Ayaka Koshibe <ayaka@onlab.us>
- Brian O'Connor <bocon@onlab.us>
- Jonathan Hart <jono@onlab.us>
- Matteo Gerola <mgerola@create-net.org>
- Michele Santuari <michele.santuari@create-net.org>
- Pavlin Radoslavov <pavlin@onlab.us>
- Saurav Das <sauravdas@alumni.stanford.edu>
- Toshio Koide <t-koide@onlab.us>
- Yuta HIGUCHI <y-higuchi@onlab.us>

The patch includes the following changes:
- New Floodlight I/O loop / state machine
- New switch/port handling
- New role management (incl. Role.EQUAL)
- Added Floodlight debug framework
- Updates to Controller.java
- Move to Loxigen's OpenflowJ library
- Added OF1.3 support
- Added support for different switches (via DriverManager)
- Updated ONOS modules to use new APIs
- Added and updated unit tests

Change-Id: Ic70a8d50f7136946193d2ba2e4dc0b4bfac5f599
diff --git a/src/main/java/net/onrc/onos/core/linkdiscovery/LinkInfo.java b/src/main/java/net/onrc/onos/core/linkdiscovery/LinkInfo.java
index fc19951..bc11c91 100644
--- a/src/main/java/net/onrc/onos/core/linkdiscovery/LinkInfo.java
+++ b/src/main/java/net/onrc/onos/core/linkdiscovery/LinkInfo.java
@@ -1,6 +1,7 @@
 /**
  *    Copyright 2011, Big Switch Networks, Inc.
  *    Originally created by David Erickson, Stanford University
+ *
  *    Licensed under the Apache License, Version 2.0 (the "License"); you may
  *    not use this file except in compliance with the License. You may obtain
  *    a copy of the License at
@@ -12,34 +13,35 @@
  *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  *    License for the specific language governing permissions and limitations
  *    under the License.
- */
+ **/
 
 package net.onrc.onos.core.linkdiscovery;
 
+import java.util.Set;
+
 import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService.LinkType;
 
+import org.projectfloodlight.openflow.protocol.OFPortState;
+
 import com.google.common.primitives.Longs;
 
 /**
  * Records information about a link.
  */
 public final class LinkInfo {
-
     /**
-     * The port states stored here are topology's last knowledge of
-     * the state of the port. This mostly mirrors the state
-     * maintained in the port list in IOFSwitch (i.e. the one returned
-     * from getPort), except that during a port status message the
-     * IOFSwitch port state will already have been updated with the
-     * new port state, so topology needs to keep its own copy so that
-     * it can determine if the port state has changed and therefore
-     * requires the new state to be written to storage.
-     *
-     * Note the port state values are defined in the OF 1.0 spec.
-     * These will change in some way once we move to OF 1.3.
+     * The port states stored here are topology's last knowledge of the state of
+     * the port. This mostly mirrors the state maintained in the port list in
+     * IOFSwitch (i.e. the one returned from getPort), except that during a port
+     * status message the IOFSwitch port state will already have been updated
+     * with the new port state, so topology needs to keep its own copy so that
+     * it can determine if the port state has changed and therefore requires the
+     * new state to be written to storage. Note the port state values are
+     * defined in the OF 1.0 spec. These will change in some way once we move to
+     * OF 1.3.
      */
-    private final int srcPortState;
-    private final int dstPortState;
+    private final Set<OFPortState> srcPortState;
+    private final Set<OFPortState> dstPortState;
 
     private final long firstSeenTime;
     private final long lastLldpReceivedTime;
@@ -54,8 +56,8 @@
      */
     public LinkInfo(long firstSeenTime,
             long lastLldpReceivedTime,
-            int srcPortState,
-            int dstPortState) {
+            Set<OFPortState> srcPortState,
+            Set<OFPortState> dstPortState) {
         this.srcPortState = srcPortState;
         this.dstPortState = dstPortState;
         this.firstSeenTime = firstSeenTime;
@@ -85,20 +87,47 @@
      *
      * @return the source port state, as defined in the OF1.0 spec
      */
-    public int getSrcPortState() {
+    public Set<OFPortState> getSrcPortState() {
         return srcPortState;
     }
 
+    public int getSrcPortStateInteger() {
+        return convertPortState(srcPortState);
+    }
+
     /**
      * Gets the state of the destination port.
      *
      * @return the destination port state, as defined in the OF1.0 spec
      */
-    public int getDstPortState() {
+    public Set<OFPortState> getDstPortState() {
         return dstPortState;
     }
 
     /**
+     * Gets the state of the destination port.
+     *
+     * @return the destination port state, as defined in the OF1.0 spec
+     */
+    public int getDstPortStateInteger() {
+        return convertPortState(dstPortState);
+    }
+
+    private int convertPortState(Set<OFPortState> ps) {
+        int ret = 0;
+        if (ps.contains(OFPortState.LINK_DOWN)) {
+            ret = 1 << 0;
+        }
+        if (ps.contains(OFPortState.BLOCKED)) {
+            ret = ret | 1 << 1;
+        }
+        if (ps.contains(OFPortState.LIVE)) {
+            ret = ret | 1 << 2;
+        }
+        return ret;
+    }
+
+    /**
      * Gets the link type.
      *
      * @return the link type
@@ -117,8 +146,8 @@
         int result = 1;
         result = prime * result + Longs.hashCode(firstSeenTime);
         result = prime * result + Longs.hashCode(lastLldpReceivedTime);
-        result = prime * result + srcPortState;
-        result = prime * result + dstPortState;
+        result = prime * result + convertPortState(srcPortState);
+        result = prime * result + convertPortState(dstPortState);
         return result;
     }
 
@@ -138,12 +167,11 @@
         LinkInfo other = (LinkInfo) obj;
 
         return firstSeenTime == other.firstSeenTime &&
-               lastLldpReceivedTime == other.lastLldpReceivedTime &&
-               srcPortState == other.srcPortState &&
-               dstPortState == other.dstPortState;
+                lastLldpReceivedTime == other.lastLldpReceivedTime &&
+                srcPortState == other.srcPortState &&
+                dstPortState == other.dstPortState;
     }
 
-
     /* (non-Javadoc)
      * @see java.lang.Object#toString()
      */