github.com/cilium/cilium@v1.16.2/pkg/datapath/fake/types/datapath.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package types 5 6 import ( 7 "context" 8 "io" 9 "net/netip" 10 11 "github.com/cilium/cilium/pkg/datapath/loader/metrics" 12 "github.com/cilium/cilium/pkg/datapath/tunnel" 13 datapath "github.com/cilium/cilium/pkg/datapath/types" 14 "github.com/cilium/cilium/pkg/option" 15 "github.com/cilium/cilium/pkg/testutils/mockmaps" 16 ) 17 18 var _ datapath.Datapath = (*FakeDatapath)(nil) 19 20 type FakeDatapath struct { 21 node *FakeNodeHandler 22 nodeAddressing datapath.NodeAddressing 23 loader datapath.Loader 24 lbmap *mockmaps.LBMockMap 25 } 26 27 // NewDatapath returns a new fake datapath 28 func NewDatapath() *FakeDatapath { 29 return NewDatapathWithNodeAddressing(NewNodeAddressing()) 30 } 31 32 func NewDatapathWithNodeAddressing(na datapath.NodeAddressing) *FakeDatapath { 33 return &FakeDatapath{ 34 node: NewNodeHandler(), 35 nodeAddressing: na, 36 loader: &FakeLoader{}, 37 lbmap: mockmaps.NewLBMockMap(), 38 } 39 } 40 41 // Node returns a fake handler for node events 42 func (f *FakeDatapath) Node() datapath.NodeHandler { 43 return f.node 44 } 45 46 func (f *FakeDatapath) NodeIDs() datapath.NodeIDHandler { 47 return f.node 48 } 49 50 func (f *FakeDatapath) NodeNeighbors() datapath.NodeNeighbors { 51 return f.node 52 } 53 54 func (f *FakeDatapath) FakeNode() *FakeNodeHandler { 55 return f.node 56 } 57 58 // LocalNodeAddressing returns a fake node addressing implementation of the 59 // local node 60 func (f *FakeDatapath) LocalNodeAddressing() datapath.NodeAddressing { 61 return f.nodeAddressing 62 } 63 64 // WriteNodeConfig pretends to write the datapath configuration to the writer. 65 func (f *FakeDatapath) WriteNodeConfig(io.Writer, *datapath.LocalNodeConfiguration) error { 66 return nil 67 } 68 69 // WriteNetdevConfig pretends to write the netdev configuration to a writer. 70 func (f *FakeDatapath) WriteNetdevConfig(io.Writer, *option.IntOptions) error { 71 return nil 72 } 73 74 // WriteTemplateConfig pretends to write the endpoint configuration to a writer. 75 func (f *FakeDatapath) WriteTemplateConfig(io.Writer, *datapath.LocalNodeConfiguration, datapath.EndpointConfiguration) error { 76 return nil 77 } 78 79 // WriteEndpointConfig pretends to write the endpoint configuration to a writer. 80 func (f *FakeDatapath) WriteEndpointConfig(io.Writer, *datapath.LocalNodeConfiguration, datapath.EndpointConfiguration) error { 81 return nil 82 } 83 84 func (f *FakeDatapath) InstallProxyRules(uint16, string) { 85 } 86 87 func (f *FakeDatapath) SupportsOriginalSourceAddr() bool { 88 return false 89 } 90 91 func (m *FakeDatapath) GetProxyPorts() map[string]uint16 { 92 return nil 93 } 94 95 func (m *FakeDatapath) InstallNoTrackRules(ip netip.Addr, port uint16) { 96 } 97 98 func (m *FakeDatapath) RemoveNoTrackRules(ip netip.Addr, port uint16) { 99 } 100 101 func (f *FakeDatapath) Loader() datapath.Loader { 102 return f.loader 103 } 104 105 func (f *FakeDatapath) WireguardAgent() datapath.WireguardAgent { 106 return nil 107 } 108 109 func (f *FakeDatapath) LBMap() datapath.LBMap { 110 return f.lbmap 111 } 112 113 func (f *FakeDatapath) LBMockMap() *mockmaps.LBMockMap { 114 return f.lbmap 115 } 116 117 func (f *FakeDatapath) BandwidthManager() datapath.BandwidthManager { 118 return &BandwidthManager{} 119 } 120 121 func (f *FakeDatapath) Orchestrator() datapath.Orchestrator { 122 return &FakeOrchestrator{} 123 } 124 125 // Loader is an interface to abstract out loading of datapath programs. 126 type FakeLoader struct { 127 } 128 129 func (f *FakeLoader) CompileOrLoad(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) error { 130 panic("implement me") 131 } 132 133 func (f *FakeLoader) ReloadDatapath(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) (string, error) { 134 panic("implement me") 135 } 136 137 func (f *FakeLoader) ReinitializeXDP(ctx context.Context, extraCArgs []string) error { 138 panic("implement me") 139 } 140 141 func (f *FakeLoader) EndpointHash(cfg datapath.EndpointConfiguration) (string, error) { 142 panic("implement me") 143 } 144 145 func (f *FakeLoader) Unload(ep datapath.Endpoint) { 146 } 147 148 func (f *FakeLoader) CallsMapPath(id uint16) string { 149 return "" 150 } 151 152 func (f *FakeLoader) CustomCallsMapPath(id uint16) string { 153 return "" 154 } 155 156 // Reinitialize does nothing. 157 func (f *FakeLoader) Reinitialize(ctx context.Context, cfg datapath.LocalNodeConfiguration, tunnelConfig tunnel.Config, iptMgr datapath.IptablesManager, p datapath.Proxy) error { 158 return nil 159 } 160 161 func (f *FakeLoader) HostDatapathInitialized() <-chan struct{} { 162 return nil 163 } 164 165 func (f *FakeLoader) DetachXDP(ifaceName string, bpffsBase, progName string) error { 166 return nil 167 } 168 169 func (f *FakeLoader) WriteEndpointConfig(w io.Writer, e datapath.EndpointConfiguration) error { 170 return nil 171 } 172 173 type FakeOrchestrator struct{} 174 175 func (f *FakeOrchestrator) Reinitialize(ctx context.Context) error { 176 return nil 177 }