blob: 9c0722cae61d6365c9ff07d3acf86fd7801a1853 [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# @brief Global data structs for LOXI code generation
30#
31# @fixme This needs to be refactored and brought into the 21st century.
32#
33
Rich Lanef1a89842014-10-12 10:04:13 -070034import loxi_globals
Rich Lanea06d0c32013-03-25 08:52:03 -070035
36################################################################
37#
38# Configuration global parameters
39#
40################################################################
41
42##
43# The map from wire protocol to enum identifier generated from input
44# This is built from the version-specific structs file info.
45# @fixme This should go away when the process structs file is updated
46wire_ver_map = {}
47
48##
Rich Lanea06d0c32013-03-25 08:52:03 -070049# The list of wire versions which are to be supported
50target_version_list = []
51
Rich Lanea06d0c32013-03-25 08:52:03 -070052##
53# The dictionary of config variables related to code
54#
Rich Lanea06d0c32013-03-25 08:52:03 -070055# @param use_obj_id Use object IDs in struct defns CURRENTLY NOT SUPPORTED
Andreas Wundsam53256162013-05-02 14:05:53 -070056#
Rich Lanea06d0c32013-03-25 08:52:03 -070057# @param return_base_types For 'get' accessors, return values when possible.
58# Otherwise all values are returned thru a call by variable parameter
59#
60# @param use_static_inlines Generate low level accessors as static inline
61# and put them in header files rather than .c files.
62#
63# @param copy_semantics One of "read", "write" or "grow". This defines the
64# way that buffer references are managed. Currently on "read" is supported.
65#
66# @param encode_typedefs Use object and member IDs (rather than names)
67# when generating the names used for accessor function typedefs
68#
Andreas Wundsam53256162013-05-02 14:05:53 -070069# @param get_returns One of "error", "value", or "void";
Rich Lanea06d0c32013-03-25 08:52:03 -070070# CURRENTLY ONLY "error" IS SUPPORTED. "error" means
71# all get operations return an error code. "value" means return a base_type
72# value when possible or void if not. "void" means always return void
73# and use a call-by-variable parameter
74#
75
Rich Lanea06d0c32013-03-25 08:52:03 -070076## These members do not get normal accessors
77
Rob Vaterlausb3f49d92013-10-01 17:57:31 -070078skip_members = ["version", "type", "length", "err_type", "stats_type", "len",
Rich Lane713d9282013-12-30 15:21:35 -080079 "type_len", "actions_len", "_command", "command", "key_length"]
Rich Lanea06d0c32013-03-25 08:52:03 -070080
81## Some OpenFlow string length constants
82#
83# These are a few length constants needed for array processing
84ofp_constants = dict(
85 OF_MAX_TABLE_NAME_LEN = 32,
86 OF_MAX_PORT_NAME_LEN = 16,
87 OF_ETH_ALEN = 6,
88 OF_DESC_STR_LEN = 256,
89 OF_SERIAL_NUM_LEN = 32
90)
91
92## List of mixed data types
93#
94# This is a list of data types which require special treatment
95# because the underlying datatype has changed between versions.
96# The main example is port which went from 16 to 32 bits. We
97# define per-version accessors for these types and those are
98# used in place of the normal ones.
99#
100# The wire protocol number is used to identify versions. For now,
101# the value is the name of the type to use for that version
102#
103# This is the map between the external type (like of_port_no_t)
Andreas Wundsam53256162013-05-02 14:05:53 -0700104# which is used by customers of this code and the internal
105# datatypes (like uint16_t) that appear on the wire for a
Rich Lanea06d0c32013-03-25 08:52:03 -0700106# particular version.
107#
108of_mixed_types = dict(
109 of_port_no_t = {
110 1: "uint16_t",
111 2: "uint32_t",
112 3: "uint32_t",
113 4: "uint32_t",
Rich Lane2dd17012014-10-16 09:55:10 -0700114 5: "uint32_t",
Rich Lanea06d0c32013-03-25 08:52:03 -0700115 "short_name":"port_no"
116 },
117 of_port_desc_t = {
118 1: "of_port_desc_t",
119 2: "of_port_desc_t",
120 3: "of_port_desc_t",
121 4: "of_port_desc_t",
Rich Lane2dd17012014-10-16 09:55:10 -0700122 5: "of_port_desc_t",
Rich Lanea06d0c32013-03-25 08:52:03 -0700123 "short_name":"port_desc"
124 },
Dan Talaycoc0e802e2013-05-18 23:52:39 -0700125 of_bsn_vport_t = {
126 1: "of_bsn_vport_t",
127 2: "of_bsn_vport_t",
128 3: "of_bsn_vport_t",
129 4: "of_bsn_vport_t",
Rich Lane2dd17012014-10-16 09:55:10 -0700130 5: "of_bsn_vport_t",
Dan Talaycoc0e802e2013-05-18 23:52:39 -0700131 "short_name":"bsn_vport"
132 },
Rich Lanea06d0c32013-03-25 08:52:03 -0700133 of_fm_cmd_t = { # Flow mod command went from u16 to u8
134 1: "uint16_t",
135 2: "uint8_t",
136 3: "uint8_t",
137 4: "uint8_t",
Rich Lane2dd17012014-10-16 09:55:10 -0700138 5: "uint8_t",
Rich Lanea06d0c32013-03-25 08:52:03 -0700139 "short_name":"fm_cmd"
140 },
141 of_wc_bmap_t = { # Wildcard bitmap
142 1: "uint32_t",
143 2: "uint32_t",
144 3: "uint64_t",
145 4: "uint64_t",
Rich Lane2dd17012014-10-16 09:55:10 -0700146 5: "uint64_t",
Rich Lanea06d0c32013-03-25 08:52:03 -0700147 "short_name":"wc_bmap"
148 },
149 of_match_bmap_t = { # Match bitmap
150 1: "uint32_t",
151 2: "uint32_t",
152 3: "uint64_t",
153 4: "uint64_t",
Rich Lane2dd17012014-10-16 09:55:10 -0700154 5: "uint64_t",
Rich Lanea06d0c32013-03-25 08:52:03 -0700155 "short_name":"match_bmap"
156 },
157 of_match_t = { # Match object
158 1: "of_match_v1_t",
159 2: "of_match_v2_t",
160 3: "of_match_v3_t",
161 4: "of_match_v3_t", # Currently uses same match as 1.2 (v3).
Rich Lane2dd17012014-10-16 09:55:10 -0700162 5: "of_match_v3_t", # Currently uses same match as 1.2 (v3).
Rich Lanea06d0c32013-03-25 08:52:03 -0700163 "short_name":"match"
164 },
165)
166
167## Base data types
168#
169# The basic types; Value is a list: bytes, to_wire, from_wire
170# The accessors deal with endian, alignment and any other host/network
171# considerations. These are common across all versions
172#
173# For get accessors, assume we memcpy from wire buf and then apply ntoh
174# For set accessors, assume we apply hton and then memcpy to wire buf
175#
176# to/from wire functions take a pointer to class and change in place
177of_base_types = dict(
178 char = dict(bytes=1, use_as_rv=1, short_name="char"),
179 uint8_t = dict(bytes=1, use_as_rv=1, short_name="u8"),
180 uint16_t = dict(bytes=2, to_w="u16_hton", from_w="u16_ntoh", use_as_rv=1,
181 short_name="u16"),
182 uint32_t = dict(bytes=4, to_w="u32_hton", from_w="u32_ntoh", use_as_rv=1,
183 short_name="u32"),
184 uint64_t = dict(bytes=8, to_w="u64_hton", from_w="u64_ntoh", use_as_rv=1,
185 short_name="u64"),
186# of_cookie_t = dict(bytes=8, to_w="u64_hton", from_w="u64_ntoh", use_as_rv=1#,
187# short_name="cookie"),
188# of_counter_t = dict(bytes=8, to_w="u64_hton", from_w="u64_ntoh", use_as_rv=1,
189# short_name="counter"),
190 of_mac_addr_t = dict(bytes=6, short_name="mac"),
Andreas Wundsamb566a162013-07-18 19:30:23 -0700191 of_ipv4_t = dict(bytes=4, short_name="ipv4"),
Rich Lanea06d0c32013-03-25 08:52:03 -0700192 of_ipv6_t = dict(bytes=16, short_name="ipv6"),
193 of_port_name_t = dict(bytes=ofp_constants["OF_MAX_PORT_NAME_LEN"],
194 short_name="port_name"),
195 of_table_name_t = dict(bytes=ofp_constants["OF_MAX_TABLE_NAME_LEN"],
196 short_name="tab_name"),
197 of_desc_str_t = dict(bytes=ofp_constants["OF_DESC_STR_LEN"],
198 short_name="desc_str"),
199 of_serial_num_t = dict(bytes=ofp_constants["OF_SERIAL_NUM_LEN"],
200 short_name="ser_num"),
Rich Lanef8a3d002014-03-19 13:33:52 -0700201 of_str64_t = dict(bytes=64, short_name="str64"),
Andreas Wundsam53256162013-05-02 14:05:53 -0700202 of_match_v1_t = dict(bytes=40, to_w="match_v1_hton",
203 from_w="match_v1_ntoh",
Rich Lanea06d0c32013-03-25 08:52:03 -0700204 short_name="match_v1"),
Andreas Wundsam53256162013-05-02 14:05:53 -0700205 of_match_v2_t = dict(bytes=88, to_w="match_v2_hton",
206 from_w="match_v2_ntoh",
Rich Lanea06d0c32013-03-25 08:52:03 -0700207 short_name="match_v2"),
Andreas Wundsam53256162013-05-02 14:05:53 -0700208 of_match_v3_t = dict(bytes=-1, to_w="match_v3_hton",
209 from_w="match_v3_ntoh",
Rich Lanea06d0c32013-03-25 08:52:03 -0700210 short_name="match_v3"),
Andreas Wundsam53256162013-05-02 14:05:53 -0700211# of_match_v4_t = dict(bytes=-1, to_w="match_v4_hton",
212# from_w="match_v4_ntoh",
Rich Lanea06d0c32013-03-25 08:52:03 -0700213# short_name="match_v4"),
Rich Lane3b2fd832013-09-24 13:44:08 -0700214 of_octets_t = dict(bytes=-1, short_name="octets"),
215 of_bitmap_128_t = dict(bytes=16, short_name="bitmap_128"),
Rich Lane119289c2014-12-01 13:44:08 -0800216 of_bitmap_512_t = dict(bytes=64, short_name="bitmap_512"),
Rich Lanefab0c822013-12-30 11:46:48 -0800217 of_checksum_128_t = dict(bytes=16, short_name="checksum_128"),
Rich Lanea06d0c32013-03-25 08:52:03 -0700218)
219
220of_scalar_types = ["char", "uint8_t", "uint16_t", "uint32_t", "uint64_t",
221 "of_port_no_t", "of_fm_cmd_t", "of_wc_bmap_t",
222 "of_match_bmap_t", "of_port_name_t", "of_table_name_t",
Andreas Wundsam53256162013-05-02 14:05:53 -0700223 "of_desc_str_t", "of_serial_num_t", "of_mac_addr_t",
Rich Lanef8a3d002014-03-19 13:33:52 -0700224 "of_ipv6_t", "of_ipv4_t", "of_bitmap_128_t", "of_checksum_128_t",
Rich Lane119289c2014-12-01 13:44:08 -0800225 "of_str64_t", "of_bitmap_512_t"]
Rich Lanea06d0c32013-03-25 08:52:03 -0700226
Rich Lanea06d0c32013-03-25 08:52:03 -0700227##
228# LOXI identifiers
229#
230# Dict indexed by identifier name. Each entry contains the information
231# as a DotDict with the following keys:
232# values: A dict indexed by wire version giving each verion's value or None
233# common: The common value to use for this identifier at the LOXI top level (TBD)
234# all_same: If True, all the values across all versions are the same
235# ofp_name: The original name for the identifier
236# ofp_group: The ofp enumerated type if defined
237
238identifiers = {}
239
240##
241# Identifiers by original group
242# Keys are the original group names. Value is a list of LOXI identifiers
243
244identifiers_by_group = {}
245
246## Ordered list of class names
247# This is per-wire-version and is a list of the classes in the order
248# they appear in the file. That is important because of the assumption
249# that data members are defined before they are included in a superclass.
250ordered_classes = {} # Indexed by wire version
251
252## Per class ordered list of member names
253ordered_members = {}
254
255## Ordered list of message classes
256ordered_messages = []
257
258## Ordered list of non message classes
259ordered_non_messages = []
260
261## The objects that need list support
262ordered_list_objects = []
263
264## Stats request/reply are pseudo objects
265ordered_pseudo_objects = []
266
267## Standard order is normally messages followed by non-messages
268standard_class_order = []
269
270## All classes in order, including psuedo classes for which most code
271# is not generated.
272all_class_order = []
273
274## Map from class, wire_version to size of fixed part of class
275base_length = {}
276
Andreas Wundsam53256162013-05-02 14:05:53 -0700277## Boolean indication of variable length, per class, wire_version,
Rich Lanea06d0c32013-03-25 08:52:03 -0700278is_fixed_length = set()
279
280## The global object ID counter
281object_id = 1 # Reserve 0 for root object
282
283## The unified view of all classes. See internal readme.
284unified = {}
285
286## Indicates data members with non-fixed start offsets
287# Indexed by (cls, version, member-name) and value is prev-member-name
288special_offsets = {}
289
Rich Lanef1a89842014-10-12 10:04:13 -0700290# Map from wire version to OF_1_x
291short_version_names = {}
Rich Lanea06d0c32013-03-25 08:52:03 -0700292
293# The iteration object that gives the wire versions supported
Rich Lanef1a89842014-10-12 10:04:13 -0700294of_version_range = []
Rich Lanea06d0c32013-03-25 08:52:03 -0700295
Rich Lanef1a89842014-10-12 10:04:13 -0700296# Map from wire version to OF_VERSION_1_x
297of_version_wire2name = {}
298
299for version in loxi_globals.OFVersions.all_supported:
300 v = version.version.replace('.', '_')
301 short_version_names[version.wire_version] = 'OF_' + v
302 of_version_range.append(version.wire_version)
303 of_version_wire2name[version.wire_version] = 'OF_VERSION_' + v
304 globals()['VERSION_' + v] = version.wire_version
Rich Lanea06d0c32013-03-25 08:52:03 -0700305
306
307################################################################
308#
309# Experimenters, vendors, extensions
310#
Andreas Wundsam53256162013-05-02 14:05:53 -0700311# Although the term "experimenter" is used for identifying
Rich Lanea06d0c32013-03-25 08:52:03 -0700312# external extension definitions, we generally use the term
313# extension when refering to the messages or objects themselves.
314#
315# Conventions:
316#
317# Extension messages should start with of_<experimenter>_
318# Extension actions should start with of_<experimenter>_action_
319# Extension instructions should start with of_<experimenter>_instructions_
320#
321# Currently, the above conventions are not enforced; the mapping
322# is done brute force in type_maps.py
323#
324################################################################
325
326# The map of known experimenters to their experimenter IDs
327experimenter_name_to_id = dict(
328 bsn = 0x005c16c7,
329 nicira = 0x00002320,
330 openflow = 0x000026e1
331 )