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 | """ |
Harshmeet Singh | 19d566b | 2014-10-06 14:08:06 -0700 | [diff] [blame] | 153 | if cls.endswith("header"): |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 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 | # |
Andreas Wundsam | 5325616 | 2013-05-02 14:05:53 -0700 | [diff] [blame] | 161 | # type_val is the primary data structure that maps an |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 162 | # (class_name, version) pair to the wire data type value |
| 163 | # |
| 164 | ################################################################ |
| 165 | |
| 166 | type_val = dict() |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 167 | inheritance_map = dict() |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 168 | |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 169 | def generate_maps(): |
| 170 | for parent, versioned in inheritance_data.items(): |
| 171 | inheritance_map[parent] = set() |
| 172 | for ver, subclasses in versioned.items(): |
| 173 | for subcls in subclasses: |
| 174 | inheritance_map[parent].add(subcls) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 175 | |
Rich Lane | 6bb28dd | 2013-05-13 15:19:14 -0700 | [diff] [blame] | 176 | for parent, versioned in inheritance_data.items(): |
| 177 | for version, subclasses in versioned.items(): |
| 178 | for subcls, value in subclasses.items(): |
| 179 | name = parent + "_" + subcls |
| 180 | type_val[(name, version)] = value |
| 181 | |
| 182 | # Special case OF-1.2 match type |
Rich Lane | a72c98e | 2013-07-12 16:40:06 -0700 | [diff] [blame] | 183 | type_val[("of_match_v3", of_g.VERSION_1_2)] = 1 |
| 184 | type_val[("of_match_v3", of_g.VERSION_1_3)] = 1 |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 185 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 186 | def sub_class_map(base_type, version): |
| 187 | """ |
| 188 | Returns an iterable object giving the instance nameys and subclass types |
| 189 | for the base_type, version values |
| 190 | """ |
| 191 | rv = [] |
| 192 | if base_type not in inheritance_map: |
| 193 | return rv |
| 194 | |
| 195 | for instance in inheritance_map[base_type]: |
| 196 | subcls = loxi_utils.instance_to_class(instance, base_type) |
| 197 | if not loxi_utils.class_in_version(subcls, version): |
| 198 | continue |
| 199 | rv.append((instance, subcls)) |
| 200 | |
| 201 | return rv |