github.com/openshift/dpu-operator@v0.0.0-20240502153209-3af840d137c2/dpu-cni/pkgs/cnitypes/cnitypes.go (about)

     1  package cnitypes
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/containernetworking/cni/pkg/types"
     8  	current "github.com/containernetworking/cni/pkg/types/100"
     9  	nadapi "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
    10  	"github.com/vishvananda/netlink"
    11  )
    12  
    13  const (
    14  	DaemonBaseDir    string = "/var/run/dpu-daemon/"
    15  	ServerSocketPath string = DaemonBaseDir + "dpu-cni/dpu-cni-server.sock"
    16  )
    17  
    18  // Request sent to the Server by the DPU CNI plugin
    19  type Request struct {
    20  	// CNI environment variables, like CNI_COMMAND and CNI_NETNS
    21  	Env map[string]string `json:"env,omitempty"`
    22  	// CNI configuration passed via stdin to the CNI plugin
    23  	Config []byte `json:"config,omitempty"`
    24  	// The DeviceInfo struct
    25  	nadapi.DeviceInfo
    26  }
    27  
    28  // Response sent to this DPU CNI plugin by the Server
    29  type Response struct {
    30  	Result *current.Result
    31  }
    32  
    33  const CNIAdd string = "ADD"
    34  const CNIUpdate string = "UPDATE"
    35  const CNIDel string = "DEL"
    36  const CNICheck string = "CHECK"
    37  
    38  // PodRequest structure built from Request which is passed to the
    39  // handler function given to the Server at creation time
    40  type PodRequest struct {
    41  	// The CNI command of the operation
    42  	Command string
    43  	// kubernetes namespace name
    44  	PodNamespace string
    45  	// kubernetes pod name
    46  	PodName string
    47  	// kubernetes pod UID
    48  	PodUID string
    49  	// kubernetes container ID
    50  	ContainerId string
    51  	// kernel network namespace path
    52  	Netns string
    53  	// Interface name to be configured
    54  	IfName string
    55  	// Path to the CNI directory
    56  	Path string
    57  	// CNI conf obtained from stdin conf
    58  	CNIConf *NetConf
    59  	// Unparsed copy of the request
    60  	CNIReq *Request
    61  	// Timestamp when the request was started
    62  	Timestamp time.Time
    63  	// ctx is a context tracking this request's lifetime
    64  	Ctx context.Context
    65  	// cancel should be called to cancel this request
    66  	Cancel context.CancelFunc
    67  
    68  	// network name, for default network, this will be types.DefaultNetworkName
    69  	NetName string
    70  
    71  	// the DeviceInfo struct
    72  	DeviceInfo nadapi.DeviceInfo
    73  }
    74  
    75  // FIXME: This file is copied from sriov-cni intentionally. We plan to trim this down once
    76  // we know what we want to support from SR-IOV.
    77  
    78  const (
    79  	Proto8021q  = "802.1q"
    80  	Proto8021ad = "802.1ad"
    81  )
    82  
    83  var VlanProtoInt = map[string]int{Proto8021q: 33024, Proto8021ad: 34984}
    84  
    85  // VfState represents the state of the VF
    86  type VfState struct {
    87  	HostIFName   string
    88  	SpoofChk     bool
    89  	Trust        bool
    90  	AdminMAC     string
    91  	EffectiveMAC string
    92  	Vlan         int
    93  	VlanQoS      int
    94  	VlanProto    int
    95  	MinTxRate    int
    96  	MaxTxRate    int
    97  	LinkState    uint32
    98  }
    99  
   100  // FillFromVfInfo - Fill attributes according to the provided netlink.VfInfo struct
   101  func (vs *VfState) FillFromVfInfo(info *netlink.VfInfo) {
   102  	vs.AdminMAC = info.Mac.String()
   103  	vs.LinkState = info.LinkState
   104  	vs.MaxTxRate = int(info.MaxTxRate)
   105  	vs.MinTxRate = int(info.MinTxRate)
   106  	vs.Vlan = info.Vlan
   107  	vs.VlanQoS = info.Qos
   108  	vs.VlanProto = info.VlanProto
   109  	vs.SpoofChk = info.Spoofchk
   110  	vs.Trust = info.Trust != 0
   111  }
   112  
   113  // NetConf extends types.NetConf for dpu-sriov-cni
   114  type NetConf struct {
   115  	types.NetConf
   116  	OrigVfState   VfState // Stores the original VF state as it was prior to any operations done during cmdAdd flow
   117  	DPDKMode      bool    `json:"-"`
   118  	Master        string
   119  	MAC           string
   120  	Vlan          *int    `json:"vlan"`
   121  	VlanQoS       *int    `json:"vlanQoS"`
   122  	VlanProto     *string `json:"vlanProto"` // 802.1ad|802.1q
   123  	DeviceID      string  `json:"deviceID"`  // PCI address of a VF in valid sysfs format
   124  	VFID          int
   125  	MinTxRate     *int   `json:"min_tx_rate"`          // Mbps, 0 = disable rate limiting
   126  	MaxTxRate     *int   `json:"max_tx_rate"`          // Mbps, 0 = disable rate limiting
   127  	SpoofChk      string `json:"spoofchk,omitempty"`   // on|off
   128  	Trust         string `json:"trust,omitempty"`      // on|off
   129  	LinkState     string `json:"link_state,omitempty"` // auto|enable|disable
   130  	RuntimeConfig struct {
   131  		Mac string `json:"mac,omitempty"`
   132  	} `json:"runtimeConfig,omitempty"`
   133  	LogLevel string `json:"logLevel,omitempty"`
   134  	LogFile  string `json:"logFile,omitempty"`
   135  }