-
Notifications
You must be signed in to change notification settings - Fork 128
/
api_mockcalls.go
108 lines (92 loc) · 3.46 KB
/
api_mockcalls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2017 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package mockcalls
import (
"go.ligato.io/cn-infra/v2/logging"
l2 "go.ligato.io/vpp-agent/v3/examples/kvscheduler/mock_plugins/l2plugin/model"
"go.ligato.io/vpp-agent/v3/pkg/idxvpp"
)
// map of bridge domains "configured" in the mock SB.
type mockBDs map[uint32]*l2.BridgeDomain
// MockBDAPI provides methods for managing bridge domains in the mock SB.
type MockBDAPI interface {
MockBDWrite
MockBDRead
}
// MockBDWrite provides write methods for bridge domains.
type MockBDWrite interface {
// CreateBridgeDomain creates new bridge domain in the mock SB.
CreateBridgeDomain(bdName string) (sbBDHandle uint32, err error)
// DeleteBridgeDomain removes existing bridge domain from the mock SB.
DeleteBridgeDomain(sbBDHandle uint32) error
// AddInterfaceToBridgeDomain puts interface into bridge domain.
AddInterfaceToBridgeDomain(sbBDHandle uint32, ifaceName string, isBVI bool) error
// DeleteInterfaceFromBridgeDomain removes interface from bridge domain.
DeleteInterfaceFromBridgeDomain(sbBDHandle uint32, ifaceName string) error
}
// MockBDRead provides read methods for bridge domains.
type MockBDRead interface {
// DumpBridgeDomains dumps bridge domains "configured" in the mock SB.
DumpBridgeDomains() (mockBDs, error)
}
// MockFIBAPI provides methods for managing FIBs.
type MockFIBAPI interface {
MockFIBWrite
MockFIBRead
}
// MockFIBWrite provides write methods for FIBs.
type MockFIBWrite interface {
// CreateL2FIB creates L2 FIB table entry in the mock SB.
CreateL2FIB(fib *l2.FIBEntry) error
// DeleteL2FIB removes existing L2 FIB table entry from the mock SB.
DeleteL2FIB(fib *l2.FIBEntry) error
}
// MockFIBRead provides read methods for FIBs.
type MockFIBRead interface {
// DumpL2FIBs dumps L2 FIB table entries "configured" in the mock SB.
DumpL2FIBs() ([]*l2.FIBEntry, error)
}
// MockBDHandler is accessor for bridge domain-related calls into mock SB.
type MockBDHandler struct {
ifaceIndex idxvpp.NameToIndex // exposed by the ifplugin
log logging.Logger
// mock SB
nextBDHandle uint32
mockBDs mockBDs
}
// MockFIBHandler is accessor for FIB-related calls into mock SB.
type MockFIBHandler struct {
ifaceIndex idxvpp.NameToIndex // exposed by the ifplugin
bdIndex idxvpp.NameToIndex // retrieved from kvscheduler by l2plugin itself
log logging.Logger
// mock SB
mockFIBs []*l2.FIBEntry
}
// NewMockBDHandler creates new instance of bridge domain handler for mock SB.
func NewMockBDHandler(ifaceIndex idxvpp.NameToIndex, log logging.Logger) MockBDAPI {
return &MockBDHandler{
ifaceIndex: ifaceIndex,
log: log,
mockBDs: make(mockBDs),
}
}
// NewMockFIBHandler creates new instance of FIB handler for mock SB.
func NewMockFIBHandler(ifaceIndex idxvpp.NameToIndex, bdIndexes idxvpp.NameToIndex,
log logging.Logger) MockFIBAPI {
return &MockFIBHandler{
ifaceIndex: ifaceIndex,
bdIndex: bdIndexes,
log: log,
}
}