func (vds *VppDataStore) SetNodeTelemetry(nodeName string, nTele map[string]telemetrymodel.NodeTelemetry) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeTelemetry for node %s", nodeName)
	}
	node.NodeTelemetry = nTele
	return nil
}
SetNodeTelemetry is a simple function to set a nodes telemetry data given its name.
package datastore
import (
	"fmt"
	"sort"
	"strconv"
	"strings"
	"sync"
	"github.com/pkg/errors"
	"github.com/contiv/vpp/plugins/crd/cache/telemetrymodel"
	"github.com/contiv/vpp/plugins/ipnet"
	"github.com/contiv/vpp/plugins/ipnet/restapi"
	"go.ligato.io/cn-infra/v2/health/statuscheck/model/status"
)
type VppDataStore struct {
	lock *sync.Mutex
	NodeMap    map[string]*telemetrymodel.Node
	LoopIPMap  map[string]*telemetrymodel.Node
	GigEIPMap  map[string]*telemetrymodel.Node
	LoopMACMap map[string]*telemetrymodel.Node
	HostIPMap  map[string]*telemetrymodel.Node
}
func (vds *VppDataStore) CreateNode(ID uint32, nodeName, IPAddr string) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	if _, ok := vds.retrieveNode(nodeName); ok {
		return fmt.Errorf("node %s already exists", nodeName)
	}
	n := &telemetrymodel.Node{
		NodeInfo: &telemetrymodel.NodeInfo{IPAddr: IPAddr, ID: ID, Name: nodeName},
	}
	n.PodMap = make(map[string]*telemetrymodel.Pod)
	vds.NodeMap[nodeName] = n
	if IPAddr != "" {
		ipa := strings.Split(IPAddr, "/")
		vds.GigEIPMap[ipa[0]] = n
	}
	return nil
}
func (vds *VppDataStore) RetrieveNode(nodeName string) (n *telemetrymodel.Node, err error) {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if ok {
		return node, nil
	}
	return nil, fmt.Errorf("node %s not found", nodeName)
}
func (vds *VppDataStore) DeleteNode(nodeName string) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	nodeID, err := strconv.Atoi(nodeName)
	if err != nil {
		return fmt.Errorf("invalid nodeId %s", nodeName)
	}
	for _, node := range vds.NodeMap {
		if node.ID == uint32(nodeID) {
			for _, intf := range node.NodeInterfaces {
				if intf.Value.Name == ipnet.DefaultVxlanBVIInterfaceName {
					delete(vds.LoopMACMap, intf.Value.PhysAddress)
					for _, ip := range intf.Value.IpAddresses {
						delete(vds.LoopIPMap, ip)
					}
				}
			}
			delete(vds.NodeMap, node.Name)
			delete(vds.GigEIPMap, node.IPAddr)
			return nil
		}
	}
	return fmt.Errorf("node %s does not exist", nodeName)
}
func (vds *VppDataStore) RetrieveAllNodes() []*telemetrymodel.Node {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	var str []string
	for k := range vds.NodeMap {
		str = append(str, k)
	}
	var nList []*telemetrymodel.Node
	sort.Strings(str)
	for _, v := range str {
		n, _ := vds.retrieveNode(v)
		nList = append(nList, n)
	}
	return nList
}
func (vds *VppDataStore) UpdateNode(ID uint32, nodeName, IPAddr string) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.NodeMap[nodeName]
	if !ok {
		return errors.Errorf("Node with name %+vds not found in vpp cache", nodeName)
	}
	node.IPAddr = IPAddr
	node.ID = ID
	if IPAddr != "" {
		ipa := strings.Split(IPAddr, "/")
		vds.GigEIPMap[ipa[0]] = node
	}
	return nil
}
func (vds *VppDataStore) ClearCache() {
	for _, node := range vds.NodeMap {
		node.NodeInterfaces = nil
		node.NodeBridgeDomains = nil
		node.NodeL2Fibs = nil
		node.NodeLiveness = nil
		node.NodeTelemetry = nil
		node.NodeIPArp = nil
	}
	vds.LoopMACMap = make(map[string]*telemetrymodel.Node)
	vds.LoopIPMap = make(map[string]*telemetrymodel.Node)
	vds.HostIPMap = make(map[string]*telemetrymodel.Node)
}
func (vds *VppDataStore) ReinitializeCache() {
	vds.ClearCache()
	vds.NodeMap = make(map[string]*telemetrymodel.Node)
}
func (vds *VppDataStore) DumpCache() {
	fmt.Printf("NodeMap: %+v\n", vds.NodeMap)
	fmt.Printf("LoopMACMap: %+v\n", vds.LoopMACMap)
	fmt.Printf("GigEIPMap: %+v\n", vds.GigEIPMap)
	fmt.Printf("HostIPMap: %+v\n", vds.HostIPMap)
	fmt.Printf("LoopIPMap: %+v\n", vds.LoopIPMap)
}
func NewVppDataStore() (n *VppDataStore) {
	return &VppDataStore{
		lock:       &sync.Mutex{},
		NodeMap:    make(map[string]*telemetrymodel.Node),
		LoopIPMap:  make(map[string]*telemetrymodel.Node),
		GigEIPMap:  make(map[string]*telemetrymodel.Node),
		LoopMACMap: make(map[string]*telemetrymodel.Node),
		HostIPMap:  make(map[string]*telemetrymodel.Node),
	}
}
func (vds *VppDataStore) SetNodeLiveness(nodeName string, nLive *status.AgentStatus) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeLiveness for node %s", nodeName)
	}
	node.NodeLiveness = nLive
	return nil
}
func (vds *VppDataStore) SetNodeInterfaces(nodeName string, nInt telemetrymodel.NodeInterfaces) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeInterfaces for node %s", nodeName)
	}
	node.NodeInterfaces = make(telemetrymodel.NodeInterfaceMap)
	for _, iface := range nInt {
		node.NodeInterfaces[iface.Metadata.SwIfIndex] = iface
	}
	return nil
}
func (vds *VppDataStore) SetLinuxInterfaces(nodeName string, nInt telemetrymodel.LinuxInterfaces) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeInterfaces for node %s", nodeName)
	}
	node.LinuxInterfaces = nInt
	return nil
}
func (vds *VppDataStore) SetNodeStaticRoutes(nodeName string, nSrs telemetrymodel.NodeStaticRoutes) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeStaticRoutes for node %s", nodeName)
	}
	node.NodeStaticRoutes = nSrs
	return nil
}
func (vds *VppDataStore) SetNodeBridgeDomain(nodeName string, nBridge telemetrymodel.NodeBridgeDomains) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeBridgeDomains for node %s", nodeName)
	}
	node.NodeBridgeDomains = nBridge
	return nil
}
func (vds *VppDataStore) SetNodeL2Fibs(nodeName string, nL2F telemetrymodel.NodeL2FibTable) error {
	vds.lock.Lock()
	defer vds.lock.Unlock()
	node, ok := vds.retrieveNode(nodeName)
	if !ok {
		return fmt.Errorf("failed to set NodeL2Fibs for node %s", nodeName)
	}
	node.NodeL2Fibs = nL2F
	return nil
}