go.ligato.io/vpp-agent/v3@v3.5.0/examples/kvscheduler/mock_plugins/l2plugin/mockcalls/fib_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 "fmt" 19 20 "google.golang.org/protobuf/proto" 21 22 l2 "go.ligato.io/vpp-agent/v3/examples/kvscheduler/mock_plugins/l2plugin/model" 23 ) 24 25 // CreateL2FIB creates L2 FIB table entry in the mock SB. 26 func (h *MockFIBHandler) CreateL2FIB(fib *l2.FIBEntry) error { 27 h.mockFIBs = append(h.mockFIBs, fib) 28 h.log.Infof("Created L2 FIB entry: %v", fib) 29 return nil 30 } 31 32 // DeleteL2FIB removes existing L2 FIB table entry from the mock SB. 33 func (h *MockFIBHandler) DeleteL2FIB(fib *l2.FIBEntry) error { 34 var idx int 35 for ; idx < len(h.mockFIBs); idx++ { 36 if proto.Equal(h.mockFIBs[idx], fib) { 37 break 38 } 39 } 40 if idx == len(h.mockFIBs) { 41 return fmt.Errorf("no such L2 FIB entry: %v", fib) 42 } 43 h.mockFIBs = append(h.mockFIBs[:idx], h.mockFIBs[idx+1:]...) 44 h.log.Infof("Deleted L2 FIB entry: %v", fib) 45 return nil 46 } 47 48 // DumpL2FIBs dumps L2 FIB table entries "configured" in the mock SB. 49 func (h *MockFIBHandler) DumpL2FIBs() ([]*l2.FIBEntry, error) { 50 h.log.Infof("Dumped L2 FIB entries: %+v", h.mockFIBs) 51 return h.mockFIBs, nil 52 }