forked from andi-bigswitch/loxigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloxi_ir.py
165 lines (131 loc) · 4.64 KB
/
loxi_ir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Copyright 2013, Big Switch Networks, Inc.
#
# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
# the following special exception:
#
# LOXI Exception
#
# As a special exception to the terms of the EPL, you may distribute libraries
# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
# that copyright and licensing notices generated by LoxiGen are not altered or removed
# from the LoxiGen Libraries and the notice provided below is (i) included in
# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
# documentation for the LoxiGen Libraries, if distributed in binary form.
#
# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
#
# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
# a copy of the EPL at:
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# EPL for the specific language governing permissions and limitations
# under the EPL.
from generic_utils import find
from collections import namedtuple
# This module is intended to be imported like this: from loxi_ir import *
# All public names are prefixed with 'OF'.
__all__ = [
'OFInput',
'OFProtocol',
'OFClass',
'OFDataMember',
'OFTypeMember',
'OFDiscriminatorMember',
'OFLengthMember',
'OFFieldLengthMember',
'OFPadMember',
'OFEnum',
'OFEnumEntry'
]
"""
One input file
@param wire_versions Set of integer wire versions this file applies to
@param classes List of OFClass objects in the same order as in the file
@param enums List of Enum objects in the same order as in the file
"""
OFInput = namedtuple('OFInput', ['wire_versions', 'classes', 'enums'])
"""
One version of the OpenFlow protocol
Combination of multiple OFInput objects.
@param wire_version
@param classes List of OFClass objects
@param enums List of Enum objects
"""
OFProtocol = namedtuple('OFProtocol', ['wire_version', 'classes', 'enums'])
"""
An OpenFlow class
All compound objects like messages, actions, instructions, etc are
uniformly represented by this class.
The members are in the same order as on the wire.
@param name
@param superclass name of the super class
@param members List of *Member objects
@param params optional dictionary of parameters
"""
class OFClass(namedtuple('OFClass', ['name', 'superclass', 'members', 'virtual', 'params'])):
def member_by_name(self, name):
return find(self.members, lambda m: hasattr(m, "name") and m.name == name)
"""
Normal field
@param name
@param oftype C-like type string
Example: packet_in.buffer_id
"""
OFDataMember = namedtuple('OFDataMember', ['name', 'oftype'])
"""
Field that declares that this is an abstract super-class and
that the sub classes will be discriminated based on this field.
E.g., 'type' is the discriminator member of the abstract superclass
of_action.
@param name
"""
OFDiscriminatorMember = namedtuple('OFDiscriminatorMember', ['name', 'oftype'])
"""
Field used to determine the type of an OpenFlow object
@param name
@param oftype C-like type string
@param value Fixed type value
Example: packet_in.type, flow_add._command
"""
OFTypeMember = namedtuple('OFTypeMember', ['name', 'oftype', 'value'])
"""
Field with the length of the containing object
@param name
@param oftype C-like type string
Example: packet_in.length, action_output.len
"""
OFLengthMember = namedtuple('OFLengthMember', ['name', 'oftype'])
"""
Field with the length of another field in the containing object
@param name
@param oftype C-like type string
@param field_name Peer field whose length this field contains
Example: packet_out.actions_len (only usage)
"""
OFFieldLengthMember = namedtuple('OFFieldLengthMember', ['name', 'oftype', 'field_name'])
"""
Zero-filled padding
@param length Length in bytes
Example: packet_in.pad
"""
OFPadMember = namedtuple('OFPadMember', ['length'])
"""
An OpenFlow enumeration
All values are Python ints.
@param name
@param entries List of OFEnumEntry objects in input order
@params dict of optional params. Currently defined:
- wire_type: the low_level type of the enum values (uint8,...)
"""
class OFEnum(namedtuple('OFEnum', ['name', 'entries', 'params'])):
@property
def values(self):
return [(e.name, e.value) for e in self.entries]
@property
def is_bitmask(self):
return "bitmask" in self.params and self.params['bitmask']
OFEnumEntry = namedtuple('OFEnumEntry', ['name', 'value', 'params'])