go.ligato.io/vpp-agent/v3@v3.5.0/tests/e2e/081_route_test.go (about) 1 // Copyright (c) 2022 Cisco and/or its affiliates. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package e2e 16 17 import ( 18 "context" 19 "testing" 20 21 . "github.com/onsi/gomega" 22 23 kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api" 24 "go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler" 25 linux_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces" 26 linux_l3 "go.ligato.io/vpp-agent/v3/proto/ligato/linux/l3" 27 linux_namespace "go.ligato.io/vpp-agent/v3/proto/ligato/linux/namespace" 28 vpp_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" 29 . "go.ligato.io/vpp-agent/v3/tests/e2e/e2etest" 30 ) 31 32 // TestIPv4Routes tests L3 routes in the default VRF and for various scopes 33 func TestIPv4Routes(t *testing.T) { 34 ctx := Setup(t) 35 defer ctx.Teardown() 36 37 const ( 38 // first subnet 39 msName1 = "microservice1" 40 subnet1 = "10.0.0.0/24" 41 tap1IP = "10.0.0.1" 42 linuxTap1IP = "10.0.0.2" 43 tap1Label = "tap-1" 44 45 // second subnet 46 msName2 = "microservice2" 47 subnet2 = "20.0.0.0/24" 48 tap2IP = "20.0.0.1" 49 linuxTap2IP = "20.0.0.2" 50 tap2Label = "tap-2" 51 52 suffix = "/24" 53 ) 54 55 // TAP interface for the first subnet 56 vppTap1 := &vpp_interfaces.Interface{ 57 Name: tap1Label, 58 Type: vpp_interfaces.Interface_TAP, 59 Enabled: true, 60 IpAddresses: []string{tap1IP + suffix}, 61 Link: &vpp_interfaces.Interface_Tap{ 62 Tap: &vpp_interfaces.TapLink{ 63 Version: 2, 64 ToMicroservice: MsNamePrefix + msName1, 65 }, 66 }, 67 } 68 linuxTap1 := &linux_interfaces.Interface{ 69 Name: tap1Label, 70 Type: linux_interfaces.Interface_TAP_TO_VPP, 71 Enabled: true, 72 IpAddresses: []string{linuxTap1IP + suffix}, 73 Link: &linux_interfaces.Interface_Tap{ 74 Tap: &linux_interfaces.TapLink{ 75 VppTapIfName: tap1Label, 76 }, 77 }, 78 Namespace: &linux_namespace.NetNamespace{ 79 Type: linux_namespace.NetNamespace_MICROSERVICE, 80 Reference: MsNamePrefix + msName1, 81 }, 82 } 83 84 // TAP interfaces for the second subnet 85 vppTap2 := &vpp_interfaces.Interface{ 86 Name: tap2Label, 87 Type: vpp_interfaces.Interface_TAP, 88 Enabled: true, 89 IpAddresses: []string{tap2IP + suffix}, 90 Link: &vpp_interfaces.Interface_Tap{ 91 Tap: &vpp_interfaces.TapLink{ 92 Version: 2, 93 ToMicroservice: MsNamePrefix + msName2, 94 }, 95 }, 96 } 97 linuxTap2 := &linux_interfaces.Interface{ 98 Name: tap2Label, 99 Type: linux_interfaces.Interface_TAP_TO_VPP, 100 Enabled: true, 101 IpAddresses: []string{linuxTap2IP + suffix}, 102 Link: &linux_interfaces.Interface_Tap{ 103 Tap: &linux_interfaces.TapLink{ 104 VppTapIfName: tap2Label, 105 }, 106 }, 107 Namespace: &linux_namespace.NetNamespace{ 108 Type: linux_namespace.NetNamespace_MICROSERVICE, 109 Reference: MsNamePrefix + msName2, 110 }, 111 } 112 113 // Routes 114 subnet1LinuxRoute := &linux_l3.Route{ 115 OutgoingInterface: tap1Label, 116 Scope: linux_l3.Route_GLOBAL, 117 DstNetwork: subnet2, 118 GwAddr: tap1IP, 119 } 120 subnet2LinuxRoute := &linux_l3.Route{ 121 OutgoingInterface: tap2Label, 122 Scope: linux_l3.Route_GLOBAL, 123 DstNetwork: subnet1, 124 GwAddr: tap2IP, 125 } 126 subnet2LinuxLinkRoute := &linux_l3.Route{ 127 OutgoingInterface: tap2Label, 128 Scope: linux_l3.Route_LINK, 129 DstNetwork: subnet1, 130 } 131 132 ctx.StartMicroservice(msName1) 133 ctx.StartMicroservice(msName2) 134 135 // configure everything in one resync 136 err := ctx.GenericClient().ResyncConfig( 137 vppTap1, linuxTap1, 138 vppTap2, linuxTap2, 139 subnet1LinuxRoute, subnet2LinuxRoute, 140 ) 141 ctx.Expect(err).ToNot(HaveOccurred()) 142 143 ctx.Eventually(ctx.GetValueStateClb(vppTap1)).Should(Equal(kvscheduler.ValueState_CONFIGURED)) 144 ctx.Expect(ctx.GetValueState(linuxTap1)).To(Equal(kvscheduler.ValueState_CONFIGURED)) 145 ctx.Expect(ctx.GetValueState(vppTap2)).To(Equal(kvscheduler.ValueState_CONFIGURED)) 146 ctx.Expect(ctx.GetValueState(linuxTap2)).To(Equal(kvscheduler.ValueState_CONFIGURED)) 147 ctx.Expect(ctx.GetValueState(subnet1LinuxRoute)).To(Equal(kvscheduler.ValueState_CONFIGURED)) 148 ctx.Expect(ctx.GetValueState(subnet2LinuxRoute)).To(Equal(kvscheduler.ValueState_CONFIGURED)) 149 150 ctx.Expect(ctx.GetRunningMicroservice(msName1).Ping("20.0.0.2")).To(Succeed()) 151 ctx.Expect(ctx.GetRunningMicroservice(msName2).Ping("10.0.0.2")).To(Succeed()) 152 153 // keep the current number of routes before the update 154 numLinuxRoutes := ctx.NumValues(&linux_l3.Route{}, kvs.SBView) 155 156 // reconfigure subnet 1 route as link local 157 err = ctx.GenericClient().ChangeRequest().Update( 158 subnet2LinuxLinkRoute, 159 ).Send(context.Background()) 160 ctx.Expect(err).ToNot(HaveOccurred()) 161 162 ctx.Expect(ctx.GetRunningMicroservice(msName1).Ping("20.0.0.2")).NotTo(Succeed()) 163 ctx.Expect(ctx.GetRunningMicroservice(msName2).Ping("10.0.0.2")).NotTo(Succeed()) 164 165 // route count should be unchanged 166 ctx.Expect(ctx.NumValues(&linux_l3.Route{}, kvs.SBView)).To(Equal(numLinuxRoutes)) 167 }