go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2106/vrrp_vppcalls_test.go (about) 1 // Copyright (c) 2021 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 vpp2106_test 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 "go.ligato.io/cn-infra/v2/logging/logrus" 22 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/vrrp" 23 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 24 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls" 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls/vpp2106" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock" 27 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 28 ) 29 30 var vrrpEntries = []*l3.VRRPEntry{ 31 { 32 Interface: "if1", 33 VrId: 4, 34 Priority: 100, 35 Interval: 100, 36 Preempt: false, 37 Accept: false, 38 Unicast: false, 39 IpAddresses: []string{"192.168.10.21"}, 40 Enabled: true, 41 }, 42 { 43 Interface: "if1", 44 VrId: 4, 45 Priority: 200, 46 Interval: 300, 47 Preempt: false, 48 Accept: false, 49 Unicast: false, 50 IpAddresses: []string{"192.168.10.22", "192.168.10.23"}, 51 Enabled: false, 52 }, 53 { 54 Interface: "if1", 55 VrId: 6, 56 Priority: 50, 57 Interval: 50, 58 Preempt: false, 59 Accept: false, 60 Unicast: false, 61 IpAddresses: []string{"192.168.10.21"}, 62 Enabled: true, 63 }, 64 } 65 66 // Test an adding of the VRRP 67 func TestAddVrrp(t *testing.T) { 68 ctx, ifIndexes, vrrpHandler := vrrpTestSetup(t) 69 defer ctx.TeardownTestCtx() 70 71 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1}) 72 73 ctx.MockVpp.MockReply(&vrrp.VrrpVrAddDelReply{}) 74 err := vrrpHandler.VppAddVrrp(vrrpEntries[0]) 75 Expect(err).To(Succeed()) 76 77 ctx.MockVpp.MockReply(&vrrp.VrrpVrAddDelReply{}) 78 err = vrrpHandler.VppAddVrrp(vrrpEntries[1]) 79 Expect(err).To(Succeed()) 80 81 ctx.MockVpp.MockReply(&vrrp.VrrpVrAddDelReply{}) 82 err = vrrpHandler.VppAddVrrp(vrrpEntries[2]) 83 Expect(err).To(Succeed()) 84 } 85 86 // Test a deletion of the VRRP 87 func TestDelVrrp(t *testing.T) { 88 ctx, ifIndexes, vrrpHandler := vrrpTestSetup(t) 89 defer ctx.TeardownTestCtx() 90 91 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1}) 92 93 ctx.MockVpp.MockReply(&vrrp.VrrpVrAddDelReply{}) 94 err := vrrpHandler.VppDelVrrp(vrrpEntries[0]) 95 Expect(err).To(Succeed()) 96 } 97 98 // Test a start of the VRRP 99 func TestStartVrrp(t *testing.T) { 100 ctx, ifIndexes, vrrpHandler := vrrpTestSetup(t) 101 defer ctx.TeardownTestCtx() 102 103 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1}) 104 105 ctx.MockVpp.MockReply(&vrrp.VrrpVrStartStopReply{}) 106 err := vrrpHandler.VppStartVrrp(vrrpEntries[0]) 107 Expect(err).To(Succeed()) 108 109 ctx.MockVpp.MockReply(&vrrp.VrrpVrStartStopReply{}) 110 err = vrrpHandler.VppStartVrrp(vrrpEntries[1]) 111 Expect(err).To(Succeed()) 112 } 113 114 // Test a stop of the VRRP 115 func TestStopVrrp(t *testing.T) { 116 ctx, ifIndexes, vrrpHandler := vrrpTestSetup(t) 117 defer ctx.TeardownTestCtx() 118 119 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1}) 120 121 ctx.MockVpp.MockReply(&vrrp.VrrpVrStartStopReply{}) 122 err := vrrpHandler.VppStopVrrp(vrrpEntries[0]) 123 Expect(err).To(Succeed()) 124 125 ctx.MockVpp.MockReply(&vrrp.VrrpVrStartStopReply{}) 126 err = vrrpHandler.VppStopVrrp(vrrpEntries[1]) 127 Expect(err).To(Succeed()) 128 } 129 130 func vrrpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.VrrpVppAPI) { 131 ctx := vppmock.SetupTestCtx(t) 132 log := logrus.NewLogger("test-log") 133 ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") 134 vrrpHandler := vpp2106.NewVrrpVppHandler(ctx.MockChannel, ifIndexes, log) 135 return ctx, ifIndexes, vrrpHandler 136 }