github.com/cilium/cilium@v1.16.2/pkg/maps/nodemap/fake/node_map.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 fakeNodeMap struct {
    14  	ids map[string]uint16
    15  }
    16  
    17  var _ nodemap.Map = &fakeNodeMap{}
    18  
    19  func NewFakeNodeMap() *fakeNodeMap {
    20  	return &fakeNodeMap{
    21  		ids: map[string]uint16{},
    22  	}
    23  }
    24  
    25  func (f fakeNodeMap) Update(ip net.IP, nodeID uint16) error {
    26  	f.ids[ip.String()] = nodeID
    27  	return nil
    28  }
    29  
    30  func (f fakeNodeMap) Size() uint32 {
    31  	return nodemap.DefaultMaxEntries
    32  }
    33  
    34  func (f fakeNodeMap) Delete(ip net.IP) error {
    35  	delete(f.ids, ip.String())
    36  	return nil
    37  }
    38  
    39  // This function is used only for tests.
    40  func (f fakeNodeMap) Lookup(ip net.IP) (uint16, error) {
    41  	if nodeID, exists := f.ids[ip.String()]; exists {
    42  		return nodeID, nil
    43  	}
    44  	return 0, fmt.Errorf("IP not found in node ID map")
    45  }
    46  
    47  func (f fakeNodeMap) IterateWithCallback(cb nodemap.NodeIterateCallback) error {
    48  	return nil
    49  }