github.com/looshlee/beatles@v0.0.0-20220727174639-742810ab631c/pkg/testutils/endpoint.go (about) 1 // Copyright 2019 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package testutils 16 17 import ( 18 identityMdl "github.com/cilium/cilium/api/v1/models" 19 "github.com/cilium/cilium/common/addressing" 20 "github.com/cilium/cilium/pkg/identity" 21 "github.com/cilium/cilium/pkg/mac" 22 "github.com/cilium/cilium/pkg/option" 23 24 "github.com/sirupsen/logrus" 25 ) 26 27 var ( 28 defaultIdentity = identity.NewIdentityFromModel(&identityMdl.Identity{ 29 ID: 42, 30 Labels: []string{"foo"}, 31 }) 32 ) 33 34 type TestEndpoint struct { 35 Id uint64 36 Identity *identity.Identity 37 Opts *option.IntOptions 38 MAC mac.MAC 39 } 40 41 func NewTestEndpoint() TestEndpoint { 42 opts := option.NewIntOptions(&option.OptionLibrary{}) 43 opts.SetBool("TEST_OPTION", true) 44 return TestEndpoint{ 45 Id: 42, 46 Identity: defaultIdentity, 47 MAC: mac.MAC([]byte{0x02, 0x00, 0x60, 0x0D, 0xF0, 0x0D}), 48 Opts: opts, 49 } 50 } 51 52 func (e *TestEndpoint) HasIpvlanDataPath() bool { return false } 53 func (e *TestEndpoint) ConntrackLocalLocked() bool { return false } 54 func (e *TestEndpoint) RequireARPPassthrough() bool { return false } 55 func (e *TestEndpoint) RequireEgressProg() bool { return false } 56 func (e *TestEndpoint) RequireRouting() bool { return false } 57 func (e *TestEndpoint) RequireEndpointRoute() bool { return false } 58 func (e *TestEndpoint) GetCIDRPrefixLengths() ([]int, []int) { return nil, nil } 59 func (e *TestEndpoint) GetID() uint64 { return e.Id } 60 func (e *TestEndpoint) StringID() string { return "42" } 61 func (e *TestEndpoint) GetIdentity() identity.NumericIdentity { return e.Identity.ID } 62 func (e *TestEndpoint) GetSecurityIdentity() *identity.Identity { return e.Identity } 63 func (e *TestEndpoint) GetNodeMAC() mac.MAC { return e.MAC } 64 func (e *TestEndpoint) GetOptions() *option.IntOptions { return e.Opts } 65 66 func (e *TestEndpoint) IPv4Address() addressing.CiliumIPv4 { 67 addr, _ := addressing.NewCiliumIPv4("192.0.2.3") 68 return addr 69 } 70 func (e *TestEndpoint) IPv6Address() addressing.CiliumIPv6 { 71 addr, _ := addressing.NewCiliumIPv6("2001:db08:0bad:cafe:600d:bee2:0bad:cafe") 72 return addr 73 } 74 75 func (e *TestEndpoint) InterfaceName() string { 76 return "cilium_test" 77 } 78 79 func (e *TestEndpoint) Logger(subsystem string) *logrus.Entry { 80 return log 81 } 82 83 func (e *TestEndpoint) SetIdentity(secID int64, newEndpoint bool) { 84 e.Identity = identity.NewIdentityFromModel(&identityMdl.Identity{ 85 ID: secID, 86 Labels: []string{"bar"}, 87 }) 88 } 89 90 func (e *TestEndpoint) StateDir() string { 91 return "test_loader" 92 } 93 94 func (e *TestEndpoint) MapPath() string { 95 return "map_path" 96 }