blob: 03e1c2a9325b95a82c5e912caaa9309b02d73fe3 [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001# 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 Wundsam542a13c2013-11-15 13:28:55 -080036import c_gen.of_g_legacy as of_g
Rich Lanea06d0c32013-03-25 08:52:03 -070037import sys
38from generic_utils import *
Rich Lanea06d0c32013-03-25 08:52:03 -070039import loxi_utils.loxi_utils as loxi_utils
Andreas Wundsam542a13c2013-11-15 13:28:55 -080040import c_gen.loxi_utils_legacy as loxi_utils
Rich Lane043a3d82013-12-10 10:57:30 -080041import loxi_globals
Rich Lanea06d0c32013-03-25 08:52:03 -070042
43invalid_type = "invalid_type"
Rich Lanea06d0c32013-03-25 08:52:03 -070044
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
56instruction_types = {
Rich Lanea06d0c32013-03-25 08:52:03 -070057 of_g.VERSION_1_0:dict(),
Rich Lane4db4d042013-05-13 18:13:48 -070058 of_g.VERSION_1_1:dict(),
59 of_g.VERSION_1_2:dict(),
60 of_g.VERSION_1_3:dict()
Rich Lanea06d0c32013-03-25 08:52:03 -070061 }
62
Rich Lane4def6972013-12-09 17:44:43 -080063instruction_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 Lanea06d0c32013-03-25 08:52:03 -070069
Rich Lanea06d0c32013-03-25 08:52:03 -070070action_types = {
Rich Lane4db4d042013-05-13 18:13:48 -070071 of_g.VERSION_1_0:dict(),
72 of_g.VERSION_1_1:dict(),
73 of_g.VERSION_1_2:dict(),
Rich Lane4def6972013-12-09 17:44:43 -080074 of_g.VERSION_1_3:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -070075 }
76
77action_id_types = {
Rich Lanea06d0c32013-03-25 08:52:03 -070078 of_g.VERSION_1_0:dict(),
79 of_g.VERSION_1_1:dict(),
80 of_g.VERSION_1_2:dict(),
Rich Lane4def6972013-12-09 17:44:43 -080081 of_g.VERSION_1_3:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -070082 }
83
84queue_prop_types = {
Rich Lane4db4d042013-05-13 18:13:48 -070085 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 Lanea06d0c32013-03-25 08:52:03 -070089 }
90
Dan Talaycoc0e802e2013-05-18 23:52:39 -070091bsn_vport_types = {
Wilson Ngc349e352014-04-14 17:06:32 -070092 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 Talaycoc0e802e2013-05-18 23:52:39 -070096 }
97
Rich Lanea06d0c32013-03-25 08:52:03 -070098oxm_types = {
Rich Lanea06d0c32013-03-25 08:52:03 -070099 of_g.VERSION_1_0:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700100 of_g.VERSION_1_1:dict(),
Rich Lane4db4d042013-05-13 18:13:48 -0700101 of_g.VERSION_1_2:dict(),
102 of_g.VERSION_1_3:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700103 }
104
105hello_elem_types = {
Rich Lanea06d0c32013-03-25 08:52:03 -0700106 of_g.VERSION_1_0:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700107 of_g.VERSION_1_1:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700108 of_g.VERSION_1_2:dict(),
Rich Lane4db4d042013-05-13 18:13:48 -0700109 of_g.VERSION_1_3:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700110 }
111
112table_feature_prop_types = {
Rich Lanea06d0c32013-03-25 08:52:03 -0700113 of_g.VERSION_1_0:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700114 of_g.VERSION_1_1:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700115 of_g.VERSION_1_2:dict(),
Rich Lane4db4d042013-05-13 18:13:48 -0700116 of_g.VERSION_1_3:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700117 }
118
119meter_band_types = {
Rich Lanea06d0c32013-03-25 08:52:03 -0700120 of_g.VERSION_1_0:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700121 of_g.VERSION_1_1:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700122 of_g.VERSION_1_2:dict(),
Rich Lane4db4d042013-05-13 18:13:48 -0700123 of_g.VERSION_1_3:dict(),
Rich Lanea06d0c32013-03-25 08:52:03 -0700124 }
125
Rich Lane713d9282013-12-30 15:21:35 -0800126bsn_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 Lanea06d0c32013-03-25 08:52:03 -0700133# All inheritance data for non-messages
134inheritance_data = dict(
135 of_instruction = instruction_types,
Rich Lane4def6972013-12-09 17:44:43 -0800136 of_instruction_id = instruction_id_types,
Rich Lanea06d0c32013-03-25 08:52:03 -0700137 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 Talaycoc0e802e2013-05-18 23:52:39 -0700143 of_meter_band = meter_band_types,
144 # BSN specific inheritance extensions
Rich Lane713d9282013-12-30 15:21:35 -0800145 of_bsn_vport = bsn_vport_types,
146 of_bsn_tlv = bsn_tlv_types,
Rich Lanea06d0c32013-03-25 08:52:03 -0700147 )
148
Rich Lanea06d0c32013-03-25 08:52:03 -0700149def class_is_virtual(cls):
150 """
151 Returns True if cls is a virtual class
152 """
Harshmeet Singh19d566b2014-10-06 14:08:06 -0700153 if cls.endswith("header"):
Rich Lanea06d0c32013-03-25 08:52:03 -0700154 return True
155 if loxi_utils.class_is_list(cls):
156 return True
Rich Lane043a3d82013-12-10 10:57:30 -0800157 return loxi_globals.unified.class_by_name(cls).virtual
Rich Lanea06d0c32013-03-25 08:52:03 -0700158
159################################################################
160#
Andreas Wundsam53256162013-05-02 14:05:53 -0700161# type_val is the primary data structure that maps an
Rich Lanea06d0c32013-03-25 08:52:03 -0700162# (class_name, version) pair to the wire data type value
163#
164################################################################
165
166type_val = dict()
Rich Lane6bb28dd2013-05-13 15:19:14 -0700167inheritance_map = dict()
Rich Lanea06d0c32013-03-25 08:52:03 -0700168
Rich Lane6bb28dd2013-05-13 15:19:14 -0700169def 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 Lanea06d0c32013-03-25 08:52:03 -0700175
Rich Lane6bb28dd2013-05-13 15:19:14 -0700176 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 Lanea72c98e2013-07-12 16:40:06 -0700183 type_val[("of_match_v3", of_g.VERSION_1_2)] = 1
184 type_val[("of_match_v3", of_g.VERSION_1_3)] = 1
Rich Lanea06d0c32013-03-25 08:52:03 -0700185
Rich Lanea06d0c32013-03-25 08:52:03 -0700186def 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