github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/network/csn.go (about)

     1  /*
     2  Copyright 2018 Mirantis
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package network
    18  
    19  import (
    20  	"net"
    21  	"os"
    22  
    23  	cnicurrent "github.com/containernetworking/cni/pkg/types/current"
    24  )
    25  
    26  // InterfaceType presents type of network interface instance.
    27  type InterfaceType int
    28  
    29  const (
    30  	// InterfaceTypeTap is a marker for tap type interface.
    31  	InterfaceTypeTap InterfaceType = iota
    32  	// InterfaceTypeVF is a marker for SR-IOV VF type interface.
    33  	InterfaceTypeVF
    34  )
    35  
    36  // InterfaceDescription holds all data required by tapmanager to identify
    37  // network interface.
    38  type InterfaceDescription struct {
    39  	// Type contains interface type designator.
    40  	Type InterfaceType
    41  	// Fo contains open File object pointing to tap device inside network
    42  	// namespace or to control file in sysfs for sr-iov VF.
    43  	// It may be nil if the interface was recovered after restarting Virtlet.
    44  	// It's only needed during the initial VM startup.
    45  	// The json tag is here so that bogus File object doesn't get stored
    46  	// in the metadata db.
    47  	Fo *os.File `json:"-"`
    48  	// Name contains original interface name for sr-iov interface.
    49  	Name string
    50  	// HardwareAddr contains original hardware address for CNI-created
    51  	// veth link.
    52  	HardwareAddr net.HardwareAddr
    53  	// PCIAddress contains a pci address for sr-iov vf interface.
    54  	PCIAddress string
    55  	// MTU contains max transfer unit value for interface.
    56  	MTU uint16
    57  	// VlanID contains vlan id of sr-iov vf interface.
    58  	VlanID int
    59  }
    60  
    61  // ContainerSideNetwork struct describes the container (VM) network
    62  // namespace properties.
    63  type ContainerSideNetwork struct {
    64  	// Result contains CNI result object describing the network settings.
    65  	Result *cnicurrent.Result
    66  	// NsPath specifies the path to the container network namespace.
    67  	NsPath string
    68  	// Interfaces contains a list of interfaces with data needed
    69  	// to configure them.
    70  	Interfaces []*InterfaceDescription
    71  }