summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-06-23 16:01:05 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-06-23 16:17:34 +0900
commit9e3899ca3427cf47fbd7df76f877f9f034a62bc3 (patch)
tree78e3a4e83a3276f2736bd1fcd13a60e896c4f831
parentc9ac97c2b1518b82a15146d8a555dd18d781e0c1 (diff)
of1.2: support ofp_instruction for OFPFlowMod
Now OFPFlowMod should be able to modify flow tables. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Reviewed-by: Simon Horman <horms@verge.net.au>
-rw-r--r--ryu/ofproto/ofproto_v1_2.py2
-rw-r--r--ryu/ofproto/ofproto_v1_2_parser.py57
2 files changed, 56 insertions, 3 deletions
diff --git a/ryu/ofproto/ofproto_v1_2.py b/ryu/ofproto/ofproto_v1_2.py
index 3fda5d55..a2d4d8e6 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 923ab618..b5c31988 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()