Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | # 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 Wundsam | 76db006 | 2013-11-15 13:34:41 -0800 | [diff] [blame] | 32 | import c_gen.of_g_legacy as of_g |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 33 | import sys |
| 34 | from generic_utils import * |
Andreas Wundsam | 542a13c | 2013-11-15 13:28:55 -0800 | [diff] [blame] | 35 | import c_gen.type_maps as type_maps |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 36 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 37 | def gen_type_data_header(out): |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 38 | out.write(""" |
| 39 | /**************************************************************** |
| 40 | * Wire type/length functions. |
| 41 | ****************************************************************/ |
| 42 | |
| 43 | extern void of_object_message_wire_length_get(of_object_t *obj, int *bytes); |
| 44 | extern void of_object_message_wire_length_set(of_object_t *obj, int bytes); |
| 45 | |
| 46 | extern void of_oxm_wire_length_get(of_object_t *obj, int *bytes); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 47 | |
| 48 | extern void of_tlv16_wire_length_get(of_object_t *obj, int *bytes); |
| 49 | extern void of_tlv16_wire_length_set(of_object_t *obj, int bytes); |
| 50 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 51 | /* Wire length is uint16 at front of structure */ |
| 52 | extern void of_u16_len_wire_length_get(of_object_t *obj, int *bytes); |
| 53 | extern void of_u16_len_wire_length_set(of_object_t *obj, int bytes); |
| 54 | |
Rich Lane | 4708572 | 2013-07-12 16:27:04 -0700 | [diff] [blame] | 55 | #define OF_OXM_LENGTH_GET(hdr) (((hdr) & 0xff) + 4) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 56 | #define OF_OXM_LENGTH_SET(hdr, val) \\ |
Rich Lane | 4708572 | 2013-07-12 16:27:04 -0700 | [diff] [blame] | 57 | (hdr) = ((hdr) & 0xffffff00) + (((val) - 4) & 0xff) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 58 | |
| 59 | extern void of_packet_queue_wire_length_get(of_object_t *obj, int *bytes); |
| 60 | extern void of_packet_queue_wire_length_set(of_object_t *obj, int bytes); |
| 61 | |
| 62 | extern void of_list_meter_band_stats_wire_length_get(of_object_t *obj, |
| 63 | int *bytes); |
| 64 | extern void of_meter_stats_wire_length_get(of_object_t *obj, int *bytes); |
| 65 | extern void of_meter_stats_wire_length_set(of_object_t *obj, int bytes); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 66 | |
Rich Lane | 127860e | 2014-10-14 11:03:49 -0700 | [diff] [blame] | 67 | extern void of_port_desc_wire_length_get(of_object_t *obj, int *bytes); |
| 68 | extern void of_port_desc_wire_length_set(of_object_t *obj, int bytes); |
| 69 | |
| 70 | extern void of_port_stats_entry_wire_length_get(of_object_t *obj, int *bytes); |
| 71 | extern void of_port_stats_entry_wire_length_set(of_object_t *obj, int bytes); |
| 72 | |
| 73 | extern void of_queue_stats_entry_wire_length_get(of_object_t *obj, int *bytes); |
| 74 | extern void of_queue_stats_entry_wire_length_set(of_object_t *obj, int bytes); |
| 75 | |
Rich Lane | 7329b54 | 2014-10-17 18:30:13 -0700 | [diff] [blame] | 76 | extern void of_queue_desc_wire_length_get(of_object_t *obj, int *bytes); |
| 77 | extern void of_queue_desc_wire_length_set(of_object_t *obj, int bytes); |
| 78 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 79 | """) |
| 80 | |
| 81 | |
| 82 | def 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 Lane | b157b0f | 2013-03-27 13:55:28 -0700 | [diff] [blame] | 96 | static const int\nof_object_fixed_len_v%d[OF_OBJECT_COUNT] = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 97 | -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 Lane | b157b0f | 2013-03-27 13:55:28 -0700 | [diff] [blame] | 113 | const int *const of_object_fixed_len[OF_VERSION_ARRAY_MAX] = { |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 114 | 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 | """) |