go.ligato.io/vpp-agent/v3@v3.5.0/examples/kvscheduler/mock_plugins/l2plugin/mockcalls/api_mockcalls.go (about) 1 // Copyright (c) 2017 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 mockcalls 16 17 import ( 18 "go.ligato.io/cn-infra/v2/logging" 19 20 l2 "go.ligato.io/vpp-agent/v3/examples/kvscheduler/mock_plugins/l2plugin/model" 21 "go.ligato.io/vpp-agent/v3/pkg/idxvpp" 22 ) 23 24 // map of bridge domains "configured" in the mock SB. 25 type mockBDs map[uint32]*l2.BridgeDomain 26 27 // MockBDAPI provides methods for managing bridge domains in the mock SB. 28 type MockBDAPI interface { 29 MockBDWrite 30 MockBDRead 31 } 32 33 // MockBDWrite provides write methods for bridge domains. 34 type MockBDWrite interface { 35 // CreateBridgeDomain creates new bridge domain in the mock SB. 36 CreateBridgeDomain(bdName string) (sbBDHandle uint32, err error) 37 // DeleteBridgeDomain removes existing bridge domain from the mock SB. 38 DeleteBridgeDomain(sbBDHandle uint32) error 39 // AddInterfaceToBridgeDomain puts interface into bridge domain. 40 AddInterfaceToBridgeDomain(sbBDHandle uint32, ifaceName string, isBVI bool) error 41 // DeleteInterfaceFromBridgeDomain removes interface from bridge domain. 42 DeleteInterfaceFromBridgeDomain(sbBDHandle uint32, ifaceName string) error 43 } 44 45 // MockBDRead provides read methods for bridge domains. 46 type MockBDRead interface { 47 // DumpBridgeDomains dumps bridge domains "configured" in the mock SB. 48 DumpBridgeDomains() (mockBDs, error) 49 } 50 51 // MockFIBAPI provides methods for managing FIBs. 52 type MockFIBAPI interface { 53 MockFIBWrite 54 MockFIBRead 55 } 56 57 // MockFIBWrite provides write methods for FIBs. 58 type MockFIBWrite interface { 59 // CreateL2FIB creates L2 FIB table entry in the mock SB. 60 CreateL2FIB(fib *l2.FIBEntry) error 61 // DeleteL2FIB removes existing L2 FIB table entry from the mock SB. 62 DeleteL2FIB(fib *l2.FIBEntry) error 63 } 64 65 // MockFIBRead provides read methods for FIBs. 66 type MockFIBRead interface { 67 // DumpL2FIBs dumps L2 FIB table entries "configured" in the mock SB. 68 DumpL2FIBs() ([]*l2.FIBEntry, error) 69 } 70 71 // MockBDHandler is accessor for bridge domain-related calls into mock SB. 72 type MockBDHandler struct { 73 ifaceIndex idxvpp.NameToIndex // exposed by the ifplugin 74 log logging.Logger 75 76 // mock SB 77 nextBDHandle uint32 78 mockBDs mockBDs 79 } 80 81 // MockFIBHandler is accessor for FIB-related calls into mock SB. 82 type MockFIBHandler struct { 83 ifaceIndex idxvpp.NameToIndex // exposed by the ifplugin 84 bdIndex idxvpp.NameToIndex // retrieved from kvscheduler by l2plugin itself 85 log logging.Logger 86 87 // mock SB 88 mockFIBs []*l2.FIBEntry 89 } 90 91 // NewMockBDHandler creates new instance of bridge domain handler for mock SB. 92 func NewMockBDHandler(ifaceIndex idxvpp.NameToIndex, log logging.Logger) MockBDAPI { 93 return &MockBDHandler{ 94 ifaceIndex: ifaceIndex, 95 log: log, 96 mockBDs: make(mockBDs), 97 } 98 } 99 100 // NewMockFIBHandler creates new instance of FIB handler for mock SB. 101 func NewMockFIBHandler(ifaceIndex idxvpp.NameToIndex, bdIndexes idxvpp.NameToIndex, 102 log logging.Logger) MockFIBAPI { 103 return &MockFIBHandler{ 104 ifaceIndex: ifaceIndex, 105 bdIndex: bdIndexes, 106 log: log, 107 } 108 }