go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/090_vxlan_gpe_test.go (about) 1 package vpp 2 3 import ( 4 "fmt" 5 "testing" 6 7 "go.ligato.io/cn-infra/v2/logging/logrus" 8 9 ifplugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/vppcalls" 10 interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" 11 12 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin" 13 ) 14 15 func TestVxlanGpe(t *testing.T) { 16 ctx := setupVPP(t) 17 defer ctx.teardownVPP() 18 19 h := ifplugin_vppcalls.CompatibleInterfaceVppHandler(ctx.vppClient, logrus.NewLogger("test")) 20 21 tests := []struct { 22 name string 23 vxLan *interfaces.VxlanLink 24 mcastSwIfIndex uint32 25 encapVrfID uint32 26 isFail bool 27 }{ 28 { 29 name: "Create VxLAN-GPE tunnel (IP4)", 30 vxLan: &interfaces.VxlanLink{ 31 SrcAddress: "20.30.40.50", 32 DstAddress: "50.40.30.20", 33 Gpe: &interfaces.VxlanLink_Gpe{ 34 Protocol: interfaces.VxlanLink_Gpe_IP4, 35 }, 36 }, 37 mcastSwIfIndex: 0xFFFFFFFF, 38 isFail: false, 39 }, 40 { 41 name: "Create VxLAN-GPE tunnel (IP6)", 42 vxLan: &interfaces.VxlanLink{ 43 SrcAddress: "20.30.40.50", 44 DstAddress: "50.40.30.20", 45 Gpe: &interfaces.VxlanLink_Gpe{ 46 Protocol: interfaces.VxlanLink_Gpe_IP6, 47 }, 48 }, 49 mcastSwIfIndex: 0xFFFFFFFF, 50 isFail: false, 51 }, 52 { 53 name: "Create VxLAN-GPE tunnel (Ethernet)", 54 vxLan: &interfaces.VxlanLink{ 55 SrcAddress: "20.30.40.50", 56 DstAddress: "50.40.30.20", 57 Gpe: &interfaces.VxlanLink_Gpe{ 58 Protocol: interfaces.VxlanLink_Gpe_ETHERNET, 59 }, 60 }, 61 mcastSwIfIndex: 0xFFFFFFFF, 62 isFail: false, 63 }, 64 { 65 name: "Create VxLAN-GPE tunnel (NSH)", 66 vxLan: &interfaces.VxlanLink{ 67 SrcAddress: "20.30.40.50", 68 DstAddress: "50.40.30.20", 69 Gpe: &interfaces.VxlanLink_Gpe{ 70 Protocol: interfaces.VxlanLink_Gpe_NSH, 71 }, 72 }, 73 mcastSwIfIndex: 0xFFFFFFFF, 74 isFail: false, 75 }, 76 { 77 name: "Create VxLAN-GPE tunnel with same source and destination", 78 vxLan: &interfaces.VxlanLink{ 79 SrcAddress: "20.30.40.50", 80 DstAddress: "20.30.40.50", 81 Gpe: &interfaces.VxlanLink_Gpe{ 82 Protocol: interfaces.VxlanLink_Gpe_IP4, 83 }, 84 }, 85 mcastSwIfIndex: 0xFFFFFFFF, 86 isFail: true, 87 }, 88 { 89 name: "Create VxLAN-GPE tunnel with src and dst ip versions mismatch", 90 vxLan: &interfaces.VxlanLink{ 91 SrcAddress: "20.30.40.50", 92 DstAddress: "::1", 93 Gpe: &interfaces.VxlanLink_Gpe{ 94 Protocol: interfaces.VxlanLink_Gpe_IP4, 95 }, 96 }, 97 mcastSwIfIndex: 0xFFFFFFFF, 98 isFail: true, 99 }, 100 } 101 for i, test := range tests { 102 t.Run(test.name, func(t *testing.T) { 103 ifName := fmt.Sprintf("test%d", i) 104 ifIdx, err := h.AddVxLanGpeTunnel(ifName, test.encapVrfID, test.mcastSwIfIndex, test.vxLan) 105 106 if err != nil { 107 if test.isFail { 108 return 109 } 110 t.Fatalf("create VxLAN-GPE tunnel failed: %v\n", err) 111 } else { 112 if test.isFail { 113 t.Fatal("create VxLAN-GPE tunnel must fail, but it's not") 114 } 115 } 116 117 ifaces, err := h.DumpInterfaces(ctx.Ctx) 118 if err != nil { 119 t.Fatalf("dumping interfaces failed: %v", err) 120 } 121 iface, ok := ifaces[ifIdx] 122 if !ok { 123 t.Fatalf("VxLAN-GPE interface was not found in dump") 124 } 125 126 vxLan := iface.Interface.GetVxlan() 127 if test.vxLan.SrcAddress != vxLan.SrcAddress { 128 t.Fatalf("expected source address <%s>, got: <%s>", test.vxLan.SrcAddress, vxLan.SrcAddress) 129 } 130 if test.vxLan.DstAddress != vxLan.DstAddress { 131 t.Fatalf("expected destination address <%s>, got: <%s>", test.vxLan.DstAddress, vxLan.DstAddress) 132 } 133 if test.vxLan.Vni != vxLan.Vni { 134 t.Fatalf("expected VNI <%d>, got: <%d>", test.vxLan.Vni, vxLan.Vni) 135 } 136 if test.vxLan.Multicast != vxLan.Multicast { 137 t.Fatalf("expected multicast interface name <%s>, got: <%s>", test.vxLan.Multicast, vxLan.Multicast) 138 } 139 if test.vxLan.Gpe.Protocol != vxLan.Gpe.Protocol { 140 t.Fatalf("expected VxLAN-GPE protocol <%d>, got: <%d>", test.vxLan.Gpe.Protocol, vxLan.Gpe.Protocol) 141 } 142 if test.vxLan.Gpe.DecapVrfId != vxLan.Gpe.DecapVrfId { 143 t.Fatalf("expected VxLAN-GPE DecapVrfId <%d>, got: <%d>", test.vxLan.Gpe.DecapVrfId, vxLan.Gpe.DecapVrfId) 144 } 145 146 err = h.DeleteVxLanGpeTunnel(ifName, test.vxLan) 147 if err != nil { 148 t.Fatalf("delete VxLAN-GPE tunnel failed: %v\n", err) 149 } 150 151 ifaces, err = h.DumpInterfaces(ctx.Ctx) 152 if err != nil { 153 t.Fatalf("dumping interfaces failed: %v", err) 154 } 155 156 if _, ok := ifaces[ifIdx]; ok { 157 t.Fatalf("VxLAN-GPE interface was found in dump after removing") 158 } 159 }) 160 } 161 }