github.com/cilium/cilium@v1.16.2/pkg/testutils/endpoint.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package testutils 5 6 import ( 7 "net/netip" 8 9 "github.com/sirupsen/logrus" 10 11 "github.com/cilium/cilium/pkg/identity" 12 "github.com/cilium/cilium/pkg/labels" 13 "github.com/cilium/cilium/pkg/mac" 14 "github.com/cilium/cilium/pkg/option" 15 ) 16 17 var ( 18 defaultIdentity = identity.NewIdentity(42, labels.NewLabelsFromModel([]string{"foo"})) 19 hostIdentity = identity.NewIdentity(identity.ReservedIdentityHost, labels.LabelHost) 20 ) 21 22 type TestEndpoint struct { 23 Id uint64 24 Identity *identity.Identity 25 Opts *option.IntOptions 26 MAC mac.MAC 27 IfIndex int 28 IPv6 netip.Addr 29 isHost bool 30 State string 31 } 32 33 func NewTestEndpoint() TestEndpoint { 34 opts := option.NewIntOptions(&option.OptionLibrary{}) 35 opts.SetBool("TEST_OPTION", true) 36 return TestEndpoint{ 37 Id: 42, 38 Identity: defaultIdentity, 39 MAC: mac.MAC([]byte{0x02, 0x00, 0x60, 0x0D, 0xF0, 0x0D}), 40 IfIndex: 0, 41 Opts: opts, 42 } 43 } 44 45 func NewTestHostEndpoint() TestEndpoint { 46 opts := option.NewIntOptions(&option.OptionLibrary{}) 47 opts.SetBool("TEST_OPTION", true) 48 return TestEndpoint{ 49 Id: 65535, 50 Identity: hostIdentity, 51 MAC: mac.MAC([]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}), 52 IfIndex: 0, 53 Opts: opts, 54 isHost: true, 55 } 56 } 57 58 func (e *TestEndpoint) ConntrackLocalLocked() bool { return false } 59 func (e *TestEndpoint) RequireARPPassthrough() bool { return false } 60 func (e *TestEndpoint) RequireEgressProg() bool { return false } 61 func (e *TestEndpoint) RequireRouting() bool { return false } 62 func (e *TestEndpoint) RequireEndpointRoute() bool { return false } 63 func (e *TestEndpoint) GetPolicyVerdictLogFilter() uint32 { return 0xffff } 64 func (e *TestEndpoint) GetCIDRPrefixLengths() ([]int, []int) { return nil, nil } 65 func (e *TestEndpoint) GetID() uint64 { return e.Id } 66 func (e *TestEndpoint) StringID() string { return "42" } 67 func (e *TestEndpoint) GetIdentity() identity.NumericIdentity { return e.Identity.ID } 68 func (e *TestEndpoint) GetIdentityLocked() identity.NumericIdentity { return e.Identity.ID } 69 func (e *TestEndpoint) GetSecurityIdentity() *identity.Identity { return e.Identity } 70 func (e *TestEndpoint) GetNodeMAC() mac.MAC { return e.MAC } 71 func (e *TestEndpoint) GetIfIndex() int { return e.IfIndex } 72 func (e *TestEndpoint) GetOptions() *option.IntOptions { return e.Opts } 73 func (e *TestEndpoint) IsHost() bool { return e.isHost } 74 75 func (e *TestEndpoint) IPv4Address() netip.Addr { 76 return netip.MustParseAddr("192.0.2.3") 77 } 78 func (e *TestEndpoint) IPv6Address() netip.Addr { 79 return e.IPv6 80 } 81 82 func (e *TestEndpoint) InterfaceName() string { 83 return "cilium_test" 84 } 85 86 func (e *TestEndpoint) Logger(subsystem string) *logrus.Entry { 87 return log 88 } 89 90 func (e *TestEndpoint) SetIdentity(secID int64, newEndpoint bool) { 91 e.Identity = identity.NewIdentity(identity.NumericIdentity(secID), labels.NewLabelsFromModel([]string{"bar"})) 92 } 93 94 func (e *TestEndpoint) StateDir() string { 95 if e.State != "" { 96 return e.State 97 } 98 return "test_loader" 99 }