Merge into master from pull request #80:
When handling OF messages from switch, use matching OF version. (https://github.com/floodlight/oftest/pull/80)
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index 3bfbcb3..56fd9fb 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -36,9 +36,12 @@
 from threading import Thread
 from threading import Lock
 from threading import Condition
-import ofp
-import ofutils
 
+import ofutils
+import loxi
+
+# Configured openflow version
+import ofp as cfg_ofp
 
 FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' 
                 for x in range(256)])
@@ -212,7 +215,10 @@
                 break
 
             # Parse the header to get type
-            hdr_version, hdr_type, hdr_length, hdr_xid = ofp.message.parse_header(pkt[offset:])
+            hdr_version, hdr_type, hdr_length, hdr_xid = cfg_ofp.message.parse_header(pkt[offset:])
+
+            # Use loxi to resolve to ofp of matching version
+            ofp = loxi.protocol(hdr_version)
 
             # Extract the raw message bytes
             if (offset + hdr_length) > len(pkt):
@@ -223,15 +229,17 @@
             #if self.filter_packet(rawmsg, hdr):
             #    continue
 
+            # Check that supported version on switch is as least as recent as
+            # the configured Openflow version in oftests
             self.logger.debug("Msg in: version %d type %s (%d) len %d xid %d",
                               hdr_version,
-                              ofp.ofp_type_map.get(hdr_type, "unknown"), hdr_type,
+                              cfg_ofp.ofp_type_map.get(hdr_type, "unknown"), hdr_type,
                               hdr_length, hdr_version)
-            if hdr_version < ofp.OFP_VERSION:
+            if hdr_version < cfg_ofp.OFP_VERSION:
                 self.logger.error("Switch only supports up to OpenFlow version %d (OFTest version is %d)",
-                                  hdr_version, ofp.OFP_VERSION)
+                                  hdr_version, cfg_ofp.OFP_VERSION)
                 print "Switch only supports up to OpenFlow version %d (OFTest version is %d)" % \
-                    (hdr_version, ofp.OFP_VERSION)
+                    (hdr_version, cfg_ofp.OFP_VERSION)
                 self.disconnect()
                 return
 
@@ -349,7 +357,7 @@
                 self.switch_socket.setsockopt(socket.IPPROTO_TCP,
                                               socket.TCP_NODELAY, True)
                 if self.initial_hello:
-                    self.message_send(ofp.message.hello())
+                    self.message_send(cfg_ofp.message.hello())
                 self.connect_cv.notify() # Notify anyone waiting
 
             # Prevent further connections
@@ -474,7 +482,7 @@
                 self.wakeup()
                 with self.connect_cv:
                     if self.initial_hello:
-                        self.message_send(ofp.message.hello())
+                        self.message_send(cfg_ofp.message.hello())
                     self.connect_cv.notify() # Notify anyone waiting
             else:
                 self.logger.error("Could not actively connect to switch %s",
@@ -591,7 +599,7 @@
 
         exp_msg_str = "unspecified"
         if exp_msg is not None:
-            exp_msg_str = ofp.ofp_type_map.get(exp_msg, "unknown (%d)" % 
+            exp_msg_str = cfg_ofp.ofp_type_map.get(exp_msg, "unknown (%d)" %
                                                exp_msg)
 
         if exp_msg is not None:
@@ -610,7 +618,7 @@
                     self.logger.debug("Looking for %s", exp_msg_str)
                     for i in range(len(self.packets)):
                         msg = self.packets[i][0]
-                        msg_str = ofp.ofp_type_map.get(msg.type, "unknown (%d)" % msg.type)
+                        msg_str = cfg_ofp.ofp_type_map.get(msg.type, "unknown (%d)" % msg.type)
                         self.logger.debug("Checking packets[%d] %s) against %s", i, msg_str, exp_msg_str)
                         if msg.type == exp_msg:
                             (msg, pkt) = self.packets.pop(i)
@@ -690,7 +698,7 @@
         msg_version, msg_type, msg_len, msg_xid = struct.unpack_from("!BBHL", outpkt)
         self.logger.debug("Msg out: buf len %d. hdr.type %s. hdr.len %d hdr.version %d hdr.xid %d",
                           len(outpkt),
-                          ofp.ofp_type_map.get(msg_type, "unknown (%d)" % msg_type),
+                          cfg_ofp.ofp_type_map.get(msg_type, "unknown (%d)" % msg_type),
                           msg_len,
                           msg_version,
                           msg_xid)