Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 1164f7a

Browse files
authored
Merge pull request #317 from renanrodrigo/add_hello_msg
Add Hello message
2 parents 62d72c4 + e7d8b32 commit 1164f7a

1 file changed

Lines changed: 98 additions & 2 deletions

File tree

pyof/v0x04/symmetric/hello.py

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,103 @@
22

33
# System imports
44

5+
from enum import Enum
6+
7+
from pyof.foundation.base import GenericMessage, GenericStruct
8+
from pyof.foundation.basic_types import BinaryData, FixedTypeList, UBInt16
9+
from pyof.v0x04.common.header import Header, Type
10+
511
# Third-party imports
612

7-
from pyof.v0x01.symmetric.hello import Hello
8-
__all__ = ('Hello',)
13+
14+
__all__ = ('Hello', 'HelloElemHeader', 'HelloElemType',
15+
'HelloElemVersionbitmap', 'ListOfHelloElements')
16+
17+
# Enums
18+
19+
20+
class HelloElemType(Enum):
21+
"""Hello element types."""
22+
23+
#: Bitmap of version supported.
24+
OFPHET_VERSIONBITMAP = 1
25+
26+
27+
# Classes
28+
29+
30+
class HelloElemHeader(GenericStruct):
31+
"""Common header for all Hello Elements."""
32+
33+
element_type = UBInt16(enum_ref=HelloElemType)
34+
length = UBInt16()
35+
36+
def __init__(self, element_type=None, length=None):
37+
"""The constructor just assigns parameters to object attributes.
38+
39+
Args:
40+
element_type: One of OFPHET_*.
41+
length: Length in bytes of the element, including this header,
42+
excluding padding.
43+
"""
44+
super().__init__()
45+
self.element_type = element_type
46+
self.length = length
47+
48+
49+
class ListOfHelloElements(FixedTypeList):
50+
"""List of Hello elements.
51+
52+
Represented by instances of HelloElemHeader and used on Hello
53+
objects.
54+
"""
55+
56+
def __init__(self, items=None):
57+
"""The constructor just assigns parameters to object attributes.
58+
59+
Args:
60+
items (HelloElemHeader): Instance or a list of instances.
61+
"""
62+
super().__init__(pyof_class=HelloElemHeader, items=items)
63+
64+
65+
class Hello(GenericMessage):
66+
"""OpenFlow Hello Message OFPT_HELLO.
67+
68+
This message includes zero or more hello elements having variable size.
69+
Unknown element types must be ignored/skipped, to allow for future
70+
extensions.
71+
"""
72+
73+
header = Header(message_type=Type.OFPT_HELLO)
74+
#: Hello element list
75+
elements = ListOfHelloElements()
76+
77+
def __init__(self, xid=None, elements=None):
78+
"""The constructor takes the parameters below.
79+
80+
Args:
81+
xid (int): xid to be used on the message header.
82+
elements: List of elements - 0 or more
83+
"""
84+
super().__init__(xid)
85+
self.elements = elements
86+
87+
88+
class HelloElemVersionbitmap(HelloElemHeader):
89+
"""Version bitmap Hello Element."""
90+
91+
#: List of bitmaps - supported versions
92+
bitmaps = BinaryData()
93+
94+
def __init__(self, bitmaps=b''):
95+
"""The constructor just assigns parameters to object attributes.
96+
97+
Args:
98+
bitmaps: -Exactly (length - 4) bytes containing the bitmaps,then
99+
-Exactly (length + 7)/8*8 - (length) (between 0 and 7)
100+
bytes of all-zero bytes.
101+
"""
102+
super().__init__(element_type=HelloElemType.OFPHET_VERSIONBITMAP,
103+
length=None)
104+
self.bitmaps = bitmaps

0 commit comments

Comments
 (0)