Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | # Copyright 2013, Big Switch Networks, Inc. |
| 2 | # |
| 3 | # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| 4 | # the following special exception: |
| 5 | # |
| 6 | # LOXI Exception |
| 7 | # |
| 8 | # As a special exception to the terms of the EPL, you may distribute libraries |
| 9 | # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| 10 | # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| 11 | # from the LoxiGen Libraries and the notice provided below is (i) included in |
| 12 | # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| 13 | # documentation for the LoxiGen Libraries, if distributed in binary form. |
| 14 | # |
| 15 | # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| 16 | # |
| 17 | # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| 18 | # a copy of the EPL at: |
| 19 | # |
| 20 | # http://www.eclipse.org/legal/epl-v10.html |
| 21 | # |
| 22 | # Unless required by applicable law or agreed to in writing, software |
| 23 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 25 | # EPL for the specific language governing permissions and limitations |
| 26 | # under the EPL. |
| 27 | |
| 28 | # |
| 29 | # Miscellaneous type information |
| 30 | # |
| 31 | # Define the map between sub-class types and wire values. In each |
| 32 | # case, an array indexed by wire version gives a hash from identifier |
| 33 | # to wire value. |
| 34 | # |
| 35 | |
Andreas Wundsam | 542a13c | 2013-11-15 13:28:55 -0800 | [diff] [blame] | 36 | import c_gen.of_g_legacy as of_g |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 37 | import sys |
| 38 | from generic_utils import * |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 39 | import loxi_utils.loxi_utils as loxi_utils |
Andreas Wundsam | 542a13c | 2013-11-15 13:28:55 -0800 | [diff] [blame] | 40 | import c_gen.loxi_utils_legacy as loxi_utils |
Rich Lane | 043a3d8 | 2013-12-10 10:57:30 -0800 | [diff] [blame] | 41 | import loxi_globals |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 42 | |
| 43 | invalid_type = "invalid_type" |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 44 | |
| 45 | ################################################################ |
| 46 | # |
| 47 | # Define type data for inheritance classes: |
| 48 | # instructions, actions, queue properties and OXM |
| 49 | # |
| 50 | # Messages are not in this group; they're treated specially for now |
| 51 | # |
| 52 | # These are indexed by wire protocol number |
| 53 | # |
| 54 | ################################################################ |
| 55 | |
| 56 | instruction_types = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 57 | of_g.VERSION_1_0:dict(), |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 58 | of_g.VERSION_1_1:dict(), |
| 59 | of_g.VERSION_1_2:dict(), |
| 60 | of_g.VERSION_1_3:dict() |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Rich Lane | 4def697 | 2013-12-09 17:44:43 -0800 | [diff] [blame] | 63 | instruction_id_types = { |
| 64 | of_g.VERSION_1_0:dict(), |
| 65 | of_g.VERSION_1_1:dict(), |
| 66 | of_g.VERSION_1_2:dict(), |
| 67 | of_g.VERSION_1_3:dict() |
| 68 | } |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 69 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 70 | action_types = { |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 71 | of_g.VERSION_1_0:dict(), |
| 72 | of_g.VERSION_1_1:dict(), |
| 73 | of_g.VERSION_1_2:dict(), |
Rich Lane | 4def697 | 2013-12-09 17:44:43 -0800 | [diff] [blame] | 74 | of_g.VERSION_1_3:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | action_id_types = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 78 | of_g.VERSION_1_0:dict(), |
| 79 | of_g.VERSION_1_1:dict(), |
| 80 | of_g.VERSION_1_2:dict(), |
Rich Lane | 4def697 | 2013-12-09 17:44:43 -0800 | [diff] [blame] | 81 | of_g.VERSION_1_3:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | queue_prop_types = { |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 85 | of_g.VERSION_1_0:dict(), |
| 86 | of_g.VERSION_1_1:dict(), |
| 87 | of_g.VERSION_1_2:dict(), |
| 88 | of_g.VERSION_1_3:dict() |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Dan Talayco | c0e802e | 2013-05-18 23:52:39 -0700 | [diff] [blame] | 91 | bsn_vport_types = { |
| 92 | # version 1.0 |
| 93 | of_g.VERSION_1_0:dict( |
| 94 | q_in_q = 0, |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame^] | 95 | l2gre = 1, |
Dan Talayco | c0e802e | 2013-05-18 23:52:39 -0700 | [diff] [blame] | 96 | ), |
| 97 | # version 1.1 |
| 98 | of_g.VERSION_1_1:dict( |
| 99 | q_in_q = 0, |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame^] | 100 | l2gre = 1, |
Dan Talayco | c0e802e | 2013-05-18 23:52:39 -0700 | [diff] [blame] | 101 | ), |
| 102 | # version 1.2 |
| 103 | of_g.VERSION_1_2:dict( |
| 104 | q_in_q = 0, |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame^] | 105 | l2gre = 1, |
Dan Talayco | c0e802e | 2013-05-18 23:52:39 -0700 | [diff] [blame] | 106 | ), |
| 107 | # version 1.3 |
| 108 | of_g.VERSION_1_3:dict( |
| 109 | q_in_q = 0, |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame^] | 110 | l2gre = 1, |
Dan Talayco | c0e802e | 2013-05-18 23:52:39 -0700 | [diff] [blame] | 111 | ) |
| 112 | } |
| 113 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 114 | oxm_types = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 115 | of_g.VERSION_1_0:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 116 | of_g.VERSION_1_1:dict(), |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 117 | of_g.VERSION_1_2:dict(), |
| 118 | of_g.VERSION_1_3:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | hello_elem_types = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 122 | of_g.VERSION_1_0:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 123 | of_g.VERSION_1_1:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 124 | of_g.VERSION_1_2:dict(), |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 125 | of_g.VERSION_1_3:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | table_feature_prop_types = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 129 | of_g.VERSION_1_0:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 130 | of_g.VERSION_1_1:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 131 | of_g.VERSION_1_2:dict(), |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 132 | of_g.VERSION_1_3:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | meter_band_types = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 136 | of_g.VERSION_1_0:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 137 | of_g.VERSION_1_1:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 138 | of_g.VERSION_1_2:dict(), |
Rich Lane | 4db4d04 | 2013-05-13 18:13:48 -0700 | [diff] [blame] | 139 | of_g.VERSION_1_3:dict(), |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Rich Lane | 713d928 | 2013-12-30 15:21:35 -0800 | [diff] [blame] | 142 | bsn_tlv_types = { |
| 143 | of_g.VERSION_1_0:dict(), |
| 144 | of_g.VERSION_1_1:dict(), |
| 145 | of_g.VERSION_1_2:dict(), |
| 146 | of_g.VERSION_1_3:dict(), |
| 147 | } |
| 148 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 149 | # All inheritance data for non-messages |
| 150 | inheritance_data = dict( |
| 151 | of_instruction = instruction_types, |
Rich Lane | 4def697 | 2013-12-09 17:44:43 -0800 | [diff] [blame] | 152 | of_instruction_id = instruction_id_types, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 153 | of_action = action_types, |
| 154 | of_action_id = action_id_types, |
| 155 | of_oxm = oxm_types, |
| 156 | of_queue_prop = queue_prop_types, |
| 157 | of_hello_elem = hello_elem_types, |
| 158 | of_table_feature_prop = table_feature_prop_types, |
Dan Talayco | c0e802e | 2013-05-18 23:52:39 -0700 | [diff] [blame] | 159 | of_meter_band = meter_band_types, |
| 160 | # BSN specific inheritance extensions |
Rich Lane | 713d928 | 2013-12-30 15:21:35 -0800 | [diff] [blame] | 161 | of_bsn_vport = bsn_vport_types, |
| 162 | of_bsn_tlv = bsn_tlv_types, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 163 | ) |
| 164 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 165 | def class_is_virtual(cls): |
| 166 | """ |
| 167 | Returns True if cls is a virtual class |
| 168 | """ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 169 | if cls.find("header") > 0: |
| 170 | return True |
| 171 | if loxi_utils.class_is_list(cls): |
| 172 | return True |
Rich Lane | 043a3d8 | 2013-12-10 10:57:30 -0800 | [diff] [blame] | 173 | return loxi_globals.unified.class_by_name(cls).virtual |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 174 | |
| 175 | ################################################################ |
| 176 | # |
| 177 | # These are message types |
| 178 | # |
| 179 | ################################################################ |
| 180 | |
Rich Lane | df847e3 | 2013-05-29 16:57:30 -0700 | [diff] [blame] | 181 | # The hardcoded message types are for inheritance parents |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 182 | message_types = { |
| 183 | # version 1.0 |
| 184 | of_g.VERSION_1_0:dict( |
Rob Vaterlaus | b3f49d9 | 2013-10-01 17:57:31 -0700 | [diff] [blame] | 185 | error_msg = 1, |
Rich Lane | df847e3 | 2013-05-29 16:57:30 -0700 | [diff] [blame] | 186 | experimenter = 4, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 187 | flow_mod = 14, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 188 | stats_request = 16, |
| 189 | stats_reply = 17, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 190 | ), |
| 191 | |
| 192 | # version 1.1 |
| 193 | of_g.VERSION_1_1:dict( |
Rob Vaterlaus | b3f49d9 | 2013-10-01 17:57:31 -0700 | [diff] [blame] | 194 | error_msg = 1, |
Rich Lane | df847e3 | 2013-05-29 16:57:30 -0700 | [diff] [blame] | 195 | experimenter = 4, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 196 | flow_mod = 14, |
Rich Lane | e311367 | 2013-12-06 17:09:57 -0800 | [diff] [blame] | 197 | group_mod = 15, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 198 | stats_request = 18, |
| 199 | stats_reply = 19, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 200 | ), |
| 201 | |
| 202 | # version 1.2 |
| 203 | of_g.VERSION_1_2:dict( |
Rob Vaterlaus | b3f49d9 | 2013-10-01 17:57:31 -0700 | [diff] [blame] | 204 | error_msg = 1, |
Rich Lane | df847e3 | 2013-05-29 16:57:30 -0700 | [diff] [blame] | 205 | experimenter = 4, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 206 | flow_mod = 14, |
Rich Lane | e311367 | 2013-12-06 17:09:57 -0800 | [diff] [blame] | 207 | group_mod = 15, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 208 | stats_request = 18, |
| 209 | stats_reply = 19, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 210 | ), |
| 211 | |
| 212 | # version 1.3 |
| 213 | of_g.VERSION_1_3:dict( |
Rob Vaterlaus | b3f49d9 | 2013-10-01 17:57:31 -0700 | [diff] [blame] | 214 | error_msg = 1, |
Rich Lane | df847e3 | 2013-05-29 16:57:30 -0700 | [diff] [blame] | 215 | experimenter = 4, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 216 | flow_mod = 14, |
Rich Lane | e311367 | 2013-12-06 17:09:57 -0800 | [diff] [blame] | 217 | group_mod = 15, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 218 | stats_request = 18, # FIXME Multipart |
| 219 | stats_reply = 19, |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 220 | ) |
| 221 | } |
| 222 | |
| 223 | ################################################################ |
| 224 | # |
| 225 | # These are other objects that have a notion of type but are |
| 226 | # not (yet) promoted to objects with inheritance |
| 227 | # |
| 228 | ################################################################ |
| 229 | |
| 230 | stats_types = { |
| 231 | # version 1.0 |
| 232 | of_g.VERSION_1_0:dict( |
| 233 | desc = 0, |
| 234 | flow = 1, |
| 235 | aggregate = 2, |
| 236 | table = 3, |
| 237 | port = 4, |
| 238 | queue = 5, |
| 239 | experimenter = 0xffff |
| 240 | ), |
| 241 | |
| 242 | # version 1.1 |
| 243 | of_g.VERSION_1_1:dict( |
| 244 | desc = 0, |
| 245 | flow = 1, |
| 246 | aggregate = 2, |
| 247 | table = 3, |
| 248 | port = 4, |
| 249 | queue = 5, |
| 250 | group = 6, |
| 251 | group_desc = 7, |
| 252 | experimenter = 0xffff |
| 253 | ), |
| 254 | |
| 255 | # version 1.2 |
| 256 | of_g.VERSION_1_2:dict( |
| 257 | desc = 0, |
| 258 | flow = 1, |
| 259 | aggregate = 2, |
| 260 | table = 3, |
| 261 | port = 4, |
| 262 | queue = 5, |
| 263 | group = 6, |
| 264 | group_desc = 7, |
| 265 | group_features = 8, |
| 266 | experimenter = 0xffff |
| 267 | ), |
| 268 | |
| 269 | # version 1.3 |
| 270 | of_g.VERSION_1_3:dict( |
| 271 | desc = 0, |
| 272 | flow = 1, |
| 273 | aggregate = 2, |
| 274 | table = 3, |
| 275 | port = 4, |
| 276 | queue = 5, |
| 277 | group = 6, |
| 278 | group_desc = 7, |
| 279 | group_features = 8, |
| 280 | meter = 9, |
| 281 | meter_config = 10, |
| 282 | meter_features = 11, |
| 283 | table_features = 12, |
| 284 | port_desc = 13, |
Rich Lane | 353a79f | 2013-11-13 10:39:56 -0800 | [diff] [blame] | 285 | experimenter = 0xffff, |
Wilson Ng | 45386fb | 2013-12-03 13:46:42 -0800 | [diff] [blame] | 286 | bsn_lacp = 0xffff, |
xinwu | 358e616 | 2013-12-04 16:49:48 -0800 | [diff] [blame] | 287 | bsn_switch_pipeline = 0xffff, |
| 288 | bsn_port_counter = 0xffff, |
| 289 | bsn_vlan_counter = 0xffff |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 290 | ) |
| 291 | } |
| 292 | |
| 293 | common_flow_mod_types = dict( |
| 294 | add = 0, |
| 295 | modify = 1, |
| 296 | modify_strict = 2, |
| 297 | delete = 3, |
| 298 | delete_strict = 4 |
| 299 | ) |
| 300 | |
| 301 | flow_mod_types = { |
| 302 | # version 1.0 |
| 303 | of_g.VERSION_1_0:common_flow_mod_types, |
| 304 | of_g.VERSION_1_1:common_flow_mod_types, |
| 305 | of_g.VERSION_1_2:common_flow_mod_types, |
| 306 | of_g.VERSION_1_3:common_flow_mod_types |
| 307 | } |
| 308 | |
| 309 | # These do not translate to objects (yet) |
| 310 | error_types = { |
| 311 | # version 1.0 |
| 312 | of_g.VERSION_1_0:dict( |
| 313 | hello_failed = 0, |
| 314 | bad_request = 1, |
| 315 | bad_action = 2, |
| 316 | flow_mod_failed = 3, |
| 317 | port_mod_failed = 4, |
| 318 | queue_op_failed = 5 |
| 319 | ), |
| 320 | |
| 321 | # version 1.1 |
| 322 | of_g.VERSION_1_1:dict( |
| 323 | hello_failed = 0, |
| 324 | bad_request = 1, |
| 325 | bad_action = 2, |
| 326 | bad_instruction = 3, |
| 327 | bad_match = 4, |
| 328 | flow_mod_failed = 5, |
| 329 | group_mod_failed = 6, |
| 330 | port_mod_failed = 7, |
| 331 | table_mod_failed = 8, |
| 332 | queue_op_failed = 9, |
| 333 | switch_config_failed = 10 |
| 334 | ), |
| 335 | |
| 336 | # version 1.2 |
| 337 | of_g.VERSION_1_2:dict( |
| 338 | hello_failed = 0, |
| 339 | bad_request = 1, |
| 340 | bad_action = 2, |
| 341 | bad_instruction = 3, |
| 342 | bad_match = 4, |
| 343 | flow_mod_failed = 5, |
| 344 | group_mod_failed = 6, |
| 345 | port_mod_failed = 7, |
| 346 | table_mod_failed = 8, |
| 347 | queue_op_failed = 9, |
| 348 | switch_config_failed = 10, |
| 349 | role_request_failed = 11, |
| 350 | experimenter = 0xffff |
| 351 | ), |
| 352 | |
| 353 | # version 1.3 |
| 354 | of_g.VERSION_1_3:dict( |
| 355 | hello_failed = 0, |
| 356 | bad_request = 1, |
| 357 | bad_action = 2, |
| 358 | bad_instruction = 3, |
| 359 | bad_match = 4, |
| 360 | flow_mod_failed = 5, |
| 361 | group_mod_failed = 6, |
| 362 | port_mod_failed = 7, |
| 363 | table_mod_failed = 8, |
| 364 | queue_op_failed = 9, |
| 365 | switch_config_failed = 10, |
| 366 | role_request_failed = 11, |
| 367 | meter_mod_failed = 12, |
| 368 | table_features_failed= 13, |
| 369 | experimenter = 0xffff |
| 370 | ) |
| 371 | } |
| 372 | |
Rich Lane | e311367 | 2013-12-06 17:09:57 -0800 | [diff] [blame] | 373 | group_mod_types = { |
| 374 | # version 1.0 |
| 375 | of_g.VERSION_1_0:dict(), |
| 376 | |
| 377 | # version 1.1 |
| 378 | of_g.VERSION_1_1:dict( |
| 379 | add = 0, |
| 380 | modify = 1, |
| 381 | delete = 2 |
| 382 | ), |
| 383 | |
| 384 | # version 1.2 |
| 385 | of_g.VERSION_1_2:dict( |
| 386 | add = 0, |
| 387 | modify = 1, |
| 388 | delete = 2 |
| 389 | ), |
| 390 | |
| 391 | # version 1.3 |
| 392 | of_g.VERSION_1_3:dict( |
| 393 | add = 0, |
| 394 | modify = 1, |
| 395 | delete = 2 |
| 396 | ) |
| 397 | } |
| 398 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 399 | ################################################################ |
| 400 | # |
Andreas Wundsam | 5325616 | 2013-05-02 14:05:53 -0700 | [diff] [blame] | 401 | # type_val is the primary data structure that maps an |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 402 | # (class_name, version) pair to the wire data type value |
| 403 | # |
| 404 | ################################################################ |
| 405 | |
| 406 | type_val = dict() |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 407 | inheritance_map = dict() |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 408 | |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 409 | def generate_maps(): |
| 410 | for parent, versioned in inheritance_data.items(): |
| 411 | inheritance_map[parent] = set() |
| 412 | for ver, subclasses in versioned.items(): |
| 413 | for subcls in subclasses: |
| 414 | inheritance_map[parent].add(subcls) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 415 | |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 416 | for version, classes in message_types.items(): |
| 417 | for cls in classes: |
| 418 | name = "of_" + cls |
| 419 | type_val[(name, version)] = classes[cls] |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 420 | |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 421 | for parent, versioned in inheritance_data.items(): |
| 422 | for version, subclasses in versioned.items(): |
| 423 | for subcls, value in subclasses.items(): |
| 424 | name = parent + "_" + subcls |
| 425 | type_val[(name, version)] = value |
| 426 | |
| 427 | # Special case OF-1.2 match type |
Rich Lane | a72c98e | 2013-07-12 16:40:06 -0700 | [diff] [blame] | 428 | type_val[("of_match_v3", of_g.VERSION_1_2)] = 1 |
| 429 | type_val[("of_match_v3", of_g.VERSION_1_3)] = 1 |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 430 | |
| 431 | # Utility function |
| 432 | def dict_to_array(d, m_val, def_val=-1): |
| 433 | """ |
| 434 | Given a dictionary, d, with each value a small integer, |
| 435 | produce an array indexed by the integer whose value is the key. |
| 436 | @param d The dictionary |
| 437 | @param m_val Ignore values greater than m_val |
| 438 | @param def_val The default value (for indices not in range of d) |
| 439 | """ |
| 440 | |
| 441 | # Get the max value in range for hash |
| 442 | max_val = 0 |
| 443 | for key in d: |
| 444 | if (d[key] > max_val) and (d[key] < m_val): |
| 445 | max_val = d[key] |
| 446 | ar = [] |
| 447 | for x in range(0, max_val + 1): |
| 448 | ar.append(def_val) |
| 449 | for key in d: |
| 450 | if (d[key] < m_val): |
| 451 | ar[d[key]] = key |
| 452 | return ar |
| 453 | |
| 454 | def type_array_len(version_indexed, max_val): |
| 455 | """ |
| 456 | Given versioned information about a type, calculate how long |
| 457 | the unified array should be. |
| 458 | |
Andreas Wundsam | 5325616 | 2013-05-02 14:05:53 -0700 | [diff] [blame] | 459 | @param version_indexed A dict indexed by version. Each value is a |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 460 | dict indexed by a name and whose value is an integer |
| 461 | @param max_val Ignore values greater than this for length calcs |
| 462 | """ |
| 463 | # First, find the max length of all arrays |
| 464 | arr_len = 0 |
| 465 | for version, val_dict in version_indexed.items(): |
| 466 | ar = dict_to_array(val_dict, max_val, invalid_type) |
| 467 | if arr_len < len(ar): |
| 468 | arr_len = len(ar) |
| 469 | return arr_len |
| 470 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 471 | def sub_class_map(base_type, version): |
| 472 | """ |
| 473 | Returns an iterable object giving the instance nameys and subclass types |
| 474 | for the base_type, version values |
| 475 | """ |
| 476 | rv = [] |
| 477 | if base_type not in inheritance_map: |
| 478 | return rv |
| 479 | |
| 480 | for instance in inheritance_map[base_type]: |
| 481 | subcls = loxi_utils.instance_to_class(instance, base_type) |
| 482 | if not loxi_utils.class_in_version(subcls, version): |
| 483 | continue |
| 484 | rv.append((instance, subcls)) |
| 485 | |
| 486 | return rv |
| 487 | |
| 488 | ################################################################ |
| 489 | # |
| 490 | # Extension related data and functions |
| 491 | # |
| 492 | ################################################################ |
| 493 | |
| 494 | # Per OF Version, per experimenter, map exp msg type (subtype) to object IDs |
| 495 | # @fixme Generate defines for OF_<exp>_SUBTYPE_<msg> for the values below? |
| 496 | extension_message_subtype = { |
| 497 | # version 1.0 |
| 498 | of_g.VERSION_1_0:dict( # Version 1.0 extensions |
| 499 | bsn = { # BSN extensions; indexed by class name, value is subtype |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 500 | }, |
| 501 | nicira = { # Nicira extensions, value is subtype |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 502 | }, |
| 503 | ), |
| 504 | of_g.VERSION_1_1:dict( # Version 1.0 extensions |
| 505 | bsn = { # BSN extensions; indexed by class name, value is subtype |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 506 | }, |
| 507 | ), |
| 508 | of_g.VERSION_1_2:dict( # Version 1.0 extensions |
| 509 | bsn = { # BSN extensions; indexed by class name, value is subtype |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 510 | }, |
| 511 | ), |
| 512 | of_g.VERSION_1_3:dict( # Version 1.0 extensions |
| 513 | bsn = { # BSN extensions; indexed by class name, value is subtype |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 514 | }, |
| 515 | ), |
| 516 | } |
| 517 | |
| 518 | # Set to empty dict if no extension actions defined |
| 519 | # Per OF Version, per experimenter, map actions to subtype |
| 520 | extension_action_subtype = { |
| 521 | # version 1.0 |
| 522 | of_g.VERSION_1_0:dict( # Version 1.0 extensions |
| 523 | bsn = { # of_action_bsn_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 524 | }, |
| 525 | nicira = { # of_action_nicira_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 526 | } |
| 527 | ), |
| 528 | of_g.VERSION_1_1:dict( # Version 1.0 extensions |
| 529 | bsn = { # of_action_bsn_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 530 | }, |
| 531 | nicira = { # of_action_nicira_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 532 | } |
| 533 | ), |
| 534 | of_g.VERSION_1_2:dict( # Version 1.0 extensions |
| 535 | bsn = { # of_action_bsn_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 536 | }, |
| 537 | nicira = { # of_action_nicira_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 538 | } |
| 539 | ), |
| 540 | of_g.VERSION_1_3:dict( # Version 1.0 extensions |
| 541 | bsn = { # of_action_bsn_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 542 | }, |
| 543 | nicira = { # of_action_nicira_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 544 | } |
| 545 | ), |
| 546 | } |
| 547 | |
| 548 | # Set to empty dict if no extension actions defined |
| 549 | # Per OF Version, per experimenter, map actions to subtype |
| 550 | extension_action_id_subtype = { |
| 551 | # version 1.0 |
| 552 | of_g.VERSION_1_0:dict(), |
| 553 | of_g.VERSION_1_1:dict(), |
| 554 | of_g.VERSION_1_2:dict(), |
| 555 | of_g.VERSION_1_3:dict( # Version 1.3 extensions |
| 556 | bsn = { # of_action_bsn_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 557 | }, |
| 558 | nicira = { # of_action_nicira_ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 559 | } |
| 560 | ), |
| 561 | } |
| 562 | |
| 563 | # Set to empty dict if no extension instructions defined |
Rich Lane | ef7b994 | 2013-11-18 16:29:28 -0800 | [diff] [blame] | 564 | extension_instruction_subtype = { |
| 565 | # version 1.0 |
| 566 | of_g.VERSION_1_0:dict(), |
| 567 | of_g.VERSION_1_1:dict(), |
| 568 | of_g.VERSION_1_2:dict(), |
| 569 | of_g.VERSION_1_3:dict( |
| 570 | bsn = { # of_instruction_bsn_ |
| 571 | }, |
| 572 | nicira = { # of_instruction_nicira_ |
| 573 | } |
| 574 | ), |
| 575 | } |