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

Commit 73c18bb

Browse files
committed
Refactoring pyof.v0x04.controller2switch.common
1 parent 9a7a786 commit 73c18bb

16 files changed

Lines changed: 234 additions & 221 deletions

pyof/v0x04/common/port.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
# Local source tree imports
77
from pyof.foundation.base import GenericBitMask, GenericStruct
8-
from pyof.foundation.basic_types import (Char, FixedTypeList, HWAddress,
9-
Pad, UBInt32)
8+
from pyof.foundation.basic_types import (Char, FixedTypeList, HWAddress, Pad,
9+
UBInt32)
1010
from pyof.foundation.constants import OFP_MAX_PORT_NAME_LEN
1111

1212
# Third-party imports
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Defines common structures and enums for controller2switch."""
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""Defines buckets structures for controller2switch."""
2+
3+
from pyof.foundation.base import GenericStruct
4+
from pyof.foundation.basic_types import (FixedTypeList, Pad, UBInt16, UBInt32,
5+
UBInt64)
6+
from pyof.v0x04.common.action import ActionHeader
7+
8+
__all__ = ('Bucket', 'BucketCounter',)
9+
10+
11+
class Bucket(GenericStruct):
12+
"""Bucket for use in groups."""
13+
14+
length = UBInt16()
15+
weight = UBInt16()
16+
watch_port = UBInt32()
17+
watch_group = UBInt32()
18+
pad = Pad(4)
19+
actions = FixedTypeList(ActionHeader)
20+
21+
def __init__(self, length=None, weight=None, watch_port=None,
22+
watch_group=None, actions=None):
23+
"""Initialize all instance variables.
24+
25+
Args:
26+
length (int): Length the bucket in bytes, including this header and
27+
any padding to make it 64-bit aligned.
28+
weight (int): Relative weight of bucket. Only defined for select
29+
groups.
30+
watch_port (int): Port whose state affects whether this bucket is
31+
live. Only required for fast failover groups.
32+
watch_group (int): Group whose state affects whether this bucket is
33+
live. Only required for fast failover groups.
34+
actions (:func:`list` of :class:`.ActionHeader`): The action length
35+
is inferred from the length field in the header.
36+
"""
37+
super().__init__()
38+
self.length = length
39+
self.weight = weight
40+
self.watch_port = watch_port
41+
self.watch_group = watch_group
42+
self.actions = actions
43+
44+
45+
class BucketCounter(GenericStruct):
46+
"""Used in group stats replies."""
47+
48+
#: Number of packets processed by bucket.
49+
packet_count = UBInt64()
50+
#: Number of bytes processed by bucket.
51+
byte_count = UBInt64()
52+
53+
def __init__(self, packet_count=None, byte_count=None):
54+
"""The constructor just assigns parameters to object attributes.
55+
56+
Args:
57+
packet_count: Number of packets processed by bucket.
58+
byte_count: Number of bytes processed by bucket.
59+
"""
60+
super().__init__()
61+
self.packet_count = packet_count
62+
self.byte_count = byte_count
63+
64+
65+
class ListOfActions(FixedTypeList):
66+
"""List of actions.
67+
68+
Represented by instances of ActionHeader and used on ActionHeader objects.
69+
"""
70+
71+
def __init__(self, items=None):
72+
"""The constructor just assings parameters to object attributes.
73+
74+
Args:
75+
items (ActionHeader): Instance or a list of instances.
76+
"""
77+
super().__init__(pyof_class=ActionHeader, items=items)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"""Module with generic messages used in controller2switch."""
2+
3+
# System imports
4+
from enum import Enum
5+
6+
from pyof.foundation.base import GenericMessage
7+
from pyof.foundation.basic_types import Pad, UBInt16, UBInt32, UBInt64
8+
from pyof.v0x04.asynchronous.flow_removed import FlowRemovedReason
9+
from pyof.v0x04.asynchronous.packet_in import PacketInReason
10+
from pyof.v0x04.asynchronous.port_status import PortReason
11+
from pyof.v0x04.common.header import Header
12+
13+
__all__ = ('ConfigFlags', 'ControllerRole',)
14+
15+
16+
class ConfigFlags(Enum):
17+
"""Handling of IP fragments."""
18+
19+
#: No special handling for fragments.
20+
OFPC_FRAG_NORMAL = 0
21+
#: Drop fragments.
22+
OFPC_FRAG_DROP = 1
23+
#: Reassemble (only if OFPC_IP_REASM set).
24+
OFPC_FRAG_REASM = 2
25+
OFPC_FRAG_MASK = 3
26+
27+
28+
class ControllerRole(Enum):
29+
"""Controller roles."""
30+
31+
#: Don’t change current role.
32+
OFPCR_ROLE_NOCHANGE = 0
33+
#: Default role, full access.
34+
OFPCR_ROLE_EQUAL = 1
35+
#: Full access, at most one master.
36+
OFPCR_ROLE_MASTER = 2
37+
#: Read-only access.
38+
OFPCR_ROLE_SLAVE = 3
39+
40+
# Base Classes for other messages - not meant to be directly used, so, because
41+
# of that, they will not be inserted on the __all__ attribute.
42+
43+
44+
class AsyncConfig(GenericMessage):
45+
"""Asynchronous message configuration base class.
46+
47+
Common structure for SetAsync and GetAsyncReply messages.
48+
49+
AsyncConfig contains three 2-element arrays. Each array controls whether
50+
the controller receives asynchronous messages with a specific
51+
:class:`~.common.header.Type`. Within each array, element 0 specifies
52+
messages of interest when the controller has a OFPCR_ROLE_EQUAL or
53+
OFPCR_ROLE_MASTER role; element 1, when the controller has a
54+
OFPCR_ROLE_SLAVE role. Each array element is a bit-mask in which a 0-bit
55+
disables receiving a message sent with the reason code corresponding to the
56+
bit index and a 1-bit enables receiving it.
57+
"""
58+
59+
#: OpenFlow :class:`~common.header.Header`
60+
#: OFPT_GET_ASYNC_REPLY or OFPT_SET_ASYNC.
61+
header = Header()
62+
packet_in_mask1 = UBInt32(enum_ref=PacketInReason)
63+
packet_in_mask2 = UBInt32(enum_ref=PacketInReason)
64+
port_status_mask1 = UBInt32(enum_ref=PortReason)
65+
port_status_mask2 = UBInt32(enum_ref=PortReason)
66+
flow_removed_mask1 = UBInt32(enum_ref=FlowRemovedReason)
67+
flow_removed_mask2 = UBInt32(enum_ref=FlowRemovedReason)
68+
69+
def __init__(self, xid=None, packet_in_mask1=None, packet_in_mask2=None,
70+
port_status_mask1=None, port_status_mask2=None,
71+
flow_removed_mask1=None, flow_removed_mask2=None):
72+
"""Base class for Asynchronous configuration messages.
73+
74+
Common structure for SetAsync and GetAsyncReply messages.
75+
76+
Args:
77+
xid (int): xid to be used on the message header.
78+
packet_in_mask1 (): .
79+
packet_in_mask2 (): .
80+
port_status_mask1 (): .
81+
port_status_mask2 (): .
82+
flow_removed_mask1 (): .
83+
flow_removed_mask2 (): .
84+
"""
85+
super().__init__(xid)
86+
self.packet_in_mask1 = packet_in_mask1
87+
self.packet_in_mask2 = packet_in_mask2
88+
self.port_status_mask1 = port_status_mask1
89+
self.port_status_mask2 = port_status_mask2
90+
self.flow_removed_mask1 = flow_removed_mask1
91+
self.flow_removed_mask2 = flow_removed_mask2
92+
93+
94+
class RoleBaseMessage(GenericMessage):
95+
"""Role basic structure for RoleRequest and RoleReply messages."""
96+
97+
#: :class:`~.common.header.Header`
98+
#: Type OFPT_ROLE_REQUEST/OFPT_ROLE_REPLY.
99+
header = Header()
100+
#: One of NX_ROLE_*. (:class:`~.controller2switch.common.ControllerRole`)
101+
role = UBInt32(enum_ref=ControllerRole)
102+
#: Align to 64 bits.
103+
pad = Pad(4)
104+
#: Master Election Generation Id.
105+
generation_id = UBInt64()
106+
107+
def __init__(self, xid=None, role=None, generation_id=None):
108+
"""The constructor just assings parameters to object attributes.
109+
110+
Args:
111+
xid (int): OpenFlow xid to the header.
112+
role (:class:`~.controller2switch.common.ControllerRole`): .
113+
generation_id (int): Master Election Generation Id.
114+
"""
115+
super().__init__(xid)
116+
self.role = role
117+
self.generation_id = generation_id
118+
119+
120+
class SwitchConfig(GenericMessage):
121+
"""Used as base class for SET_CONFIG and GET_CONFIG_REPLY messages."""
122+
123+
#: OpenFlow :class:`~common.header.Header`
124+
header = Header()
125+
flags = UBInt16(enum_ref=ConfigFlags)
126+
miss_send_len = UBInt16()
127+
128+
def __init__(self, xid=None, flags=None, miss_send_len=None):
129+
"""The constructor just assings parameters to object attributes.
130+
131+
Args:
132+
xid (int): xid to be used on the message header.
133+
flags (ConfigFlags): OFPC_* flags.
134+
miss_send_len (int): UBInt16 max bytes of new flow that the
135+
datapath should send to the controller.
136+
"""
137+
super().__init__(xid)
138+
self.flags = flags
139+
self.miss_send_len = miss_send_len

0 commit comments

Comments
 (0)