4242from pyof .v0x04 .symmetric .experimenter import ExperimenterHeader
4343from pyof .v0x04 .symmetric .hello import Hello
4444
45- __all__ = ('new_message_from_header' , 'new_message_from_message_type' )
45+ __all__ = ('MESSAGE_TYPES' , 'new_message_from_header' ,
46+ 'new_message_from_message_type' , 'unpack_message' )
47+
48+ MESSAGE_TYPES = {
49+
50+ # Symetric/Immutable messages
51+ str (Type .OFPT_HELLO ): Hello ,
52+ str (Type .OFPT_ERROR ): ErrorMsg ,
53+ str (Type .OFPT_ECHO_REQUEST ): EchoRequest ,
54+ str (Type .OFPT_ECHO_REPLY ): EchoReply ,
55+ str (Type .OFPT_EXPERIMENTER ): ExperimenterHeader ,
56+
57+ # Switch configuration messages
58+ # Controller/Switch messages
59+ str (Type .OFPT_FEATURES_REQUEST ): FeaturesRequest ,
60+ str (Type .OFPT_FEATURES_REPLY ): FeaturesReply ,
61+ str (Type .OFPT_GET_CONFIG_REQUEST ): GetConfigRequest ,
62+ str (Type .OFPT_GET_CONFIG_REPLY ): GetConfigReply ,
63+ str (Type .OFPT_SET_CONFIG ): SetConfig ,
64+
65+ # Async messages
66+ str (Type .OFPT_PACKET_IN ): PacketIn ,
67+ str (Type .OFPT_FLOW_REMOVED ): FlowRemoved ,
68+ str (Type .OFPT_PORT_STATUS ): PortStatus ,
69+
70+ # Controller command messages
71+ # Controller/Switch message
72+ str (Type .OFPT_PACKET_OUT ): PacketOut ,
73+ str (Type .OFPT_FLOW_MOD ): FlowMod ,
74+ str (Type .OFPT_GROUP_MOD ): GroupMod ,
75+ str (Type .OFPT_PORT_MOD ): PortMod ,
76+ str (Type .OFPT_TABLE_MOD ): TableMod ,
77+
78+ # Multipart messages.
79+ # Controller/Switch message
80+ str (Type .OFPT_MULTIPART_REPLY ): MultipartReply ,
81+ str (Type .OFPT_MULTIPART_REQUEST ): MultipartRequest ,
82+
83+ # Barrier messages
84+ # Controller/Switch message
85+ str (Type .OFPT_BARRIER_REQUEST ): BarrierRequest ,
86+ str (Type .OFPT_BARRIER_REPLY ): BarrierReply ,
87+
88+ # Queue Configuration messages
89+ # Controller/Switch message
90+ str (Type .OFPT_QUEUE_GET_CONFIG_REQUEST ): QueueGetConfigRequest ,
91+ str (Type .OFPT_QUEUE_GET_CONFIG_REPLY ): QueueGetConfigReply ,
92+
93+ # Controller role change request message
94+ # Controller/Switch message
95+ str (Type .OFPT_ROLE_REQUEST ): RoleRequest ,
96+ str (Type .OFPT_ROLE_REPLY ): RoleReply ,
97+
98+ # Asynchronous message configuration
99+ # Controller/Switch message
100+ str (Type .OFPT_GET_ASYNC_REQUEST ): GetAsyncRequest ,
101+ str (Type .OFPT_GET_ASYNC_REPLY ): GetAsyncReply ,
102+ str (Type .OFPT_SET_ASYNC ): SetAsync ,
103+
104+ # Meters and rate limiters configuration messages
105+ # Controller/Switch message
106+ str (Type .OFPT_METER_MOD ): MeterMod ,
107+ }
46108
47109
48110def new_message_from_message_type (message_type ):
@@ -60,73 +122,11 @@ def new_message_from_message_type(message_type):
60122
61123 """
62124 message_type = str (message_type )
63-
64- available_classes = {
65-
66- # Symetric/Immutable messages
67- str (Type .OFPT_HELLO ): Hello ,
68- str (Type .OFPT_ERROR ): ErrorMsg ,
69- str (Type .OFPT_ECHO_REQUEST ): EchoRequest ,
70- str (Type .OFPT_ECHO_REPLY ): EchoReply ,
71- str (Type .OFPT_EXPERIMENTER ): ExperimenterHeader ,
72-
73- # Switch configuration messages
74- # Controller/Switch messages
75- str (Type .OFPT_FEATURES_REQUEST ): FeaturesRequest ,
76- str (Type .OFPT_FEATURES_REPLY ): FeaturesReply ,
77- str (Type .OFPT_GET_CONFIG_REQUEST ): GetConfigRequest ,
78- str (Type .OFPT_GET_CONFIG_REPLY ): GetConfigReply ,
79- str (Type .OFPT_SET_CONFIG ): SetConfig ,
80-
81- # Async messages
82- str (Type .OFPT_PACKET_IN ): PacketIn ,
83- str (Type .OFPT_FLOW_REMOVED ): FlowRemoved ,
84- str (Type .OFPT_PORT_STATUS ): PortStatus ,
85-
86- # Controller command messages
87- # Controller/Switch message
88- str (Type .OFPT_PACKET_OUT ): PacketOut ,
89- str (Type .OFPT_FLOW_MOD ): FlowMod ,
90- str (Type .OFPT_GROUP_MOD ): GroupMod ,
91- str (Type .OFPT_PORT_MOD ): PortMod ,
92- str (Type .OFPT_TABLE_MOD ): TableMod ,
93-
94- # Multipart messages.
95- # Controller/Switch message
96- str (Type .OFPT_MULTIPART_REPLY ): MultipartReply ,
97- str (Type .OFPT_MULTIPART_REQUEST ): MultipartRequest ,
98-
99- # Barrier messages
100- # Controller/Switch message
101- str (Type .OFPT_BARRIER_REQUEST ): BarrierRequest ,
102- str (Type .OFPT_BARRIER_REPLY ): BarrierReply ,
103-
104- # Queue Configuration messages
105- # Controller/Switch message
106- str (Type .OFPT_QUEUE_GET_CONFIG_REQUEST ): QueueGetConfigRequest ,
107- str (Type .OFPT_QUEUE_GET_CONFIG_REPLY ): QueueGetConfigReply ,
108-
109- # Controller role change request message
110- # Controller/Switch message
111- str (Type .OFPT_ROLE_REQUEST ): RoleRequest ,
112- str (Type .OFPT_ROLE_REPLY ): RoleReply ,
113-
114- # Asynchronous message configuration
115- # Controller/Switch message
116- str (Type .OFPT_GET_ASYNC_REQUEST ): GetAsyncRequest ,
117- str (Type .OFPT_GET_ASYNC_REPLY ): GetAsyncReply ,
118- str (Type .OFPT_SET_ASYNC ): SetAsync ,
119-
120- # Meters and rate limiters configuration messages
121- # Controller/Switch message
122- str (Type .OFPT_METER_MOD ): MeterMod ,
123- }
124-
125- if message_type not in available_classes :
125+ if message_type not in MESSAGE_TYPES :
126126 msg = "Define class for {} in {}" .format (message_type , __file__ )
127127 raise ValueError (msg )
128128
129- message_class = available_classes .get (message_type )
129+ message_class = MESSAGE_TYPES .get (message_type )
130130 message_instance = message_class ()
131131
132132 return message_instance
@@ -166,7 +166,15 @@ def new_message_from_header(header):
166166
167167
168168def unpack_message (buffer ):
169- """Unpack the whole buffer, including header pack."""
169+ """Unpack the whole buffer, including header pack.
170+
171+ Args:
172+ buffer (bytes): Bytes representation of a openflow message.
173+
174+ Returns:
175+ object: Instance of openflow message.
176+
177+ """
170178 hdr_size = Header ().get_size ()
171179 hdr_buff , msg_buff = buffer [:hdr_size ], buffer [hdr_size :]
172180 header = Header ()
0 commit comments