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