go.ligato.io/vpp-agent/v3@v3.5.0/examples/kvscheduler/mock_plugins/ifplugin/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  	"go.ligato.io/vpp-agent/v3/examples/kvscheduler/mock_plugins/ifplugin/model"
    21  )
    22  
    23  // map of interfaces "configured" in the mock SB.
    24  type mockIfaces map[uint32]*mock_interfaces.Interface
    25  
    26  // MockIfaceAPI provides methods for creating and managing interfaces
    27  // in the mock SB
    28  type MockIfaceAPI interface {
    29  	MockIfaceWrite
    30  	MockIfaceRead
    31  }
    32  
    33  // MockIfaceWrite provides write methods for interface plugin
    34  type MockIfaceWrite interface {
    35  	// CreateLoopbackInterface creates loopback in the mock SB.
    36  	CreateLoopbackInterface(ifaceName string) (sbIfaceHandle uint32, err error)
    37  	// DeleteLoopbackInterface deletes loopback in the mock SB.
    38  	DeleteLoopbackInterface(sbIfaceHandle uint32) error
    39  
    40  	// CreateTapInterface creates TAP interface in the mock SB.
    41  	CreateTapInterface(ifaceName string) (sbIfaceHandle uint32, err error)
    42  	// CreateTapInterface deletes TAP interface in the mock SB.
    43  	DeleteTapInterface(sbIfaceHandle uint32) error
    44  
    45  	// InterfaceAdminDown puts the given mock interface DOWN.
    46  	InterfaceAdminDown(sbIfaceHandle uint32) error
    47  	// InterfaceAdminUp puts the given interface UP.
    48  	InterfaceAdminUp(sbIfaceHandle uint32) error
    49  
    50  	// SetInterfaceMac changes MAC address of the given interface.
    51  	SetInterfaceMac(sbIfaceHandle uint32, macAddress string) error
    52  }
    53  
    54  // MockIfaceRead provides read methods for interface plugin
    55  type MockIfaceRead interface {
    56  	// DumpInterfaces returns interfaces configured in the mock SB.
    57  	DumpInterfaces() (mockIfaces, error)
    58  }
    59  
    60  // MockIfaceHandler is accessor for calls into mock SB.
    61  type MockIfaceHandler struct {
    62  	log logging.Logger
    63  
    64  	// mock SB
    65  	nextIfaceHandle uint32
    66  	mockIfaces      mockIfaces
    67  }
    68  
    69  // NewMockIfHandler creates new instance of interface handler for mock SB.
    70  func NewMockIfaceHandler(log logging.Logger) MockIfaceAPI {
    71  	return &MockIfaceHandler{
    72  		log:        log,
    73  		mockIfaces: make(mockIfaces),
    74  	}
    75  }