Now OFPFlowMod should be able to modify flow tables.

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/ofproto/ofproto_v1_2.py        |    2 +-
 ryu/ofproto/ofproto_v1_2_parser.py |   57 ++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/ryu/ofproto/ofproto_v1_2.py b/ryu/ofproto/ofproto_v1_2.py
index 3fda5d5..a2d4d8e 100644
--- a/ryu/ofproto/ofproto_v1_2.py
+++ b/ryu/ofproto/ofproto_v1_2.py
@@ -227,7 +227,7 @@ assert (calcsize(OFP_INSTRUCTION_GOTO_TABLE_PACK_STR) ==
         OFP_INSTRUCTION_GOTO_TABLE_SIZE)
 
 # struct ofp_instruction_write_metadata
-OFP_INSTRUCTION_WRITE_METADATA_PACK_STR = '!HH4bQQ'
+OFP_INSTRUCTION_WRITE_METADATA_PACK_STR = '!HH4xQQ'
 OFP_INSTRUCTION_WRITE_METADATA_SIZE = 24
 assert (calcsize(OFP_INSTRUCTION_WRITE_METADATA_PACK_STR) ==
         OFP_INSTRUCTION_WRITE_METADATA_SIZE)
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py 
b/ryu/ofproto/ofproto_v1_2_parser.py
index 923ab61..b5c3198 100644
--- a/ryu/ofproto/ofproto_v1_2_parser.py
+++ b/ryu/ofproto/ofproto_v1_2_parser.py
@@ -320,7 +320,7 @@ class OFPPacketOut(MsgBase):
 class OFPFlowMod(MsgBase):
     def __init__(self, datapath, cookie, cookie_mask, table_id, command,
                  idle_timeout, hard_timeout, priority, buffer_id, out_port,
-                 out_group, flags, match):
+                 out_group, flags, match, instructions):
         super(OFPFlowMod, self).__init__(datapath)
         self.cookie = cookie
         self.cookie_mask = cookie_mask
@@ -334,6 +334,7 @@ class OFPFlowMod(MsgBase):
         self.out_group = out_group
         self.flags = flags
         self.match = match
+        self.instructions = instructions
 
     def _serialize_body(self):
         msg_pack_into(ofproto_v1_2.OFP_FLOW_MOD_PACK_STR0, self.buf,
@@ -345,7 +346,57 @@ class OFPFlowMod(MsgBase):
 
         offset = (ofproto_v1_2.OFP_FLOW_MOD_SIZE -
                   ofproto_v1_2.OFP_MATCH_SIZE)
-        self.match.serialize(self.buf, offset)
+
+        match_len = self.match.serialize(self.buf, offset)
+        offset += match_len
+
+        for inst in self.instructions:
+            inst.serialize(self.buf, offset)
+            offset += inst.len
+
+
+class OFPInstructionGotoTable(object):
+    def __init__(self, table_id):
+        super(OFPInstructionGotoTable, self).__init__()
+        self.type = ofproto_v1_2.OFPID_GOTO_TABLE
+        self.len = ofproto_v1_2.OFP_INSTRUCTION_GOTO_TABLE_SIZE
+        self.table_id = table_id
+
+    def serialize(self, buf, offset):
+        msg_pack_into(ofproto_v1_2.OFP_INSTRUCTION_GOTO_TABLE_PACK_STR,
+                      buf, offset, self.type, self.len, self.table_id)
+
+
+class OFPInstructionWriteMetadata(object):
+    def __init__(self, metadata, metadata_mask):
+        super(OFPInstructionWriteMetadata, self).__init__()
+        self.type = ofproto_v1_2.OFPIT_WRITE_METADATA
+        self.len = ofproto_v1_2.OFP_INSTRUCTION_WRITE_METADATA_SIZE
+        self.metadata = metadata
+        self.metadata_mask = metadata_mask
+
+    def serialize(self, buf, offset):
+        msg_pack_into(ofproto_v1_2.OFP_INSTRUCTION_WRITE_METADATA_PACK_STR,
+                      buf, offset, self.type, self.len, self.metadata,
+                      self.metadata_mask)
+
+
+class OFPInstructionActions(object):
+    def __init__(self, type_, actions):
+        super(OFPInstructionActions, self).__init__()
+        self.type = type_
+        self.actions = actions
+
+    def serialize(self, buf, offset):
+        action_offset = offset + ofproto_v1_2.OFP_INSTRUCTION_ACTIONS_SIZE
+        for a in self.actions:
+            a.serialize(buf, action_offset)
+            action_offset += a.len
+
+        self.len = action_offset - offset
+
+        msg_pack_into(ofproto_v1_2.OFP_INSTRUCTION_ACTIONS_PACK_STR,
+                      buf, offset, self.type, self.len)
 
 
 class OFPActionHeader(object):
@@ -1052,6 +1103,8 @@ class OFPMatch(object):
         pad_len = 8 - (length % 8)
         ofproto_parser.msg_pack_into("%dx" % pad_len, buf, field_offset)
 
+        return length + pad_len
+
     @classmethod
     def parser(cls, buf, offset):
         match = OFPMatch()
-- 
1.7.4.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to