Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -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 | |
Andreas Wundsam | fef7d5f | 2013-08-01 22:15:44 -0700 | [diff] [blame] | 28 | from generic_utils import find |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 29 | from collections import namedtuple |
| 30 | |
Andreas Wundsam | d30c107 | 2013-11-15 13:36:57 -0800 | [diff] [blame] | 31 | # This module is represents the frontend IR. |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 32 | __all__ = [ |
| 33 | 'OFInput', |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 34 | 'OFClass', |
| 35 | 'OFDataMember', |
| 36 | 'OFTypeMember', |
Andreas Wundsam | 780e0c9 | 2013-08-02 17:48:27 -0700 | [diff] [blame] | 37 | 'OFDiscriminatorMember', |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 38 | 'OFLengthMember', |
| 39 | 'OFFieldLengthMember', |
| 40 | 'OFPadMember', |
Rich Lane | 7bc2377 | 2013-11-29 17:47:46 -0800 | [diff] [blame] | 41 | 'OFVersionMember', |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 42 | 'OFEnum', |
Andreas Wundsam | 4ee5146 | 2013-07-30 11:00:37 -0700 | [diff] [blame] | 43 | 'OFEnumEntry' |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 44 | ] |
| 45 | |
| 46 | """ |
| 47 | One input file |
| 48 | |
| 49 | @param wire_versions Set of integer wire versions this file applies to |
| 50 | @param classes List of OFClass objects in the same order as in the file |
| 51 | @param enums List of Enum objects in the same order as in the file |
| 52 | """ |
Andreas Wundsam | d30c107 | 2013-11-15 13:36:57 -0800 | [diff] [blame] | 53 | OFInput = namedtuple('OFInput', ['filename', 'wire_versions', 'classes', 'enums']) |
Rich Lane | 7c49d4e | 2013-10-02 15:57:46 -0700 | [diff] [blame] | 54 | |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 55 | """ |
| 56 | An OpenFlow class |
| 57 | |
| 58 | All compound objects like messages, actions, instructions, etc are |
| 59 | uniformly represented by this class. |
| 60 | |
| 61 | The members are in the same order as on the wire. |
| 62 | |
| 63 | @param name |
Andreas Wundsam | 780e0c9 | 2013-08-02 17:48:27 -0700 | [diff] [blame] | 64 | @param superclass name of the super class |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 65 | @param members List of *Member objects |
Andreas Wundsam | fef7d5f | 2013-08-01 22:15:44 -0700 | [diff] [blame] | 66 | @param params optional dictionary of parameters |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 67 | """ |
Andreas Wundsam | d30c107 | 2013-11-15 13:36:57 -0800 | [diff] [blame] | 68 | OFClass = namedtuple('OFClass', ['name', 'superclass', 'members', 'virtual', 'params']) |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 69 | |
| 70 | """ |
| 71 | Normal field |
| 72 | |
| 73 | @param name |
| 74 | @param oftype C-like type string |
| 75 | |
| 76 | Example: packet_in.buffer_id |
| 77 | """ |
| 78 | OFDataMember = namedtuple('OFDataMember', ['name', 'oftype']) |
| 79 | |
| 80 | """ |
Andreas Wundsam | 780e0c9 | 2013-08-02 17:48:27 -0700 | [diff] [blame] | 81 | Field that declares that this is an abstract super-class and |
| 82 | that the sub classes will be discriminated based on this field. |
| 83 | E.g., 'type' is the discriminator member of the abstract superclass |
| 84 | of_action. |
| 85 | |
| 86 | @param name |
| 87 | """ |
Andreas Wundsam | 7933beb | 2013-08-02 22:36:42 -0700 | [diff] [blame] | 88 | OFDiscriminatorMember = namedtuple('OFDiscriminatorMember', ['name', 'oftype']) |
Andreas Wundsam | 780e0c9 | 2013-08-02 17:48:27 -0700 | [diff] [blame] | 89 | |
| 90 | """ |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 91 | Field used to determine the type of an OpenFlow object |
| 92 | |
| 93 | @param name |
| 94 | @param oftype C-like type string |
| 95 | @param value Fixed type value |
| 96 | |
| 97 | Example: packet_in.type, flow_add._command |
| 98 | """ |
| 99 | OFTypeMember = namedtuple('OFTypeMember', ['name', 'oftype', 'value']) |
| 100 | |
| 101 | """ |
| 102 | Field with the length of the containing object |
| 103 | |
| 104 | @param name |
| 105 | @param oftype C-like type string |
| 106 | |
| 107 | Example: packet_in.length, action_output.len |
| 108 | """ |
| 109 | OFLengthMember = namedtuple('OFLengthMember', ['name', 'oftype']) |
| 110 | |
| 111 | """ |
| 112 | Field with the length of another field in the containing object |
| 113 | |
| 114 | @param name |
| 115 | @param oftype C-like type string |
| 116 | @param field_name Peer field whose length this field contains |
| 117 | |
| 118 | Example: packet_out.actions_len (only usage) |
| 119 | """ |
| 120 | OFFieldLengthMember = namedtuple('OFFieldLengthMember', ['name', 'oftype', 'field_name']) |
| 121 | |
| 122 | """ |
| 123 | Zero-filled padding |
| 124 | |
| 125 | @param length Length in bytes |
| 126 | |
| 127 | Example: packet_in.pad |
| 128 | """ |
| 129 | OFPadMember = namedtuple('OFPadMember', ['length']) |
| 130 | |
| 131 | """ |
Rich Lane | 7bc2377 | 2013-11-29 17:47:46 -0800 | [diff] [blame] | 132 | Field with the version of an OpenFlow object |
| 133 | |
| 134 | @param name |
| 135 | @param oftype C-like type string |
| 136 | |
| 137 | Example: hello.version |
| 138 | """ |
| 139 | OFVersionMember = namedtuple('OFVersionMember', ['name', 'oftype']) |
| 140 | |
| 141 | """ |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 142 | An OpenFlow enumeration |
| 143 | |
| 144 | All values are Python ints. |
| 145 | |
| 146 | @param name |
Andreas Wundsam | 4ee5146 | 2013-07-30 11:00:37 -0700 | [diff] [blame] | 147 | @param entries List of OFEnumEntry objects in input order |
| 148 | @params dict of optional params. Currently defined: |
| 149 | - wire_type: the low_level type of the enum values (uint8,...) |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 150 | """ |
Andreas Wundsam | d30c107 | 2013-11-15 13:36:57 -0800 | [diff] [blame] | 151 | OFEnum = namedtuple('OFEnum', ['name', 'entries', 'params']) |
Andreas Wundsam | 4ee5146 | 2013-07-30 11:00:37 -0700 | [diff] [blame] | 152 | OFEnumEntry = namedtuple('OFEnumEntry', ['name', 'value', 'params']) |