@@ -19,7 +19,6 @@ import (
1919 "encoding/json"
2020 "errors"
2121 "fmt"
22- "github.com/k8snetworkplumbingwg/ovs-cni/pkg/config"
2322 "math/rand"
2423 "net"
2524 "os/exec"
@@ -28,6 +27,8 @@ import (
2827 "syscall"
2928 "time"
3029
30+ "github.com/k8snetworkplumbingwg/ovs-cni/pkg/config"
31+
3132 "github.com/containernetworking/cni/pkg/skel"
3233 cnitypes "github.com/containernetworking/cni/pkg/types"
3334 types040 "github.com/containernetworking/cni/pkg/types/040"
@@ -96,6 +97,8 @@ const mtu = 1456
9697const defaultMTU = 1500
9798const IFNAME = "eth0"
9899const systemType = "system"
100+ const defaultVlanMode = "access"
101+ const vlanMode = "native-untagged"
99102
100103var _ = BeforeSuite (func () {
101104 output , err := exec .Command ("ovs-vsctl" , "show" ).CombinedOutput ()
@@ -330,7 +333,7 @@ var testFunc = func(version string) {
330333 Expect (len (brPorts )).To (Equal (0 ))
331334 }
332335
333- testAdd := func (conf string , setVlan , setMtu bool , Trunk string , targetNs ns.NetNS ) (string , cnitypes.Result ) {
336+ testAdd := func (conf string , setVlan , setMtu , setVLanMode bool , Trunk string , targetNs ns.NetNS ) (string , cnitypes.Result ) {
334337 args := & skel.CmdArgs {
335338 ContainerID : "dummy" ,
336339 Netns : targetNs .Path (),
@@ -378,6 +381,19 @@ var testFunc = func(version string) {
378381 Expect (portVlan ).To (Equal ("[]" ))
379382 }
380383
384+ By ("Checking that port the VLAN Mode matches expected state" )
385+ portVlanMode , err := getPortAttribute (hostIface .Name , "vlan_mode" )
386+ Expect (err ).NotTo (HaveOccurred ())
387+ if setVLanMode {
388+ Expect (portVlanMode ).To (Equal (vlanMode ))
389+ } else {
390+ if ! setVlan || Trunk != "" {
391+ Expect (portVlanMode ).To (Equal ("trunk" ))
392+ } else {
393+ Expect (portVlanMode ).To (Equal (defaultVlanMode ))
394+ }
395+ }
396+
381397 if setMtu {
382398 Expect (hostLink .Attrs ().MTU ).To (Equal (mtu ))
383399 } else {
@@ -478,7 +494,7 @@ var testFunc = func(version string) {
478494 defer func () {
479495 closeNS (targetNs )
480496 }()
481- hostIfName , result := testAdd (conf , true , false , "" , targetNs )
497+ hostIfName , result := testAdd (conf , true , false , false , "" , targetNs )
482498 testCheck (conf , result , targetNs )
483499 testDel (conf , hostIfName , targetNs , true )
484500 })
@@ -495,7 +511,7 @@ var testFunc = func(version string) {
495511 defer func () {
496512 closeNS (targetNs )
497513 }()
498- hostIfName , result := testAdd (conf , false , false , "" , targetNs )
514+ hostIfName , result := testAdd (conf , false , false , false , "" , targetNs )
499515 testCheck (conf , result , targetNs )
500516 testDel (conf , hostIfName , targetNs , true )
501517 })
@@ -513,7 +529,7 @@ var testFunc = func(version string) {
513529 defer func () {
514530 closeNS (targetNs )
515531 }()
516- hostIfName , result := testAdd (conf , false , false , "[10, 11, 12, 15, 17, 18]" , targetNs )
532+ hostIfName , result := testAdd (conf , false , false , false , "[10, 11, 12, 15, 17, 18]" , targetNs )
517533 testCheck (conf , result , targetNs )
518534 testDel (conf , hostIfName , targetNs , true )
519535 })
@@ -531,7 +547,7 @@ var testFunc = func(version string) {
531547 defer func () {
532548 closeNS (targetNs )
533549 }()
534- hostIfName , result := testAdd (conf , false , false , "[10, 11, 12, 15, 17, 18]" , targetNs )
550+ hostIfName , result := testAdd (conf , false , false , false , "[10, 11, 12, 15, 17, 18]" , targetNs )
535551 testCheck (conf , result , targetNs )
536552 testDel (conf , hostIfName , targetNs , true )
537553 })
@@ -609,7 +625,7 @@ var testFunc = func(version string) {
609625 defer func () {
610626 closeNS (targetNs )
611627 }()
612- hostIfName , result := testAdd (conf , false , true , "" , targetNs )
628+ hostIfName , result := testAdd (conf , false , true , false , "" , targetNs )
613629 testCheck (conf , result , targetNs )
614630 testDel (conf , hostIfName , targetNs , true )
615631 })
@@ -628,7 +644,7 @@ var testFunc = func(version string) {
628644 _ = targetNs .Close ()
629645 _ = testutils .UnmountNS (targetNs )
630646 }()
631- hostIfName , result := testAdd (conf , false , false , "" , targetNs )
647+ hostIfName , result := testAdd (conf , false , false , false , "" , targetNs )
632648 testCheck (conf , result , targetNs )
633649 Expect (targetNs .Close ()).To (Succeed ())
634650 Expect (testutils .UnmountNS (targetNs )).To (Succeed ())
@@ -647,7 +663,7 @@ var testFunc = func(version string) {
647663 defer func () {
648664 closeNS (targetNs )
649665 }()
650- hostIfName , result := testAdd (conf , false , false , "" , targetNs )
666+ hostIfName , result := testAdd (conf , false , false , false , "" , targetNs )
651667 testCheck (conf , result , targetNs )
652668 err := targetNs .Do (func (ns.NetNS ) error {
653669 defer GinkgoRecover ()
@@ -779,7 +795,7 @@ var testFunc = func(version string) {
779795 defer func () {
780796 closeNS (targetNs )
781797 }()
782- hostIfName , result := testAdd (conf , false , false , "" , targetNs )
798+ hostIfName , result := testAdd (conf , false , false , false , "" , targetNs )
783799 testCheck (conf , result , targetNs )
784800 testDel (conf , hostIfName , targetNs , true )
785801 })
@@ -796,7 +812,7 @@ var testFunc = func(version string) {
796812 defer func () {
797813 closeNS (targetNs )
798814 }()
799- hostIfName , result := testAdd (conf , false , false , "" , targetNs )
815+ hostIfName , result := testAdd (conf , false , false , false , "" , targetNs )
800816 testCheck (conf , result , targetNs )
801817 testDel (conf , hostIfName , targetNs , true )
802818 })
@@ -904,6 +920,65 @@ var testFunc = func(version string) {
904920 ContainSubstring (secondHostIface .Name ), "OVS port with healthy interface should have been kept" )
905921 })
906922 })
923+
924+ Context ("with vlan mode set explicitly" , func () {
925+ conf := fmt .Sprintf (`{
926+ "cniVersion": "%s",
927+ "name": "mynet",
928+ "type": "ovs",
929+ "bridge": "%s",
930+ "vlan_mode":"%s"
931+
932+ }` , version , bridgeName , vlanMode )
933+ It ("should successfully complete ADD, CHECK and DEL commands" , func () {
934+ targetNs := newNS ()
935+ defer func () {
936+ closeNS (targetNs )
937+ }()
938+ hostIfName , result := testAdd (conf , false , false , true , "" , targetNs )
939+ testCheck (conf , result , targetNs )
940+ testDel (conf , hostIfName , targetNs , true )
941+ })
942+ })
943+ Context ("with vlan mode not set explicitly" , func () {
944+ conf := fmt .Sprintf (`{
945+ "cniVersion": "%s",
946+ "name": "mynet",
947+ "type": "ovs",
948+ "bridge": "%s"
949+
950+ }` , version , bridgeName )
951+ It ("should successfully complete ADD, CHECK and DEL commands" , func () {
952+ targetNs := newNS ()
953+ defer func () {
954+ closeNS (targetNs )
955+ }()
956+ hostIfName , result := testAdd (conf , false , false , false , "" , targetNs )
957+ testCheck (conf , result , targetNs )
958+ testDel (conf , hostIfName , targetNs , true )
959+ })
960+ })
961+ Context ("with vlan mode set explicitly along with tag and trunk" , func () {
962+ conf := fmt .Sprintf (`{
963+ "cniVersion": "%s",
964+ "name": "mynet",
965+ "type": "ovs",
966+ "bridge": "%s",
967+ "vlan": %d,
968+ "trunk": [ {"minID": 10, "maxID": 12}, {"id": 15}, {"minID": 17, "maxID": 18} ],
969+ "vlan_mode": "%s"
970+
971+ }` , version , bridgeName , vlanID , vlanMode )
972+ It ("should successfully complete ADD, CHECK and DEL commands" , func () {
973+ targetNs := newNS ()
974+ defer func () {
975+ closeNS (targetNs )
976+ }()
977+ hostIfName , result := testAdd (conf , true , false , true , "" , targetNs )
978+ testCheck (conf , result , targetNs )
979+ testDel (conf , hostIfName , targetNs , true )
980+ })
981+ })
907982 })
908983}
909984
0 commit comments