Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # This python script generates wrapper functions for OpenFlow messages |
| 4 | # |
| 5 | # See the doc string below for more info |
| 6 | # |
| 7 | |
| 8 | # To do: |
| 9 | # Default type values for messages |
| 10 | # Generate all message objects |
| 11 | # Action list objects? |
| 12 | # Autogen lengths when possible |
| 13 | # Dictionaries for enum strings |
| 14 | # Resolve sub struct initializers (see ofp_flow_mod) |
| 15 | |
| 16 | |
| 17 | """ |
| 18 | Generate wrapper classes for OpenFlow messages |
| 19 | |
| 20 | (C) Copyright Stanford University |
| 21 | Date February 2010 |
| 22 | Created by dtalayco |
| 23 | |
| 24 | Attempting to follow http://www.python.org/dev/peps/pep-0008/ |
| 25 | The main exception is that our class names do not use CamelCase |
| 26 | so as to more closely match the original C code names. |
| 27 | |
| 28 | This file is meant to generate a file of_wrapper.py which imports |
| 29 | the base classes generated form automatic processing of openflow.h |
| 30 | and produces wrapper classes for each OpenFlow message type. |
| 31 | |
| 32 | This file will normally be included in of_message.py which provides |
| 33 | additional hand-generated work. |
| 34 | |
| 35 | There are two types of structures/classes here: base components and |
| 36 | message classes. |
| 37 | |
| 38 | Base components are the base data classes which are fixed |
| 39 | length structures including: |
| 40 | ofp_header |
| 41 | Each ofp_action structure |
| 42 | ofp_phy_port |
| 43 | The array elements of all the stats reply messages |
| 44 | The base components are to be imported from a file of_header.py. |
| 45 | |
| 46 | Message classes define a complete message on the wire. These are |
| 47 | comprised of possibly variable length lists of possibly variably |
| 48 | typed objects from the base component list above. |
| 49 | |
| 50 | Each OpenFlow message has a header and zero or more fixed length |
| 51 | members (the "core members" of the class) followed by zero or more |
| 52 | variable length lists. |
| 53 | |
| 54 | The wrapper classes should live in their own name space, probably |
| 55 | of_message. Automatically generated base component and skeletons for |
| 56 | the message classes are assumed generated and the wrapper classes |
| 57 | will inherit from those. |
| 58 | |
| 59 | Every message class must implement pack and unpack functions to |
| 60 | convert between the class and a string representing what goes on the |
| 61 | wire. |
| 62 | |
| 63 | For unpacking, the low level (base-component) classes must implement |
| 64 | their own unpack functions. A single top level unpack function |
| 65 | will do the parsing and call the lower layer unpack functions as |
| 66 | appropriate. |
| 67 | |
| 68 | Every base and message class should implement a show function to |
| 69 | (recursively) display the contents of the object. |
| 70 | |
| 71 | Certain OpenFlow message types are further subclassed. These include |
| 72 | stats_request, stats_reply and error. |
| 73 | |
| 74 | """ |
| 75 | |
| 76 | # Don't generate header object in messages |
| 77 | # Map each message to a body that doesn't include the header |
| 78 | # The body has does not include variable length info at the end |
| 79 | |
| 80 | import re |
| 81 | import string |
| 82 | import sys |
Rich Lane | 6242d9f | 2013-01-06 17:35:39 -0800 | [diff] [blame] | 83 | sys.path.append("../../src/python/of10") |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 84 | from cstruct import * |
| 85 | from class_maps import class_to_members_map |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 86 | |
| 87 | message_top_matter = """ |
| 88 | # Python OpenFlow message wrapper classes |
| 89 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 90 | from cstruct import * |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 91 | from action_list import action_list |
Dan Talayco | 411489d | 2010-02-12 23:03:46 -0800 | [diff] [blame] | 92 | from error import * |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 93 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 94 | # Define templates for documentation |
| 95 | class ofp_template_msg: |
| 96 | \""" |
| 97 | Sample base class for template_msg; normally auto generated |
| 98 | This class should live in the of_header name space and provides the |
| 99 | base class for this type of message. It will be wrapped for the |
| 100 | high level API. |
| 101 | |
| 102 | \""" |
| 103 | def __init__(self): |
| 104 | \""" |
| 105 | Constructor for base class |
| 106 | |
| 107 | \""" |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 108 | # Additional base data members declared here |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 109 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 110 | # Normally will define pack, unpack, __len__ functions |
| 111 | |
| 112 | class template_msg(ofp_template_msg): |
| 113 | \""" |
| 114 | Sample class wrapper for template_msg |
| 115 | This class should live in the of_message name space and provides the |
| 116 | high level API for an OpenFlow message object. These objects must |
| 117 | implement the functions indicated in this template. |
| 118 | |
| 119 | \""" |
| 120 | def __init__(self): |
| 121 | \""" |
| 122 | Constructor |
| 123 | Must set the header type value appropriately for the message |
| 124 | |
| 125 | \""" |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 126 | |
| 127 | ##@var header |
| 128 | # OpenFlow message header: length, version, xid, type |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 129 | ofp_template_msg.__init__(self) |
| 130 | # For a real message, will be set to an integer |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 131 | self.type = "TEMPLATE_MSG_VALUE" |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 132 | def pack(self): |
| 133 | \""" |
| 134 | Pack object into string |
| 135 | |
| 136 | @return The packed string which can go on the wire |
| 137 | |
| 138 | \""" |
| 139 | pass |
| 140 | def unpack(self, binary_string): |
| 141 | \""" |
| 142 | Unpack object from a binary string |
| 143 | |
| 144 | @param binary_string The wire protocol byte string holding the object |
| 145 | represented as an array of bytes. |
| 146 | |
| 147 | @return Typically returns the remainder of binary_string that |
| 148 | was not parsed. May give a warning if that string is non-empty |
| 149 | |
| 150 | \""" |
| 151 | pass |
| 152 | def __len__(self): |
| 153 | \""" |
| 154 | Return the length of this object once packed into a string |
| 155 | |
| 156 | @return An integer representing the number bytes in the packed |
| 157 | string. |
| 158 | |
| 159 | \""" |
| 160 | pass |
| 161 | def show(self, prefix=''): |
| 162 | \""" |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 163 | Generate a string (with multiple lines) describing the contents |
| 164 | of the object in a readable manner |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 165 | |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 166 | @param prefix Pre-pended at the beginning of each line. |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 167 | |
| 168 | \""" |
| 169 | pass |
| 170 | def __eq__(self, other): |
| 171 | \""" |
| 172 | Return True if self and other hold the same data |
| 173 | |
| 174 | @param other Other object in comparison |
| 175 | |
| 176 | \""" |
| 177 | pass |
| 178 | def __ne__(self, other): |
| 179 | \""" |
| 180 | Return True if self and other do not hold the same data |
| 181 | |
| 182 | @param other Other object in comparison |
| 183 | |
| 184 | \""" |
| 185 | pass |
| 186 | """ |
| 187 | |
| 188 | # Dictionary mapping wrapped classes to the auto-generated structure |
| 189 | # underlieing the class (body only, not header or var-length data) |
| 190 | message_class_map = { |
| 191 | "hello" : "ofp_header", |
| 192 | "error" : "ofp_error_msg", |
| 193 | "echo_request" : "ofp_header", |
| 194 | "echo_reply" : "ofp_header", |
| 195 | "vendor" : "ofp_vendor_header", |
| 196 | "features_request" : "ofp_header", |
| 197 | "features_reply" : "ofp_switch_features", |
| 198 | "get_config_request" : "ofp_header", |
| 199 | "get_config_reply" : "ofp_switch_config", |
| 200 | "set_config" : "ofp_switch_config", |
| 201 | "packet_in" : "ofp_packet_in", |
| 202 | "flow_removed" : "ofp_flow_removed", |
| 203 | "port_status" : "ofp_port_status", |
| 204 | "packet_out" : "ofp_packet_out", |
| 205 | "flow_mod" : "ofp_flow_mod", |
| 206 | "port_mod" : "ofp_port_mod", |
| 207 | "stats_request" : "ofp_stats_request", |
| 208 | "stats_reply" : "ofp_stats_reply", |
| 209 | "barrier_request" : "ofp_header", |
| 210 | "barrier_reply" : "ofp_header", |
| 211 | "queue_get_config_request" : "ofp_queue_get_config_request", |
| 212 | "queue_get_config_reply" : "ofp_queue_get_config_reply" |
| 213 | } |
| 214 | |
| 215 | # These messages have a string member at the end of the data |
| 216 | string_members = [ |
| 217 | "hello", |
| 218 | "error", |
| 219 | "echo_request", |
| 220 | "echo_reply", |
| 221 | "vendor", |
| 222 | "packet_in", |
| 223 | "packet_out" |
| 224 | ] |
| 225 | |
| 226 | # These messages have a list (with the given name) in the data, |
| 227 | # after the core members; the type is given for validation |
| 228 | list_members = { |
| 229 | "features_reply" : ('ports', None), |
| 230 | "packet_out" : ('actions', 'action_list'), |
| 231 | "flow_mod" : ('actions', 'action_list'), |
| 232 | "queue_get_config_reply" : ('queues', None) |
| 233 | } |
| 234 | |
| 235 | _ind = " " |
| 236 | |
| 237 | def _p1(s): print _ind + s |
| 238 | def _p2(s): print _ind * 2 + s |
| 239 | def _p3(s): print _ind * 3 + s |
| 240 | def _p4(s): print _ind * 4 + s |
| 241 | |
| 242 | # Okay, this gets kind of ugly: |
| 243 | # There are three variables: |
| 244 | # has_core_members: If parent class is not ofp_header, has inheritance |
| 245 | # has_list: Whether class has trailing array or class |
| 246 | # has_string: Whether class has trailing string |
| 247 | |
| 248 | def gen_message_wrapper(msg): |
| 249 | """ |
| 250 | Generate a wrapper for the given message based on above info |
| 251 | @param msg String identifying the message name for the class |
| 252 | """ |
| 253 | |
| 254 | msg_name = "OFPT_" + msg.upper() |
| 255 | parent = message_class_map[msg] |
| 256 | |
| 257 | has_list = False # Has trailing list |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 258 | has_core_members = True |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 259 | has_string = False # Has trailing string |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 260 | if msg in list_members.keys(): |
| 261 | (list_var, list_type) = list_members[msg] |
| 262 | has_list = True |
| 263 | if msg in string_members: |
| 264 | has_string = True |
| 265 | |
| 266 | if has_core_members: |
| 267 | print "class " + msg + "(" + parent + "):" |
| 268 | else: |
| 269 | print "class " + msg + ":" |
| 270 | _p1('"""') |
| 271 | _p1("Wrapper class for " + msg) |
| 272 | print |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 273 | _p1("OpenFlow message header: length, version, xid, type") |
| 274 | _p1("@arg length: The total length of the message") |
| 275 | _p1("@arg version: The OpenFlow version (" + str(OFP_VERSION) + ")") |
| 276 | _p1("@arg xid: The transaction ID") |
| 277 | _p1("@arg type: The message type (" + msg_name + "=" + |
| 278 | str(eval(msg_name)) + ")") |
| 279 | print |
| 280 | if has_core_members and parent in class_to_members_map.keys(): |
| 281 | _p1("Data members inherited from " + parent + ":") |
| 282 | for var in class_to_members_map[parent]: |
| 283 | _p1("@arg " + var) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 284 | if has_list: |
| 285 | if list_type == None: |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 286 | _p1("@arg " + list_var + ": Variable length array of TBD") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 287 | else: |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 288 | _p1("@arg " + list_var + ": Object of type " + list_type); |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 289 | if has_string: |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 290 | _p1("@arg data: Binary string following message members") |
| 291 | print |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 292 | _p1('"""') |
| 293 | |
| 294 | print |
Rich Lane | c3c2ae1 | 2013-01-04 10:13:17 -0800 | [diff] [blame] | 295 | _p1("def __init__(self, **kwargs):") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 296 | if has_core_members: |
| 297 | _p2(parent + ".__init__(self)") |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 298 | _p2("self.version = OFP_VERSION") |
| 299 | _p2("self.type = " + msg_name) |
Rich Lane | 8fbfd66 | 2013-03-11 15:30:44 -0700 | [diff] [blame] | 300 | _p2("self.xid = None") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 301 | if has_list: |
Rich Lane | 0f0adc9 | 2013-01-04 15:13:02 -0800 | [diff] [blame] | 302 | _p2('self.' + list_var + ' = []') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 303 | if has_string: |
| 304 | _p2('self.data = ""') |
Rich Lane | c3c2ae1 | 2013-01-04 10:13:17 -0800 | [diff] [blame] | 305 | _p2('for (k, v) in kwargs.items():') |
| 306 | _p3('if hasattr(self, k):') |
| 307 | _p4('setattr(self, k, v)') |
| 308 | _p3('else:') |
| 309 | _p4('raise NameError("field %s does not exist in %s" % (k, self.__class__))') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 310 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 311 | print """ |
| 312 | |
| 313 | def pack(self): |
| 314 | \""" |
| 315 | Pack object into string |
| 316 | |
| 317 | @return The packed string which can go on the wire |
| 318 | |
| 319 | \""" |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 320 | self.length = len(self) |
| 321 | packed = "" |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 322 | """ |
| 323 | |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 324 | # Have to special case the action length calculation for pkt out |
| 325 | if msg == 'packet_out': |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 326 | _p2('self.actions_len = 0') |
| 327 | _p2('for obj in self.actions:') |
| 328 | _p3('self.actions_len += len(obj)') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 329 | if has_core_members: |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 330 | _p2("packed += " + parent + ".pack(self)") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 331 | if has_list: |
| 332 | if list_type == None: |
| 333 | _p2('for obj in self.' + list_var + ':') |
| 334 | _p3('packed += obj.pack()') |
| 335 | else: |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 336 | _p2('packed += ' + list_type + '(self.' + list_var + ').pack()') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 337 | if has_string: |
| 338 | _p2('packed += self.data') |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 339 | _p2("return packed") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 340 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 341 | print """ |
| 342 | def unpack(self, binary_string): |
| 343 | \""" |
| 344 | Unpack object from a binary string |
| 345 | |
| 346 | @param binary_string The wire protocol byte string holding the object |
| 347 | represented as an array of bytes. |
Dan Talayco | 411489d | 2010-02-12 23:03:46 -0800 | [diff] [blame] | 348 | @return The remainder of binary_string that was not parsed. |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 349 | |
| 350 | \""" |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 351 | """ |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 352 | if has_core_members: |
| 353 | _p2("binary_string = " + parent + ".unpack(self, binary_string)") |
| 354 | if has_list: |
Dan Talayco | ff60649 | 2010-05-13 14:22:37 -0700 | [diff] [blame] | 355 | if msg == "features_reply": # Special case port parsing |
| 356 | # For now, cheat and assume the rest of the message is port list |
| 357 | _p2("while len(binary_string) >= OFP_PHY_PORT_BYTES:") |
| 358 | _p3("new_port = ofp_phy_port()") |
| 359 | _p3("binary_string = new_port.unpack(binary_string)") |
| 360 | _p3("self.ports.append(new_port)") |
| 361 | elif list_type == None: |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 362 | _p2("for obj in self." + list_var + ":") |
| 363 | _p3("binary_string = obj.unpack(binary_string)") |
| 364 | elif msg == "packet_out": # Special case this |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 365 | _p2("obj = action_list()") |
| 366 | _p2('binary_string = obj.unpack(' + |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 367 | 'binary_string, bytes=self.actions_len)') |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 368 | _p2("self.actions = list(obj)") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 369 | elif msg == "flow_mod": # Special case this |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 370 | _p2("ai_len = self.length - (OFP_FLOW_MOD_BYTES + " + |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 371 | "OFP_HEADER_BYTES)") |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 372 | _p2("obj = action_list()") |
| 373 | _p2("binary_string = obj.unpack(binary_string, " + |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 374 | "bytes=ai_len)") |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 375 | _p2("self.actions = list(obj)") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 376 | else: |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 377 | _p2("obj = " + list_type + "()") |
| 378 | _p2("binary_string = obj.unpack(binary_string)") |
| 379 | _p2("self." + list_var + " = list(obj)") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 380 | if has_string: |
| 381 | _p2("self.data = binary_string") |
| 382 | _p2("binary_string = ''") |
| 383 | else: |
| 384 | _p2("# Fixme: If no self.data, add check for data remaining") |
| 385 | _p2("return binary_string") |
| 386 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 387 | print """ |
| 388 | def __len__(self): |
| 389 | \""" |
| 390 | Return the length of this object once packed into a string |
| 391 | |
| 392 | @return An integer representing the number bytes in the packed |
| 393 | string. |
| 394 | |
| 395 | \""" |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 396 | length = 0 |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 397 | """ |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 398 | if has_core_members: |
| 399 | _p2("length += " + parent + ".__len__(self)") |
| 400 | if has_list: |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 401 | _p2("for obj in self." + list_var + ":") |
| 402 | _p3("length += len(obj)") |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 403 | if has_string: |
| 404 | _p2("length += len(self.data)") |
| 405 | _p2("return length") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 406 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 407 | print """ |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 408 | def show(self, prefix=''): |
| 409 | \""" |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 410 | Generate a string (with multiple lines) describing the contents |
| 411 | of the object in a readable manner |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 412 | |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 413 | @param prefix Pre-pended at the beginning of each line. |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 414 | |
| 415 | \""" |
| 416 | """ |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 417 | _p2("outstr = prefix + '" + msg + " (" + msg_name + ")\\n'") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 418 | _p2("prefix += ' '") |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 419 | _p2("outstr += prefix + 'ofp header\\n'") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 420 | if has_core_members: |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 421 | _p2("outstr += " + parent + ".show(self, prefix)") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 422 | if has_list: |
| 423 | if list_type == None: |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 424 | _p2('outstr += prefix + "Array ' + list_var + '\\n"') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 425 | _p2('for obj in self.' + list_var +':') |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 426 | _p3("outstr += obj.show(prefix + ' ')") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 427 | else: |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 428 | _p2('outstr += prefix + "List ' + list_var + '\\n"') |
Rich Lane | e6ea3fe | 2013-03-08 17:54:38 -0800 | [diff] [blame] | 429 | _p2('for obj in self.' + list_var + ':') |
| 430 | _p3('outstr += obj.show(prefix + " ")') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 431 | if has_string: |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 432 | _p2("outstr += prefix + 'data is of length ' + str(len(self.data)) + '\\n'") |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 433 | _p2("##@todo Fix this circular reference") |
| 434 | _p2("# if len(self.data) > 0:") |
| 435 | _p3("# obj = of_message_parse(self.data)") |
| 436 | _p3("# if obj != None:") |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 437 | _p4("# outstr += obj.show(prefix)") |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 438 | _p3("# else:") |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 439 | _p4('# outstr += prefix + "Unable to parse data\\n"') |
| 440 | _p2('return outstr') |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 441 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 442 | print """ |
| 443 | def __eq__(self, other): |
| 444 | \""" |
| 445 | Return True if self and other hold the same data |
| 446 | |
| 447 | @param other Other object in comparison |
| 448 | |
| 449 | \""" |
| 450 | if type(self) != type(other): return False |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 451 | """ |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 452 | if has_core_members: |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 453 | _p2("if not " + parent + ".__eq__(self, other): return False") |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 454 | if has_string: |
| 455 | _p2("if self.data != other.data: return False") |
| 456 | if has_list: |
| 457 | _p2("if self." + list_var + " != other." + list_var + ": return False") |
| 458 | _p2("return True") |
| 459 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 460 | print """ |
| 461 | def __ne__(self, other): |
| 462 | \""" |
| 463 | Return True if self and other do not hold the same data |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 464 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 465 | @param other Other object in comparison |
| 466 | |
| 467 | \""" |
| 468 | return not self.__eq__(other) |
| 469 | """ |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 470 | |
| 471 | |
| 472 | ################################################################ |
| 473 | # |
| 474 | # Stats request subclasses |
| 475 | # description_request, flow, aggregate, table, port, vendor |
| 476 | # |
| 477 | ################################################################ |
| 478 | |
| 479 | # table and desc stats requests are special with empty body |
| 480 | extra_ofp_stats_req_defs = """ |
| 481 | # Stats request bodies for desc and table stats are not defined in the |
| 482 | # OpenFlow header; We define them here. They are empty classes, really |
| 483 | |
| 484 | class ofp_desc_stats_request: |
| 485 | \""" |
| 486 | Forced definition of ofp_desc_stats_request (empty class) |
| 487 | \""" |
| 488 | def __init__(self): |
| 489 | pass |
| 490 | def pack(self, assertstruct=True): |
| 491 | return "" |
| 492 | def unpack(self, binary_string): |
| 493 | return binary_string |
| 494 | def __len__(self): |
| 495 | return 0 |
| 496 | def show(self, prefix=''): |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 497 | return prefix + "ofp_desc_stats_request (empty)\\n" |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 498 | def __eq__(self, other): |
| 499 | return type(self) == type(other) |
| 500 | def __ne__(self, other): |
| 501 | return type(self) != type(other) |
| 502 | |
| 503 | OFP_DESC_STATS_REQUEST_BYTES = 0 |
| 504 | |
| 505 | class ofp_table_stats_request: |
| 506 | \""" |
| 507 | Forced definition of ofp_table_stats_request (empty class) |
| 508 | \""" |
| 509 | def __init__(self): |
| 510 | pass |
| 511 | def pack(self, assertstruct=True): |
| 512 | return "" |
| 513 | def unpack(self, binary_string): |
| 514 | return binary_string |
| 515 | def __len__(self): |
| 516 | return 0 |
| 517 | def show(self, prefix=''): |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 518 | return prefix + "ofp_table_stats_request (empty)\\n" |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 519 | def __eq__(self, other): |
| 520 | return type(self) == type(other) |
| 521 | def __ne__(self, other): |
| 522 | return type(self) != type(other) |
| 523 | |
| 524 | OFP_TABLE_STATS_REQUEST_BYTES = 0 |
| 525 | |
| 526 | """ |
| 527 | |
| 528 | stats_request_template = """ |
| 529 | class --TYPE--_stats_request(ofp_stats_request, ofp_--TYPE--_stats_request): |
| 530 | \""" |
| 531 | Wrapper class for --TYPE-- stats request message |
| 532 | \""" |
Rich Lane | c3c2ae1 | 2013-01-04 10:13:17 -0800 | [diff] [blame] | 533 | def __init__(self, **kwargs): |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 534 | ofp_stats_request.__init__(self) |
| 535 | ofp_--TYPE--_stats_request.__init__(self) |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 536 | self.version = OFP_VERSION |
| 537 | self.type = OFPT_STATS_REQUEST |
Rich Lane | 8fbfd66 | 2013-03-11 15:30:44 -0700 | [diff] [blame] | 538 | self.xid = None |
Rich Lane | 7c7342a | 2013-03-11 14:16:58 -0700 | [diff] [blame] | 539 | self.stats_type = --STATS_NAME-- |
Rich Lane | c3c2ae1 | 2013-01-04 10:13:17 -0800 | [diff] [blame] | 540 | for (k, v) in kwargs.items(): |
| 541 | if hasattr(self, k): |
| 542 | setattr(self, k, v) |
| 543 | else: |
| 544 | raise NameError("field %s does not exist in %s" % (k, self.__class__)) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 545 | |
| 546 | def pack(self, assertstruct=True): |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 547 | self.length = len(self) |
| 548 | packed = "" |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 549 | packed += ofp_stats_request.pack(self) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 550 | packed += ofp_--TYPE--_stats_request.pack(self) |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 551 | return packed |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 552 | |
| 553 | def unpack(self, binary_string): |
| 554 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 555 | binary_string = ofp_--TYPE--_stats_request.unpack(self, binary_string) |
| 556 | if len(binary_string) != 0: |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 557 | print "ERROR unpacking --TYPE--: extra data" |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 558 | return binary_string |
| 559 | |
| 560 | def __len__(self): |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 561 | return OFP_STATS_REQUEST_BYTES + \\ |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 562 | OFP_--TYPE_UPPER--_STATS_REQUEST_BYTES |
| 563 | |
| 564 | def show(self, prefix=''): |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 565 | outstr = prefix + "--TYPE--_stats_request\\n" |
| 566 | outstr += prefix + "ofp header:\\n" |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 567 | outstr += ofp_stats_request.show(self) |
| 568 | outstr += ofp_--TYPE--_stats_request.show(self) |
| 569 | return outstr |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 570 | |
| 571 | def __eq__(self, other): |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 572 | if type(self) != type(other): return False |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 573 | return (ofp_stats_request.__eq__(self, other) and |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 574 | ofp_--TYPE--_stats_request.__eq__(self, other)) |
| 575 | |
| 576 | def __ne__(self, other): return not self.__eq__(other) |
| 577 | """ |
| 578 | |
| 579 | ################################################################ |
| 580 | # |
| 581 | # Stats replies always have an array at the end. |
| 582 | # For aggregate and desc, these arrays are always of length 1 |
| 583 | # This array is always called stats |
| 584 | # |
| 585 | ################################################################ |
| 586 | |
| 587 | |
| 588 | # Template for objects stats reply messages |
| 589 | stats_reply_template = """ |
| 590 | class --TYPE--_stats_reply(ofp_stats_reply): |
| 591 | \""" |
| 592 | Wrapper class for --TYPE-- stats reply |
| 593 | \""" |
| 594 | def __init__(self): |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 595 | ofp_stats_reply.__init__(self) |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 596 | self.version = OFP_VERSION |
| 597 | self.type = OFPT_STATS_REPLY |
Rich Lane | 8fbfd66 | 2013-03-11 15:30:44 -0700 | [diff] [blame] | 598 | self.xid = None |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 599 | self.stats_type = --STATS_NAME-- |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 600 | # stats: Array of type --TYPE--_stats_entry |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 601 | self.entries = [] |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 602 | |
| 603 | def pack(self, assertstruct=True): |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 604 | self.length = len(self) |
| 605 | packed = "" |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 606 | packed += ofp_stats_reply.pack(self) |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 607 | for obj in self.entries: |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 608 | packed += obj.pack() |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 609 | return packed |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 610 | |
| 611 | def unpack(self, binary_string): |
| 612 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 613 | dummy = --TYPE--_stats_entry() |
| 614 | while len(binary_string) >= len(dummy): |
| 615 | obj = --TYPE--_stats_entry() |
| 616 | binary_string = obj.unpack(binary_string) |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 617 | self.entries.append(obj) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 618 | if len(binary_string) != 0: |
| 619 | print "ERROR unpacking --TYPE-- stats string: extra bytes" |
| 620 | return binary_string |
| 621 | |
| 622 | def __len__(self): |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 623 | length = OFP_STATS_REPLY_BYTES |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 624 | for obj in self.entries: |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 625 | length += len(obj) |
| 626 | return length |
| 627 | |
| 628 | def show(self, prefix=''): |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 629 | outstr = prefix + "--TYPE--_stats_reply\\n" |
| 630 | outstr += prefix + "ofp header:\\n" |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 631 | outstr += ofp_stats_reply.show(self) |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 632 | outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\\n' |
| 633 | for obj in self.entries: |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 634 | outstr += obj.show() |
| 635 | return outstr |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 636 | |
| 637 | def __eq__(self, other): |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 638 | if type(self) != type(other): return False |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 639 | return (ofp_stats_reply.__eq__(self, other) and |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 640 | self.entries == other.entries) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 641 | |
| 642 | def __ne__(self, other): return not self.__eq__(other) |
| 643 | """ |
| 644 | |
| 645 | # |
| 646 | # To address variations in stats reply bodies, the following |
| 647 | # "_entry" classes are defined for each element in the reply |
| 648 | # |
| 649 | |
| 650 | extra_stats_entry_defs = """ |
| 651 | # Stats entries define the content of one element in a stats |
| 652 | # reply for the indicated type; define _entry for consistency |
| 653 | |
| 654 | aggregate_stats_entry = ofp_aggregate_stats_reply |
| 655 | desc_stats_entry = ofp_desc_stats |
| 656 | port_stats_entry = ofp_port_stats |
| 657 | queue_stats_entry = ofp_queue_stats |
| 658 | table_stats_entry = ofp_table_stats |
| 659 | """ |
| 660 | |
| 661 | # Special case flow_stats to handle actions_list |
| 662 | |
| 663 | flow_stats_entry_def = """ |
| 664 | # |
| 665 | # Flow stats entry contains an action list of variable length, so |
| 666 | # it is done by hand |
| 667 | # |
| 668 | |
| 669 | class flow_stats_entry(ofp_flow_stats): |
| 670 | \""" |
| 671 | Special case flow stats entry to handle action list object |
| 672 | \""" |
| 673 | def __init__(self): |
| 674 | ofp_flow_stats.__init__(self) |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 675 | self.actions = [] |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 676 | |
| 677 | def pack(self, assertstruct=True): |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 678 | self.length = len(self) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 679 | packed = ofp_flow_stats.pack(self, assertstruct) |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 680 | packed += action_list(self.actions).pack() |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 681 | if len(packed) != self.length: |
| 682 | print("ERROR: flow_stats_entry pack length not equal", |
| 683 | self.length, len(packed)) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 684 | return packed |
| 685 | |
| 686 | def unpack(self, binary_string): |
| 687 | binary_string = ofp_flow_stats.unpack(self, binary_string) |
| 688 | ai_len = self.length - OFP_FLOW_STATS_BYTES |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 689 | if ai_len < 0: |
| 690 | print("ERROR: flow_stats_entry unpack length too small", |
| 691 | self.length) |
Rich Lane | 62e9685 | 2013-03-11 12:04:45 -0700 | [diff] [blame] | 692 | obj = action_list() |
| 693 | binary_string = obj.unpack(binary_string, bytes=ai_len) |
| 694 | self.actions = list(obj) |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 695 | return binary_string |
| 696 | |
| 697 | def __len__(self): |
| 698 | return OFP_FLOW_STATS_BYTES + len(self.actions) |
| 699 | |
| 700 | def show(self, prefix=''): |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 701 | outstr = prefix + "flow_stats_entry\\n" |
| 702 | outstr += ofp_flow_stats.show(self, prefix + ' ') |
Rich Lane | e6ea3fe | 2013-03-08 17:54:38 -0800 | [diff] [blame] | 703 | outstr += prefix + "List actions\\n" |
| 704 | for obj in self.actions: |
| 705 | outstr += obj.show(prefix + ' ') |
Dan Talayco | 46755fa | 2010-03-09 21:44:29 -0800 | [diff] [blame] | 706 | return outstr |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 707 | |
| 708 | def __eq__(self, other): |
Dan Talayco | 36f2f1f | 2010-02-10 22:40:26 -0800 | [diff] [blame] | 709 | if type(self) != type(other): return False |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 710 | return (ofp_flow_stats.__eq__(self, other) and |
| 711 | self.actions == other.actions) |
| 712 | |
| 713 | def __ne__(self, other): return not self.__eq__(other) |
| 714 | """ |
| 715 | |
| 716 | stats_types = [ |
| 717 | 'aggregate', |
| 718 | 'desc', |
| 719 | 'flow', |
| 720 | 'port', |
| 721 | 'queue', |
| 722 | 'table'] |
| 723 | |
| 724 | if __name__ == '__main__': |
| 725 | |
| 726 | print message_top_matter |
| 727 | |
| 728 | print """ |
| 729 | ################################################################ |
| 730 | # |
| 731 | # OpenFlow Message Definitions |
| 732 | # |
| 733 | ################################################################ |
| 734 | """ |
| 735 | |
| 736 | msg_types = message_class_map.keys() |
| 737 | msg_types.sort() |
| 738 | |
| 739 | for t in msg_types: |
| 740 | gen_message_wrapper(t) |
| 741 | print |
| 742 | |
| 743 | print """ |
| 744 | ################################################################ |
| 745 | # |
| 746 | # Stats request and reply subclass definitions |
| 747 | # |
| 748 | ################################################################ |
| 749 | """ |
| 750 | |
| 751 | print extra_ofp_stats_req_defs |
| 752 | print extra_stats_entry_defs |
| 753 | print flow_stats_entry_def |
| 754 | |
| 755 | # Generate stats request and reply subclasses |
| 756 | for t in stats_types: |
| 757 | stats_name = "OFPST_" + t.upper() |
| 758 | to_print = re.sub('--TYPE--', t, stats_request_template) |
| 759 | to_print = re.sub('--TYPE_UPPER--', t.upper(), to_print) |
| 760 | to_print = re.sub('--STATS_NAME--', stats_name, to_print) |
| 761 | print to_print |
| 762 | to_print = re.sub('--TYPE--', t, stats_reply_template) |
| 763 | to_print = re.sub('--STATS_NAME--', stats_name, to_print) |
| 764 | print to_print |
| 765 | |
Dan Talayco | 411489d | 2010-02-12 23:03:46 -0800 | [diff] [blame] | 766 | # Lastly, generate a tuple containing all the message classes |
| 767 | print """ |
| 768 | message_type_list = ( |
| 769 | aggregate_stats_reply, |
| 770 | aggregate_stats_request, |
| 771 | bad_action_error_msg, |
| 772 | bad_request_error_msg, |
| 773 | barrier_reply, |
| 774 | barrier_request, |
| 775 | desc_stats_reply, |
| 776 | desc_stats_request, |
| 777 | echo_reply, |
| 778 | echo_request, |
| 779 | features_reply, |
| 780 | features_request, |
| 781 | flow_mod, |
| 782 | flow_mod_failed_error_msg, |
| 783 | flow_removed, |
| 784 | flow_stats_reply, |
| 785 | flow_stats_request, |
| 786 | get_config_reply, |
| 787 | get_config_request, |
| 788 | hello, |
| 789 | hello_failed_error_msg, |
| 790 | packet_in, |
| 791 | packet_out, |
| 792 | port_mod, |
| 793 | port_mod_failed_error_msg, |
| 794 | port_stats_reply, |
| 795 | port_stats_request, |
| 796 | port_status, |
| 797 | queue_get_config_reply, |
| 798 | queue_get_config_request, |
| 799 | queue_op_failed_error_msg, |
| 800 | queue_stats_reply, |
| 801 | queue_stats_request, |
| 802 | set_config, |
| 803 | table_stats_reply, |
| 804 | table_stats_request, |
| 805 | vendor |
| 806 | ) |
| 807 | """ |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 808 | |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame^] | 809 | print """ |
| 810 | _flow_mod = flow_mod |
| 811 | flow_mod = None |
| 812 | |
| 813 | class flow_add(_flow_mod): |
| 814 | def __init__(self, **kwargs): |
| 815 | _flow_mod.__init__(self, **kwargs) |
| 816 | self.command = OFPFC_ADD |
| 817 | |
| 818 | class flow_modify(_flow_mod): |
| 819 | def __init__(self, **kwargs): |
| 820 | _flow_mod.__init__(self, **kwargs) |
| 821 | self.command = OFPFC_MODIFY |
| 822 | |
| 823 | class flow_modify_strict(_flow_mod): |
| 824 | def __init__(self, **kwargs): |
| 825 | _flow_mod.__init__(self, **kwargs) |
| 826 | self.command = OFPFC_MODIFY_STRICT |
| 827 | |
| 828 | class flow_delete(_flow_mod): |
| 829 | def __init__(self, **kwargs): |
| 830 | _flow_mod.__init__(self, **kwargs) |
| 831 | self.command = OFPFC_DELETE |
| 832 | |
| 833 | class flow_delete_strict(_flow_mod): |
| 834 | def __init__(self, **kwargs): |
| 835 | _flow_mod.__init__(self, **kwargs) |
| 836 | self.command = OFPFC_DELETE_STRICT |
| 837 | """ |
| 838 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 839 | # |
| 840 | # OFP match variants |
| 841 | # ICMP 0x801 (?) ==> icmp_type/code replace tp_src/dst |
| 842 | # |
| 843 | |
| 844 | |