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 | |
| 28 | from collections import namedtuple |
| 29 | |
| 30 | # This module is intended to be imported like this: from loxi_ir import * |
| 31 | # All public names are prefixed with 'OF'. |
| 32 | __all__ = [ |
| 33 | 'OFInput', |
| 34 | 'OFProtocol', |
| 35 | 'OFClass', |
| 36 | 'OFDataMember', |
| 37 | 'OFTypeMember', |
| 38 | 'OFLengthMember', |
| 39 | 'OFFieldLengthMember', |
| 40 | 'OFPadMember', |
| 41 | 'OFEnum', |
Andreas Wundsam | 4ee5146 | 2013-07-30 11:00:37 -0700 | [diff] [blame] | 42 | 'OFEnumEntry' |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 43 | ] |
| 44 | |
| 45 | """ |
| 46 | One input file |
| 47 | |
| 48 | @param wire_versions Set of integer wire versions this file applies to |
| 49 | @param classes List of OFClass objects in the same order as in the file |
| 50 | @param enums List of Enum objects in the same order as in the file |
| 51 | """ |
| 52 | OFInput = namedtuple('OFInput', ['wire_versions', 'classes', 'enums']) |
| 53 | |
| 54 | """ |
| 55 | One version of the OpenFlow protocol |
| 56 | |
| 57 | Combination of multiple OFInput objects. |
| 58 | |
| 59 | @param wire_version |
| 60 | @param classes List of OFClass objects |
| 61 | @param enums List of Enum objects |
| 62 | """ |
| 63 | OFProtocol = namedtuple('OFProtocol', ['wire_version', 'classes', 'enums']) |
| 64 | |
| 65 | """ |
| 66 | An OpenFlow class |
| 67 | |
| 68 | All compound objects like messages, actions, instructions, etc are |
| 69 | uniformly represented by this class. |
| 70 | |
| 71 | The members are in the same order as on the wire. |
| 72 | |
| 73 | @param name |
| 74 | @param members List of *Member objects |
| 75 | """ |
| 76 | OFClass = namedtuple('OFClass', ['name', 'members']) |
| 77 | |
| 78 | """ |
| 79 | Normal field |
| 80 | |
| 81 | @param name |
| 82 | @param oftype C-like type string |
| 83 | |
| 84 | Example: packet_in.buffer_id |
| 85 | """ |
| 86 | OFDataMember = namedtuple('OFDataMember', ['name', 'oftype']) |
| 87 | |
| 88 | """ |
| 89 | Field used to determine the type of an OpenFlow object |
| 90 | |
| 91 | @param name |
| 92 | @param oftype C-like type string |
| 93 | @param value Fixed type value |
| 94 | |
| 95 | Example: packet_in.type, flow_add._command |
| 96 | """ |
| 97 | OFTypeMember = namedtuple('OFTypeMember', ['name', 'oftype', 'value']) |
| 98 | |
| 99 | """ |
| 100 | Field with the length of the containing object |
| 101 | |
| 102 | @param name |
| 103 | @param oftype C-like type string |
| 104 | |
| 105 | Example: packet_in.length, action_output.len |
| 106 | """ |
| 107 | OFLengthMember = namedtuple('OFLengthMember', ['name', 'oftype']) |
| 108 | |
| 109 | """ |
| 110 | Field with the length of another field in the containing object |
| 111 | |
| 112 | @param name |
| 113 | @param oftype C-like type string |
| 114 | @param field_name Peer field whose length this field contains |
| 115 | |
| 116 | Example: packet_out.actions_len (only usage) |
| 117 | """ |
| 118 | OFFieldLengthMember = namedtuple('OFFieldLengthMember', ['name', 'oftype', 'field_name']) |
| 119 | |
| 120 | """ |
| 121 | Zero-filled padding |
| 122 | |
| 123 | @param length Length in bytes |
| 124 | |
| 125 | Example: packet_in.pad |
| 126 | """ |
| 127 | OFPadMember = namedtuple('OFPadMember', ['length']) |
| 128 | |
| 129 | """ |
| 130 | An OpenFlow enumeration |
| 131 | |
| 132 | All values are Python ints. |
| 133 | |
| 134 | @param name |
Andreas Wundsam | 4ee5146 | 2013-07-30 11:00:37 -0700 | [diff] [blame] | 135 | @param entries List of OFEnumEntry objects in input order |
| 136 | @params dict of optional params. Currently defined: |
| 137 | - wire_type: the low_level type of the enum values (uint8,...) |
Rich Lane | 4d9f0f6 | 2013-05-09 15:50:57 -0700 | [diff] [blame] | 138 | """ |
Andreas Wundsam | 4ee5146 | 2013-07-30 11:00:37 -0700 | [diff] [blame] | 139 | class OFEnum(namedtuple('OFEnum', ['name', 'entries', 'params'])): |
| 140 | @property |
| 141 | def values(self): |
| 142 | return [(e.name, e.value) for e in self.entries] |
| 143 | |
| 144 | OFEnumEntry = namedtuple('OFEnumEntry', ['name', 'value', 'params']) |