blob: 9e266ebb18f4b0ecdfbd3f460c7a6c9ee7c98c5f [file] [log] [blame]
Rich Lane4d9f0f62013-05-09 15:50:57 -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
Andreas Wundsamfef7d5f2013-08-01 22:15:44 -070028from generic_utils import find
Rich Lane4d9f0f62013-05-09 15:50:57 -070029from collections import namedtuple
30
31# This module is intended to be imported like this: from loxi_ir import *
32# All public names are prefixed with 'OF'.
33__all__ = [
34 'OFInput',
35 'OFProtocol',
36 'OFClass',
37 'OFDataMember',
38 'OFTypeMember',
39 'OFLengthMember',
40 'OFFieldLengthMember',
41 'OFPadMember',
42 'OFEnum',
Andreas Wundsam4ee51462013-07-30 11:00:37 -070043 'OFEnumEntry'
Rich Lane4d9f0f62013-05-09 15:50:57 -070044]
45
46"""
47One 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"""
53OFInput = namedtuple('OFInput', ['wire_versions', 'classes', 'enums'])
54
55"""
56One version of the OpenFlow protocol
57
58Combination of multiple OFInput objects.
59
60@param wire_version
61@param classes List of OFClass objects
62@param enums List of Enum objects
63"""
64OFProtocol = namedtuple('OFProtocol', ['wire_version', 'classes', 'enums'])
65
66"""
67An OpenFlow class
68
69All compound objects like messages, actions, instructions, etc are
70uniformly represented by this class.
71
72The members are in the same order as on the wire.
73
74@param name
75@param members List of *Member objects
Andreas Wundsamfef7d5f2013-08-01 22:15:44 -070076@param super_class name of the super class
77@param params optional dictionary of parameters
Rich Lane4d9f0f62013-05-09 15:50:57 -070078"""
Andreas Wundsamcd2d5252013-08-02 13:35:57 -070079class OFClass(namedtuple('OFClass', ['name', 'members', 'superclass', 'params'])):
Andreas Wundsamfef7d5f2013-08-01 22:15:44 -070080 def member_by_name(self, name):
81 return find(self.members, lambda m: hasattr(m, "name") and m.name == name)
Rich Lane4d9f0f62013-05-09 15:50:57 -070082
83"""
84Normal field
85
86@param name
87@param oftype C-like type string
88
89Example: packet_in.buffer_id
90"""
91OFDataMember = namedtuple('OFDataMember', ['name', 'oftype'])
92
93"""
94Field used to determine the type of an OpenFlow object
95
96@param name
97@param oftype C-like type string
98@param value Fixed type value
99
100Example: packet_in.type, flow_add._command
101"""
102OFTypeMember = namedtuple('OFTypeMember', ['name', 'oftype', 'value'])
103
104"""
105Field with the length of the containing object
106
107@param name
108@param oftype C-like type string
109
110Example: packet_in.length, action_output.len
111"""
112OFLengthMember = namedtuple('OFLengthMember', ['name', 'oftype'])
113
114"""
115Field with the length of another field in the containing object
116
117@param name
118@param oftype C-like type string
119@param field_name Peer field whose length this field contains
120
121Example: packet_out.actions_len (only usage)
122"""
123OFFieldLengthMember = namedtuple('OFFieldLengthMember', ['name', 'oftype', 'field_name'])
124
125"""
126Zero-filled padding
127
128@param length Length in bytes
129
130Example: packet_in.pad
131"""
132OFPadMember = namedtuple('OFPadMember', ['length'])
133
134"""
135An OpenFlow enumeration
136
137All values are Python ints.
138
139@param name
Andreas Wundsam4ee51462013-07-30 11:00:37 -0700140@param entries List of OFEnumEntry objects in input order
141@params dict of optional params. Currently defined:
142 - wire_type: the low_level type of the enum values (uint8,...)
Rich Lane4d9f0f62013-05-09 15:50:57 -0700143"""
Andreas Wundsam4ee51462013-07-30 11:00:37 -0700144class OFEnum(namedtuple('OFEnum', ['name', 'entries', 'params'])):
145 @property
146 def values(self):
147 return [(e.name, e.value) for e in self.entries]
148
149OFEnumEntry = namedtuple('OFEnumEntry', ['name', 'value', 'params'])