github.com/zhyoulun/cilium@v1.6.12/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) GetIdentityLocked() identity.NumericIdentity { return e.Identity.ID }
    63  func (e *TestEndpoint) GetSecurityIdentity() *identity.Identity     { return e.Identity }
    64  func (e *TestEndpoint) GetNodeMAC() mac.MAC                         { return e.MAC }
    65  func (e *TestEndpoint) GetOptions() *option.IntOptions              { return e.Opts }
    66  
    67  func (e *TestEndpoint) IPv4Address() addressing.CiliumIPv4 {
    68  	addr, _ := addressing.NewCiliumIPv4("192.0.2.3")
    69  	return addr
    70  }
    71  func (e *TestEndpoint) IPv6Address() addressing.CiliumIPv6 {
    72  	addr, _ := addressing.NewCiliumIPv6("2001:db08:0bad:cafe:600d:bee2:0bad:cafe")
    73  	return addr
    74  }
    75  
    76  func (e *TestEndpoint) InterfaceName() string {
    77  	return "cilium_test"
    78  }
    79  
    80  func (e *TestEndpoint) Logger(subsystem string) *logrus.Entry {
    81  	return log
    82  }
    83  
    84  func (e *TestEndpoint) SetIdentity(secID int64, newEndpoint bool) {
    85  	e.Identity = identity.NewIdentityFromModel(&identityMdl.Identity{
    86  		ID:     secID,
    87  		Labels: []string{"bar"},
    88  	})
    89  }
    90  
    91  func (e *TestEndpoint) StateDir() string {
    92  	return "test_loader"
    93  }
    94  
    95  func (e *TestEndpoint) MapPath() string {
    96  	return "map_path"
    97  }