blob: 6c45d4dc6586c29e6f18b5f1dfb7969e29dbf1f9 [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 C code generation for LOXI type related maps
30#
31
Andreas Wundsam76db0062013-11-15 13:34:41 -080032import c_gen.of_g_legacy as of_g
Rich Lanea06d0c32013-03-25 08:52:03 -070033import sys
34from generic_utils import *
Andreas Wundsam542a13c2013-11-15 13:28:55 -080035import c_gen.type_maps as type_maps
Rich Lanea06d0c32013-03-25 08:52:03 -070036
Rich Lanea06d0c32013-03-25 08:52:03 -070037def gen_type_data_header(out):
Rich Lanea06d0c32013-03-25 08:52:03 -070038 out.write("""
39/****************************************************************
40 * Wire type/length functions.
41 ****************************************************************/
42
43extern void of_object_message_wire_length_get(of_object_t *obj, int *bytes);
44extern void of_object_message_wire_length_set(of_object_t *obj, int bytes);
45
46extern void of_oxm_wire_length_get(of_object_t *obj, int *bytes);
Rich Lanea06d0c32013-03-25 08:52:03 -070047
48extern void of_tlv16_wire_length_get(of_object_t *obj, int *bytes);
49extern void of_tlv16_wire_length_set(of_object_t *obj, int bytes);
50
Rich Lanea06d0c32013-03-25 08:52:03 -070051/* Wire length is uint16 at front of structure */
52extern void of_u16_len_wire_length_get(of_object_t *obj, int *bytes);
53extern void of_u16_len_wire_length_set(of_object_t *obj, int bytes);
54
Rich Lane47085722013-07-12 16:27:04 -070055#define OF_OXM_LENGTH_GET(hdr) (((hdr) & 0xff) + 4)
Rich Lanea06d0c32013-03-25 08:52:03 -070056#define OF_OXM_LENGTH_SET(hdr, val) \\
Rich Lane47085722013-07-12 16:27:04 -070057 (hdr) = ((hdr) & 0xffffff00) + (((val) - 4) & 0xff)
Rich Lanea06d0c32013-03-25 08:52:03 -070058
59extern void of_packet_queue_wire_length_get(of_object_t *obj, int *bytes);
60extern void of_packet_queue_wire_length_set(of_object_t *obj, int bytes);
61
62extern void of_list_meter_band_stats_wire_length_get(of_object_t *obj,
63 int *bytes);
64extern void of_meter_stats_wire_length_get(of_object_t *obj, int *bytes);
65extern void of_meter_stats_wire_length_set(of_object_t *obj, int bytes);
Rich Lanea06d0c32013-03-25 08:52:03 -070066
67""")
68
69
70def gen_length_array(out):
71 """
72 Generate an array giving the lengths of all objects/versions
73 @param out The file handle to which to write
74 """
75 out.write("""
76/**
77 * An array with the number of bytes in the fixed length part
78 * of each OF object
79 */
80""")
81
82 for version in of_g.of_version_range:
83 out.write("""
Rich Laneb157b0f2013-03-27 13:55:28 -070084static const int\nof_object_fixed_len_v%d[OF_OBJECT_COUNT] = {
Rich Lanea06d0c32013-03-25 08:52:03 -070085 -1, /* of_object is not instantiable */
86""" % version)
87 for i, cls in enumerate(of_g.all_class_order):
88 comma = ","
89 if i == len(of_g.all_class_order) - 1:
90 comma = ""
91 val = "-1" + comma
92 if (cls, version) in of_g.base_length:
93 val = str(of_g.base_length[(cls, version)]) + comma
94 out.write(" %-5s /* %d: %s */\n" % (val, i + 1, cls))
95 out.write("};\n")
96
97 out.write("""
98/**
99 * Unified map of fixed length part of each object
100 */
Rich Laneb157b0f2013-03-27 13:55:28 -0700101const int *const of_object_fixed_len[OF_VERSION_ARRAY_MAX] = {
Rich Lanea06d0c32013-03-25 08:52:03 -0700102 NULL,
103""")
104 for version in of_g.of_version_range:
105 out.write(" of_object_fixed_len_v%d,\n" % version)
106 out.write("""
107};
108""")
109
Andreas Wundsam53256162013-05-02 14:05:53 -0700110
Rich Lanef70be942013-07-18 13:33:14 -0700111def gen_extra_length_array(out):
112 """
113 Generate an array giving the extra lengths of all objects/versions
114 @param out The file handle to which to write
115 """
116 out.write("""
117/**
118 * An array with the number of bytes in the extra length part
119 * of each OF object
120 */
121""")
122
123 for version in of_g.of_version_range:
124 out.write("""
125static const int\nof_object_extra_len_v%d[OF_OBJECT_COUNT] = {
126 -1, /* of_object is not instantiable */
127""" % version)
128 for i, cls in enumerate(of_g.all_class_order):
129 comma = ","
130 if i == len(of_g.all_class_order) - 1:
131 comma = ""
132 val = "-1" + comma
133 if (cls, version) in of_g.base_length:
134 val = str(of_g.extra_length.get((cls, version), 0)) + comma
135 out.write(" %-5s /* %d: %s */\n" % (val, i + 1, cls))
136 out.write("};\n")
137
138 out.write("""
139/**
140 * Unified map of extra length part of each object
141 */
142const int *const of_object_extra_len[OF_VERSION_ARRAY_MAX] = {
143 NULL,
144""")
145 for version in of_g.of_version_range:
146 out.write(" of_object_extra_len_v%d,\n" % version)
147 out.write("""
148};
149""")