blob: a94552501a68a421ba2737b3708194cf90ffa168 [file] [log] [blame]
Rich Lane629393f2013-01-10 15:37:33 -08001
2# Python OpenFlow instruction wrapper classes
3
4from cstruct import *
5from action_list import action_list
6
7
8
9class instruction_write_metadata(ofp_instruction_write_metadata):
10 """
11 Wrapper class for write_metadata instruction object
12
13 Data members inherited from ofp_instruction_write_metadata:
14 @arg type
15 @arg len
16 @arg metadata
17 @arg metadata_mask
18
19 """
20 def __init__(self):
21 ofp_instruction_write_metadata.__init__(self)
22 self.type = OFPIT_WRITE_METADATA
23 self.len = self.__len__()
24 def show(self, prefix=''):
25 outstr = prefix + "instruction_write_metadata\n"
26 outstr += ofp_instruction_write_metadata.show(self, prefix)
27 return outstr
28
29
30class instruction_goto_table(ofp_instruction_goto_table):
31 """
32 Wrapper class for goto_table instruction object
33
34 Data members inherited from ofp_instruction_goto_table:
35 @arg type
36 @arg len
37 @arg table_id
38
39 """
40 def __init__(self):
41 ofp_instruction_goto_table.__init__(self)
42 self.type = OFPIT_GOTO_TABLE
43 self.len = self.__len__()
44 def show(self, prefix=''):
45 outstr = prefix + "instruction_goto_table\n"
46 outstr += ofp_instruction_goto_table.show(self, prefix)
47 return outstr
48
49
50class instruction_write_actions(ofp_instruction_actions):
51 """
52 Wrapper class for write_actions instruction object
53
54 Data members inherited from ofp_instruction_actions:
55 @arg type
56 @arg len
57
58 """
59 def __init__(self):
60 ofp_instruction_actions.__init__(self)
61 self.type = OFPIT_WRITE_ACTIONS
62 self.actions = action_list()
63 self.len = self.__len__()
64 def show(self, prefix=''):
65 outstr = prefix + "instruction_write_actions\n"
66 outstr += ofp_instruction_actions.show(self, prefix)
67 outstr += self.actions.show(prefix)
68 return outstr
69 def unpack(self, binary_string):
70 binary_string = ofp_instruction_actions.unpack(self, binary_string)
71 bytes = self.len - OFP_INSTRUCTION_ACTIONS_BYTES
72 self.actions = action_list()
73 binary_string = self.actions.unpack(binary_string, bytes=bytes)
74 return binary_string
75 def pack(self):
76 self.len = self.__len__()
77 packed = ""
78 packed += ofp_instruction_actions.pack(self)
79 packed += self.actions.pack()
80 return packed
81 def __len__(self):
82 return ofp_instruction_actions.__len__(self) + self.actions.__len__()
83
84
85class instruction_apply_actions(ofp_instruction_actions):
86 """
87 Wrapper class for apply_actions instruction object
88
89 Data members inherited from ofp_instruction_actions:
90 @arg type
91 @arg len
92
93 """
94 def __init__(self):
95 ofp_instruction_actions.__init__(self)
96 self.type = OFPIT_APPLY_ACTIONS
97 self.actions = action_list()
98 self.len = self.__len__()
99 def show(self, prefix=''):
100 outstr = prefix + "instruction_apply_actions\n"
101 outstr += ofp_instruction_actions.show(self, prefix)
102 outstr += self.actions.show(prefix)
103 return outstr
104 def unpack(self, binary_string):
105 binary_string = ofp_instruction_actions.unpack(self, binary_string)
106 bytes = self.len - OFP_INSTRUCTION_ACTIONS_BYTES
107 self.actions = action_list()
108 binary_string = self.actions.unpack(binary_string, bytes=bytes)
109 return binary_string
110 def pack(self):
111 self.len = self.__len__()
112 packed = ""
113 packed += ofp_instruction_actions.pack(self)
114 packed += self.actions.pack()
115 return packed
116 def __len__(self):
117 return ofp_instruction_actions.__len__(self) + self.actions.__len__()
118
119
120class instruction_clear_actions(ofp_instruction):
121 """
122 Wrapper class for clear_actions instruction object
123
124 Data members inherited from ofp_instruction:
125 @arg type
126 @arg len
127
128 """
129 def __init__(self):
130 ofp_instruction.__init__(self)
131 self.type = OFPIT_CLEAR_ACTIONS
132 self.len = self.__len__()
133 def show(self, prefix=''):
134 outstr = prefix + "instruction_clear_actions\n"
135 outstr += ofp_instruction.show(self, prefix)
136 return outstr
137
138instruction_class_list = (
139 instruction_apply_actions,
140 instruction_clear_actions,
141 instruction_goto_table,
142 instruction_write_actions,
143 instruction_write_metadata)