-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathof13.lua
2796 lines (2331 loc) · 126 KB
/
of13.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- =================================================
-- OpenFlow 1.3 protocol define
-- =================================================
of13_proto = Proto("of13","OpenFlow 1.3")
-- flags bits. Support true/false filter.
local VALS_BOOL = {[0] = "False", [1] = "True"}
-- =================================================
-- OpenFlow 1.3 dissection
-- =================================================
-- -------------------------------------------------
-- 7.1 OpenFlow Header
-- -------------------------------------------------
ofp_header_version_F = ProtoField.uint8("of13.version", "Version", base.HEX)
ofp_header_type_F = ProtoField.uint8("of13.type", "Type")
ofp_header_length_F = ProtoField.uint16("of13.length", "Length")
ofp_header_xid_F = ProtoField.uint32("of13.xid", "Transaction ID")
ofp_type = {
-- Immutable messages
[0] = "OFPT_HELLO",
[1] = "OFPT_ERROR",
[2] = "OFPT_ECHO_REQUEST",
[3] = "OFPT_ECHO_REPLY",
[4] = "OFPT_EXPERIMENTER",
-- Switch configuration messages
[5] = "OFPT_FEATURES_REQUEST",
[6] = "OFPT_FEATURES_REPLY",
[7] = "OFPT_GET_CONFIG_REQUEST",
[8] = "OFPT_GET_CONFIG_REPLY",
[9] = "OFPT_SET_CONFIG",
-- Asynchronous messages
[10] = "OFPT_PACKET_IN",
[11] = "OFPT_FLOW_REMOVED",
[12] = "OFPT_PORT_STATUS",
-- Controller command messages
[13] = "OFPT_PACKET_OUT",
[14] = "OFPT_FLOW_MOD",
[15] = "OFPT_GROUP_MOD",
[16] = "OFPT_PORT_MOD",
[17] = "OFPT_TABLE_MOD",
-- Statistics messages
[18] = "OFPT_MULTIPART_REQUEST",
[19] = "OFPT_MULTIPART_REPLY",
-- Barrier messages
[20] = "OFPT_BARRIER_REQUEST",
[21] = "OFPT_BARRIER_REPLY",
-- Queue Configuration messages
[22] = "OFPT_QUEUE_GET_CONFIG_REQUEST",
[23] = "OFPT_QUEUE_GET_CONFIG_REPLY",
-- Controller role change request messages
[24] = "OFPT_ROLE_REQUEST",
[25] = "OFPT_ROLE_REPLY",
-- Asynchronous message configuration
[26] = "OFPT_GET_ASYNC_REQUEST",
[27] = "OFPT_GET_ASYNC_REPLY",
[28] = "OFPT_SET_ASYNC",
-- Meters and rate limiters configuration messages
[29] = "OFPT_METER_MOD",
}
ofp_port_no = {
-- Maximum number of physical and logical switch ports.
[0xffffff00] = "OFPP_MAX",
-- Reserved OpenFlow Port (fake output "ports").
-- Send the packet out the input port. This reserved port must be explicitly used in order to send back out of the input port.
[0xfffffff8] = "OFPP_IN_PORT",
-- Submit the packet to the first flow table NB: This destination port can only be used in packet-out messages.
[0xfffffff9] = "OFPP_TABLE",
-- Process with normal L2/L3 switching.
[0xfffffffa] = "OFPP_NORMAL",
-- All physical ports in VLAN, except input port and those blocked or link down.
[0xfffffffb] = "OFPP_FLOOD",
-- All physical ports except input port.
[0xfffffffc] = "OFPP_ALL",
-- Send to controller.
[0xfffffffd] = "OFPP_CONTROLLER",
-- Local openflow "port".
[0xfffffffe] = "OFPP_LOCAL",
-- Wildcard port used only for flow mod(delete) and flow stats requests. Selects all flows regardless of output port (including flows with no output port).
[0xffffffff] = "OFPP_ANY",
}
function of13_proto.dissector(buffer, pinfo, tree)
-- First, get the general header
local _version_range = buffer(0,1)
local _type_range = buffer(1,1)
local _length_range = buffer(2,2)
local _xid_range = buffer(4,4)
local pointer = 8
local _version = _version_range:uint()
local _type = _type_range:uint()
local _length = _length_range:uint()
local _xid = _xid_range:uint()
-- Only dissect version is 0x04(=openflow 1.3)
-- TODO: Before this function, place the version switching function.
if _version == 0x04 then
-- Add OpenFlow 1.3 Tree
local of13_tree = tree:add(of13_proto, buffer(), "OpenFlow 1.3 " .. ofp_type[_type])
-- OpenFlow 1.3 general header
of13_tree:add(ofp_header_version_F, _version_range, _version):append_text(" (OpenFlow 1.3)")
of13_tree:add(ofp_header_type_F, _type_range, _type):append_text(" (" .. ofp_type[_type] .. ")")
of13_tree:add(ofp_header_length_F, _length_range, _length)
of13_tree:add(ofp_header_xid_F, _xid_range, _xid)
if ofp_type[_type] == "OFPT_HELLO" then
-- 7.5.1 Hello
-- The OFPT_HELLO message has no body; that is, it consists only of an OpenFlow header.
return
elseif ofp_type[_type] == "OFPT_ERROR" then
ofp_error_msg(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_ECHO_REQUEST" then
-- 7.5.2 Echo Request
-- An Echo Request message consists of an OpenFlow header
-- plus an arbitrary-length data field. The data fieeld might be
-- a message timestamp to check latency, various lengths to
-- measure bandwidth, or zero-size to verify liveness between the
-- switch and controller.
return
elseif ofp_type[_type] == "OFPT_ECHO_REPLY" then
-- 7.5.3 Echo Reply
-- An Echo Reply message consists of an OpenFlow header plus the
-- unmodified data field of an echo request message.
return
elseif ofp_type[_type] == "OFPT_EXPERIMENTER" then
ofp_experimenter_header(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_FEATURES_REQUEST" then
-- 7.3.1 Handshake
-- This message does not contain a body beyond the OpenFlow header.
return
elseif ofp_type[_type] == "OFPT_FEATURES_REPLY" then
ofp_switch_features(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_GET_CONFIG_REQUEST" then
-- There is no body for OFPT_GET_CONFIG_REQUEST
return
elseif ofp_type[_type] == "OFPT_GET_CONFIG_REPLY" or
ofp_type[_type] == "OFPT_SET_CONFIG" then
ofp_switch_config(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_PACKET_IN" then
ofp_packet_in(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_FLOW_REMOVED" then
ofp_flow_removed(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_PORT_STATUS" then
ofp_port_status(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_PACKET_OUT" then
ofp_packet_out(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_FLOW_MOD" then
ofp_flow_mod(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_GROUP_MOD" then
ofp_group_mod(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_PORT_MOD" then
ofp_port_mod(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_TABLE_MOD" then
ofp_table_mod(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_MULTIPART_REQUEST" then
ofp_multipart_request(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_MULTIPART_REPLY" then
ofp_multipart_reply(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_BARRIER_REQUEST" or
ofp_type[_type] == "OFPT_BARRIER_REPLY" then
-- 7.3.8 Barrier Message
-- This message has no body.
return
elseif ofp_type[_type] == "OFPT_QUEUE_GET_CONFIG_REQUEST" then
ofp_queue_get_config_request(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_QUEUE_GET_CONFIG_REPLY" then
ofp_queue_get_config_reply(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_ROLE_REQUEST" or
ofp_type[_type] == "OFPT_ROLE_REPLY" then
ofp_role_request(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_GET_ASYNC_REQUEST" then
-- There is no body for OFPT_GET_ASYNC_REQUEST beyond the OpenFlow header.
return
elseif ofp_type[_type] == "OFPT_GET_ASYNC_REPLY" or
ofp_type[_type] == "OFPT_SET_ASYNC" then
-- The OFPT_SET_ASYNC and OFPT_GET_ASYNC_REPLY messages have the following format:
ofp_async_config(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
elseif ofp_type[_type] == "OFPT_METER_MOD" then
ofp_meter_mod(buffer(pointer,buffer:len()-pointer), pinfo, of13_tree)
end
end
end
-- -------------------------------------------------
-- 7.2 Common Structures
-- -------------------------------------------------
-- 7.2.1 Port Structures
-- -------------------------------------------------
ofp_port_port_no_F = ProtoField.uint32("of13.port_port_no", "Port")
ofp_port_pad1_F = ProtoField.uint32("of13.port_pad1", "Padding")
ofp_port_hw_addr_F = ProtoField.string("of13.port_hw_addr", "HW Addr")
ofp_port_pad2_F = ProtoField.string("of13.port_pad2", "Padding")
ofp_port_name_F = ProtoField.string("of13.port_name", "Name")
ofp_port_config_F = ProtoField.uint32("of13.port_config", "Config")
ofp_port_state_F = ProtoField.uint32("of13.port_state", "State")
ofp_port_curr_F = ProtoField.uint32("of13.port_curr", "Current features")
ofp_port_advertised_F = ProtoField.uint32("of13.port_advertised", "Advertize features")
ofp_port_supported_F = ProtoField.uint32("of13.port_supported", "Supported features")
ofp_port_peer_F = ProtoField.uint32("of13.port_peer", "Advertize features by peer")
ofp_port_curr_speed_F = ProtoField.uint32("of13.port_curr_speed", "Port bitrate [kbps]")
ofp_port_max_speed_F = ProtoField.uint32("of13.port_max_speed", "Max bitrate [kbps]")
function ofp_port(buffer, pinfo, tree)
local _port_no_range = buffer(0,4)
local _pad1_range = buffer(4,4)
local _hw_addr_range = buffer(8,6)
local _pad2_range = buffer(14,2)
local _name_range = buffer(16,16)
local _config_range = buffer(32,4)
local _state_range = buffer(36,4)
local _curr_range = buffer(40,4)
local _advertised_range = buffer(44,4)
local _supported_range = buffer(48,4)
local _peer_range = buffer(52,4)
local _curr_speed_range = buffer(56,4)
local _max_speed_range = buffer(60,4)
local pointer = 64
local _port_no = _port_no_range:uint()
local _pad1 = tostring(_pad1_range)
local _hw_addr = tostring(_hw_addr_range:ether())
local _pad2 = tostring(_pad2_range)
local _name = _name_range:stringz()
local _config = _config_range:uint()
local _state = _state_range:uint()
local _curr = _curr_range:uint()
local _advertised = _advertised_range:uint()
local _supported = _supported_range:uint()
local _peer = _peer_range:uint()
local _curr_speed = _curr_speed_range:uint()
local _max_speed = _max_speed_range:uint()
tree:add(ofp_port_port_no_F , _port_no_range , _port_no )
tree:add(ofp_port_pad1_F , _pad1_range , _pad1 )
tree:add(ofp_port_hw_addr_F , _hw_addr_range , _hw_addr )
tree:add(ofp_port_pad2_F , _pad2_range , _pad2 )
tree:add(ofp_port_name_F , _name_range , _name )
tree:add(ofp_port_config_F , _config_range , _config )
tree:add(ofp_port_state_F , _state_range , _state )
tree:add(ofp_port_curr_F , _curr_range , _curr )
tree:add(ofp_port_advertised_F, _advertised_range, _advertised)
tree:add(ofp_port_supported_F , _supported_range , _supported )
tree:add(ofp_port_peer_F , _peer_range , _peer )
tree:add(ofp_port_curr_speed_F, _curr_speed_range, _curr_speed)
tree:add(ofp_port_max_speed_F , _max_speed_range , _max_speed )
return pointer
end
-- 7.2.2 Queue Structures
-- -------------------------------------------------
ofp_packet_queue_queue_id_F = ProtoField.uint32("of13.packet_queue_queue_id", "Queue ID")
ofp_packet_queue_port_F = ProtoField.uint32("of13.packet_queue_port", "Port")
ofp_packet_queue_len_F = ProtoField.uint16("of13.packet_queue_len", "Length")
ofp_packet_queue_pad_F = ProtoField.string("of13.packet_queue_pad", "Padding")
ofp_queue_properties = {
[1] = "OFPQT_MIN_RATE",
[2] = "OFPQT_MAX_RATE",
[0xffff] = "OFPQT_EXPERIMENTER",
}
ofp_port_features = {
[0] = "OFPPF_10MB_HD", -- 10 Mb half-duplex rate support.
[1] = "OFPPF_10MB_FD", -- 10 Mb full-duplex rate support.
[2] = "OFPPF_100MB_HD", -- 100 Mb half-duplex rate support.
[3] = "OFPPF_100MB_FD", -- 100 Mb full-duplex rate support.
[4] = "OFPPF_1GB_HD", -- 1 Gb half-duplex rate support.
[5] = "OFPPF_1GB_FD", -- 1 Gb full-duplex rate support.
[6] = "OFPPF_10GB_FD", -- 10 Gb full-duplex rate support.
[7] = "OFPPF_40GB_FD", -- 40 Gb full-duplex rate support.
[8] = "OFPPF_100GB_FD", -- 100 Gb full-duplex rate support.
[9] = "OFPPF_1TB_FD", -- 1 Tb full-duplex rate support.
[10] = "OFPPF_OTHER", -- Other rate", not in the list.
[11] = "OFPPF_COPPER", -- Copper medium.
[12] = "OFPPF_FIBER", -- Fiber medium.
[13] = "OFPPF_AUTONEG", -- Auto-negotiation.
[14] = "OFPPF_PAUSE", -- Pause.
[15] = "OFPPF_PAUSE_ASYM", -- Asymmetric pause.
}
function ofp_packet_queue(buffer, pinfo, tree)
local _queue_id_range = buffer(0,4)
local _port_range = buffer(4,4)
local _len_range = buffer(8,2)
local _pad_range = buffer(10,6)
local pointer = 16
local _queue_id = _queue_id_range:uint()
local _port = _port_range:uint()
local _len = _len_range:uint()
local _pad = tostring(_pad_range)
tree:add(ofp_packet_queue_queue_id_F, _queue_id_range, _queue_id)
tree:add(ofp_packet_queue_port_F , _port_range , _port )
tree:add(ofp_packet_queue_len_F , _len_range , _len )
tree:add(ofp_packet_queue_pad_F , _pad_range , _pad )
-- XXX : ofp_queue_prop_header
return pointer
end
function ofp_queue_prop_header(buffer, pinfo, tree)
return 0
end
function ofp_queue_prop_min_rate(buffer, pinfo, tree)
return 0
end
function ofp_queue_prop_max_rate(buffer, pinfo, tree)
return 0
end
function ofp_queue_prop_experimenter(buffer, pinfo, tree)
return 0
end
-- 7.2.3 Flow Match Structures
-- -------------------------------------------------
ofp_match_F = ProtoField.string("of13.match", "Flow Match Header")
ofp_match_type_F = ProtoField.uint16("of13.match_type", "Type")
ofp_match_length_F = ProtoField.uint16("of13.match_length", "Length")
ofp_match_ofp_oxm_F = ProtoField.uint16("of13.match_oxm", "OXM")
ofp_match_pad_F = ProtoField.string("of13.match_pad", "Padding")
ofp_oxm_F = ProtoField.string("of13.oxm", "Flow Match Fileld")
ofp_oxm_class_F = ProtoField.uint16("of13.oxm_class", "Match class: member class ie reserved class", base.HEX)
ofp_oxm_field_F = ProtoField.uint8("of13.oxm_field", "Match field within the class", base.HEX, nil, 0xfe)
ofp_oxm_hasmask_F = ProtoField.uint8("of13.oxm_hasmask", "Set if OXM include a bitmask in payload", base.HEX, VALS_BOOL, 0x01)
ofp_oxm_length_F = ProtoField.uint8("of13.oxm_length", "Length of OXM payload")
ofp_oxm_value_F = ProtoField.string("of13.oxm_value", "Value")
ofp_oxm_mask_F = ProtoField.string("of13.oxm_mask", "Mask ")
ofp_match_type_string = {
[0] = "OFPMT_STANDARD",
[1] = "OFPMT_OXM",
}
ofp_oxm_field_string = {
[0x0000] = "OFPXMC_NXM_0", -- Backward compatibility with NXM
[0x0001] = "OFPXMC_NXM_1", -- Backward compatibility with NXM
[0x0003] = "OFPXMC_BSN_0", -- Big Switch Networks
[0x0004] = "OFPXMC_HP_0", -- HP
[0x0005] = "OFPXMC_FS_0", -- Freescale
[0x8000] = "OFPXMC_OPENFLOW_BASIC", -- Basic class for OpenFlow
[0xFFFF] = "OFPXMC_EXPERIMENTER", -- Experimenter class
}
oxm_ofb_match_fields = {
-- {Name, bit length, mask}
[0] = {"OFPXMT_OFB_IN_PORT", 32, nil}, -- Switch input port.
[1] = {"OFPXMT_OFB_IN_PHY_PORT", 32, nil}, -- Switch physical input port.
[2] = {"OFPXMT_OFB_METADATA", 64, true}, -- Metadata passed between tables.
[3] = {"OFPXMT_OFB_ETH_DST", 48, true}, -- Ethernet destination address.
[4] = {"OFPXMT_OFB_ETH_SRC", 48, true}, -- Ethernet source address.
[5] = {"OFPXMT_OFB_ETH_TYPE", 16, nil}, -- Ethernet frame type.
[6] = {"OFPXMT_OFB_VLAN_VID", 13, true}, -- VLAN id.
[7] = {"OFPXMT_OFB_VLAN_PCP", 3, nil}, -- VLAN priority.
[8] = {"OFPXMT_OFB_IP_DSCP", 6, nil}, -- IP DSCP (6 bits in ToS field).
[9] = {"OFPXMT_OFB_IP_ECN", 2, nil}, -- IP ECN (2 bits in ToS field).
[10] = {"OFPXMT_OFB_IP_PROTO", 8, nil}, -- IP protocol.
[11] = {"OFPXMT_OFB_IPV4_SRC", 32, true}, -- IPv4 source address.
[12] = {"OFPXMT_OFB_IPV4_DST", 32, true}, -- IPv4 destination address.
[13] = {"OFPXMT_OFB_TCP_SRC", 16, nil}, -- TCP source port.
[14] = {"OFPXMT_OFB_TCP_DST", 16, nil}, -- TCP destination port.
[15] = {"OFPXMT_OFB_UDP_SRC", 16, nil}, -- UDP source port.
[16] = {"OFPXMT_OFB_UDP_DST", 16, nil}, -- UDP destination port.
[17] = {"OFPXMT_OFB_SCTP_SRC", 16, nil}, -- SCTP source port.
[18] = {"OFPXMT_OFB_SCTP_DST", 16, nil}, -- SCTP destination port.
[19] = {"OFPXMT_OFB_ICMPV4_TYPE", 8, nil}, -- ICMP type.
[20] = {"OFPXMT_OFB_ICMPV4_CODE", 8, nil}, -- ICMP code.
[21] = {"OFPXMT_OFB_ARP_OP", 16, nil}, -- ARP opcode.
[22] = {"OFPXMT_OFB_ARP_SPA", 32, true}, -- ARP source IPv4 address.
[23] = {"OFPXMT_OFB_ARP_TPA", 32, true}, -- ARP target IPv4 address.
[24] = {"OFPXMT_OFB_ARP_SHA", 48, true}, -- ARP source hardware address.
[25] = {"OFPXMT_OFB_ARP_THA", 48, true}, -- ARP target hardware address.
[26] = {"OFPXMT_OFB_IPV6_SRC", 128, true}, -- IPv6 source address.
[27] = {"OFPXMT_OFB_IPV6_DST", 128, true}, -- IPv6 destination address.
[28] = {"OFPXMT_OFB_IPV6_FLABEL", 20, true}, -- IPv6 Flow Label
[29] = {"OFPXMT_OFB_ICMPV6_TYPE", 8, nil}, -- ICMPv6 type.
[30] = {"OFPXMT_OFB_ICMPV6_CODE", 8, nil}, -- ICMPv6 code.
[31] = {"OFPXMT_OFB_IPV6_ND_TARGET", 128, nil}, -- Target address for ND.
[32] = {"OFPXMT_OFB_IPV6_ND_SLL", 48, nil}, -- Source link-layer for ND.
[33] = {"OFPXMT_OFB_IPV6_ND_TLL", 48, nil}, -- Target link-layer for ND.
[34] = {"OFPXMT_OFB_MPLS_LABEL", 20, nil}, -- MPLS label.
[35] = {"OFPXMT_OFB_MPLS_TC", 3, nil}, -- MPLS TC.
[36] = {"OFPXMT_OFP_MPLS_BOS", 1, nil}, -- MPLS BoS bit.
[37] = {"OFPXMT_OFB_PBB_ISID", 24, true}, -- PBB I-SID.
[38] = {"OFPXMT_OFB_TUNNEL_ID", 64, true}, -- Logical Port Metadata.
[39] = {"OFPXMT_OFB_IPV6_EXTHDR", 9, true}, -- IPv6 Extension Header pseudo-field
}
function ofp_match(buffer, pinfo, tree)
local _type_range = buffer(0,2)
local _length_range = buffer(2,2)
local pointer = 4
local _type = _type_range:uint()
local _length = _length_range:uint()
local subtree = tree:add(ofp_match_F, buffer(0,_length), "Flow Match Header")
local _type_F = subtree:add(ofp_match_type_F, _type_range, _type)
if ofp_match_type_string[_type] ~= nil then
_type_F:append_text(" (" .. ofp_match_type_string[_type] .. ")")
end
subtree:add(ofp_match_length_F, _length_range, _length)
while pointer < _length do
if ofp_match_type_string[_type] ~= nil then
offset = ofp_oxm_field(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
pointer = pointer + offset
else
break
end
end
local _pad_range = buffer(pointer, math.ceil(_length/8)*8 - pointer)
local _pad = tostring(_pad_range)
subtree:add(ofp_match_pad_F, _pad_range, _pad)
pointer = pointer + (math.ceil(_length/8)*8 - pointer)
return pointer
end
function ofp_oxm_field(buffer, pinfo, tree)
local _class_range = buffer(0,2)
local _fh_range = buffer(2,1)
local _length_range = buffer(3,1)
local pointer = 4
local _class = _class_range:uint()
local _fh = _fh_range:uint()
local _field = _fh_range:bitfield(0, 7)
local _hasmask = _fh_range:bitfield(7, 1)
local _length = _length_range:uint()
local subtree = tree:add(ofp_oxm_F, buffer(0, pointer + _length), "Flow Match Field Structure")
subtree:add(ofp_oxm_class_F, _class_range, _class):append_text(" (" .. ofp_oxm_field_string[_class] .. ")")
subtree:add(ofp_oxm_field_F, _fh_range, _fh):append_text(" (" .. oxm_ofb_match_fields[_field][1] .. ")")
subtree:add(ofp_oxm_hasmask_F, _fh_range, _fh)
subtree:add(ofp_oxm_length_F, _length_range, _length)
local _value_range = buffer(pointer, _length)
local _mask_range
if _hasmask == 1 then
_value_range = buffer(pointer, _length/2)
_mask_range = buffer(pointer+(_length/2), _length/2)
end
if ofp_oxm_field_string[_class] == "OFPXMC_OPENFLOW_BASIC" then
if _hasmask == 1 then
if oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IN_PORT" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IN_PHY_PORT" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
subtree:add(ofp_oxm_mask_F, _mask_range, _mask_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_METADATA" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ETH_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ETH_SRC" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ether()))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range:ether()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ETH_TYPE" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
-- XXX - combination for VLAN tags.
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_VLAN_VID" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_VLAN_PCP" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IP_DSCP" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IP_ECN" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IP_PROTO" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
subtree:add(ofp_oxm_mask_F, _mask_range, _mask_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV4_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV4_DST" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ipv4()))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range:ipv4()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_TCP_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_TCP_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_UDP_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_UDP_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_SCTP_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_SCTP_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV4_TYPE" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV4_CODE" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
subtree:add(ofp_oxm_mask_F, _mask_range, _mask_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_OP" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_SPA" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_TPA" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ipv4()))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range:ipv4()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_SHA" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_THA" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ether()))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range:ether()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_FLABEL" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV6_TYPE" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV6_CODE" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
subtree:add(ofp_oxm_mask_F, _mask_range, _mask_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_ND_TARGET" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_ND_SLL" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_ND_TLL" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_MPLS_LABEL" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_MPLS_TC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFP_MPLS_BOS" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_PBB_ISID" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_TUNNEL_ID" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
subtree:add(ofp_oxm_mask_F, _mask_range, _mask_range:uint())
-- XXX
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_EXTHDR" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
else
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
end
else
if oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IN_PORT" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IN_PHY_PORT" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_METADATA" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ETH_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ETH_SRC" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ether()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ETH_TYPE" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_VLAN_VID" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_VLAN_PCP" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IP_DSCP" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IP_ECN" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IP_PROTO" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV4_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV4_DST" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ipv4()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_TCP_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_TCP_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_UDP_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_UDP_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_SCTP_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_SCTP_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV4_TYPE" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV4_CODE" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_OP" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_SPA" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_TPA" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ipv4()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_SHA" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ARP_THA" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range:ether()))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_SRC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_DST" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_FLABEL" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV6_TYPE" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_ICMPV6_CODE" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_ND_TARGET" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_ND_SLL" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_ND_TLL" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_MPLS_LABEL" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_MPLS_TC" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFP_MPLS_BOS" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_PBB_ISID" or
oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_TUNNEL_ID" then
subtree:add(ofp_oxm_value_F, _value_range, _value_range:uint())
elseif oxm_ofb_match_fields[_field][1] == "OFPXMT_OFB_IPV6_EXTHDR" then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
else
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
end
end
else
if _hasmask == 1 then
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
subtree:add(ofp_oxm_mask_F, _mask_range, tostring(_mask_range))
else
subtree:add(ofp_oxm_value_F, _value_range, tostring(_value_range))
end
end
pointer = pointer + _length
return pointer
end
-- 7.2.4 Flow Instruction Structures
-- -------------------------------------------------
ofp_instruction_F = ProtoField.string("of13.instruction", "Flow Instruction")
ofp_instruction_type_F = ProtoField.string("of13.instruction_type", "Type")
ofp_instruction_length_F = ProtoField.string("of13.instruction_length", "Length")
ofp_instruction_table_id_F = ProtoField.string("of13.instruction_table_id", "Table ID")
ofp_instruction_pad_F = ProtoField.string("of13.instruction_pad", "Padding")
ofp_instruction_metadata_F = ProtoField.string("of13.instruction_metadata", "Metadata")
ofp_instruction_metadata_mask_F = ProtoField.string("of13.instruction_metadata_mask", "Metadata mask")
ofp_instruction_meter_F = ProtoField.string("of13.instruction_meter", "Meter")
-- 7.2.4 Flow Instruction Structures
-- -------------------------------------------------
ofp_instruction_type = {
[1] = "OFPIT_GOTO_TABLE", -- Setup the next table in the lookup pipeline
[2] = "OFPIT_WRITE_METADATA", -- Setup the metadata field for use later in pipeline
[3] = "OFPIT_WRITE_ACTIONS", -- Write the action(s) onto the datapath action set
[4] = "OFPIT_APPLY_ACTIONS", -- Applies the action(s) immediately
[5] = "OFPIT_CLEAR_ACTIONS", -- Clears all actions from the datapath action set
[6] = "OFPIT_METER", -- Apply meter (rate limiter)
[0xffff] = "OFPIT_EXPERIMENTER", -- Experimenter instruction
}
function ofp_instruction(buffer, pinfo, tree)
if buffer:len() < 4 then
return
end
local _type_range = buffer(0,2)
local _length_range = buffer(2,2)
local pointer = 4
local _type = _type_range:uint()
local _length = _length_range:uint()
local subtree = tree:add(ofp_instruction_F, buffer(0,_length), "Flow Instruction")
local _type_F = subtree:add(ofp_instruction_type_F, _type_range, _type)
if ofp_instruction_type[_type] ~= nil then
_type_F:append_text(" (" .. ofp_instruction_type[_type] .. ")")
end
subtree:add(ofp_instruction_length_F, _length_range, _length)
if _length < 8 then
return
end
if ofp_instruction_type[_type] == "OFPIT_GOTO_TABLE" then
local _table_id_range = buffer(pointer,1)
local _pad_range = buffer(pointer+1,3)
pointer = pointer + 4
local _table_id = _table_id_range:uint()
local _pad = tostring(_pad_range)
subtree:add(ofp_instruction_table_id_F, _table_id_range, _table_id)
subtree:add(ofp_instruction_pad_F , _pad_range , _pad )
elseif ofp_instruction_type[_type] == "OFPIT_WRITE_METADATA" then
local _pad_range = buffer(pointer,4)
local _metadata_range = buffer(pointer+4,8)
local _metadata_mask_range = buffer(pointer+12,8)
pointer = pointer + 20
local _pad = tostring(_pad_range)
local _metadata = _metadata_range:uint64()
local _metadata_mask = _metadata_mask_range:uint64()
subtree:add(ofp_instruction_pad_F , _pad_range , _pad)
subtree:add(ofp_instruction_metadata_F, _metadata_range, _metadata)
subtree:add(ofp_instruction_metadata_mask_F, _metadata_mask_range, _metadata_mask)
elseif ofp_instruction_type[_type] == "OFPIT_WRITE_ACTIONS" or
ofp_instruction_type[_type] == "OFPIT_APPLY_ACTIONS" or
ofp_instruction_type[_type] == "OFPIT_CLEAR_ACTIONS" then
local _pad_range = buffer(pointer,4)
pointer = pointer + 4
local _pad = tostring(_pad_range)
subtree:add(ofp_instruction_pad_F, _pad_range, _pad)
-- Action Header dissector
while buffer:len() > pointer do
offset = ofp_action_header(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
pointer = pointer + offset
end
elseif ofp_instruction_type[_type] == "OFPIT_METER" then
local _meter_range = buffer(pointer,4)
pointer = pointer + 4
local _meter = _meter_range:uint()
subtree:add(ofp_instruction_meter_F, _meter_range, _meter)
elseif ofp_instruction_type[_type] == "OFPIT_EXPERIMENTER" then
Dissector.get("data"):call(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
end
return pointer
end
-- 7.2.5 Action Structures
-- -------------------------------------------------
ofp_action_header_F = ProtoField.string("of13.action", "Action")
ofp_action_header_type_F = ProtoField.uint16("of13.action_type", "One of OFPAT_*")
ofp_action_header_length_F = ProtoField.uint16("of13.action_length", "Length of action, including this header")
ofp_action_header_pad_F = ProtoField.string("of13.action_pad", "Pad to 64 bits")
ofp_action_output_port_F = ProtoField.uint32("of13.action_output_port", "Output port")
ofp_action_output_max_len_F = ProtoField.uint16("of13.action_output_maxlen", "Max length to send to controller")
ofp_action_output_pad_F = ProtoField.string("of13.action_output_pad", "Pad to 64 bits")
ofp_action_group_group_id_F = ProtoField.uint32("of13.action_group_id", "Group ID")
ofp_action_group_queue_id_F = ProtoField.uint32("of13.action_queue_id", "Queue ID")
ofp_action_mpls_ttl_mpls_ttl_F = ProtoField.uint32("of13.action_mpls_ttl", "MPLS TTL")
ofp_action_mpls_ttl_pad_F = ProtoField.string("of13.action_mpls_pad", "Padding")
ofp_action_nw_ttl_nw_ttl_F = ProtoField.uint8("of13.nw_ttl", "IP TTL")
ofp_action_nw_ttl_pad_F = ProtoField.string("of13.nw_ttl_pad", "Pad to 64 bits")
ofp_action_push_ethertype_F = ProtoField.uint16("of13.action_push_type", "EtherType", base.HEX)
ofp_action_push_pad_F = ProtoField.string("of13.action_push_pad", "Padding")
ofp_action_pop_mpls_ethertype_F = ProtoField.uint16("of13.action_pop_mpls_type", "EtherType", base.HEX)
ofp_action_pop_mpls_pad_F = ProtoField.string("of13.action_pop_mpls_pad", "Padding")
ofp_action_set_field_type_F = ProtoField.uint16("of13.action_set_field_type", "Type")
ofp_action_set_field_len_F = ProtoField.uint16("of13.action_set_field_len", "Length")
ofp_action_experimenter_F = ProtoField.uint32("of13.action_expetimenter", "Experimenter")
ofp_action_type = {
[0] = "OFPAT_OUTPUT", -- Output to switch port.
[11] = "OFPAT_COPY_TTL_OUT", -- Copy TTL "outwards" -- from next-to-outermost to outermost
[12] = "OFPAT_COPY_TTL_IN", -- Copy TTL "inwards" -- from outermost to next-to-outermost
[15] = "OFPAT_SET_MPLS_TTL", -- MPLS TTL
[16] = "OFPAT_DEC_MPLS_TTL", -- Decrement MPLS TTL
[17] = "OFPAT_PUSH_VLAN", -- Push a new VLAN tag
[18] = "OFPAT_POP_VLAN", -- Pop the outer VLAN tag
[19] = "OFPAT_PUSH_MPLS", -- Push a new MPLS tag
[20] = "OFPAT_POP_MPLS", -- Pop the outer MPLS tag
[21] = "OFPAT_SET_QUEUE", -- Set queue id when outputting to a port
[22] = "OFPAT_GROUP", -- Apply group.
[23] = "OFPAT_SET_NW_TTL", -- IP TTL.
[24] = "OFPAT_DEC_NW_TTL", -- Decrement IP TTL.
[25] = "OFPAT_SET_FIELD", -- Set a header field using OXM TLV format.
[26] = "OFPAT_PUSH_PBB", -- Push a new PBB service tag (I-TAG)
[27] = "OFPAT_POP_PBB", -- Pop the outer PBB service tag (I-TAG)
[0xffff] = "OFPAT_EXPERIMENTER",
}
ofp_controller_max_len = {
[0xffe5] = "OFPCML_MAX", -- maximum max_len value which can be used to request a specific byte length.
[0xffff] = "OFPCML_NO_BUFFER", -- indicates that no buffering should be applied and the whole packet is to be sent to the controller.
}
function ofp_action_header(buffer, pinfo, tree)
local _type_range = buffer(0,2)
local _length_range = buffer(2,2)
local pointer = 4
local _type = _type_range:uint()
local _length = _length_range:uint()
local subtree = tree:add(ofp_action_header_F, buffer(0,_length), "Action header")
local _type_F = subtree:add(ofp_action_header_type_F, _type_range, _type)
if ofp_action_type[_type] ~= nil then
_type_F:append_text(" (" .. ofp_action_type[_type] .. ")")
end
subtree:add(ofp_action_header_length_F, _length_range, _length)
if ofp_action_type[_type] == "OFPAT_OUTPUT" then
offset = ofp_action_output(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_COPY_TTL_OUT" or
ofp_action_type[_type] == "OFPAT_COPY_TTL_IN" or
ofp_action_type[_type] == "OFPAT_DEC_MPLS_TTL" or
ofp_action_type[_type] == "OFPAT_POP_VLAN" or
ofp_action_type[_type] == "OFPAT_DEC_NW_TTL" or
ofp_action_type[_type] == "OFPAT_POP_PBB" then
local _pad_range = buffer(pointer,4)
local _pad = tostring(_pad_range)
subtree:add(ofp_action_header_pad_F, _pad_range, _pad)
offset = 4
elseif ofp_action_type[_type] == "OFPAT_SET_MPLS_TTL" then
offset = ofp_action_mpls_ttl(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_PUSH_VLAN" then
offset = ofp_action_push(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_PUSH_MPLS" then
offset = ofp_action_push(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_POP_MPLS" then
offset = ofp_action_pop_mpls(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_SET_QUEUE" then
offset = ofp_action_set_queue(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_GROUP" then
offset = ofp_action_group(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_SET_NW_TTL" then
offset = ofp_action_nw_ttl(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_SET_FIELD" then
offset = ofp_oxm_field(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
pointer = pointer + offset
local _pad_range = buffer(pointer, math.ceil(_length/8)*8 - pointer)
local _pad = tostring(_pad_range)
subtree:add(ofp_action_header_pad_F, _pad_range, _pad)
offset = (math.ceil(_length/8)*8) - pointer
elseif ofp_action_type[_type] == "OFPAT_PUSH_PBB" then
offset = ofp_action_push(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
elseif ofp_action_type[_type] == "OFPAT_EXPERIMENTER" then
offset = ofp_action_experimenter(buffer(pointer,buffer:len()-pointer), pinfo, subtree)
else
local _pad_range = buffer(pointer,buffer:len()-pointer)
local _pad = tostring(_pad_range)
subtree:add(ofp_action_header_pad_F, _pad_range, _pad)
offset = buffer:len()-pointer
end
pointer = pointer + offset
return pointer
end
function ofp_action_output(buffer, pinfo, tree)
local _port_range = buffer(0,4)
local _max_len_range = buffer(4,2)
local _pad_range = buffer(6,6)
local pointer = 12
local _port = _port_range:uint()
local _max_len = _max_len_range:uint()
local _pad = tostring(_pad_range)
local _port_F = tree:add(ofp_action_output_port_F, _port_range, _port)
if ofp_port_no[_port] ~= nil then
_port_F:append_text(" (" .. ofp_port_no[_port] .. ")")
end
local _max_len_F = tree:add(ofp_action_output_max_len_F, _max_len_range, _max_len)
if ofp_controller_max_len[_max_len] ~= nil then
_max_len_F:append_text(" (" .. ofp_controller_max_len[_max_len] .. ")")
end
tree:add(ofp_action_output_pad_F, _pad_range, _pad)
return pointer
end
function ofp_action_group(buffer, pinfo, tree)
local _group_id_range = buffer(0,4)
local pointer = 4
local _group_id = _group_id_range:uint()
tree:add(ofp_action_group_group_id_F, _group_id_range, _group_id)
return pointer
end
function ofp_action_set_queue(buffer, pinfo, tree)
local _queue_id_range = buffer(0,4)
local pointer = 4
local _queue_id = _queue_id_range:uint()
tree:add(ofp_action_group_queue_id_F, _queue_id_range, _queue_id)
return pointer
end
function ofp_action_mpls_ttl(buffer, pinfo, tree)
local _mpls_ttl_range = buffer(0,1)
local _pad_range = buffer(1,3)
local pointer = 4
local _mpls_ttl = _mpls_ttl_range:uint()
local _pad = tostring(_pad_range)
tree:add(ofp_action_mpls_ttl_mpls_ttl_F, _mpls_ttl_range, _mpls_ttl)
tree:add(ofp_action_mpls_ttl_pad_F, _pad_range, _pad)
return pointer
end
function ofp_action_nw_ttl(buffer, pinfo, tree)
local _nw_ttl_range = buffer(0,1)
local _pad_range = buffer(1,3)
local pointer = 4
local _nw_ttl = _nw_ttl_range:uint()
local _pad = tostring(_pad_range)
tree:add(ofp_action_nw_ttl_nw_ttl_F, _nw_ttl_range, _nw_ttl)
tree:add(ofp_action_nw_ttl_pad_F, _pad_range, _pad)
return pointer
end
function ofp_action_push(buffer, pinfo, tree)
local _ethertype_range = buffer(0,2)
local _pad_range = buffer(2,2)
local pointer = 4
local _ethertype = _ethertype_range:uint()
local _pad = tostring(_pad_range)
tree:add(ofp_action_push_ethertype_F, _ethertype_range, _ethertype)
tree:add(ofp_action_push_pad_F, _pad_range, _pad)
return pointer
end
function ofp_action_pop_mpls(buffer, pinfo, tree)
local _ethertype_range = buffer(0,2)
local _pad_range = buffer(2,2)
local pointer = 4
local _ethertype = _ethertype_range:uint()
local _pad = tostring(_pad_range)
tree:add(ofp_action_pop_mpls_ethertype_F, _ethertype_range, _ethertype)
tree:add(ofp_action_pop_mpls_pad_F, _pad_range, _pad)
return pointer
end