blob: 36ad5f636344dedf4fff68429ee7ce1dfe176490 [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 Lane7329b542014-10-17 18:30:13 -070076extern void of_queue_desc_wire_length_get(of_object_t *obj, int *bytes);
77extern void of_queue_desc_wire_length_set(of_object_t *obj, int bytes);
78
Rich Lanea06d0c32013-03-25 08:52:03 -070079""")
80
81
82def gen_length_array(out):
83 """
84 Generate an array giving the lengths of all objects/versions
85 @param out The file handle to which to write
86 """
87 out.write("""
88/**
89 * An array with the number of bytes in the fixed length part
90 * of each OF object
91 */
92""")
93
94 for version in of_g.of_version_range:
95 out.write("""
Rich Laneb157b0f2013-03-27 13:55:28 -070096static const int\nof_object_fixed_len_v%d[OF_OBJECT_COUNT] = {
Rich Lanea06d0c32013-03-25 08:52:03 -070097 -1, /* of_object is not instantiable */
98""" % version)
99 for i, cls in enumerate(of_g.all_class_order):
100 comma = ","
101 if i == len(of_g.all_class_order) - 1:
102 comma = ""
103 val = "-1" + comma
104 if (cls, version) in of_g.base_length:
105 val = str(of_g.base_length[(cls, version)]) + comma
106 out.write(" %-5s /* %d: %s */\n" % (val, i + 1, cls))
107 out.write("};\n")
108
109 out.write("""
110/**
111 * Unified map of fixed length part of each object
112 */
Rich Laneb157b0f2013-03-27 13:55:28 -0700113const int *const of_object_fixed_len[OF_VERSION_ARRAY_MAX] = {
Rich Lanea06d0c32013-03-25 08:52:03 -0700114 NULL,
115""")
116 for version in of_g.of_version_range:
117 out.write(" of_object_fixed_len_v%d,\n" % version)
118 out.write("""
119};
120""")