OpenFlow/Protocol.pm untested

filter: Statementstmt 0.0% 0 / 676 Branchbran 0.0% 0 / 254 Conditioncond 0.0% 0 / 84 MC/DCmcdc 0.0% 0 / 46 Subroutinesub 0.0% 0 / 36 Podpod 0.0% 0 / 30 totaltotal 0.0% 0 / 1126 CC 128 SCAR 71.9
CC
128
Cov
0%
ofpt_decode
3080.0
ofpt_encode
1056.0
struct_decode__ofp_match
552.0
CRAP 1327.4
1 #
2 # $Id$
3 #
4 package Net::OpenFlow::Protocol;
5  
6 #use bigint;
7 use strict;
8 use warnings;
9 use Carp;
10  
11  
12 =head1 NAME
13  
14 Net::OpenFlow::Protocol - Protocol library for OpenFlow.
15  
16 =head1 VERSION
17  
18 Version 0.01
19  
20 =head1 SYNOPSIS
21  
22 This module allows encoding and decoding of OpenFlow messages from an OpenFlow switch.
23  
24 use Net::OpenFlow::Protocol;
25  
26  
27 my $ofp = Net::OpenFlow::Protocol->new;
28  
29 my $of_message = $ofp->ofpt_decode(\$of_message);
30  
31 my $of_message_type = $of_message->{'ofp_header'}{'type'};
32  
33 =head1 FUNCTIONS
34  
35 =over
36  
37 =cut
38  
39 our $VERSION = 0.01;
40  
41 our $openflow_version = 0x01;
42  
43 my $misc_defines = {
44 0x01 => {
45 OFPFW_NW_SRC_SHIFT => 8,
46 OFPFW_NW_SRC_BITS => 6,
47 OFPFW_NW_DST_SHIFT => 14,
48 OFPFW_NW_DST_BITS => 6,
49 OFPP_NONE => 0xffff,
50 },
51 };
52  
53 my $ofp_enums = {};
54  
55 $ofp_enums->{'ofp_action_type'} = {
56 0x01 => {
57 0x0000 => q{OFPAT_OUTPUT},
58 0x0001 => q{OFPAT_SET_VLAN_VID},
59 0x0002 => q{OFPAT_SET_VLAN_PCP},
60 0x0003 => q{OFPAT_STRIP_VLAN},
61 0x0004 => q{OFPAT_SET_DL_SRC},
62 0x0005 => q{OFPAT_SET_DL_DST},
63 0x0006 => q{OFPAT_SET_NW_SRC},
64 0x0007 => q{OFPAT_SET_NW_DST},
65 0x0008 => q{OFPAT_SET_NW_TOS},
66 0x0009 => q{OFPAT_SET_TP_SRC},
67 0x000a => q{OFPAT_SET_TP_DST},
68 0x000b => q{OFPAT_ENQUEUE},
69 0xffff => q{OFPAT_VENDOR},
70 },
71 0x02 => {
72 0x0000 => q{OFPAT_OUTPUT},
73 0x0001 => q{OFPAT_SET_VLAN_VID},
74 0x0002 => q{OFPAT_SET_VLAN_PCP},
75 0x0004 => q{OFPAT_SET_DL_SRC},
76 0x0005 => q{OFPAT_SET_DL_DST},
77 0x0006 => q{OFPAT_SET_NW_SRC},
78 0x0007 => q{OFPAT_SET_NW_DST},
79 0x0008 => q{OFPAT_SET_NW_TOS},
80 0x0009 => q{OFPAT_SET_TP_SRC},
81 0x000a => q{OFPAT_SET_TP_DST},
82 0x000b => q{OFPAT_COPY_TTL_OUT},
83 0x000c => q{OFPAT_COPY_TTL_IN},
84 0x000d => q{OFPAT_SET_MPLS_LABEL},
85 0x000e => q{OFPAT_SET_MPLS_TC},
86 0x000f => q{OFPAT_SET_MPLS_TTL},
87 0x0010 => q{OFPAT_DEC_MPLS_TTL},
88 0x0011 => q{OFPAT_PUSH_VLAN},
89 0x0012 => q{OFPAT_POP_VLAN},
90 0x0013 => q{OFPAT_PUSH_MPLS},
91 0x0014 => q{OFPAT_POP_MPLS},
92 0x0015 => q{OFPAT_SET_QUEUE},
93 0x0016 => q{OFPAT_GROUP},
94 0x0017 => q{OFPAT_SET_NW_TTL},
95 0x0018 => q{OFPAT_DEC_NW_TTL},
96 0xffff => q{OFPAT_EXPERIMENTER},
97 },
98 };
99  
100 $ofp_enums->{'ofp_bad_action_code'} = {
101 0x01 => {
102 0x0000 => q{OFPBAC_BAD_TYPE},
103 0x0001 => q{OFPBAC_BAD_LEN},
104 0x0002 => q{OFPBAC_BAD_VENDOR},
105 0x0003 => q{OFPBAC_BAD_VENDOR_TYPE},
106 0x0004 => q{OFPBAC_BAD_OUT_PORT},
107 0x0005 => q{OFPBAC_BAD_ARGUMENT},
108 0x0006 => q{OFPBAC_EPERM},
109 0x0007 => q{OFPBAC_TOO_MANY},
110 0x0008 => q{OFPBAC_BAD_QUEUE},
111 },
112 0x02 => {
113 0x0000 => q{OFPBAC_BAD_TYPE},
114 0x0001 => q{OFPBAC_BAD_LEN},
115 0x0002 => q{OFPBAC_BAD_EXPERMIMENTER},
116 0x0003 => q{OFPBAC_BAD_EXPERMIMENTER_TYPE},
117 0x0004 => q{OFPBAC_BAD_OUT_PORT},
118 0x0005 => q{OFPBAC_BAD_ARGUMENT},
119 0x0006 => q{OFPBAC_EPERM},
120 0x0007 => q{OFPBAC_TOO_MANY},
121 0x0008 => q{OFPBAC_BAD_QUEUE},
122 0x0009 => q{OFPBAC_BAD_OUT_GROUP},
123 0x000a => q{OFPBAC_MATCH_INCONSISTENT},
124 0x000b => q{OFPBAC_UNSUPPORTED_ORDER},
125 0x000c => q{OFPBAC_BAD_TAG},
126 },
127 };
128  
129 $ofp_enums->{'ofp_bad_instruction_code'} = {
130 0x02 => {
131 0x0000 => q{OFPBIC_UNKNOWN_INST},
132 0x0001 => q{OFPBIC_UNSUP_INST},
133 0x0002 => q{OFPBIC_BAD_TABLE_ID},
134 0x0003 => q{OFPBIC_UNSUP_METADATA},
135 0x0004 => q{OFPBIC_UNSUP_METADATA_MASK},
136 0x0005 => q{OFPBIC_UNSUP_EXP_INST},
137 },
138 };
139  
140 $ofp_enums->{'ofp_bad_match_code'} = {
141 0x02 => {
142 0x0000 => q{OFPBMC_BAD_TYPE},
143 0x0001 => q{OFPBMC_BAD_LEN},
144 0x0002 => q{OFPBMC_BAD_TAG},
145 0x0003 => q{OFPBMC_BAD_DL_ADDR_MASK},
146 0x0004 => q{OFPBMC_BAD_NW_ADDR_MASK},
147 0x0005 => q{OFPBMC_BAD_WILDCARDS},
148 0x0006 => q{OFPBMC_BAD_FIELD},
149 0x0007 => q{OFPBMC_BAD_VALUE},
150 },
151 };
152  
153 $ofp_enums->{'ofp_bad_request_code'} = {
154 0x01 => {
155 0x0000 => q{OFPBRC_BAD_VERSION},
156 0x0001 => q{OFPBRC_BAD_TYPE},
157 0x0002 => q{OFPBRC_BAD_STAT},
158 0x0003 => q{OFPBRC_BAD_VENDOR},
159 0x0004 => q{OFPBRC_BAD_SUBTYPE},
160 0x0005 => q{OFPBRC_EPERM},
161 0x0006 => q{OFPBRC_BAD_LEN},
162 0x0007 => q{OFPBRC_BUFFER_EMPTY},
163 0x0008 => q{OFPBRC_BUFFER_UNKNOWN},
164 },
165 0x02 => {
166 0x0000 => q{OFPBRC_BAD_VERSION},
167 0x0001 => q{OFPBRC_BAD_TYPE},
168 0x0002 => q{OFPBRC_BAD_STAT},
169 0x0003 => q{OFPBRC_BAD_EXPERMIMENTER},
170 0x0004 => q{OFPBRC_BAD_SUBTYPE},
171 0x0005 => q{OFPBRC_EPERM},
172 0x0006 => q{OFPBRC_BAD_LEN},
173 0x0007 => q{OFPBRC_BUFFER_EMPTY},
174 0x0008 => q{OFPBRC_BUFFER_UNKNOWN},
175 0x0009 => q{OFPBRC_BAD_TABLE_ID},
176 },
177 };
178  
179 $ofp_enums->{'ofp_capabilities'} = {
180 bitfield => q{},
181 0x01 => {
182 (1 << 0) => q{OFPC_FLOW_STATS},
183 (1 << 1) => q{OFPC_TABLE_STATS},
184 (1 << 2) => q{OFPC_PORT_STATS},
185 (1 << 3) => q{OFPC_STP},
186 (1 << 4) => q{OFPC_RESERVED},
187 (1 << 5) => q{OFPC_IP_REASM},
188 (1 << 6) => q{OFPC_QUEUE_STATS},
189 (1 << 7) => q{OFPC_ARP_MATCH_IP},
190 },
191 };
192  
193 $ofp_enums->{'ofp_config_flags'} = {
194 0x01 => {
195 0x0000 => q{OFPC_FRAG_NORMAL},
196 0x0001 => q{OFPC_FRAG_DROP},
197 0x0002 => q{OFPC_FRAG_REASM},
198 0x0003 => q{OFPC_FRAG_MASK},
199 },
200 };
201  
202 $ofp_enums->{'ofp_error_type'} = {
203 0x01 => {
204 0x0000 => q{OFPET_HELLO_FAILED},
205 0x0001 => q{OFPET_BAD_REQUEST},
206 0x0002 => q{OFPET_BAD_ACTION},
207 0x0003 => q{OFPET_FLOW_MOD_FAILED},
208 0x0004 => q{OFPET_PORT_MOD_FAILED},
209 0x0005 => q{OFPET_QUEUE_OP_FAILED},
210 },
211 0x02 => {
212 0x0000 => q{OFPET_HELLO_FAILED},
213 0x0001 => q{OFPET_BAD_REQUEST},
214 0x0002 => q{OFPET_BAD_ACTION},
215 0x0003 => q{OFPET_BAD_INSTRUCTION},
216 0x0004 => q{OFPET_BAD_MATCH},
217 0x0005 => q{OFPET_FLOW_MOD_FAILED},
218 0x0006 => q{OFPET_GROUP_MOD_FAILED},
219 0x0007 => q{OFPET_PORT_MOD_FAILED},
220 0x0008 => q{OFPET_TABLE_MOD_FAILED},
221 0x0009 => q{OFPET_QUEUE_OP_FAILED},
222 0x000a => q{OFPET_SWITCH_CONFIG_FAILED},
223 }
224 };
225  
226 $ofp_enums->{'ofp_flow_mod_command'} = {
227 0x01 => {
228 0x0000 => q{OFPFC_ADD},
229 0x0001 => q{OFPFC_MODIFY},
230 0x0002 => q{OFPFC_MODIFY_STRICT},
231 0x0003 => q{OFPFC_DELETE},
232 0x0004 => q{OFPFC_DELETE_STRICT},
233 },
234 };
235  
236 $ofp_enums->{'ofp_flow_mod_failed_code'} = {
237 0x01 => {
238 0x0000 => q{OFPFMFC_ALL_TABLES_FULL},
239 0x0001 => q{OFPFMFC_OVERLAP},
240 0x0002 => q{OFPFMFC_EPERM},
241 0x0003 => q{OFPFMFC_BAD_EMERG_TIMEOUT},
242 0x0004 => q{OFPFMFC_BAD_COMMAND},
243 0x0005 => q{OFPFMFC_UNSUPPORTED},
244 },
245 };
246  
247 $ofp_enums->{'ofp_flow_mod_flags'} = {
248 bitfield => q{},
249 0x01 => {
250 (1 << 0) => q{OFPFF_SEND_FLOW_REM},
251 (1 << 1) => q{OFPFF_CHECK_OVERLAP},
252 (1 << 2) => q{OFPFF_EMERG},
253 },
254 };
255  
256 $ofp_enums->{'ofp_flow_wildcards'} = {
257 bitfield => q{},
258 0x01 => {
259 (1 << 0) => q{OFPFW_IN_PORT},
260 (1 << 1) => q{OFPFW_DL_VLAN},
261 (1 << 2) => q{OFPFW_DL_SRC},
262 (1 << 3) => q{OFPFW_DL_DST},
263 (1 << 4) => q{OFPFW_DL_TYPE},
264 (1 << 5) => q{OFPFW_NW_PROTO},
265 (1 << 6) => q{OFPFW_TP_SRC},
266 (1 << 7) => q{OFPFW_TP_DST},
267 (((1 << $misc_defines->{0x01}{'OFPFW_NW_SRC_BITS'}) - 1) << $misc_defines->{0x01}{'OFPFW_NW_SRC_SHIFT'}) => q{OFPFW_NW_SRC_MASK},
268 (32 << $misc_defines->{0x01}{'OFPFW_NW_SRC_SHIFT'}) => q{OFPFW_NW_SRC_ALL},
269 (((1 << $misc_defines->{0x01}{'OFPFW_NW_DST_BITS'}) - 1) << $misc_defines->{0x01}{'OFPFW_NW_DST_SHIFT'}) => q{OFPFW_NW_DST_MASK},
270 (32 << $misc_defines->{0x01}{'OFPFW_NW_DST_SHIFT'}) => q{OFPFW_NW_DST_ALL},
271 (1 << 20) => q{OFPFW_DL_VLAN_PCP},
272 (1 << 21) => q{OFPFW_NW_TOS},
273 ((1 << 22) - 1) => q{OFPFW_ALL},
274 },
275 0x02 => {
276 (1 << 0) => q{OFPFW_IN_PORT},
277 (1 << 1) => q{OFPFW_DL_VLAN},
278 (1 << 2) => q{OFPFW_DL_VLAN_PCP},
279 (1 << 3) => q{OFPFW_DL_TYPE},
280 (1 << 4) => q{OFPFW_NW_TOS},
281 (1 << 5) => q{OFPFW_NW_PROTO},
282 (1 << 6) => q{OFPFW_TP_SRC},
283 (1 << 7) => q{OFPFW_TP_DST},
284 ((1 << 10) - 1) => q{OFPFW_ALL},
285 }
286 };
287  
288 $ofp_enums->{'ofp_hello_failed_code'} = {
289 0x01 => {
290 0x0000 => q{OFPHFC_INCOMPATIBLE},
291 0x0001 => q{OFPHFC_EPERM},
292 },
293 };
294  
295 $ofp_enums->{'ofp_hello_failed_code'}{0x02} = $ofp_enums->{'ofp_hello_failed_code'}{0x01};
296  
297 $ofp_enums->{'ofp_packet_in_reason'} = {
298 0x01 => {
299 0x00 => q{OFPR_NO_MATCH},
300 0x01 => q{OFPR_ACTION},
301 },
302 };
303  
304 $ofp_enums->{'ofp_port_config'} = {
305 bitfield => q{},
306 0x01 => {
307 (1 << 0) => q{OFPPC_PORT_DOWN},
308 (1 << 1) => q{OFPPC_NO_STP},
309 (1 << 2) => q{OFPPC_NO_RECV},
310 (1 << 3) => q{OFPPC_NO_RECV_STP},
311 (1 << 4) => q{OFPPC_NO_FLOOD},
312 (1 << 5) => q{OFPPC_NO_FWD},
313 (1 << 6) => q{OFPPC_NO_PACKET_IN},
314 },
315 };
316  
317 $ofp_enums->{'ofp_port_features'} = {
318 bitfield => q{},
319 0x01 => {
320 (1 << 0) => q{OFPPF_10MB_HD},
321 (1 << 1) => q{OFPPF_10MB_FD},
322 (1 << 2) => q{OFPPF_100MB_HD},
323 (1 << 3) => q{OFPPF_100MB_FD},
324 (1 << 4) => q{OFPPF_1GB_HD},
325 (1 << 5) => q{OFPPF_1GB_FD},
326 (1 << 6) => q{OFPPF_10GB_FD},
327 (1 << 7) => q{OFPPF_COPPER},
328 (1 << 8) => q{OFPPF_FIBER},
329 (1 << 9) => q{OFPPF_AUTONEG},
330 (1 << 10) => q{OFPPF_PAUSE},
331 (1 << 11) => q{OFPPF_PAUSE_ASYM},
332 },
333 };
334  
335 $ofp_enums->{'ofp_port_mod_failed_code'} = {
336 0x01 => {
337 0x0000 => q{OFPPMFC_BAD_PORT},
338 0x0001 => q{OFPPMFC_BAD_HW_ADDR},
339 },
340 0x02 => {
341 0x0000 => q{OFPPMFC_BAD_PORT},
342 0x0001 => q{OFPPMFC_BAD_HW_ADDR},
343 0x0002 => q{OFPPMFC_BAD_CONFIG},
344 0x0003 => q{OFPPMFC_BAD_ADVERTISE},
345 },
346 };
347  
348 $ofp_enums->{'ofp_port_reason'} = {
349 0x01 => {
350 0x00 => q{OFPPR_ADD},
351 0x01 => q{OFPPR_DELETE},
352 0x02 => q{OFPPR_MODIFY},
353 },
354 };
355  
356 $ofp_enums->{'ofp_port_state'} = {
357 bitfield => q{},
358 0x01 => {
359 (1 << 0) => q{OFPPS_LINK_DOWN},
360 (0 << 8) => q{OFPPS_STP_LISTEN},
361 (1 << 8) => q{OFPPS_STP_LEARN},
362 (2 << 8) => q{OFPPS_STP_FORWARD},
363 (3 << 8) => q{OFPPS_STP_BLOCK},
364 (4 << 8) => q{OFPPS_STP_MASK},
365 },
366 };
367  
368 $ofp_enums->{'ofp_queue_op_failed_code'} = {
369 0x01 => {
370 0x0000 => q{OFPQOFC_BAD_PORT},
371 0x0001 => q{OFPQOFC_BAD_QUEUE},
372 0x0002 => q{OFPQOFC_EPERM},
373 },
374 };
375  
376 $ofp_enums->{'ofp_queue_properties'} = {
377 0x01 => {
378 0x00 => q{OFPQT_NONE},
379 0x01 => q{OFPQT_MIN_RATE},
380 },
381 };
382  
383 $ofp_enums->{'ofp_stats_req_flags'} = {
384 bitfield => q{},
385 0x01 => {
386 (1 << 0) => q{OFPSF_REPLY_MORE},
387 },
388 };
389  
390 $ofp_enums->{'ofp_stats_types'} = {
391 0x01 => {
392 0x0000 => q{OFPST_DESC},
393 0x0001 => q{OFPST_FLOW},
394 0x0002 => q{OFPST_AGGREGATE},
395 0x0003 => q{OFPST_TABLE},
396 0x0004 => q{OFPST_PORT},
397 0x0005 => q{OFPST_QUEUE},
398 0xffff => q{OFPST_VENDOR},
399 },
400 0x02 => {
401 0x0000 => q{OFPST_DESC},
402 0x0001 => q{OFPST_FLOW},
403 0x0002 => q{OFPST_AGGREGATE},
404 0x0003 => q{OFPST_TABLE},
405 0x0004 => q{OFPST_PORT},
406 0x0005 => q{OFPST_QUEUE},
407 0x0006 => q{OFPST_GROUP},
408 0x0007 => q{OFPST_GROUP_DESC},
409 0xffff => q{OFPST_EXPERIMENTER},
410 },
411 };
412  
413 $ofp_enums->{ofp_switch_config_failed_code} = {
414 0x02 => {
415 0x00 => q{OFPSCFC_BAD_FLAGS},
416 0x01 => q{OFPSCFC_BAD_LEN},
417 },
418 };
419  
420 $ofp_enums->{'ofp_table_mod_failed_code'} = {
421 0x02 => {
422 0x00 => q{OFPTMFC_BAD_TABLE},
423 0x01 => q{OFPTMFC_BAD_CONFIG},
424 },
425 };
426  
427 $ofp_enums->{'ofp_type'} = {
428 0x01 => {
429 0x00 => q{OFPT_HELLO},
430 0x01 => q{OFPT_ERROR},
431 0x02 => q{OFPT_ECHO_REQUEST},
432 0x03 => q{OFPT_ECHO_REPLY},
433 0x04 => q{OFPT_VENDOR},
434 0x05 => q{OFPT_FEATURES_REQUEST},
435 0x06 => q{OFPT_FEATURES_REPLY},
436 0x07 => q{OFPT_GET_CONFIG_REQUEST},
437 0x08 => q{OFPT_GET_CONFIG_REPLY},
438 0x09 => q{OFPT_SET_CONFIG},
439 0x0a => q{OFPT_PACKET_IN},
440 0x0b => q{OFPT_FLOW_REMOVED},
441 0x0c => q{OFPT_PORT_STATUS},
442 0x0d => q{OFPT_PACKET_OUT},
443 0x0e => q{OFPT_FLOW_MOD},
444 0x0f => q{OFPT_PORT_MOD},
445 0x10 => q{OFPT_STATS_REQUEST},
446 0x11 => q{OFPT_STATS_REPLY},
447 0x12 => q{OFPT_BARRIER_REQUEST},
448 0x13 => q{OFPT_BARRIER_REPLY},
449 0x14 => q{OFPT_QUEUE_GET_CONFIG_REQUEST},
450 0x15 => q{OFPT_QUEUE_GET_CONFIG_REPLY},
451 },
452 0x02 => {
453 0x00 => q{OFPT_HELLO},
454 0x01 => q{OFPT_ERROR},
455 0x02 => q{OFPT_ECHO_REQUEST},
456 0x03 => q{OFPT_ECHO_REPLY},
457 0x04 => q{OFPT_EXPERIMENTER},
458 0x05 => q{OFPT_FEATURES_REQUEST},
459 0x06 => q{OFPT_FEATURES_REPLY},
460 0x07 => q{OFPT_GET_CONFIG_REQUEST},
461 0x08 => q{OFPT_GET_CONFIG_REPLY},
462 0x09 => q{OFPT_SET_CONFIG},
463 0x0a => q{OFPT_PACKET_IN},
464 0x0b => q{OFPT_FLOW_REMOVED},
465 0x0c => q{OFPT_PORT_STATUS},
466 0x0d => q{OFPT_PACKET_OUT},
467 0x0e => q{OFPT_FLOW_MOD},
468 0x0f => q{OFPT_GROUP_MOD},
469 0x10 => q{OFPT_PORT_MOD},
470 0x11 => q{OFPT_TABLE_MOD},
471 0x12 => q{OFPT_STATS_REQUEST},
472 0x13 => q{OFPT_STATS_REPLY},
473 0x14 => q{OFPT_BARRIER_REQUEST},
474 0x15 => q{OFPT_BARRIER_REPLY},
475 0x16 => q{OFPT_QUEUE_GET_CONFIG_REQUEST},
476 0x17 => q{OFPT_QUEUE_GET_CONFIG_REPLY},
477 },
478 };
479  
480 my $struct_types = {
481 ofp_header => {
482 0x01 => {
483 format => q{C C n N},
484 length => 8,
485 },
486 },
487 ofp_match => {
488 0x01 => {
489 format => q{N n H12 H12 n C x n C C x2 N N n n},
490 length => 40,
491 },
492 0x02 => {
493 format => q{n n N N H12 H12 H12 H12 n C x n C C N N N N n n N C x Q> Q>},
494 length => 88,
495 },
496 },
497 };
498  
499 our $header_length = __PACKAGE__->struct_sizeof(0x01, q{ofp_header});
500  
501 $struct_types->{'ofp_action_dl_addr'}{0x01} = {
502 format => q{n H12 x6},
503 length => 16,
504 };
505  
506 $struct_types->{'ofp_action_enqueue'}{0x01} = {
507 format => q{n n n x6 N},
508 length => 16,
509 };
510  
511 $struct_types->{'ofp_action_header'}{0x01} = {
512 format => q{n n x4},
513 length => 8,
514 };
515  
516 $struct_types->{'ofp_action_nw_addr'}{0x01} = {
517 format => q{n n N},
518 length => 8,
519 };
520  
521 $struct_types->{'ofp_action_nw_tos'}{0x01} = {
522 format => q{n n C C3},
523 length => 8,
524 };
525  
526 $struct_types->{'ofp_action_output'}{0x01} = {
527 format => q{n n n n},
528 length => 8,
529 };
530  
531 $struct_types->{'ofp_action_tp_port'}{0x01} = {
532 format => q{n n n C2},
533 length => 8,
534 };
535  
536 $struct_types->{'ofp_action_vendor_header'}{0x01} = {
537 format => q{n n N},
538 length => 8,
539 };
540  
541 $struct_types->{'ofp_action_vlan_pcp'}{0x01} = {
542 format => q{n n C x3},
543 length => 8,
544 };
545  
546 $struct_types->{'ofp_action_vlan_vid'}{0x01} = {
547 format => q{n n n x2},
548 length => 8,
549 };
550  
551 $struct_types->{'ofp_desc_stats'}{0x01} = {
552 format => q{Z256 Z256 Z256 Z32 Z256},
553 length => 1056,
554 };
555  
556 $struct_types->{'ofp_error_msg'}{0x01} = {
557 format => qq/(a$header_length) n n/,
558 length => 12,
559 };
560  
561 $struct_types->{'ofp_flow_mod'} = {
562 0x01 => {
563 format => qq/(a$header_length) (a$struct_types->{'ofp_match'}{0x01}{'length'}) Q> n n n n N n n/,
564 length => 72,
565 },
566 };
567  
568 $struct_types->{'ofp_flow_stats'} = {
569 0x01 => {
570 format => qq/n C x (a$struct_types->{'ofp_match'}{0x01}{'length'}) N N n n n x6 Q> Q> Q>/,
571 length => 88,
572 },
573 };
574  
575 $struct_types->{'ofp_flow_stats_request'} = {
576 0x01 => {
577 format => qq/(a$struct_types->{'ofp_match'}{0x01}{'length'}) C x n/,
578 length => 44,
579 },
580 };
581  
582 $struct_types->{'ofp_packet_in'}{0x01} = {
583 format => qq/(a$header_length) N n n C x/,
584 length => 20,
585 };
586  
587 $struct_types->{'ofp_packet_out'}{0x01} = {
588 format => qq/(a$header_length) N n n/,
589 length => 16,
590 };
591  
592 $struct_types->{'ofp_packet_queue'}{0x01} = {
593 format => q/N n x2/,
594 length => 8,
595 };
596  
597 $struct_types->{'ofp_phy_port'}{0x01} = {
598 format => q{n H12 A16 N N N N N N},
599 length => 48,
600 };
601  
602 $struct_types->{'ofp_port_mod'}{0x01} = {
603 format => qq/(a$header_length) n H12 N N N x4/,
604 length => 32,
605 };
606  
607 $struct_types->{'ofp_port_stats'}{0x01} = {
608 format => q{n x6 Q>12},
609 length => 104,
610 };
611  
612 $struct_types->{'ofp_port_stats_request'}{0x01} = {
613 format => q{n x6},
614 length => 8,
615 };
616  
617 $struct_types->{'ofp_port_status'}{0x01} = {
618 format => qq/(a$header_length) C x7 a48/,
619 length => 64,
620 };
621  
622 $struct_types->{'ofp_queue_get_config_reply'}{0x01} = {
623 format => qq/(a$header_length) n x6/,
624 length => 16,
625 };
626  
627 $struct_types->{'ofp_queue_get_config_request'}{0x01} = {
628 format => qq/(a$header_length) n x2/,
629 length => 12,
630 };
631  
632 $struct_types->{'ofp_queue_prop_header'}{0x01} = {
633 format => q{n n x4},
634 length => 8,
635 };
636  
637 $struct_types->{'ofp_queue_prop_min_rate'}{0x01} = {
638 format => q{n x6},
639 length => 16,
640 };
641  
642 $struct_types->{'ofp_stats_reply'}{0x01} = {
643 format => qq/(a$header_length) n n/,
644 length => 12,
645 };
646  
647 $struct_types->{'ofp_stats_request'}{0x01} = {
648 format => qq/(a$header_length) n n/,
649 length => 12,
650 };
651  
652 $struct_types->{'ofp_switch_config'}{0x01} = {
653 format => qq/(a$header_length) n n/,
654 length => 12,
655 };
656  
657 $struct_types->{'ofp_switch_features'}{0x01} = {
658 format => qq/(a$header_length) H16 N C x3 N N/,
659 length => 32,
660 };
661  
662 $struct_types->{'ofp_table_stats'}{0x01} = {
663 format => q/C x3 a32 N N N Q> Q>/,
664 length => 64,
665 };
666  
667 $struct_types->{'ofp_experimenter_header'} = {
668 0x02 => {
669 format => qq/(a$header_length) N x4/,
670 length => 16,
671 },
672 };
673  
674 =item C<< bitfield_decode >>
675  
676 This function will decode the bitfield specified by $bitfield into the $enum_type.
677  
678 my $ret = $ofp->bitfield_decode($of_version, $enum_type, $bitfield);
679  
680 =cut
681  
682 sub bitfield_decode($$$$) {
683 my $self = shift;
684 my ($version, $enum_type, $bitfield) = @_;
685  
686 unless (
687 defined($ofp_enums->{$enum_type}{$version})
688 and
689 (ref($ofp_enums->{$enum_type}{$version}) eq q{HASH})
690 and
691 defined($ofp_enums->{$enum_type}{'bitfield'})
692 ) {
693 croak qq{Invalid bitfield type [$version][$enum_type]};
694 }
695  
696 my $ret = [];
697  
698 foreach my $enum (sort {$a <=> $b} keys(%{$ofp_enums->{$enum_type}{$version}})) {
699 if (($bitfield & $enum) == $enum) {
700 push @{$ret}, $ofp_enums->{$enum_type}{$version}{$enum};
701 }
702 }
703  
704 return $ret;
705 }
706  
707 =item C<< bitfield_encode >>
708  
709 This function will encode bits specified into the bitfield $enum_type.
710  
711 my $ret = $ofp->bitfield_encode($of_version, $enum_type, $bits);
712  
713 =cut
714  
715 sub bitfield_encode($$$$) {
716 my $self = shift;
717 my ($version, $enum_type, $bits) = @_;
718  
719 unless (
720 defined($ofp_enums->{$enum_type}{$version})
721 and
722 (ref($ofp_enums->{$enum_type}{$version}) eq q{HASH})
723 and
724 defined($ofp_enums->{$enum_type}{'bitfield'})
725 ) {
726 croak qq{Invalid bitfield type [$version][$enum_type]};
727 }
728  
729 my $ret = 0;
730  
731 foreach my $enum (keys %{$ofp_enums->{$enum_type}{$version}}) {
732 foreach (@{$bits}) {
733 if ($_ eq $ofp_enums->{$enum_type}{$version}{$enum}) {
734 $ret |= $enum;
735 last;
736 }
737 }
738 }
739  
740 return $ret;
741 }
742  
743 =item C<< enum_lookup >>
744  
745 This function will
746  
747 my $ret = $ofp->enum_lookup($of_version, $enum_type, $lookup);
748  
749 =cut
750  
751 sub enum_lookup($$$$) {
752 my $self = shift;
753 my ($version, $enum_type, $lookup) = @_;
754  
755 unless (defined($ofp_enums->{$enum_type}{$version}) and (ref($ofp_enums->{$enum_type}{$version}) eq q{HASH})) {
756 croak qq{Invalid enum type [$version][$enum_type]};
757 }
758  
759 my $ret;
760  
761 $ret = $ofp_enums->{$enum_type}{$version}{$lookup};
762  
763 return $ret;
764 }
765  
766 =item C<< enum_lookup__by_value >>
767  
768 This function will
769  
770 my $ret = $ofp->enum_lookup__by_value($of_version, $enum_type, $lookup);
771  
772 =cut
773  
774 sub enum_lookup__by_value($$$$) {
775 my $self = shift;
776 my ($version, $enum_type, $lookup) = @_;
777  
778 unless (defined($ofp_enums->{$enum_type}{$version}) and (ref($ofp_enums->{$enum_type}{$version}) eq q{HASH})) {
779 croak qq{Invalid enum type [$version][$enum_type]};
780 }
781  
782 my @sorted_enum = sort {$a <=> $b} keys(%{$ofp_enums->{$enum_type}{$version}});
783  
784 my $ret;
785  
786 foreach (@sorted_enum) {
787 if ($ofp_enums->{$enum_type}{$version}{$_} eq $lookup) {
788 $ret = $_;
789 last;
790 }
791 }
792  
793 return $ret;
794 }
795  
796 =item C<< new >>
797  
798 This is the constructor for the Net::OpenFlow::Protocol module.
799  
800 my $ofp = Net::OpenFlow::Protocol->new;
801  
802 =cut
803  
804 sub new {
805 my $class = shift;
806  
807 my $self = {};
808  
809 bless $self, $class;
810  
811 $self->new_init(@_);
812  
813 return $self;
814 }
815  
816 sub new_init {
817 my $self = shift;
818 }
819  
820 =item C<< ofpt_decode >>
821  
822 This function decodes OpenFlow messages.
823 The input is a reference to a scalar containing the OpenFlow message.
824 The returned value is a hash reference containing the decoded message parameters.
825 This always contains a ofp_header hash in the returned value which will have a type describing the message received.
826 Based on this value the other parameters may be interpreted.
827  
828 my $ret = $ofp->ofpt_decode(\$of_message);
829  
830 my $of_message_type = $ret->{'ofp_header'}{'type'};
831  
832 =cut
833  
834 sub ofpt_decode($$) {
835 my $self = shift;
836 my $message = shift;
837  
838 unless (defined($message) and (ref($message) eq q{SCALAR})) {
839 croak q{Invalid OFPT message};
840 }
841  
842 my ($pdu_version, $pdu_type) = unpack(q{C C}, ${$message});
843  
844 unless ($pdu_version) {
845 croak $self->__debug($self->__hex_preview(${$message}, 32));
846 }
847  
848 $pdu_type = $self->enum_lookup($pdu_version, q{ofp_type}, $pdu_type);
849  
850 my $ret = {};
851  
852 if ($pdu_type eq q{OFPT_BARRIER_REPLY}) {
853 $ret->{'ofp_header'} = $self->struct_decode__ofp_header($message);
854 $ret->{'ofp_header'}{'type'} = $pdu_type;
855 }
856 elsif ($pdu_type eq q{OFPT_BARRIER_REQUEST}) {
857 # N/A - Controller -> Datapath
858 }
859 elsif ($pdu_type eq q{OFPT_ECHO_REPLY}) {
860 $ret->{'ofp_header'} = $self->struct_decode__ofp_header($message);
861 $ret->{'ofp_header'}{'type'} = $pdu_type;
862  
863 $self->struct_chomp($pdu_version, q{ofp_header}, $message);
864 $ret->{'body'} = ${$message};
865 }
866 elsif ($pdu_type eq q{OFPT_ECHO_REQUEST}) {
867 $ret->{'ofp_header'} = $self->struct_decode__ofp_header($message);
868 $ret->{'ofp_header'}{'type'} = $pdu_type;
869  
870 $self->struct_chomp($pdu_version, q{ofp_header}, $message);
871 $ret->{'body'} = ${$message};
872 }
873 elsif ($pdu_type eq q{OFPT_ERROR}) {
874 my $struct_values = $self->struct_decode($pdu_version, q{ofp_error_msg}, $message);
875 my $pdu_length = $self->struct_chomp($pdu_version, q{ofp_error_msg}, $message);
876  
877 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
878 $ret->{'ofp_header'}{'type'} = $pdu_type;
879  
880 my $ofpet = $self->enum_lookup($pdu_version, q{ofp_error_type}, $struct_values->[1]);
881 $ret->{'type'} = $ofpet;
882  
883 if ($ofpet eq q{OFPET_HELLO_FAILED}) {
884 $ret->{'code'} = $self->enum_lookup($pdu_version, q{ofp_hello_failed_code}, $struct_values->[2]);
885 }
886 elsif ($ofpet eq q{OFPET_BAD_REQUEST}) {
887 $ret->{'code'} = $self->enum_lookup($pdu_version, q{ofp_bad_request_code}, $struct_values->[2]);
888 }
889 elsif ($ofpet eq q{OFPET_BAD_ACTION}) {
890 $ret->{'code'} = $self->enum_lookup($pdu_version, q{ofp_bad_action_code}, $struct_values->[2]);
891 }
892 elsif ($ofpet eq q{OFPET_FLOW_MOD_FAILED}) {
893 $ret->{'code'} = $self->enum_lookup($pdu_version, q{ofp_flow_mod_failed_code}, $struct_values->[2]);
894 }
895 elsif ($ofpet eq q{OFPET_PORT_MOD_FAILED}) {
896 $ret->{'code'} = $self->enum_lookup($pdu_version, q{ofp_port_mod_fail_code}, $struct_values->[2]);
897 }
898 elsif ($ofpet eq q{OFPET_QUEUE_OP_FAILED}) {
899 $ret->{'code'} = $self->enum_lookup($pdu_version, q{ofp_queue_op_failed_code}, $struct_values->[2]);
900 }
901 else {
902 $ret->{'code'} = $struct_values->[2];
903 }
904  
905 if ($pdu_length) {
906 $ret->{'data'} = ${$message};
907 }
908 }
909 elsif ($pdu_type eq q{OFPT_FEATURES_REPLY}) {
910 my $struct_values = $self->struct_decode($pdu_version, q{ofp_switch_features}, $message);
911  
912 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
913 $ret->{'ofp_header'}{'type'} = $pdu_type;
914  
915 $ret->{'datapath_id'} = $self->__format_pretty__hex_string($struct_values->[1]);
916 $ret->{'n_buffers'} = $struct_values->[2];
917 $ret->{'n_tables'} = $struct_values->[3];
918 $ret->{'capabilities'} = $struct_values->[4];
919 $ret->{'actions'} = $struct_values->[5];
920  
921 my $pdu_length = $self->struct_chomp($pdu_version, q{ofp_switch_features}, $message);
922  
923 if (($pdu_length % $self->struct_sizeof($pdu_version, q{ofp_phy_port})) == 0) {
924 while($pdu_length) {
925 push @{$ret->{'body'}}, $self->struct_decode__ofp_phy_port($pdu_version, $message);
926  
927 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_phy_port}, $message);
928 }
929 }
930 else {
931 carp qq{Bad format packet};
932 }
933 }
934 elsif ($pdu_type eq q{OFPT_FEATURES_REQUEST}) {
935 # N/A - Controller -> Datapath
936 }
937 elsif ($pdu_type eq q{OFPT_FLOW_MOD}) {
938 # N/A - Controller -> Datapath
939 }
940 elsif ($pdu_type eq q{OFPT_FLOW_REMOVED}) {
941 my $struct_values = $self->struct_decode($pdu_version, q{ofp_flow_removed}, $message);
942  
943 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
944 $ret->{'ofp_header'}{'type'} = $pdu_type;
945  
946 $ret->{'match'} = $self->struct_decode__ofp_match($pdu_version, \$struct_values->[1]);
947 $ret->{'cookie'} = $struct_values->[2];
948 $ret->{'priority'} = $struct_values->[3];
949 $ret->{'reason'} = $self->enum_lookup($pdu_version, q{ofp_flow_removed_reason}, $struct_values->[4]);
950 $ret->{'duation_sec'} = $struct_values->[5];
951 $ret->{'duation_nsec'} = $struct_values->[6];
952 $ret->{'idle_timeout'} = $struct_values->[7];
953 $ret->{'packet_count'} = $struct_values->[8];
954 $ret->{'byte_count'} = $struct_values->[9];
955 }
956 elsif ($pdu_type eq q{OFPT_GET_CONFIG_REPLY}) {
957 my $struct_values = $self->struct_decode($pdu_version, q{ofp_switch_config}, $message);
958  
959 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
960 $ret->{'ofp_header'}{'type'} = $pdu_type;
961  
962 $ret->{'flags'} = $struct_values->[1];
963 $ret->{'miss_send_len'} = $struct_values->[2];
964 }
965 elsif ($pdu_type eq q{OFPT_GET_CONFIG_REQUEST}) {
966 # N/A - Controller -> Datapath
967 }
968 elsif ($pdu_type eq q{OFPT_HELLO}) {
969 $ret = $self->struct_decode__ofp_header($message);
970 $ret->{'type'} = $pdu_type;
971 }
972 elsif ($pdu_type eq q{OFPT_PACKET_IN}) {
973 my $struct_values = $self->struct_decode($pdu_version, q{ofp_packet_in}, $message);
974  
975 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
976 $ret->{'ofp_header'}{'type'} = $pdu_type;
977  
978 $ret->{'buffer_id'} = $struct_values->[1];
979 $ret->{'total_len'} = $struct_values->[2];
980 $ret->{'in_port'} = $struct_values->[3];
981 $ret->{'reason'} = $struct_values->[4];
982 }
983 elsif ($pdu_type eq q{OFPT_PACKET_OUT}) {
984 # N/A - Controller -> Datapath
985 }
986 elsif ($pdu_type eq q{OFPT_PORT_MOD}) {
987 # N/A - Controller -> Datapath
988 }
989 elsif ($pdu_type eq q{OFPT_PORT_STATUS}) {
990 my $struct_values = $self->struct_decode($pdu_version, q{ofp_port_status}, $message);
991  
992 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
993 $ret->{'ofp_header'}{'type'} = $pdu_type;
994  
995 $ret->{'reason'} = $struct_values->[1];
996 $ret->{'ofp_phy_port'} = $self->struct_decode__ofp_phy_port($pdu_version, \$struct_values->[2]);
997 }
998 elsif ($pdu_type eq q{OFPT_QUEUE_GET_CONFIG_REPLY}) {
999 my $struct_values = $self->struct_decode($pdu_version, q{ofp_queue_get_config_reply}, $message);
1000 my $pdu_length = $self->struct_chomp($pdu_version, q{ofp_queue_get_config_reply}, $message);
1001  
1002 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
1003 $ret->{'ofp_header'}{'type'} = $pdu_type;
1004  
1005 $ret->{'port'} = $struct_values->[1];
1006  
1007 while ($pdu_length >= $self->struct_sizeof($pdu_version, q{ofp_packet_queue})) {
1008 my $struct_values = $self->struct_decode($pdu_version, q{ofp_packet_queue}, $message);
1009 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_packet_queue}, $message);
1010  
1011 $ret->{'queue_id'} = $struct_values->[0];
1012  
1013 my $remaining_bytes = ($struct_values->[1] - $self->struct_sizeof($pdu_version, q{ofp_packet_queue}));
1014  
1015 my $properties = [];
1016  
1017 if (($remaining_bytes % $self->struct_sizeof($pdu_version, q{ofp_queue_prop_header})) == 0) {
1018 # while ($remaining_bytes) {
1019 # }
1020 }
1021 else {
1022 }
1023 }
1024 }
1025 elsif ($pdu_type eq q{OFPT_QUEUE_GET_CONFIG_REQUEST}) {
1026 # N/A - Controller -> Datapath
1027 }
1028 elsif ($pdu_type eq q{OFPT_SET_CONFIG} ){
1029 # N/A - Controller -> Datapath
1030 }
1031 elsif ($pdu_type eq q{OFPT_STATS_REQUEST}) {
1032 # N/A - Controller -> Datapath
1033 }
1034 elsif ($pdu_type eq q{OFPT_STATS_REPLY}) {
1035 my $struct_values = $self->struct_decode($pdu_version, q{ofp_stats_reply}, $message);
1036 my $pdu_length = $self->struct_chomp($pdu_version, q{ofp_stats_reply}, $message);
1037  
1038 $ret->{'ofp_header'} = $self->struct_decode__ofp_header(\$struct_values->[0]);
1039 $ret->{'ofp_header'}{'type'} = $pdu_type;
1040  
1041 my $ofpst = $self->enum_lookup($pdu_version, q{ofp_stats_types}, $struct_values->[1]);
1042  
1043 $ret->{'type'} = $ofpst;
1044 $ret->{'flags'} = $struct_values->[2];
1045  
1046 if ($ofpst eq q{OFPST_DESC}) {
1047 if (($pdu_length % $self->struct_sizeof($pdu_version, q{ofp_desc_stats})) == 0) {
1048 while ($pdu_length) {
1049 my $struct_values = $self->struct_decode($pdu_version, q{ofp_desc_stats}, $message);
1050 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_desc_stats}, $message);
1051  
1052 push @{$ret->{'body'}}, {
1053 q{mfr_desc} => $struct_values->[0],
1054 q{hw_desc} => $struct_values->[1],
1055 q{sw_desc} => $struct_values->[2],
1056 q{serial_num} => $struct_values->[3],
1057 q{dp_desc} => $struct_values->[4],
1058 };
1059 }
1060 }
1061 else {
1062 }
1063 }
1064 elsif ($ofpst eq q{OFPST_FLOW}) {
1065 while ($pdu_length >= $self->struct_sizeof($pdu_version, q{ofp_flow_stats})) {
1066 my $struct_values = $self->struct_decode($pdu_version, q{ofp_flow_stats}, $message);
1067 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_flow_stats}, $message);
1068  
1069 my $remaining_bytes = ($struct_values->[0] - $self->struct_sizeof($pdu_version, q{ofp_flow_stats}));
1070  
1071 my $actions = [];
1072  
1073 if (($remaining_bytes % $self->struct_sizeof($pdu_version, q{ofp_action_header})) == 0) {
1074 while ($remaining_bytes) {
1075 my ($action_type, $action_length) = unpack(q{n n}, ${$message});
1076 $action_type = $self->enum_lookup($pdu_version, q{ofp_action_type}, $action_type);
1077  
1078 my $action = {
1079 q{type} => $action_type,
1080 length => $action_length
1081 };
1082  
1083 if ($action_type eq q{OFPAT_OUTPUT}) {
1084 my $ofp_action_output = $self->struct_decode($pdu_version, q{ofp_action_output}, $message);
1085 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_output}, $message);
1086  
1087 $action->{'port'} = $ofp_action_output->[2];
1088 $action->{'max_len'} = $ofp_action_output->[3];
1089 }
1090 elsif ($action_type eq q{OFPAT_SET_VLAN_VID}) {
1091 my $ofp_action_vlan_vid = $self->struct_decode($pdu_version, q{ofp_action_vlan_vid}, $message);
1092 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_vlan_vid}, $message);
1093  
1094 $action->{'vlan_vid'} = $ofp_action_vlan_vid->[2];
1095 }
1096 elsif ($action_type eq q{OFPAT_SET_VLAN_PCP}) {
1097 my $ofp_action_vlan_pcp = $self->struct_decode($pdu_version, q{ofp_action_vlan_pcp}, $message);
1098 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_vlan_pcp}, $message);
1099  
1100 $action->{'vlan_pcp'} = $ofp_action_vlan_pcp->[2];
1101 }
1102 elsif ($action_type eq q{OFPAT_STRIP_VLAN}) {
1103 }
1104 elsif ($action_type eq q{OFPAT_SET_DL_SRC}) {
1105 my $ofp_action_dl_addr = $self->struct_decode($pdu_version, q{ofp_action_dl_addr}, $message);
1106 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_dl_addr}, $message);
1107  
1108 $action->{'dl_addr'} = $self->__format_pretty__hex_string($ofp_action_dl_addr->[2]);
1109 }
1110 elsif ($action_type eq q{OFPAT_SET_DL_DST}) {
1111 my $ofp_action_dl_addr = $self->struct_decode($pdu_version, q{ofp_action_dl_addr}, $message);
1112 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_dl_addr}, $message);
1113  
1114 $action->{'dl_addr'} = $self->__format_pretty__hex_string($ofp_action_dl_addr->[2]);
1115 }
1116 elsif ($action_type eq q{OFPAT_SET_NW_SRC}) {
1117 my $ofp_action_nw_addr = $self->struct_decode($pdu_version, q{ofp_action_nw_addr}, $message);
1118 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_nw_addr}, $message);
1119  
1120 $action->{'nw_addr'} = $ofp_action_nw_addr->[2];
1121 }
1122 elsif ($action_type eq q{OFPAT_SET_NW_DST}) {
1123 my $ofp_action_nw_addr = $self->struct_decode($pdu_version, q{ofp_action_nw_addr}, $message);
1124 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_nw_addr}, $message);
1125  
1126 $action->{'nw_addr'} = $ofp_action_nw_addr->[2];
1127 }
1128 elsif ($action_type eq q{OFPAT_SET_NW_TOS}) {
1129 my $ofp_action_nw_tos = $self->struct_decode($pdu_version, q{ofp_action_nw_tos}, $message);
1130 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_nw_tos}, $message);
1131  
1132 $action->{'nw_tos'} = $ofp_action_nw_tos->[2];
1133 }
1134 elsif ($action_type eq q{OFPAT_SET_TP_SRC}) {
1135 my $ofp_action_tp_port = $self->struct_decode($pdu_version, q{ofp_action_tp_port}, $message);
1136 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_tp_port}, $message);
1137  
1138 $action->{'tp_port'} = $ofp_action_tp_port->[2];
1139 }
1140 elsif ($action_type eq q{OFPAT_SET_TP_DST}) {
1141 my $ofp_action_tp_port = $self->struct_decode($pdu_version, q{ofp_action_tp_port}, $message);
1142 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_tp_port}, $message);
1143  
1144 $action->{'tp_port'} = $ofp_action_tp_port->[2];
1145 }
1146 elsif ($action_type eq q{OFPAT_ENQUEUE}) {
1147 my $ofp_action_enqueue = $self->struct_decode($pdu_version, q{ofp_action_enqueue}, $message);
1148 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_enqueue}, $message);
1149  
1150 $action->{'port'} = $ofp_action_enqueue->[2];
1151 $action->{'queue_id'} = $ofp_action_enqueue->[3];
1152 }
1153 elsif ($action_type eq q{OFPAT_VENDOR}) {
1154 my $ofp_action_vendor = $self->struct_decode($pdu_version, q{ofp_action_vendor}, $message);
1155 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_action_vendor}, $message);
1156 }
1157 else {
1158 }
1159  
1160 push @{$actions}, $action;
1161  
1162 $remaining_bytes -= $action_length;
1163 }
1164 }
1165  
1166 push @{$ret->{'body'}}, {
1167 length => $struct_values->[0],
1168 table_id => $struct_values->[1],
1169 match => $self->struct_decode__ofp_match($pdu_version, \$struct_values->[2]),
1170 duration_sec => $struct_values->[3],
1171 duration_nsec => $struct_values->[4],
1172 priority => $struct_values->[5],
1173 idle_timeout => $struct_values->[6],
1174 hard_timeout => $struct_values->[7],
1175 cookie => $struct_values->[8],
1176 packet_count => $struct_values->[9],
1177 byte_count => $struct_values->[10],
1178 actions => $actions,
1179 };
1180 }
1181 }
1182 elsif ($ofpst eq q{OFPST_TABLE}) {
1183 if (($pdu_length % $self->struct_sizeof($pdu_version, q{ofp_table_stats})) == 0) {
1184 while ($pdu_length) {
1185 my $struct_values = $self->struct_decode($pdu_version, q{ofp_table_stats}, $message);
1186 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_table_stats}, $message);
1187  
1188 push @{$ret->{'body'}}, {
1189 table_id => $struct_values->[0],
1190 name => $struct_values->[1],
1191 wildcards => $struct_values->[2],
1192 max_entries => $struct_values->[3],
1193 active_count => $struct_values->[4],
1194 lookup_count => $struct_values->[5],
1195 matched_count => $struct_values->[6],
1196 };
1197 }
1198 }
1199 else {
1200 }
1201 }
1202 elsif ($ofpst eq q{OFPST_PORT}) {
1203 if (($pdu_length % $self->struct_sizeof($pdu_version, q{ofp_port_stats})) == 0) {
1204 while ($pdu_length) {
1205 my $struct_values = $self->struct_decode($pdu_version, q{ofp_port_stats}, $message);
1206 $pdu_length = $self->struct_chomp($pdu_version, q{ofp_port_stats}, $message);
1207  
1208 push @{$ret->{'body'}}, {
1209 port_no => $struct_values->[0],
1210 rx_packets => $struct_values->[1],
1211 tx_packets => $struct_values->[2],
1212 rx_bytes => $struct_values->[3],
1213 tx_bytes => $struct_values->[4],
1214 rx_dropped => $struct_values->[5],
1215 tx_dropped => $struct_values->[6],
1216 rx_errors => $struct_values->[7],
1217 tx_errors => $struct_values->[8],
1218 rx_frame_err => $struct_values->[9],
1219 rx_over_err => $struct_values->[10],
1220 rx_crc_err => $struct_values->[11],
1221 collisions => $struct_values->[12],
1222 };
1223 }
1224 }
1225 else {
1226 }
1227 }
1228 else {
1229 carp qq{Invalid OFPST type [$ofpst]};
1230 }
1231 }
1232 elsif ($pdu_type eq q{OFPT_VENDOR}) {
1233 }
1234 else {
1235 carp qq{Invalid type [$pdu_version][$pdu_type]};
1236 }
1237  
1238 return $ret;
1239 }
1240  
1241 =item C<< ofpt_encode >>
1242  
1243 This function encodes OpenFlow messages.
1244 The inputs are the OpenFlow protocol version, the type of message to be encoded, the xid, arguements to the type of message and any message body.
1245 The struct_args are the members of the relevant OpenFlow struct. THe struct_body is any optional payload that will be attached to the message.
1246  
1247 my $ret = $ofp->ofpt_encode($of_version, $of_type, $xid, $struct_args, $struct_body);
1248  
1249 =cut
1250  
1251 sub ofpt_encode($$$;$$) {
1252 my $self = shift;
1253 my ($version, $type, $xid, $struct_args, $struct_body) = @_;
1254  
1255 if (defined $struct_args) {
1256 unless (ref($struct_args) eq q{ARRAY}) {
1257 croak qq{Invalid struct args [$version][$type][$xid]};
1258 }
1259 }
1260  
1261 my $ret;
1262  
1263 my $ofp_type;
1264  
1265 if ($type =~ m{^\d+$}) {
1266 $ofp_type = $self->enum_lookup($version, q{ofp_type}, $type);
1267 }
1268 else {
1269 $ofp_type = $type;
1270  
1271 $type = $self->enum_lookup__by_value($version, q{ofp_type}, $ofp_type);
1272 }
1273  
1274 if ($ofp_type eq q{OFPT_HELLO}) {
1275 $ret = $self->struct_encode(
1276 $version,
1277 q{ofp_header},
1278 [
1279 $version,
1280 $type,
1281 $self->struct_sizeof($version, q{ofp_header}),
1282 $xid
1283 ]
1284 );
1285 }
1286 elsif ($ofp_type eq q{OFPT_ERROR}) {
1287 if (scalar(@{$struct_args}) == 2) {
1288 unshift @{$struct_args}, $self->struct_encode(
1289 $version,
1290 q{ofp_header},
1291 [
1292 $version,
1293 $type,
1294 ($self->struct_sizeof($version, q{ofp_error_msg}) + length(($struct_body // q{}))),
1295 $xid
1296 ]
1297 );
1298 }
1299  
1300 $ret = $self->struct_encode($version, q{ofp_error_msg}, @{$struct_args}, $struct_body);
1301 }
1302 elsif ($ofp_type eq q{OFPT_ECHO_REQUEST}) {
1303 $ret = $self->struct_encode(
1304 $version,
1305 q{ofp_header},
1306 [
1307 $version,
1308 $type,
1309 ($self->struct_sizeof($version, q{ofp_header}) + length(($struct_body // q{}))),
1310 $xid
1311 ],
1312 $struct_body,
1313 );
1314 }
1315 elsif ($ofp_type eq q{OFPT_ECHO_REPLY}) {
1316 $ret = $self->struct_encode(
1317 $version,
1318 q{ofp_header},
1319 [
1320 $version,
1321 $type,
1322 ($self->struct_sizeof($version, q{ofp_header}) + length(($struct_body // q{}))),
1323 $xid
1324 ],
1325 $struct_body,
1326 );
1327 }
1328 elsif ($ofp_type eq q{OFPT_VENDOR}) {
1329 }
1330 elsif ($ofp_type eq q{OFPT_FEATURES_REQUEST}) {
1331 $ret = $self->struct_encode(
1332 $version,
1333 q{ofp_header},
1334 [
1335 $version,
1336 $type,
1337 $self->struct_sizeof($version, q{ofp_header}),
1338 $xid
1339 ],
1340 );
1341 }
1342 elsif ($ofp_type eq q{OFPT_FEATURES_REPLY}) {
1343 # N/A
1344 }
1345 elsif ($ofp_type eq q{OFPT_GET_CONFIG_REQUEST}) {
1346 $ret = $self->struct_encode(
1347 $version,
1348 q{ofp_header},
1349 [
1350 $version,
1351 $type,
1352 $self->struct_sizeof($version, q{ofp_header}),
1353 $xid
1354 ]
1355 );
1356 }
1357 elsif ($ofp_type eq q{OFPT_GET_CONFIG_REPLY}) {
1358 # N/A
1359 }
1360 elsif ($ofp_type eq q{OFPT_SET_CONFIG}) {
1361 }
1362 elsif ($ofp_type eq q{OFPT_PACKET_IN}) {
1363 # N/A
1364 }
1365 elsif ($ofp_type eq q{OFPT_FLOW_REMOVED}) {
1366 # N/A
1367 }
1368 elsif ($ofp_type eq q{OFPT_PORT_STATUS}) {
1369 # N/A
1370 }
1371 elsif ($ofp_type eq q{OFPT_PACKET_OUT}) {
1372 if (scalar(@{$struct_args}) == 3) {
1373 unshift @{$struct_args}, $self->struct_encode(
1374 $version,
1375 q{ofp_header},
1376 [
1377 $version,
1378 $type,
1379 ($self->struct_sizeof($version, q{ofp_packet_out}) + length(($struct_body // q{}))),
1380 $xid
1381 ]
1382 );
1383 }
1384  
1385 $ret = $self->struct_encode($version, q{ofp_packet_out}, $struct_args, $struct_body);
1386 }
1387 elsif ($ofp_type eq q{OFPT_FLOW_MOD}) {
1388 if (scalar(@{$struct_args}) == 9) {
1389 unshift @{$struct_args}, $self->struct_encode(
1390 $version,
1391 q{ofp_header},
1392 [
1393 $version,
1394 $type,
1395 ($self->struct_sizeof($version, q{ofp_flow_mod}) + length(($struct_body // q{}))),
1396 $xid
1397 ]
1398 );
1399 }
1400  
1401 $ret = $self->struct_encode($version, q{ofp_flow_mod}, $struct_args, $struct_body);
1402 }
1403 elsif ($ofp_type eq q{OFPT_PORT_MOD}) {
1404 if (scalar(@{$struct_args}) == 5) {
1405 unshift @{$struct_args}, $self->struct_encode(
1406 $version,
1407 q{ofp_header},
1408 [
1409 $version,
1410 $type,
1411 ($self->struct_sizeof($version, q{ofp_port_mod}) + length(($struct_body // q{}))),
1412 $xid
1413 ]
1414 );
1415 }
1416  
1417 $ret = $self->struct_encode($version, q{ofp_port_mod}, $struct_args);
1418 }
1419 elsif ($ofp_type eq q{OFPT_STATS_REQUEST}) {
1420 if (scalar(@{$struct_args}) == 2) {
1421 unshift @{$struct_args}, $self->struct_encode(
1422 $version,
1423 q{ofp_header},
1424 [
1425 $version,
1426 $type,
1427 ($self->struct_sizeof($version, q{ofp_stats_request}) + length(($struct_body // q{}))),
1428 $xid
1429 ]
1430 );
1431 }
1432  
1433 $ret = $self->struct_encode($version, q{ofp_stats_request}, $struct_args, $struct_body);
1434 }
1435 elsif ($ofp_type eq q{OFPT_STATS_REPLY}) {
1436 # N/A
1437 }
1438 elsif ($ofp_type eq q{OFPT_BARRIER_REQUEST}) {
1439 $ret = $self->struct_encode(
1440 $version,
1441 q{ofp_header},
1442 [
1443 $version,
1444 $type,
1445 $self->struct_sizeof($version, q{ofp_header}),
1446 $xid
1447 ]
1448 );
1449 }
1450 elsif ($ofp_type eq q{OFPT_BARRIER_REPLY}) {
1451 # N/A
1452 }
1453 elsif ($ofp_type eq q{OFPT_QUEUE_GET_CONFIG_REQUEST}) {
1454 if (scalar(@{$struct_args}) == 1) {
1455 unshift @{$struct_args}, $self->struct_encode(
1456 $version,
1457 q{ofp_header},
1458 [
1459 $version,
1460 $type,
1461 $self->struct_sizeof($version, q{ofp_queue_get_config_request}),
1462 $xid
1463 ]
1464 );
1465 }
1466  
1467 $ret = $self->struct_encode($version, q{ofp_queue_get_config_request}, $struct_args);
1468 }
1469 elsif ($ofp_type eq q{OFPT_QUEUE_GET_CONFIG_REPLY}) {
1470 # N/A
1471 }
1472 else {
1473 croak qq{Invalid ofp type [$version][$ofp_type]};
1474 }
1475  
1476 return $ret;
1477 }
1478  
1479 sub struct_chomp($$$$) {
1480 my $self = shift;
1481 my ($version, $struct_type, $struct_data) = @_;
1482  
1483 my $struct_type__length = $self->struct_sizeof($version, $struct_type);
1484  
1485 ${$struct_data} = substr(${$struct_data}, $struct_type__length, (length(${$struct_data}) - $struct_type__length));
1486  
1487 my $ret = length(${$struct_data});
1488  
1489 return $ret;
1490 }
1491  
1492 sub struct_decode($$$$) {
1493 my $self = shift;
1494 my ($version, $struct_type, $struct_data) = @_;
1495  
1496 unless (defined($struct_types->{$struct_type}{$version}) and (ref($struct_types->{$struct_type}{$version}) eq q{HASH})) {
1497 croak qq{Invalid struct type [$version][$struct_type]};
1498 }
1499  
1500 unless (defined($struct_data) and (ref($struct_data) eq q{SCALAR})) {
1501 croak qq{Invalid struct data [$struct_type]};
1502 }
1503  
1504 my $ret;
1505  
1506 my $struct_data__length = length(${$struct_data});
1507 my $struct_type__length = $self->struct_sizeof($version, $struct_type);
1508  
1509 if ($struct_data__length >= $struct_type__length) {
1510 $ret = [unpack($struct_types->{$struct_type}{$version}{'format'}, ${$struct_data})];
1511 }
1512 else {
1513 croak qq{sizeof($struct_type) < $struct_type__length [$struct_data__length]};
1514 }
1515  
1516 return $ret;
1517 }
1518  
1519 sub struct_decode__ofp_header($$) {
1520 my $self = shift;
1521 my ($struct_data) = @_;
1522  
1523 my $ofp_header = $self->struct_decode(0x01, q{ofp_header}, $struct_data);
1524  
1525 my $ret = {
1526 version => $ofp_header->[0],
1527 type => $ofp_header->[1],
1528 length => $ofp_header->[2],
1529 xid => $ofp_header->[3],
1530 };
1531  
1532 return $ret;
1533 }
1534  
1535 sub struct_decode__ofp_match($$$) {
1536 my $self = shift;
1537 my ($version, $struct_data) = @_;
1538  
1539 my $ofp_match = $self->struct_decode($version, q{ofp_match}, $struct_data);
1540  
1541 my $ret;
1542  
1543 if ($version == 0x01) {
1544 $ret = {
1545 wildcards => $ofp_match->[0],
1546 in_port => $ofp_match->[1],
1547 dl_src => $self->__format_pretty__hex_string($ofp_match->[2]),
1548 dl_dst => $self->__format_pretty__hex_string($ofp_match->[3]),
1549 dl_vlan => $ofp_match->[4],
1550 dl_vlan_pcp => $ofp_match->[5],
1551 dl_type => sprintf(q{0x%0.4x}, $ofp_match->[6]),
1552 nw_tos => $ofp_match->[7],
1553 nw_proto => $ofp_match->[8],
1554 nw_src => $ofp_match->[9],
1555 nw_dst => $ofp_match->[10],
1556 tp_src => $ofp_match->[11],
1557 tp_dst => $ofp_match->[12],
1558 };
1559 }
1560 elsif ($version == 0x02) {
1561 $ret = {
1562 type => $ofp_match->[0],
1563 length => $ofp_match->[1],
1564 in_port => $ofp_match->[2],
1565 wildcards => $ofp_match->[3],
1566 dl_src => $self->__format_pretty__hex_string($ofp_match->[4]),
1567 dl_src_mask => $ofp_match->[5],
1568 dl_dst => $self->__format_pretty__hex_string($ofp_match->[6]),
1569 dl_dst_mask => $ofp_match->[7],
1570 dl_vlan => $ofp_match->[8],
1571 dl_vlan_pcp => $ofp_match->[9],
1572 dl_type => sprintf(q{0x%0.4x}, $ofp_match->[10]),
1573 nw_tos => $ofp_match->[11],
1574 nw_proto => $ofp_match->[12],
1575 nw_src => $ofp_match->[13],
1576 nw_src_mask => $ofp_match->[14],
1577 nw_dst => $ofp_match->[15],
1578 nw_dst_mask => $ofp_match->[16],
1579 tp_src => $ofp_match->[17],
1580 tp_dst => $ofp_match->[18],
1581 mpls_label => $ofp_match->[19],
1582 mpls_tc => $ofp_match->[20],
1583 metadata => $ofp_match->[21],
1584 metadata_mask => $ofp_match->[22],
1585 };
1586 }
1587 else {
1588 croak qq{Unsupported version [$version]};
1589 }
1590  
1591 foreach my $wildcard (@{$self->bitfield_decode($version, q{ofp_flow_wildcards}, $ret->{'wildcards'})}) {
1592 if ($wildcard eq q{OFPFW_IN_PORT}) {
1593 if ($ret->{'in_port'} == 0) {
1594 $ret->{'in_port'} = q{*};
1595 }
1596 }
1597 elsif ($wildcard eq q{OFPFW_DL_VLAN}) {
1598 if ($ret->{'dl_vlan'} == 0) {
1599 $ret->{'dl_vlan'} = q{*};
1600 }
1601 }
1602 elsif ($wildcard eq q{OFPFW_DL_SRC}) {
1603 if ($ret->{'dl_src'} == 0) {
1604 $ret->{'dl_src'} = q{*};
1605 }
1606 }
1607 elsif ($wildcard eq q{OFPFW_DL_DST}) {
1608 if ($ret->{'dl_dst'} == 0) {
1609 $ret->{'dl_dst'} = q{*};
1610 }
1611 }
1612 elsif ($wildcard eq q{OFPFW_DL_TYPE}) {
1613 if ($ret->{'dl_type'} == 0) {
1614 $ret->{'dl_type'} = q{*};
1615 }
1616 }
1617 elsif ($wildcard eq q{OFPFW_NW_PROTO}) {
1618 if ($ret->{'nw_proto'} == 0) {
1619 $ret->{'nw_proto'} = q{*};
1620 }
1621 }
1622 elsif ($wildcard eq q{OFPFW_TP_SRC}) {
1623 if ($ret->{'tp_src'} == 0) {
1624 $ret->{'tp_src'} = q{*};
1625 }
1626 }
1627 elsif ($wildcard eq q{OFPFW_TP_DST}) {
1628 if ($ret->{'tp_dst'} == 0) {
1629 $ret->{'tp_dst'} = q{*};
1630 }
1631 }
1632 elsif ($wildcard eq q{OFPFW_DL_VLAN_PCP}) {
1633 if ($ret->{'dl_vlan_pcp'} == 0) {
1634 $ret->{'dl_vlan_pcp'} = q{*};
1635 }
1636 }
1637 elsif ($wildcard eq q{OFPFW_NW_TOS}) {
1638 if ($ret->{'nw_tos'} == 0) {
1639 $ret->{'nw_tos'} = q{*};
1640 }
1641 }
1642 }
1643  
1644 return $ret;
1645 }
1646  
1647 sub struct_decode__ofp_phy_port($$$) {
1648 my $self = shift;
1649 my ($version, $struct_data) = @_;
1650  
1651 my $ofp_phy_port = $self->struct_decode($version, q{ofp_phy_port}, $struct_data);
1652  
1653 my $ret = {
1654 port_no => $ofp_phy_port->[0],
1655 hw_addr => $self->__format_pretty__hex_string($ofp_phy_port->[1]),
1656 name => $ofp_phy_port->[2],
1657 config => $ofp_phy_port->[3],
1658 state => $ofp_phy_port->[4],
1659 curr => $ofp_phy_port->[5],
1660 advertised => $ofp_phy_port->[6],
1661 supported => $ofp_phy_port->[7],
1662 peer => $ofp_phy_port->[8],
1663 };
1664  
1665 return $ret;
1666 }
1667  
1668 sub struct_encode($$$;$$) {
1669 my $self = shift;
1670 my ($version, $struct_type, $struct_args, $struct_body) = @_;
1671  
1672 unless (defined($struct_types->{$struct_type}{$version}) and (ref($struct_types->{$struct_type}{$version}) eq q{HASH})) {
1673 croak qq{Invalid struct type [$version][$struct_type]};
1674 }
1675  
1676 my $ret;
1677  
1678 $ret = pack($struct_types->{$struct_type}{$version}{'format'}, @{$struct_args});
1679  
1680 my $ret_length = length($ret);
1681 my $struct_type__length = $self->struct_sizeof($version, $struct_type);
1682  
1683 unless ($ret_length == $struct_type__length) {
1684 carp qq{sizeof(struct $struct_type) != $struct_type__length [$ret_length]};
1685 }
1686  
1687 if (defined $struct_body) {
1688 $ret .= $struct_body;
1689 }
1690  
1691 return $ret;
1692 }
1693  
1694 sub struct_encode__ofp_match($$$) {
1695 my $self = shift;
1696 my ($version, $ofp_match) = @_;
1697  
1698 my $wildcards = ($ofp_match->{'wildcards'} // $self->bitfield_encode(
1699 $version,
1700 q{ofp_flow_wildcards},
1701 [
1702 q{OFPFW_ALL},
1703 ],
1704 )
1705 );
1706 my $in_port = ($ofp_match->{'in_port'} // 0);
1707 my $dl_src = ($ofp_match->{'dl_src'} // 0);
1708 my $dl_dst = ($ofp_match->{'dl_dst'} // 0);
1709 my $dl_vlan = ($ofp_match->{'dl_vlan'} // 0);
1710 my $dl_vlan_pcp = ($ofp_match->{'dl_vlan_pcp'} // 0);
1711 my $dl_type = ($ofp_match->{'dl_type'} // 0);
1712 my $nw_tos = ($ofp_match->{'nw_tos'} // 0);
1713 my $nw_proto = ($ofp_match->{'nw_proto'} // 0);
1714 my $nw_src = ($ofp_match->{'nw_src'} // 0);
1715 my $nw_dst = ($ofp_match->{'nw_dst'} // 0);
1716 my $tp_src = ($ofp_match->{'tp_src'} // 0);
1717 my $tp_dst = ($ofp_match->{'tp_dst'} // 0);
1718  
1719 my $ret = $self->struct_encode(
1720 $version,
1721 q{ofp_match},
1722 [
1723 $wildcards,
1724 $in_port,
1725 $dl_src,
1726 $dl_dst,
1727 $dl_vlan,
1728 $dl_vlan_pcp,
1729 $dl_type,
1730 $nw_tos,
1731 $nw_proto,
1732 $nw_src,
1733 $nw_dst,
1734 $tp_src,
1735 $tp_dst,
1736 ]
1737 );
1738  
1739 return $ret;
1740 }
1741  
1742 sub struct_sizeof($$$) {
1743 my $self = shift;
1744 my ($version, $struct_type) = @_;
1745  
1746 my $ret = $struct_types->{$struct_type}{$version}{'length'};
1747  
1748 return $ret;
1749 }
1750  
1751 sub __format_pretty__arrayref {
1752 my $self = shift;
1753 my $a = shift;
1754  
1755 my $ret = [];
1756  
1757 foreach (@{$a}) {
1758 if (ref($_) eq q{ARRAY}) {
1759 push @{$ret}, (q{[} . join(q{, }, @{$self->__format_pretty__arrayref($_)}) . q{]});
1760 }
1761 elsif (ref($_) eq q{SCALAR}) {
1762 push @{$ret}, $self->__format_pretty__bit_string(${$_});
1763 }
1764 else {
1765 push @{$ret}, $self->__format_pretty__bit_string($_);
1766 }
1767 }
1768  
1769 return $ret;
1770 }
1771  
1772 sub __format_pretty__bit_string {
1773 my $self = shift;
1774 my ($bit_string, $len) = @_;
1775  
1776 $len //= 16;
1777  
1778 my $ret;
1779  
1780 if (defined $bit_string) {
1781 if ($bit_string =~ /^[\x20-\x7e]+$/) {
1782 $ret = $bit_string;
1783 }
1784 else {
1785 $ret = (q/{/ . $self->__hex_preview($bit_string, $len) . q/}:/ . length($bit_string));
1786 }
1787 }
1788 else {
1789 $ret = q{undef};
1790 }
1791  
1792 return $ret;
1793 }
1794  
1795 sub __format_pretty__hex_string {
1796 my $self = shift;
1797 my $hex_string = shift;
1798  
1799 my $ret = join(q{:}, unpack(q{(a2)*}, $hex_string));
1800  
1801 return $ret;
1802 }
1803  
1804 sub __hex_preview($$$) {
1805 my $self = shift;
1806 my ($data, $len) = @_;
1807  
1808 $len //= 8;
1809  
1810 return join(q{ }, unpack(q{(a2)*}, unpack(qq{H$len}, $data)));
1811 }
1812  
1813 =back
1814  
1815 =cut
1816  
1817 package Net::OpenFlow::Protocol::Debug;
1818  
1819 use parent qw{Net::OpenFlow::Protocol};
1820 use strict;
1821 use warnings;
1822  
1823  
1824 sub bitfield_decode($$$$) {
1825 my $self = shift;
1826 my ($version, $enum_type, $bitfield) = @_;
1827  
1828 my $ret = $self->SUPER::bitfield_decode($version, $enum_type, $bitfield);
1829  
1830 print STDERR $self->__function_debug(q{bitfield_decode}, $ret, [$version, $enum_type, $bitfield]) . qq{\n};
1831  
1832 return $ret;
1833 }
1834  
1835  
1836 sub bitfield_encode($$$$) {
1837 my $self = shift;
1838 my ($version, $enum_type, $bits) = @_;
1839  
1840 my $ret = $self->SUPER::bitfield_encode($version, $enum_type, $bits);
1841  
1842 print STDERR $self->__function_debug(q{bitfield_encode}, $ret, [$version, $enum_type, $bits]) . qq{\n};
1843  
1844 return $ret;
1845 }
1846  
1847 sub enum_lookup($$$$) {
1848 my $self = shift;
1849 my ($version, $enum_type, $lookup) = @_;
1850  
1851 my $ret = $self->SUPER::enum_lookup($version, $enum_type, $lookup);
1852  
1853 print STDERR $self->__function_debug(q{enum_lookup}, $ret, [$version, $enum_type, $lookup]) . qq{\n};
1854  
1855 return $ret;
1856 }
1857  
1858 sub enum_lookup__by_value($$$$) {
1859 my $self = shift;
1860  
1861 my $ret = $self->SUPER::enum_lookup__by_value(@_);
1862  
1863 print STDERR $self->__function_debug(q{enum_lookup__by_value}, $ret, [@_]) . qq{\n};
1864  
1865 return $ret;
1866 }
1867  
1868 sub ofpt_encode($$$;$$) {
1869 my $self = shift;
1870  
1871 my $ret = $self->SUPER::ofpt_encode(@_);
1872  
1873 print STDERR $self->__function_debug(q{ofpt_encode}, $self->__format_pretty__bit_string($ret), [@_]) . qq{\n};
1874  
1875 return $ret;
1876 }
1877  
1878 sub ofpt_decode($$) {
1879 my $self = shift;
1880 my $message = shift;
1881  
1882 my $__debug__message = $self->__format_pretty__bit_string(${$message});
1883  
1884 my $ret = $self->SUPER::ofpt_decode($message);
1885  
1886 print STDERR $self->__function_debug(q{ofpt_decode}, $ret, [$__debug__message]) . qq{\n};
1887  
1888 return $ret;
1889 }
1890  
1891 sub struct_chomp($$$$) {
1892 my $self = shift;
1893 my ($version, $struct_type, $struct_data) = @_;
1894  
1895 my $ret = $self->SUPER::struct_chomp($version, $struct_type, $struct_data);
1896  
1897 print STDERR $self->__function_debug(q{struct_chomp}, $ret, [$version, $struct_type, $self->__format_pretty__bit_string(${$struct_data})]) . qq{\n};
1898  
1899 return $ret;
1900 }
1901  
1902 sub struct_encode($$$;$$) {
1903 my $self = shift;
1904 my ($version, $struct_type, $struct_args, $struct_body) = @_;
1905  
1906 my $ret = $self->SUPER::struct_encode($version, $struct_type, $struct_args, $struct_body);
1907  
1908 print STDERR $self->__function_debug(q{struct_encode}, $self->__format_pretty__bit_string($ret, 32), [$version, $struct_type, $struct_args, $struct_body]) . qq{\n};
1909  
1910 return $ret;
1911 }
1912  
1913 sub struct_decode($$$$) {
1914 my $self = shift;
1915 my ($version, $struct_type, $struct_data) = @_;
1916  
1917 my $__debug__struct_data = $self->__format_pretty__bit_string(${$struct_data});
1918  
1919 my $ret = $self->SUPER::struct_decode($version, $struct_type, $struct_data);
1920  
1921 print STDERR $self->__function_debug(q{struct_decode}, $ret, [$version, $struct_type, $__debug__struct_data]) . qq{\n};
1922  
1923 return $ret;
1924 }
1925  
1926 sub __function_debug {
1927 my $self = shift;
1928 my ($name, $retval, $args) = @_;
1929  
1930 $name //= q{UNKNOWN};
1931 $retval //= q{undef};
1932 $args //= q{};
1933  
1934 my $formatted_retval;
1935  
1936 if (ref($retval) eq q{ARRAY}) {
1937 $formatted_retval = join(q{, }, @{$self->__format_pretty__arrayref($retval)});
1938 }
1939 elsif (ref($retval) eq q{SCALAR}) {
1940 $formatted_retval = ${$retval};
1941 }
1942 else {
1943 $formatted_retval = $retval;
1944 }
1945  
1946 my $formatted_args;
1947  
1948 if (ref($args) eq q{ARRAY}) {
1949 $formatted_args = join(q{, }, @{$self->__format_pretty__arrayref($args)});
1950 }
1951 else {
1952 $formatted_args = $args;
1953 }
1954  
1955 return ((ref($self) or $self) . q{::} . $name . qq{($formatted_args) = [$formatted_retval]});
1956 }
1957  
1958 1;