|
1
|
|
|
"""Defines Header 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 GenericStruct |
|
8
|
1 |
|
from pyof.foundation.basic_types import UBInt8, UBInt16, UBInt32 |
|
9
|
1 |
|
from pyof.v0x04.common.constants import OFP_VERSION |
|
10
|
|
|
|
|
11
|
|
|
# Third-party imports |
|
12
|
|
|
|
|
13
|
1 |
|
__all__ = ('Header', 'Type') |
|
14
|
|
|
|
|
15
|
|
|
# Enums |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
1 |
|
class Type(IntEnum): |
|
19
|
|
|
"""Enumeration of Message Types.""" |
|
20
|
|
|
|
|
21
|
|
|
# Symetric/Immutable messages |
|
22
|
1 |
|
OFPT_HELLO = 0 |
|
23
|
1 |
|
OFPT_ERROR = 1 |
|
24
|
1 |
|
OFPT_ECHO_REQUEST = 2 |
|
25
|
1 |
|
OFPT_ECHO_REPLY = 3 |
|
26
|
1 |
|
OFPT_EXPERIMENTER = 4 |
|
27
|
|
|
|
|
28
|
|
|
# Switch configuration messages |
|
29
|
|
|
# Controller/Switch messages |
|
30
|
1 |
|
OFPT_FEATURES_REQUEST = 5 |
|
31
|
1 |
|
OFPT_FEATURES_REPLY = 6 |
|
32
|
1 |
|
OFPT_GET_CONFIG_REQUEST = 7 |
|
33
|
1 |
|
OFPT_GET_CONFIG_REPLY = 8 |
|
34
|
1 |
|
OFPT_SET_CONFIG = 9 |
|
35
|
|
|
|
|
36
|
|
|
# Async messages |
|
37
|
1 |
|
OFPT_PACKET_IN = 10 |
|
38
|
1 |
|
OFPT_FLOW_REMOVED = 11 |
|
39
|
1 |
|
OFPT_PORT_STATUS = 12 |
|
40
|
|
|
|
|
41
|
|
|
# Controller command messages |
|
42
|
|
|
# Controller/Switch message |
|
43
|
1 |
|
OFPT_PACKET_OUT = 13 |
|
44
|
1 |
|
OFPT_FLOW_MOD = 14 |
|
45
|
1 |
|
OFPT_GROUP_MOD = 15 |
|
46
|
1 |
|
OFPT_PORT_MOD = 16 |
|
47
|
1 |
|
OFPT_TABLE_MOD = 17 |
|
48
|
|
|
|
|
49
|
|
|
# Multipart messages. |
|
50
|
|
|
# Controller/Switch message |
|
51
|
1 |
|
OFPT_MULTIPART_REQUEST = 18 |
|
52
|
1 |
|
OFPT_MULTIPART_REPLY = 19 |
|
53
|
|
|
|
|
54
|
|
|
# Barrier messages |
|
55
|
|
|
# Controller/Switch message |
|
56
|
1 |
|
OFPT_BARRIER_REQUEST = 20 |
|
57
|
1 |
|
OFPT_BARRIER_REPLY = 21 |
|
58
|
|
|
|
|
59
|
|
|
# Queue Configuration messages |
|
60
|
|
|
# Controller/Switch message |
|
61
|
1 |
|
OFPT_QUEUE_GET_CONFIG_REQUEST = 22 |
|
62
|
1 |
|
OFPT_QUEUE_GET_CONFIG_REPLY = 23 |
|
63
|
|
|
|
|
64
|
|
|
# Controller role change request message |
|
65
|
|
|
# Controller/Switch message |
|
66
|
1 |
|
OFPT_ROLE_REQUEST = 24 |
|
67
|
1 |
|
OFPT_ROLE_REPLY = 25 |
|
68
|
|
|
|
|
69
|
|
|
# Asynchronous message configuration |
|
70
|
|
|
# Controller/Switch message |
|
71
|
1 |
|
OFPT_GET_ASYNC_REQUEST = 26 |
|
72
|
1 |
|
OFPT_GET_ASYNC_REPLY = 27 |
|
73
|
1 |
|
OFPT_SET_ASYNC = 28 |
|
74
|
|
|
|
|
75
|
|
|
# Meters and rate limiters configuration messages |
|
76
|
|
|
# Controller/Switch message |
|
77
|
1 |
|
OFPT_METER_MOD = 29 |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
# Classes |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
1 |
|
class Header(GenericStruct): |
|
84
|
|
|
"""Representation of an OpenFlow message Header.""" |
|
85
|
|
|
|
|
86
|
1 |
|
version = UBInt8(OFP_VERSION) |
|
87
|
1 |
|
message_type = UBInt8(enum_ref=Type) |
|
88
|
1 |
|
length = UBInt16() |
|
89
|
1 |
|
xid = UBInt32() |
|
90
|
|
|
|
|
91
|
1 |
|
def __init__(self, message_type=None, length=None, xid=None): |
|
92
|
|
|
"""Create a Header with the optional parameters below. |
|
93
|
|
|
|
|
94
|
|
|
Args: |
|
95
|
|
|
message_type (~pyof.v0x04.common.header.Type): |
|
96
|
|
|
One of the OFPT_* constants. |
|
97
|
|
|
length (int): Length including this ofp_header. |
|
98
|
|
|
xid (int): Transaction id associated with this packet. Replies use |
|
99
|
|
|
the same id as was in the request to facilitate pairing. |
|
100
|
|
|
""" |
|
101
|
1 |
|
super().__init__() |
|
102
|
1 |
|
self.message_type = message_type |
|
103
|
1 |
|
self.length = length |
|
104
|
1 |
|
self.xid = xid |
|
105
|
|
|
|
|
106
|
|
|
def __repr__(self): |
|
107
|
|
|
return (f"{type(self).__name__}(version={self.version}, " |
|
108
|
|
|
f"xid={self.xid}, {self.message_type!s})") |
|
109
|
|
|
|