We need this OFPHET_VERSIONBITMAP stuff for all the OF versions.

=
>From 3ab4043b9ea3ba9786bb5e2c9d34b8083482c50e Mon Sep 17 00:00:00 2001
From: FUJITA Tomonori <[email protected]>
Date: Sat, 1 Dec 2012 00:06:41 +0900
Subject: [PATCH] of1.3: support OFPHET_VERSIONBITMAP

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/ofproto/ofproto_v1_3.py        |   17 +++++++++++++
 ryu/ofproto/ofproto_v1_3_parser.py |   46 ++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/ryu/ofproto/ofproto_v1_3.py b/ryu/ofproto/ofproto_v1_3.py
index e2869df..021b2d5 100644
--- a/ryu/ofproto/ofproto_v1_3.py
+++ b/ryu/ofproto/ofproto_v1_3.py
@@ -1006,6 +1006,23 @@ OFP_EXPERIMENTER_HEADER_SIZE = 16
 assert (calcsize(OFP_EXPERIMENTER_HEADER_PACK_STR) + OFP_HEADER_SIZE
         == OFP_EXPERIMENTER_HEADER_SIZE)
 
+# struct ofp_hello
+OFP_HELLO_HEADER_SIZE = 8
+
+# struct ofp_hello_elem_header
+OFP_HELLO_ELEM_HEADER_PACK_STR = '!HH'
+OFP_HELLO_ELEM_HEADER_SIZE = 4
+assert (calcsize(OFP_HELLO_ELEM_HEADER_PACK_STR) == OFP_HELLO_ELEM_HEADER_SIZE)
+
+# enum ofp_hello_elem_type
+OFPHET_VERSIONBITMAP = 1
+
+# struct ofp_hello_elem_versionbitmap
+OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_PACK_STR = '!HH'
+OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_SIZE = 4
+assert (calcsize(OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_PACK_STR) ==
+        OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_SIZE)
+
 # OXM
 
 
diff --git a/ryu/ofproto/ofproto_v1_3_parser.py 
b/ryu/ofproto/ofproto_v1_3_parser.py
index db31dea..11dd365 100644
--- a/ryu/ofproto/ofproto_v1_3_parser.py
+++ b/ryu/ofproto/ofproto_v1_3_parser.py
@@ -56,6 +56,52 @@ class OFPHello(MsgBase):
     def __init__(self, datapath):
         super(OFPHello, self).__init__(datapath)
 
+    @classmethod
+    def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
+        msg = super(OFPHello, cls).parser(datapath, version, msg_type,
+                                          msg_len, xid, buf)
+
+        offset = ofproto_v1_3.OFP_HELLO_HEADER_SIZE
+        elems = []
+        while offset < msg.msg_len:
+            type_, length = struct.unpack_from(
+                ofproto_v1_3.OFP_HELLO_ELEM_HEADER_PACK_STR, msg.buf, offset)
+
+            # better to register Hello Element classes but currently
+            # Only VerisonBitmap is supported so let's be simple.
+
+            if type_ == ofproto_v1_3.OFPHET_VERSIONBITMAP:
+                elem = OFPHelloElemVersionBitmap.parser(msg.buf, offset)
+                elems.append(elem)
+
+            offset += length
+        msg.elements = elems
+        return msg
+
+
+class OFPHelloElemVersionBitmap(object):
+    def __init__(self, type_, length, bitmaps):
+        super(OFPHelloElemVersionBitmap, self).__init__()
+        self.type = type_
+        self.length = length
+        self.bitmaps = bitmaps
+
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, length = struct.unpack_from(
+            ofproto_v1_3.OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_PACK_STR,
+            buf, offset)
+        bitmaps_len = (length -
+                       ofproto_v1_3.OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_SIZE)
+        offset += ofproto_v1_3.OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_SIZE
+        bitmaps = []
+        while bitmaps_len > 0:
+            bitmap = struct.unpack_from('!I', buf, offset)
+            bitmaps.append(bitmap)
+            bitmaps_len -= 4
+
+        return cls(type_, length, bitmaps)
+
 
 @_register_parser
 @_set_msg_type(ofproto_v1_3.OFPT_ERROR)
-- 
1.7.4.4


------------------------------------------------------------------------------
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to