blob: c7a175f691f3073e7514491c5c98bd48081e97d3 [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
Rich Lane127860e2014-10-14 11:03:49 -070067extern void of_port_desc_wire_length_get(of_object_t *obj, int *bytes);
68extern void of_port_desc_wire_length_set(of_object_t *obj, int bytes);
69
70extern void of_port_stats_entry_wire_length_get(of_object_t *obj, int *bytes);
71extern void of_port_stats_entry_wire_length_set(of_object_t *obj, int bytes);
72
73extern void of_queue_stats_entry_wire_length_get(of_object_t *obj, int *bytes);
74extern void of_queue_stats_entry_wire_length_set(of_object_t *obj, int bytes);
75
Rich Lanea06d0c32013-03-25 08:52:03 -070076""")
77
78
79def gen_length_array(out):
80 """
81 Generate an array giving the lengths of all objects/versions
82 @param out The file handle to which to write
83 """
84 out.write("""
85/**
86 * An array with the number of bytes in the fixed length part
87 * of each OF object
88 */
89""")
90
91 for version in of_g.of_version_range:
92 out.write("""
Rich Laneb157b0f2013-03-27 13:55:28 -070093static const int\nof_object_fixed_len_v%d[OF_OBJECT_COUNT] = {
Rich Lanea06d0c32013-03-25 08:52:03 -070094 -1, /* of_object is not instantiable */
95""" % version)
96 for i, cls in enumerate(of_g.all_class_order):
97 comma = ","
98 if i == len(of_g.all_class_order) - 1:
99 comma = ""
100 val = "-1" + comma
101 if (cls, version) in of_g.base_length:
102 val = str(of_g.base_length[(cls, version)]) + comma
103 out.write(" %-5s /* %d: %s */\n" % (val, i + 1, cls))
104 out.write("};\n")
105
106 out.write("""
107/**
108 * Unified map of fixed length part of each object
109 */
Rich Laneb157b0f2013-03-27 13:55:28 -0700110const int *const of_object_fixed_len[OF_VERSION_ARRAY_MAX] = {
Rich Lanea06d0c32013-03-25 08:52:03 -0700111 NULL,
112""")
113 for version in of_g.of_version_range:
114 out.write(" of_object_fixed_len_v%d,\n" % version)
115 out.write("""
116};
117""")
118
Andreas Wundsam53256162013-05-02 14:05:53 -0700119
Rich Lanef70be942013-07-18 13:33:14 -0700120def gen_extra_length_array(out):
121 """
122 Generate an array giving the extra lengths of all objects/versions
123 @param out The file handle to which to write
124 """
125 out.write("""
126/**
127 * An array with the number of bytes in the extra length part
128 * of each OF object
129 */
130""")
131
132 for version in of_g.of_version_range:
133 out.write("""
134static const int\nof_object_extra_len_v%d[OF_OBJECT_COUNT] = {
135 -1, /* of_object is not instantiable */
136""" % version)
137 for i, cls in enumerate(of_g.all_class_order):
138 comma = ","
139 if i == len(of_g.all_class_order) - 1:
140 comma = ""
141 val = "-1" + comma
142 if (cls, version) in of_g.base_length:
143 val = str(of_g.extra_length.get((cls, version), 0)) + comma
144 out.write(" %-5s /* %d: %s */\n" % (val, i + 1, cls))
145 out.write("};\n")
146
147 out.write("""
148/**
149 * Unified map of extra length part of each object
150 */
151const int *const of_object_extra_len[OF_VERSION_ARRAY_MAX] = {
152 NULL,
153""")
154 for version in of_g.of_version_range:
155 out.write(" of_object_extra_len_v%d,\n" % version)
156 out.write("""
157};
158""")