|
1
|
|
|
"""Defines physical port classes and related items.""" |
|
2
|
|
|
|
|
3
|
|
|
# System imports |
|
4
|
1 |
|
from enum import IntEnum |
|
5
|
|
|
|
|
6
|
|
|
# Local source tree imports |
|
7
|
1 |
|
from pyof.foundation.base import GenericBitMask, GenericStruct |
|
8
|
1 |
|
from pyof.foundation.basic_types import ( |
|
9
|
|
|
Char, FixedTypeList, HWAddress, UBInt16, UBInt32) |
|
10
|
1 |
|
from pyof.foundation.constants import OFP_MAX_PORT_NAME_LEN |
|
11
|
|
|
|
|
12
|
|
|
# Third-party imports |
|
13
|
|
|
|
|
14
|
1 |
|
__all__ = ('PhyPort', 'ListOfPhyPorts', 'Port', 'PortConfig', 'PortFeatures', |
|
15
|
|
|
'PortState') |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
1 |
|
class Port(IntEnum): |
|
19
|
|
|
"""Port numbering. |
|
20
|
|
|
|
|
21
|
|
|
Physical ports are numbered starting from 1. Port number 0 is reserved by |
|
22
|
|
|
the specification and must not be used for a switch physical port. |
|
23
|
|
|
""" |
|
24
|
|
|
|
|
25
|
|
|
#: Maximum number of physical switch ports. |
|
26
|
1 |
|
OFPP_MAX = 0xff00 |
|
27
|
|
|
#: Send the packet out the input port. This virtual port must be explicitly |
|
28
|
|
|
#: used in order to send back out of the input port. |
|
29
|
1 |
|
OFPP_IN_PORT = 0xfff8 |
|
30
|
|
|
#: Perform actions in flow table. |
|
31
|
|
|
#: NB: This can only be the destination port for packet-out messages |
|
32
|
1 |
|
OFPP_TABLE = 0xfff9 |
|
33
|
|
|
#: Process with normal L2/L3 switching. |
|
34
|
1 |
|
OFPP_NORMAL = 0xfffa |
|
35
|
|
|
#: All physical ports except input port and those disabled by STP |
|
36
|
1 |
|
OFPP_FLOOD = 0xfffb |
|
37
|
|
|
#: All physical ports except input port |
|
38
|
1 |
|
OFPP_ALL = 0xfffc |
|
39
|
|
|
#: Send to controller |
|
40
|
1 |
|
OFPP_CONTROLLER = 0xfffd |
|
41
|
|
|
#: Local openflow "port" |
|
42
|
1 |
|
OFPP_LOCAL = 0xfffe |
|
43
|
|
|
#: Not associated with a physical port |
|
44
|
1 |
|
OFPP_NONE = 0xffff |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
1 |
|
class PortConfig(GenericBitMask): |
|
48
|
|
|
"""Flags to indicate behavior of the physical port. |
|
49
|
|
|
|
|
50
|
|
|
These flags are used in OFPPhyPort to describe the current configuration. |
|
51
|
|
|
They are used in the OFPPortMod message to configure the port's behavior. |
|
52
|
|
|
""" |
|
53
|
|
|
|
|
54
|
|
|
#: Port is administratively down. |
|
55
|
1 |
|
OFPPC_PORT_DOWN = 1 << 0 |
|
56
|
|
|
#: Disable 802.1D spanning tree on port. |
|
57
|
1 |
|
OFPPC_NO_STP = 1 << 1 |
|
58
|
|
|
#: Drop all packets except 802.1D spanning tree. |
|
59
|
1 |
|
OFPPC_NO_RECV = 1 << 2 |
|
60
|
|
|
#: Drop received 802.1D STP packets. |
|
61
|
1 |
|
OFPPC_NO_RECV_STP = 1 << 3 |
|
62
|
|
|
#: Do not include this port when flooding. |
|
63
|
1 |
|
OFPPC_FLOOD = 1 << 4 |
|
64
|
|
|
#: Drop packets forwarded to port. |
|
65
|
1 |
|
OFPPC_NO_FWD = 1 << 5 |
|
66
|
|
|
#: Do not send packet-in msgs for port. |
|
67
|
1 |
|
OFPPC_NO_PACKET_IN = 1 << 6 |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
1 |
|
class PortFeatures(GenericBitMask): |
|
71
|
|
|
"""Physical ports features. |
|
72
|
|
|
|
|
73
|
|
|
The :attr:`curr`, :attr:`advertised`, :attr:`supported`, and :attr:`peer` |
|
74
|
|
|
fields indicate link modes (10M to 10G full and half-duplex), link type |
|
75
|
|
|
(copper/fiber) and link features (autone-gotiation and pause). |
|
76
|
|
|
""" |
|
77
|
|
|
|
|
78
|
|
|
#: 10 Mb half-duplex rate support. |
|
79
|
1 |
|
OFPPF_10MB_HD = 1 << 0 |
|
80
|
|
|
#: 10 Mb full-duplex rate support. |
|
81
|
1 |
|
OFPPF_10MB_FD = 1 << 1 |
|
82
|
|
|
#: 100 Mb half-duplex rate support. |
|
83
|
1 |
|
OFPPF_100MB_HD = 1 << 2 |
|
84
|
|
|
#: 100 Mb full-duplex rate support. |
|
85
|
1 |
|
OFPPF_100MB_FD = 1 << 3 |
|
86
|
|
|
#: 1 Gb half-duplex rate support. |
|
87
|
1 |
|
OFPPF_1GB_HD = 1 << 4 |
|
88
|
|
|
#: 1 Gb full-duplex rate support. |
|
89
|
1 |
|
OFPPF_1GB_FD = 1 << 5 |
|
90
|
|
|
#: 10 Gb full-duplex rate support. |
|
91
|
1 |
|
OFPPF_10GB_FD = 1 << 6 |
|
92
|
|
|
#: Copper medium. |
|
93
|
1 |
|
OFPPF_COPPER = 1 << 7 |
|
94
|
|
|
#: Fiber medium. |
|
95
|
1 |
|
OFPPF_FIBER = 1 << 8 |
|
96
|
|
|
#: Auto-negotiation. |
|
97
|
1 |
|
OFPPF_AUTONEG = 1 << 9 |
|
98
|
|
|
#: Pause. |
|
99
|
1 |
|
OFPPF_PAUSE = 1 << 10 |
|
100
|
|
|
#: Asymmetric pause. |
|
101
|
1 |
|
OFPPF_PAUSE_ASYM = 1 << 11 |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
1 |
|
class PortState(GenericBitMask): |
|
105
|
|
|
"""Current state of the physical port. |
|
106
|
|
|
|
|
107
|
|
|
These are not configurable from the controller. |
|
108
|
|
|
|
|
109
|
|
|
The ``OFPPS_STP_*`` bits have no effect on switch operation. The controller |
|
110
|
|
|
must adjust :attr:`PortConfig.OFPPC_NO_RECV`, |
|
111
|
|
|
:attr:`~PortConfig.OFPPC_NO_FWD`, and |
|
112
|
|
|
:attr:`~PortConfig.OFPPC_NO_PACKET_IN` appropriately to fully implement an |
|
113
|
|
|
802.1D spanning tree. |
|
114
|
|
|
""" |
|
115
|
|
|
|
|
116
|
|
|
#: Not learning or relaying frames. |
|
117
|
1 |
|
OFPPS_LINK_DOWN = 1 << 0 |
|
118
|
|
|
#: Not learning or relaying frames. |
|
119
|
1 |
|
OFPPS_STP_LISTEN = 0 << 8 |
|
120
|
|
|
#: Learning but not relaying frames. |
|
121
|
1 |
|
OFPPS_STP_LEARN = 1 << 8 |
|
122
|
|
|
#: Learning and relaying frames. |
|
123
|
1 |
|
OFPPS_STP_FORWARD = 2 << 8 |
|
124
|
|
|
#: Not part of spanning tree. |
|
125
|
1 |
|
OFPPS_STP_BLOCK = 3 << 8 |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
# Classes |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
1 |
|
class PhyPort(GenericStruct): |
|
132
|
|
|
"""Description of a physical port. |
|
133
|
|
|
|
|
134
|
|
|
The port_no field is a value the datapath associates with a physical port. |
|
135
|
|
|
The hw_addr field typically is the MAC address for the port; |
|
136
|
|
|
:data:`OFP_ETH_ALEN` is 6. The name field is a null-terminated string |
|
137
|
|
|
containing a human-readable name for the interface. The value of |
|
138
|
|
|
:data:`OFP_MAX_PORT_NAME_LEN` is 16. |
|
139
|
|
|
|
|
140
|
|
|
:attr:`curr`, :attr:`advertised`, :attr:`supported` and :attr:`peer` are |
|
141
|
|
|
bitmaps of :class:`~pyof.v0x01.common.phy_port.PortFeatures` enum values |
|
142
|
|
|
that describe features. If unsupported or unavailable, set all bits to |
|
143
|
|
|
zero. |
|
144
|
|
|
""" |
|
145
|
|
|
|
|
146
|
1 |
|
port_no = UBInt16() |
|
147
|
1 |
|
hw_addr = HWAddress() |
|
148
|
1 |
|
name = Char(length=OFP_MAX_PORT_NAME_LEN) |
|
149
|
1 |
|
config = UBInt32(enum_ref=PortConfig) |
|
150
|
1 |
|
state = UBInt32(enum_ref=PortState) |
|
151
|
1 |
|
curr = UBInt32(enum_ref=PortFeatures) |
|
152
|
1 |
|
advertised = UBInt32(enum_ref=PortFeatures) |
|
153
|
1 |
|
supported = UBInt32(enum_ref=PortFeatures) |
|
154
|
1 |
|
peer = UBInt32(enum_ref=PortFeatures) |
|
155
|
|
|
|
|
156
|
1 |
|
def __init__(self, port_no=None, hw_addr=None, name=None, config=0, |
|
157
|
|
|
state=PortState.OFPPS_STP_LISTEN, curr=0, advertised=0, |
|
158
|
|
|
supported=0, peer=0): |
|
159
|
|
|
"""Create a PhyPort with the optional parameters below. |
|
160
|
|
|
|
|
161
|
|
|
Args: |
|
162
|
|
|
port_no (int): Port number. |
|
163
|
|
|
hw_addr (HWAddress): Hardware address. |
|
164
|
|
|
name(str): Null-terminated name. |
|
165
|
|
|
config (~pyof.v0x01.common.phy_port.PortConfig): |
|
166
|
|
|
Bitmap of OFPPC* flags. |
|
167
|
|
|
state (~pyof.v0x01.common.phy_port.PortState): |
|
168
|
|
|
Bitmap of OFPPS* flags. |
|
169
|
|
|
curr (~pyof.v0x01.common.phy_port.PortFeatures): Current features. |
|
170
|
|
|
advertised (~pyof.v0x01.common.phy_port.PortFeatures): |
|
171
|
|
|
Features being advertised by the port. |
|
172
|
|
|
supported (~pyof.v0x01.common.phy_port.PortFeatures): |
|
173
|
|
|
Features supported by the port. |
|
174
|
|
|
peer (~pyof.v0x01.common.phy_port.PortFeatures): |
|
175
|
|
|
Features advertised by peer. |
|
176
|
|
|
""" |
|
177
|
1 |
|
super().__init__() |
|
178
|
1 |
|
self.port_no = port_no |
|
179
|
1 |
|
self.hw_addr = hw_addr |
|
180
|
1 |
|
self.name = name |
|
181
|
1 |
|
self.config = config |
|
182
|
1 |
|
self.state = state |
|
183
|
1 |
|
self.curr = curr |
|
184
|
1 |
|
self.advertised = advertised |
|
185
|
1 |
|
self.supported = supported |
|
186
|
1 |
|
self.peer = peer |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
1 |
|
class ListOfPhyPorts(FixedTypeList): |
|
190
|
|
|
"""List of PhyPorts. |
|
191
|
|
|
|
|
192
|
|
|
Represented by instances of PhyPort and used on |
|
193
|
|
|
:class:`pyof.v0x01.common.phy_port.FeaturesReply`/ |
|
194
|
|
|
:class:`pyof.v0x01.controller2switch.features_reply.SwitchFeatures` |
|
195
|
|
|
objects. |
|
196
|
|
|
""" |
|
197
|
|
|
|
|
198
|
1 |
|
def __init__(self, items=None): |
|
199
|
|
|
"""Create a ListOfPhyPorts with the optional parameters below. |
|
200
|
|
|
|
|
201
|
|
|
Args: |
|
202
|
|
|
items (:class:`list`, :class:`PhyPort`): One :class:`PhyPort` |
|
203
|
|
|
instance or list. |
|
204
|
|
|
""" |
|
205
|
1 |
|
super().__init__(pyof_class=PhyPort, |
|
206
|
|
|
items=items) |
|
207
|
|
|
|