github.com/cilium/cilium@v1.16.2/pkg/maps/nodemap/fake/node_map_v2.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package fake
     5  
     6  import (
     7  	"fmt"
     8  	"net"
     9  
    10  	"github.com/cilium/cilium/pkg/maps/nodemap"
    11  )
    12  
    13  type fakeNodeMapV2 struct {
    14  	ids map[string]nodemap.NodeValueV2
    15  }
    16  
    17  var _ nodemap.Map = &fakeNodeMap{}
    18  
    19  func NewFakeNodeMapV2() *fakeNodeMapV2 {
    20  	return &fakeNodeMapV2{
    21  		ids: map[string]nodemap.NodeValueV2{},
    22  	}
    23  }
    24  
    25  func (f fakeNodeMapV2) Update(ip net.IP, nodeID uint16, SPI uint8) error {
    26  	f.ids[ip.String()] = nodemap.NodeValueV2{
    27  		NodeID: nodeID,
    28  		SPI:    SPI,
    29  	}
    30  	return nil
    31  }
    32  
    33  func (f fakeNodeMapV2) Size() uint32 {
    34  	return nodemap.DefaultMaxEntries
    35  }
    36  
    37  func (f fakeNodeMapV2) Delete(ip net.IP) error {
    38  	delete(f.ids, ip.String())
    39  	return nil
    40  }
    41  
    42  // This function is used only for tests.
    43  func (f fakeNodeMapV2) Lookup(ip net.IP) (*nodemap.NodeValueV2, error) {
    44  	if nodeValue, exists := f.ids[ip.String()]; exists {
    45  		return &nodeValue, nil
    46  	}
    47  	return nil, fmt.Errorf("IP not found in node ID map")
    48  }
    49  
    50  func (f fakeNodeMapV2) IterateWithCallback(cb nodemap.NodeIterateCallbackV2) error {
    51  	return nil
    52  }