summaryrefslogtreecommitdiff
path: root/tests/tunnel.at
blob: ddeb66bc9fb7b94f0c37f346b8d09feafa4d620b (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
AT_BANNER([tunnel])

AT_SETUP([tunnel - input])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 ofport_request=1\
                    -- add-port br0 p2 -- set Interface p2 type=gre \
                    options:local_ip=2.2.2.2 options:remote_ip=1.1.1.1 \
                    ofport_request=2 \
                    -- add-port br0 p3 -- set Interface p3 type=gre \
                    options:remote_ip=2.2.2.2 ofport_request=3])
AT_DATA([flows.txt], [dnl
actions=IN_PORT
])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: remote_ip=1.1.1.1)
    p2 2/1: (gre: local_ip=2.2.2.2, remote_ip=1.1.1.1)
    p3 3/1: (gre: remote_ip=2.2.2.2)
])

dnl remote_ip
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=1.2.3.4,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,flags(df))),1
])

dnl local_ip, remote_ip
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(src=2.2.2.2,dst=1.1.1.1,ttl=64,flags(df))),1
])

dnl reconfigure, local_ip, remote_ip
AT_CHECK([ovs-vsctl set Interface p2 type=gre options:local_ip=2.2.2.3 \
          options:df_default=false options:ttl=1 options:csum=true \
          -- set Interface p3 type=vxlan])
AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: remote_ip=1.1.1.1)
    p2 2/1: (gre: csum=true, df_default=false, local_ip=2.2.2.3, remote_ip=1.1.1.1, ttl=1)
    p3 3/4789: (vxlan: remote_ip=2.2.2.2)
])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,flags(df))),1
])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.3,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(src=2.2.2.3,dst=1.1.1.1,ttl=1,flags(csum))),1
])

dnl nonexistent tunnel
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=5.5.5.5,dst=6.6.6.6,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [2], [ignore], [dnl
no OpenFlow tunnel port for this packet
ovs-appctl: ovs-vswitchd: server returned an error
])

OVS_VSWITCHD_STOP(["/receive tunnel port not found/d"])
AT_CLEANUP

AT_SETUP([tunnel - ECN decapsulation])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2])
AT_DATA([flows.txt], [dnl
actions=2
])

AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: remote_ip=1.1.1.1)
    p2 2/2: (dummy)
])

dnl Tunnel CE and encapsulated packet CE
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,tos=0x3,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=3,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=3,tun_flags=-df-csum-key,in_port=1,nw_ecn=3,nw_frag=no
Datapath actions: 2
])

dnl Tunnel CE and encapsulated packet ECT(1)
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,tos=0x3,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=1,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=3,tun_flags=-df-csum-key,in_port=1,nw_ecn=1,nw_frag=no
Datapath actions: set(ipv4(tos=0x3/0x3)),2
])

dnl Tunnel CE and encapsulated packet ECT(2)
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,tos=0x3,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=2,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=3,tun_flags=-df-csum-key,in_port=1,nw_ecn=2,nw_frag=no
Datapath actions: set(ipv4(tos=0x3/0x3)),2
])

dnl Tunnel CE and encapsulated packet Non-ECT
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,tos=0x3,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -3 stdout], [0],
  [Final flow: unchanged
Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=3,tun_flags=-df-csum-key,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: drop
])
OVS_VSWITCHD_STOP(["/dropping tunnel packet marked ECN CE but is not ECN capable/d"])
AT_CLEANUP

AT_SETUP([tunnel - input with matching tunnel mask])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 \
                    ofport_request=1	\
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: remote_ip=1.1.1.1)
    p2 2/2: (dummy)
])

AT_CHECK([ovs-appctl dpctl/add-flow "tunnel(dst=1.1.1.1,src=3.3.3.200/255.255.255.0,tp_dst=123,tp_src=1,ttl=64),recirc_id(0),in_port(1),eth(),eth_type(0x0800),ipv4()" "2"])

AT_CHECK([ovs-appctl dpctl/dump-flows | tail -1], [0], [dnl
recirc_id(0),tunnel(src=3.3.3.200/255.255.255.0,dst=1.1.1.1,ttl=64,tp_src=1,tp_dst=123),in_port(1),eth(),eth_type(0x0800), packets:0, bytes:0, used:never, actions:2
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - too long nested attributes])
OVS_VSWITCHD_START([add-port br0 p1 \
    -- set Interface p1 type=gre options:remote_ip=1.1.1.1 ofport_request=1 \
    -- add-port br0 p2 -- set Interface p2 type=dummy ofport_request=2])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: remote_ip=1.1.1.1)
    p2 2/2: (dummy)
])

dst_single="dst=1.1.1.1"
dst_rep=${dst_single}
dnl Size of one OVS_TUNNEL_KEY_ATTR_IPV4_DST is 4 bytes + NLA_HDRLEN (4 bytes).
dnl One nested message has room for UINT16_MAX - NLA_HDRLEN (4) bytes, i.e.
dnl (UINT16_MAX - NLA_HDRLEN) / (4 + NLA_HDRLEN) = 8191.375 of dst addresses.
for i in `seq 1 8192` ; do
    dst_rep="${dst_rep},${dst_single}"
done

AT_CHECK([ovs-appctl dpctl/add-flow "tunnel(${dst_rep})" "2" 2>&1 | dnl
          sed "s/${dst_single},//g"], [], [dnl
ovs-vswitchd: parsing flow key (syntax error at tunnel(dst=1.1.1.1)) (Argument list too long)
ovs-appctl: ovs-vswitchd: server returned an error
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - output])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 options:local_ip=2.2.2.2 \
                    options:key=5 ofport_request=1\
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2])
AT_DATA([flows.txt], [dnl
actions=output:1
])

OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: key=5, local_ip=2.2.2.2, remote_ip=1.1.1.1)
    p2 2/2: (dummy)
])

dnl Basic
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,ttl=64,flags(df|key))),1
])

dnl ECN
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=1,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,tos=0x1,ttl=64,flags(df|key))),1
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - unencrypted tunnel and not setting skb_mark])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 options:local_ip=2.2.2.2 \
                    options:key=5 ofport_request=1\
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
AT_DATA([flows.txt], [dnl
actions=output:1
])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,ttl=64,flags(df|key))),1
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - unencrypted tunnel and setting skb_mark to 1])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 options:local_ip=2.2.2.2 \
                    options:key=5 ofport_request=1\
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
AT_DATA([flows.txt], [dnl
actions=load:0x1->NXM_NX_PKT_MARK[[]],output:1
])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,ttl=64,flags(df|key))),set(skb_mark(0x1)),1
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - unencrypted tunnel and setting skb_mark to 2])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 options:local_ip=2.2.2.2 \
                    options:key=5 ofport_request=1\
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
AT_DATA([flows.txt], [dnl
actions=load:0x2->NXM_NX_PKT_MARK[[]],output:1
])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,ttl=64,flags(df|key))),set(skb_mark(0x2)),1
])

AT_CHECK([ovs-appctl netdev-dummy/receive p2 'aa55aa550001f8bc124434b6080045000054ba20000040018486010103580101037001004227e75400030af3195500000000f265010000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637'])

ovs-appctl time/warp 5000

AT_CHECK([
ovs-appctl coverage/read-counter datapath_drop_invalid_port
], [0], [dnl
1
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - ToS and TTL inheritance])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 options:tos=inherit \
                    options:ttl=inherit ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
AT_DATA([flows.txt], [dnl
actions=output:1
])

OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: remote_ip=1.1.1.1, tos=inherit, ttl=inherit)
    p2 2/2: (dummy)
])

dnl Basic
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,tos=0x4,ttl=128,flags(df))),1
])

dnl ECN
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=5,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,tos=0x5,ttl=128,flags(df))),1
])

dnl non-IP
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0806),arp(sip=1.2.3.4,tip=5.6.7.8,op=1,sha=00:0f:10:11:12:13,tha=00:14:15:16:17:18)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,flags(df))),1
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - set_tunnel])
OVS_VSWITCHD_START([dnl
    add-port br0 p1 -- set Interface p1 type=gre options:key=flow \
        options:remote_ip=1.1.1.1 ofport_request=1 \
    -- add-port br0 p2 -- set Interface p2 type=gre options:key=flow \
        options:remote_ip=2.2.2.2 ofport_request=2 \
    -- add-port br0 p3 -- set Interface p3 type=gre options:key=flow \
        options:remote_ip=3.3.3.3 ofport_request=3 \
    -- add-port br0 p4 -- set Interface p4 type=gre options:key=flow \
        options:remote_ip=4.4.4.4 ofport_request=4])
AT_DATA([flows.txt], [dnl
actions=set_tunnel:1,output:1,set_tunnel:2,output:2,set_tunnel:3,output:3,set_tunnel:5,output:4
])

OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: key=flow, remote_ip=1.1.1.1)
    p2 2/1: (gre: key=flow, remote_ip=2.2.2.2)
    p3 3/1: (gre: key=flow, remote_ip=3.3.3.3)
    p4 4/1: (gre: key=flow, remote_ip=4.4.4.4)
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(100),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
set(tunnel(tun_id=0x1,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x2,dst=2.2.2.2,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x3,dst=3.3.3.3,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x5,dst=4.4.4.4,ttl=64,flags(df|key))),1
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - key])
OVS_VSWITCHD_START([dnl
    add-port br0 p1 -- set Interface p1 type=gre options:key=1 \
        options:remote_ip=1.1.1.1 ofport_request=1 \
    -- add-port br0 p2 -- set Interface p2 type=gre options:in_key=2 \
        options:out_key=3 options:remote_ip=1.1.1.1 ofport_request=2 \
    -- add-port br0 p3 -- set Interface p3 type=gre options:out_key=5 \
        options:remote_ip=1.1.1.1 ofport_request=3])
AT_DATA([flows.txt], [dnl
actions=IN_PORT,output:1,output:2,output:3
])

OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: key=1, remote_ip=1.1.1.1)
    p2 2/1: (gre: in_key=2, out_key=3, remote_ip=1.1.1.1)
    p3 3/1: (gre: out_key=5, remote_ip=1.1.1.1)
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x1,src=1.1.1.1,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
set(tunnel(tun_id=0x1,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x3,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x5,dst=1.1.1.1,ttl=64,flags(df|key))),1
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x2,src=1.1.1.1,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
set(tunnel(tun_id=0x3,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x1,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x5,dst=1.1.1.1,ttl=64,flags(df|key))),1
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(src=1.1.1.1,dst=2.2.2.2,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
set(tunnel(tun_id=0x5,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x1,dst=1.1.1.1,ttl=64,flags(df|key))),1,dnl
set(tunnel(tun_id=0x3,dst=1.1.1.1,ttl=64,flags(df|key))),1
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0xf,src=1.1.1.1,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [2], [ignore], [dnl
no OpenFlow tunnel port for this packet
ovs-appctl: ovs-vswitchd: server returned an error
])
OVS_VSWITCHD_STOP(["/receive tunnel port not found/d"])
AT_CLEANUP

AT_SETUP([tunnel - key match])
OVS_VSWITCHD_START([dnl
    add-port br0 p1 -- set Interface p1 type=gre options:key=flow \
        options:remote_ip=1.1.1.1 ofport_request=1 \
    -- add-port br0 p2 -- set Interface p2 type=gre options:key=3 \
        options:remote_ip=3.3.3.3 ofport_request=2 \
    -- add-port br0 p3 -- set Interface p3 type=dummy ofport_request=3 \
    -- add-port br0 p4 -- set Interface p4 type=dummy ofport_request=4 \
    -- add-port br0 p5 -- set Interface p5 type=dummy ofport_request=5])
AT_DATA([flows.txt], [dnl
tun_id=2,actions=output:3
tun_id=3,actions=output:4,set_tunnel:2,resubmit:99,set_tunnel:4,output:2,resubmit:99
tun_id=4,actions=output:5
])

OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (gre: key=flow, remote_ip=1.1.1.1)
    p2 2/1: (gre: key=3, remote_ip=3.3.3.3)
    p3 3/3: (dummy)
    p4 4/4: (dummy)
    p5 5/5: (dummy)
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x2,src=1.1.1.1,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [dnl
Datapath actions: 3
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x3,src=1.1.1.1,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [dnl
Datapath actions: 4,3,set(tunnel(tun_id=0x3,dst=3.3.3.3,ttl=64,flags(df|key))),1,5
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x3,src=3.3.3.3,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [dnl
Datapath actions: 4,3,5
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.2,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0], [dnl
Datapath actions: drop
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - Geneve])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=geneve \
                    options:remote_ip=1.1.1.1 ofport_request=1 options:dst_port=5000])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/5000: (geneve: dst_port=5000, remote_ip=1.1.1.1)
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - VXLAN])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \
                    options:remote_ip=1.1.1.1 ofport_request=1])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/4789: (vxlan: remote_ip=1.1.1.1)
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - table version])
dnl check if changes in the egress bridge flow table affects
dnl discovering the link layer address of tunnel endpoints.
OVS_VSWITCHD_START([add-port br0 p0 -- set Interface p0 type=dummy ofport_request=1 other-config:hwaddr=aa:55:aa:55:00:00])
AT_CHECK([ovs-vsctl add-br int-br -- set bridge int-br datapath_type=dummy], [0])
AT_CHECK([ovs-vsctl add-port int-br v1 -- set Interface v1 type=vxlan \
                       options:remote_ip=172.31.1.2 options:key=123 \
                       ofport_request=2 \
                 -- add-port int-br v2 -- set Interface v2 type=internal \
                       ofport_request=3 \
                       ], [0])

AT_CHECK([ovs-appctl dpif/show], [0], [dnl
dummy@ovs-dummy: hit:0 missed:0
  br0:
    br0 65534/100: (dummy-internal)
    p0 1/1: (dummy)
  int-br:
    int-br 65534/2: (dummy-internal)
    v1 2/4789: (vxlan: key=123, remote_ip=172.31.1.2)
    v2 3/3: (dummy-internal)
])

dnl First setup dummy interface IP address, then add the route
dnl so that tnl-port table can get valid IP address for the device.
AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 172.31.1.1/24], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 172.31.1.0/24 br0], [0], [OK
])

dnl change the flow table to bump the internal table version
AT_CHECK([ovs-ofctl add-flow int-br action=normal])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 action=normal])

dnl Check Neighbour discovery.
AT_CHECK([ovs-vsctl -- set Interface p0 options:pcap=p0.pcap])

AT_CHECK([ovs-appctl netdev-dummy/receive int-br 'in_port(2),eth(src=aa:55:aa:55:00:00,dst=f8:bc:12:ff:ff:ff),eth_type(0x0800),ipv4(src=1.1.3.92,dst=1.1.3.88,proto=1,tos=0,ttl=64,frag=no),icmp(type=0,code=0)'])
AT_CHECK([ovs-pcap p0.pcap > p0.pcap.txt 2>&1])

dnl When the wrong version is used, the flow is not visible and the
dnl packet is dropped.
AT_CHECK([cat p0.pcap.txt | grep ffffffffffffaa55aa55000008060001080006040001aa55aa550000ac1f0101000000000000ac1f0102 | uniq], [0], [dnl
ffffffffffffaa55aa55000008060001080006040001aa55aa550000ac1f0101000000000000ac1f0102
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - LISP])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=lisp \
                    options:remote_ip=1.1.1.1 ofport_request=1])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/4341: (lisp: remote_ip=1.1.1.1)
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - ERSPAN])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=erspan \
                    options:remote_ip=1.1.1.1 options:key=1 options:erspan_ver=1 \
                    options:erspan_idx=0x0 ofport_request=1 \
                 -- add-port br0 p2 -- set Interface p2 type=erspan \
                    options:remote_ip=1.1.1.1 ofport_request=2 \
                    options:key=flow options:erspan_ver=1 options:erspan_idx=flow \
                 -- add-port br0 p3 -- set Interface p3 type=erspan \
                    options:remote_ip=1.1.1.1 ofport_request=3 \
                    options:key=10 options:erspan_ver=2 options:erspan_dir=flow \
                    options:erspan_hwid=flow \
                 -- add-port br0 p4 -- set Interface p4 type=erspan \
                    options:remote_ip=1.2.3.4 ofport_request=4 \
                    options:key=flow options:erspan_ver=flow\
                 ])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (erspan: erspan_idx=0x0, erspan_ver=1, key=1, remote_ip=1.1.1.1)
    p2 2/1: (erspan: erspan_idx=flow, erspan_ver=1, key=flow, remote_ip=1.1.1.1)
    p3 3/1: (erspan: erspan_dir=flow, erspan_hwid=flow, erspan_ver=2, key=10, remote_ip=1.1.1.1)
    p4 4/1: (erspan: erspan_dir=flow, erspan_hwid=flow, erspan_idx=flow, erspan_ver=flow, key=flow, remote_ip=1.2.3.4)
])

dnl Check ERSPAN v1 flow-based tunnel push
AT_CHECK([ovs-ofctl add-flow br0 "in_port=1, actions=set_tunnel:11,set_field:0x1->tun_erspan_idx,2"])

dnl Check ERSPAN v2 flow-based tunnel push
AT_CHECK([ovs-ofctl add-flow br0 "in_port=2, actions=set_field:1->tun_erspan_dir,set_field:0x0->tun_erspan_hwid,3"])

AT_CHECK([ovs-ofctl add-flow br0 "in_port=3, actions=set_field:2->tun_erspan_ver,set_field:1->tun_erspan_dir,set_field:0x0->tun_erspan_hwid,4"])

AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip],
[0], [dnl
NXST_FLOW reply:
 in_port=1 actions=set_tunnel:0xb,set_field:0x1->tun_erspan_idx,output:2
 in_port=2 actions=set_field:1->tun_erspan_dir,set_field:0->tun_erspan_hwid,output:3
 in_port=3 actions=set_field:2->tun_erspan_ver,set_field:1->tun_erspan_dir,set_field:0->tun_erspan_hwid,output:4
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - different VXLAN UDP port])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \
                    options:remote_ip=1.1.1.1 ofport_request=1 options:dst_port=4341])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/4341: (vxlan: dst_port=4341, remote_ip=1.1.1.1)
])

dnl change UDP port

AT_CHECK([ovs-vsctl -- set Interface p1 options:dst_port=5000])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/5000: (vxlan: dst_port=5000, remote_ip=1.1.1.1)
])

dnl change UDP port to default

AT_CHECK([ovs-vsctl -- set Interface p1 options:dst_port=4789])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/4789: (vxlan: remote_ip=1.1.1.1)
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([ofproto-dpif - set_field - tun_src/tun_dst/tun_id])
OVS_VSWITCHD_START([dnl
    add-port br0 p1 -- set Interface p1 type=gre options:key=flow \
        options:remote_ip=1.1.1.1 ofport_request=1 \
    -- add-port br0 p2 -- set Interface p2 type=gre options:key=flow \
        options:remote_ip=flow ofport_request=2 \
    -- add-port br0 p3 -- set Interface p3 type=gre options:key=flow \
        options:remote_ip=flow options:local_ip=flow ofport_request=3 \
    -- add-port br0 p4 -- set Interface p4 type=gre options:key=3 \
        options:remote_ip=flow ofport_request=4 \
    -- add-port br0 p5 -- set Interface p5 type=gre options:key=flow \
        options:remote_ip=5.5.5.5 ofport_request=5])

OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP
add_of_ports br0 90
AT_DATA([flows.txt], [dnl
in_port=90 actions=resubmit:1,resubmit:2,resubmit:3,resubmit:4,resubmit:5
in_port=1 actions=set_field:42->tun_id,output:1
in_port=2 actions=set_field:3.3.3.3->tun_dst,output:2
in_port=3 actions=set_field:1.1.1.1->tun_src,set_field:4.4.4.4->tun_dst,output:3
in_port=4 actions=set_field:2.2.2.2->tun_dst,output:4
in_port=5 actions=set_field:5->tun_id
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(90),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x2a,dst=1.1.1.1,ttl=64,flags(df|key))),1,set(tunnel(tun_id=0x2a,dst=3.3.3.3,ttl=64,flags(df|key))),1,set(tunnel(tun_id=0x2a,src=1.1.1.1,dst=4.4.4.4,ttl=64,flags(df|key))),1,set(tunnel(tun_id=0x3,dst=2.2.2.2,ttl=64,flags(df|key))),1
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - ERSPAN v1/v2 metadata])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy \
                        ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                        ofport_request=2])

# Add these ports separately to ensure that they get the datapath port
# number expected below.
ovs-vsctl -- add-port br0 p3 \
          -- set Interface p3 type=erspan \
                              ofport_request=3 \
                              options:remote_ip=1.1.1.1 \
                              options:key=1 options:erspan_ver=1 \
                              options:erspan_idx=7 \
          -- add-port br0 p4 \
          -- set Interface p4 type=erspan \
                              ofport_request=4 \
                              options:remote_ip=1.1.1.2 \
                              options:key=2 options:erspan_ver=2 \
                              options:erspan_dir=1 \
                              options:erspan_hwid=7
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (dummy)
    p2 2/2: (dummy)
    p3 3/3: (erspan: erspan_idx=0x7, erspan_ver=1, key=1, remote_ip=1.1.1.1)
    p4 4/3: (erspan: erspan_dir=1, erspan_hwid=0x7, erspan_ver=2, key=2, remote_ip=1.1.1.2)
])

AT_DATA([flows.txt], [dnl
in_port=1,actions=3
in_port=2,actions=4
in_port=3,tun_erspan_ver=1,tun_erspan_idx=0x7,actions=1
in_port=4,tun_erspan_ver=2,tun_erspan_dir=1,tun_erspan_hwid=0xf/0x1,actions=2
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

dnl test encap: in_port=1,actions=3 (erspan v1 port)
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x1,dst=1.1.1.1,ttl=64,erspan(ver=1,idx=0x7),flags(df|key))),3
])

dnl test encap: in_port=2,actions=4 (erspan v2 port)
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x2,dst=1.1.1.2,ttl=64,erspan(ver=2,dir=1,hwid=0x7),flags(df|key))),3
])

dnl receive packet from ERSPAN port with v1 metadata
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x1,src=1.1.1.1,dst=2.2.2.2,ttl=64,erspan(ver=1,idx=0x7),flags(df|key)),in_port(3),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0x1,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=0,tun_erspan_ver=1,tun_erspan_idx=0x7,tun_flags=+df-csum+key,in_port=3,nw_frag=no
Datapath actions: 1
])

dnl receive packet from ERSPAN port with wrong v1 metadata
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x1,src=1.1.1.1,dst=2.2.2.2,ttl=64,erspan(ver=1,idx=0xabcd),flags(df|key)),in_port(3),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0x1,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=0,tun_erspan_ver=1,tun_erspan_idx=0xabcd,tun_flags=+df-csum+key,in_port=3,nw_frag=no
Datapath actions: drop
])

dnl receive packet from ERSPAN port with v2 metadata
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x2,src=1.1.1.2,dst=2.2.2.2,ttl=64,erspan(ver=2,dir=1,hwid=0x7),flags(df|key)),in_port(3),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0x2,tun_src=1.1.1.2,tun_dst=2.2.2.2,tun_tos=0,tun_erspan_ver=2,tun_erspan_dir=1,tun_erspan_hwid=0x1,tun_flags=+df-csum+key,in_port=4,nw_frag=no
Datapath actions: 2
])

dnl receive packet from ERSPAN port with wrong v2 metadata
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x2,src=1.1.1.2,dst=2.2.2.2,ttl=64,erspan(ver=2,dir=0,hwid=0x17),flags(df|key)),in_port(3),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0x2,tun_src=1.1.1.2,tun_dst=2.2.2.2,tun_tos=0,tun_erspan_ver=2,tun_erspan_dir=0,tun_erspan_hwid=0x1,tun_flags=+df-csum+key,in_port=4,nw_frag=no
Datapath actions: drop
])

dnl test wildcard mask: recevie all v2 regardless of its metadata
AT_CHECK([ovs-ofctl del-flows br0 in_port=4,tun_erspan_ver=2,tun_erspan_dir=1,tun_erspan_hwid=0xf/0x1])
AT_CHECK([ovs-ofctl add-flow br0 in_port=4,tun_erspan_ver=2,tun_erspan_dir=0/0,tun_erspan_hwid=0x0/0x0,actions=2])

AT_CHECK([ovs-ofctl --sort=in_port dump-flows br0 | ofctl_strip],
[0], [dnl
 in_port=1 actions=output:3
 in_port=2 actions=output:4
 tun_erspan_ver=1,tun_erspan_idx=0x7,in_port=3 actions=output:1
 tun_erspan_ver=2,in_port=4 actions=output:2
])

dnl this time it won't drop
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x2,src=1.1.1.2,dst=2.2.2.2,ttl=64,erspan(ver=2,dir=0,hwid=0x17),flags(df|key)),in_port(3),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0x2,tun_src=1.1.1.2,tun_dst=2.2.2.2,tun_tos=0,tun_erspan_ver=2,tun_flags=+df-csum+key,in_port=4,nw_frag=no
Datapath actions: 2
])

dnl flow-based erspan_idx options
AT_CHECK([ovs-vsctl add-port br0 p5 -- set Interface p5 type=erspan \
          options:remote_ip=1.1.1.2 ofport_request=5 \
          options:key=flow options:erspan_ver=1 options:erspan_idx=flow])

AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-flow br0 "in_port=1, actions=set_tunnel:11,set_field:0x7->tun_erspan_idx,5"])

AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip],
[0], [dnl
NXST_FLOW reply:
 in_port=1 actions=set_tunnel:0xb,set_field:0x7->tun_erspan_idx,output:5
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0xb,dst=1.1.1.2,ttl=64,erspan(ver=1,idx=0x7),flags(df|key))),3
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - Geneve metadata])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=geneve \
                    options:remote_ip=1.1.1.1 ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=0,len=4}->tun_metadata0,{class=0xffff,type=1,len=8}->tun_metadata1"])

AT_DATA([flows.txt], [dnl
in_port=2,actions=set_field:0xa->tun_metadata0,set_field:0x1234567890abcdef->tun_metadata1,1
tun_metadata0=0xb/0xf,actions=2
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

dnl Option generation
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=6081,geneve({class=0xffff,type=0,len=4,0xa}{class=0xffff,type=0x1,len=8,0x1234567890abcdef}),flags(df))),6081
])

dnl Option match
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0xb}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata0=0xb/0xf,in_port=1,nw_frag=no
Datapath actions: 2
])

dnl Skip unknown option
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0xb}{class=0xffff,type=2,len=4,0xc}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata0=0xb/0xf,in_port=1,nw_frag=no
Datapath actions: 2
])

dnl Check mapping table constraints
AT_CHECK([ovs-ofctl del-flows br0])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=2,len=124}->tun_metadata2,{class=0xffff,type=3,len=124}->tun_metadata3"], [1], [ignore],
[OFPT_ERROR (xid=0x4): NXTTMFC_TABLE_FULL
NXT_TLV_TABLE_MOD (xid=0x4):
 ADD mapping table:
  class  type  length  match field
 ------  ----  ------  --------------
 0xffff   0x2     124  tun_metadata2
 0xffff   0x3     124  tun_metadata3
])

AT_CHECK([ovs-ofctl add-flow br0 "tun_metadata0,tun_metadata0,actions=drop"], [1], [ignore],
[ovs-ofctl: field tun_metadata0 set multiple times
])

AT_CHECK([ovs-ofctl add-flow br0 "tun_metadata0=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef,tun_metadata1=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef,tun_metadata2=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef,tun_metadata3=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef,tun_metadata4=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef,actions=drop"], [1], [ignore],
[ovs-ofctl: field tun_metadata4 exceeds maximum size for tunnel metadata (used 320, max 256)
])

dnl Allocation and match with fragmented address space
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=2,len=124}->tun_metadata2"])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=3,len=4}->tun_metadata3"])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=4,len=112}->tun_metadata4"])
AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=3,len=4}->tun_metadata3"])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=3,len=8}->tun_metadata3"])

AT_CHECK([ovs-ofctl add-flow br0 tun_metadata3=0x1234567890abcdef,actions=2])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=3,len=8,0x1234567890abcdef}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata3=0x1234567890abcdef,in_port=1,nw_frag=no
Datapath actions: 2
])

AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip],
[0], [dnl
NXST_FLOW reply:
 tun_metadata3=0x1234567890abcdef actions=output:2
])

dnl A TLV mapping should not be removed if any active flow uses the mapping.
AT_CHECK([ovs-ofctl del-tlv-map br0], [1], [], [dnl
OFPT_ERROR (xid=0x4): NXTTMFC_INVALID_TLV_DEL
NXT_TLV_TABLE_MOD (xid=0x4):
 CLEAR
])

AT_CHECK([ovs-ofctl del-flows br0], [0])
AT_CHECK([ovs-ofctl del-tlv-map br0], [0])

dnl Flow modification
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=1,len=4}->tun_metadata0"])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=2,len=4}->tun_metadata1"])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=3,len=4}->tun_metadata2"])

AT_CHECK([ovs-ofctl add-flow br0 "in_port=1 actions=multipath(eth_src,50,modulo_n,1,0,tun_metadata0[[0..31]])"])
AT_CHECK([ovs-ofctl add-flow br0 "in_port=2 actions=push:tun_metadata1[[0..31]],clone(move:tun_metadata2[[0..31]]->reg0[[0..31]])"])

AT_CHECK([ovs-ofctl add-flow br0 "in_port=1 actions=output:4"])
AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=3,len=4}->tun_metadata0"])

AT_CHECK([ovs-ofctl add-flow br0 "in_port=2 actions=push:tun_metadata2[[0..31]]"])
AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=2,len=4}->tun_metadata1"])
AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=3,len=4}->tun_metadata2"], [1], [], [dnl
OFPT_ERROR (xid=0x4): NXTTMFC_INVALID_TLV_DEL
NXT_TLV_TABLE_MOD (xid=0x4):
 DEL mapping table:
  class  type  length  match field
 ------  ----  ------  --------------
 0xffff   0x3       4  tun_metadata2
])

AT_CHECK([ovs-ofctl del-flows br0], [0])
AT_CHECK([ovs-ofctl del-tlv-map br0], [0])

dnl Learn action
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=1,len=4}->tun_metadata1"])
AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=2,len=4}->tun_metadata2"])
AT_CHECK([ovs-ofctl add-flow br0 "in_port=2, eth_src=00:00:00:00:00:01 actions=learn(tun_metadata1[[0..31]]=reg1, output:NXM_OF_IN_PORT[[]])"])
AT_CHECK([ovs-ofctl add-flow br0 "in_port=2, eth_src=00:00:00:00:00:02 actions=learn(reg1[[0..31]]=0xFF, load:reg1[[0..31]]->tun_metadata2[[0..31]])"])
flow1="in_port(2),eth(src=00:00:00:00:00:01,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0800)"
flow2="in_port(2),eth(src=00:00:00:00:00:02,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0800)"
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow1" -generate], [0], [stdout])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow2" -generate], [0], [stdout])

dnl Delete flows with learn action
AT_CHECK([ovs-ofctl del-flows br0 "in_port=2"])

AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=1,len=4}->tun_metadata1"], [1], [], [dnl
OFPT_ERROR (xid=0x4): NXTTMFC_INVALID_TLV_DEL
NXT_TLV_TABLE_MOD (xid=0x4):
 DEL mapping table:
  class  type  length  match field
 ------  ----  ------  --------------
 0xffff   0x1       4  tun_metadata1
])
AT_CHECK([ovs-ofctl del-flows br0 "tun_metadata1"])
AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=1,len=4}->tun_metadata1"])

AT_CHECK([ovs-ofctl del-tlv-map br0 "{class=0xffff,type=2,len=4}->tun_metadata2"], [1], [], [dnl
OFPT_ERROR (xid=0x4): NXTTMFC_INVALID_TLV_DEL
NXT_TLV_TABLE_MOD (xid=0x4):
 DEL mapping table:
  class  type  length  match field
 ------  ----  ------  --------------
 0xffff   0x2       4  tun_metadata2
])
AT_CHECK([ovs-ofctl del-flows br0 "reg1=0xFF"])
AT_CHECK([ovs-ofctl del-tlv-map br0], [0])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - Geneve option present])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=geneve \
                    options:remote_ip=1.1.1.1 ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=0,len=4}->tun_metadata0,{class=0xffff,type=1,len=0}->tun_metadata1,{class=0xffff,type=2,len=4}->tun_metadata2"])

AT_DATA([flows.txt], [dnl
priority=1,tun_metadata0,actions=2
priority=2,tun_metadata1=0,actions=IN_PORT
priority=3,tun_metadata2=0,actions=drop
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort],
[0], [dnl
 priority=1,tun_metadata0 actions=output:2
 priority=2,tun_metadata1 actions=IN_PORT
 priority=3,tun_metadata2=0 actions=drop
NXST_FLOW reply:
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x12345678}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata0,tun_metadata1=NP,tun_metadata2=NP,in_port=1,nw_frag=no
Datapath actions: 2
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=1,len=0}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata1,tun_metadata2=NP,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=6081,geneve({class=0xffff,type=0x1,len=0}),flags(df))),6081
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - Delete Geneve option])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=geneve \
                    options:remote_ip=1.1.1.1 ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=0,len=4}->tun_metadata0,{class=0xffff,type=1,len=4}->tun_metadata1,{class=0xffff,type=2,len=4}->tun_metadata3"])

AT_DATA([flows.txt], [dnl
table=0,tun_metadata0=0x11112222,actions=set_field:0x55556666->tun_metadata1,resubmit(,1)
table=0,tun_metadata0=0x33334444,actions=delete_field:tun_metadata0,set_field:0x77778888->tun_metadata1,resubmit(,1)
table=0,tun_metadata0=0x88889999,actions=delete_field:tun_metadata3,resubmit(,1)
table=1,actions=IN_PORT
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x11112222}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata0=0x11112222,tun_metadata1=NP,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=6081,geneve({class=0xffff,type=0,len=4,0x11112222}{class=0xffff,type=0x1,len=4,0x55556666}),flags(df))),6081
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x33334444}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata0=0x33334444,tun_metadata1=NP,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=6081,geneve({class=0xffff,type=0x1,len=4,0x77778888}),flags(df))),6081
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x88889999}),flags(df|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=+df-csum+key,tun_metadata0=0x88889999,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=6081,geneve({class=0xffff,type=0,len=4,0x88889999}),flags(df))),6081
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - concomitant IPv6 and IPv4 tunnels])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \
                    options:remote_ip=1.1.1.1 ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=vxlan \
                    options:remote_ip=2001:cafe::1 ofport_request=2])
AT_DATA([flows.txt], [dnl
in_port=1,actions=2
in_port=2,actions=1
])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0,src=1.1.1.1,dst=1.1.1.2,ttl=64),in_port(4789)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(ipv6_dst=2001:cafe::1,ttl=64,tp_dst=4789,flags(df))),4789
])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x0,ipv6_src=2001:cafe::1,ipv6_dst=2001:cafe::2,ttl=64),in_port(4789)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=4789,flags(df))),4789
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - concomitant incompatible tunnels on the same port])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \
                    options:remote_ip=flow ofport_request=1])

AT_CHECK([ovs-vsctl add-port br0 p2 -- set Interface p2 type=vxlan \
                    options:remote_ip=flow options:exts=gbp options:key=1 ofport_request=2], [0],
  [], [ignore])

AT_CHECK([grep 'p2: could not set configuration (File exists)' ovs-vswitchd.log | sed "s/^.*\(p2:.*\)$/\1/"], [0],
  [p2: could not set configuration (File exists)
])

OVS_VSWITCHD_STOP(["/p2: VXLAN-GBP, and non-VXLAN-GBP tunnels can't be configured on the same dst_port/d
/p2: could not set configuration (File exists)/d"])
AT_CLEANUP

AT_SETUP([tunnel - concomitant incompatible tunnels on different ports])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \
                    options:remote_ip=flow ofport_request=1])

AT_CHECK([ovs-vsctl add-port br0 p2 -- set Interface p2 type=vxlan options:dst_port=9000 \
                    options:remote_ip=flow options:exts=gbp ofport_request=2])

AT_CHECK([grep p2 ovs-vswitchd.log | sed "s/^.*\(bridge br0:.*\)$/\1/"], [0],
  [bridge br0: added interface p2 on port 2
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - Mix Geneve/GRE options])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=geneve \
                    options:remote_ip=1.1.1.1 options:csum=true ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2 ofport_request=2 \
                    -- add-port br0 p3 -- set Interface p3 type=gre \
                    options:remote_ip=2.2.2.2 options:csum=false options:key=123 ofport_request=3])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

AT_DATA([flows.txt], [dnl
priority=1,in_port=1,actions=3
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort],
[0], [dnl
 priority=1,in_port=1 actions=output:3
NXST_FLOW reply:
])

dnl the input packet from geneve tunnel has flags(-df+csum+key) flags, making
dnl sure that the output gre tunnel has (+df-csum+key).
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x12345678}),flags(csum|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=-df+csum+key,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: set(tunnel(tun_id=0x7b,dst=2.2.2.2,ttl=64,flags(df|key))),1
])

AT_CHECK([ovs-ofctl add-tlv-map br0 "{class=0xffff,type=0,len=4}->tun_metadata0"])
AT_CHECK([ovs-ofctl del-flows br0])

AT_DATA([flows2.txt], [dnl
priority=1,in_port=1,tun_metadata0=0x123, actions=3
])
AT_CHECK([ovs-ofctl add-flows br0 flows2.txt])

AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x0,src=1.1.1.1,dst=1.1.1.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x123}),flags(csum|key)),in_port(6081),skb_mark(0),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,eth,ip,tun_id=0,tun_src=1.1.1.1,tun_dst=1.1.1.2,tun_tos=0,tun_flags=-df+csum+key,tun_metadata0=0x123,in_port=1,nw_ecn=0,nw_frag=no
Datapath actions: set(tunnel(tun_id=0x7b,dst=2.2.2.2,ttl=64,flags(df|key))),1
])

dnl without the fix, the actions have geneve options:
dnl set(tunnel(tun_id=0x7b,dst=2.2.2.2,ttl=64,geneve({class=0xffff,type=0,len=4,0x123}),flags(df|key))),1
dnl which is not correct

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - neighbor entry add and deletion])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
                    options:remote_ip=1.1.1.1 options:local_ip=2.2.2.2 \
                    options:key=5 ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=gre \
                    options:local_ip=3.3.3.3 options:remote_ip=4.4.4.4 \
                    ofport_request=2])
AT_CHECK([ovs-vsctl add-br br1 -- set bridge br1 datapath_type=dummy], [0])

dnl Populate tunnel neighbor cache table
AT_CHECK([
    ovs-appctl tnl/arp/set p1 10.0.0.1 00:00:10:00:00:01
    ovs-appctl tnl/arp/set p1 10.0.0.2 00:00:10:00:00:02
    ovs-appctl tnl/arp/set p2 10.0.1.1 00:00:10:00:01:01
    ovs-appctl tnl/arp/set br0 10.0.2.1 00:00:10:00:02:01
    ovs-appctl tnl/arp/set br0 10.0.2.2 00:00:10:00:02:02
    ovs-appctl tnl/arp/set br1 20.0.0.1 00:00:20:00:00:01
], [0], [stdout])

AT_CHECK([ovs-appctl tnl/neigh/show | tail -n+3 | sort], [0], [dnl
10.0.0.1                                      00:00:10:00:00:01   p1
10.0.0.2                                      00:00:10:00:00:02   p1
10.0.1.1                                      00:00:10:00:01:01   p2
10.0.2.1                                      00:00:10:00:02:01   br0
10.0.2.2                                      00:00:10:00:02:02   br0
20.0.0.1                                      00:00:20:00:00:01   br1
])

dnl neighbor table after deleting port p1
AT_CHECK([ovs-vsctl del-port br0 p1],[0], [stdout])
AT_CHECK([ovs-appctl tnl/neigh/show | tail -n+3 | grep -w p1 | sort], [0], [dnl
])

dnl neighbor table after deleting bridge br0
AT_CHECK([ovs-vsctl del-br br0],[0], [stdout])
AT_CHECK([ovs-appctl tnl/neigh/show | tail -n+3 | sort], [0], [dnl
20.0.0.1                                      00:00:20:00:00:01   br1
])

dnl neighbor table after deleting bridge br1
AT_CHECK([ovs-vsctl del-br br1],[0], [stdout])
AT_CHECK([ovs-appctl tnl/neigh/show | tail -n+3 | sort], [0], [dnl
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - GTP-U basic])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gtpu \
                    options:remote_ip=1.1.1.1 \
                    options:key=123 ofport_request=1])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/2152: (gtpu: key=123, remote_ip=1.1.1.1)
])

AT_CHECK([ovs-appctl tnl/ports/show |sort], [0], [dnl
Listening ports:
gtpu_sys_2152 (2152) ref_cnt=1
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([tunnel - GTP-U push and pop])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy \
                    ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=dummy \
                    ofport_request=2])

# Add these ports separately to ensure that they get the datapath port
# number expected below.
ovs-vsctl -- add-port br0 p3 \
          -- set Interface p3 type=gtpu \
                              ofport_request=3 \
                              options:remote_ip=1.1.1.1 \
                              options:key=3 \
                              options:packet_type=legacy_l3
ovs-vsctl -- add-port br0 p4 \
          -- set Interface p4 type=gtpu \
                              ofport_request=4 \
                              options:remote_ip=1.1.1.2 \
                              options:key=4 \
                              options:packet_type=legacy_l3
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

dnl AT_CHECK([ovs-appctl dpif/show | tail -n +4], [0], [dnl
AT_CHECK([ovs-appctl dpif/show | tail -n +4], [0], [dnl
    p1 1/1: (dummy)
    p2 2/2: (dummy)
    p3 3/2152: (gtpu: key=3, remote_ip=1.1.1.1)
    p4 4/2152: (gtpu: key=4, remote_ip=1.1.1.2)
])

AT_DATA([flows.txt], [dnl
in_port=1,actions=3
in_port=2,actions=4
in_port=3,tun_gtpu_flags=0x30,tun_gtpu_msgtype=255,actions=1
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl tnl/ports/show |sort], [0], [dnl
Listening ports:
gtpu_sys_2152 (2152) ref_cnt=2
])

dnl Encap: in_port=1,actions=3
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(tun_id=0x3,dst=1.1.1.1,ttl=64,tp_dst=2152,flags(df|key))),pop_eth,2152
])

dnl receive packet from GTP-U port, match it, and output to layer3 GRE
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'recirc_id(0),tunnel(tun_id=0x3,src=1.1.1.1,dst=2.2.2.2,ttl=64,gtpu(flags=0x30,msgtype=255),flags(df|key)),in_port(2152),packet_type(ns=1,id=0),skb_mark(0),ipv4(frag=no)'], [0], [stdout])
AT_CHECK([tail -2 stdout], [0],
  [Megaflow: recirc_id=0,packet_type=(1,0),tun_id=0x3,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_tos=0,gtpu_flags=0x30,gtpu_msgtype=255,tun_flags=+df-csum+key,in_port=3,dl_type=0x0000
Datapath actions: push_eth(src=00:00:00:00:00:00,dst=00:00:00:00:00:00),1
])

OVS_VSWITCHD_STOP
AT_CLEANUP

dnl This test configures two tunnels, then deletes the second and re-uses its
dnl name for different types of ports.  This was introduced to detect errors
dnl where port configuration persists even when the port is deleted and
dnl readded.
AT_SETUP([tunnel - re-create port with different types])
OVS_VSWITCHD_START(
  [add-port br0 p0 -- set int p0 type=gre options:remote_ip=127.0.0.1 -- \
   add-port br0 p1 -- set int p1 type=dummy -- \
   add-port br0 p2 -- set int p2 type=dummy])

AT_CHECK([ovs-vsctl set int p1 type=gre options:remote_ip=127.0.0.1])
AT_CHECK([ovs-vsctl del-port p1])
AT_CHECK([ovs-vsctl add-port br0 p1 -- set int p1 type=dummy])

OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
OVS_APP_EXIT_AND_WAIT([ovsdb-server])]
AT_CLEANUP

AT_SETUP([tunnel - SRV6 basic])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy \
                    ofport_request=1 \
                    -- add-port br0 p2 -- set Interface p2 type=srv6 \
                    options:remote_ip=flow \
                    ofport_request=2])
OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP

dnl First setup dummy interface IP address, then add the route
dnl so that tnl-port table can get valid IP address for the device.
AT_CHECK([ovs-appctl netdev-dummy/ip6addr br0 fc00::1/64], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add fc00::0/64 br0], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/show], [0], [dnl
Route Table:
User: fc00::/64 dev br0 SRC fc00::1
])

AT_DATA([flows.txt], [dnl
in_port=1,actions=set_field:fc00::2->tun_ipv6_dst,output:2
in_port=2,actions=1
])
AT_CHECK([ovs-ofctl add-flows br0 flows.txt])

AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
    br0 65534/100: (dummy-internal)
    p1 1/1: (dummy)
    p2 2/6: (srv6: remote_ip=flow)
])

AT_CHECK([ovs-appctl tnl/ports/show |sort], [0], [dnl
Listening ports:
srv6_sys (6) ref_cnt=1
srv6_sys (6) ref_cnt=1
])

AT_CHECK([ovs-appctl ofproto/list-tunnels], [0], [dnl
port 6: p2 (srv6: ::->flow, key=0, legacy_l3, dp port=6, ttl=64)
])

dnl Encap: ipv4 inner packet
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(ipv6_dst=fc00::2,ttl=64,flags(df))),pop_eth,6
])

dnl Encap: ipv6 inner packet
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x86dd),ipv6(src=2001:cafe::92,dst=2001:cafe::88,label=0,proto=47,tclass=0x0,hlimit=64)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
  [Datapath actions: set(tunnel(ipv6_dst=fc00::2,ttl=64,flags(df))),pop_eth,6
])

OVS_VSWITCHD_STOP
AT_CLEANUP