Documentation ¶
Index ¶
- Constants
- Variables
- func ActiveVethPort(vethPort string) error
- func AddVethToOvsWithVlanID(ovsBridge, vethPort, vlanID string) error
- func CreateRoute(linkIndex int, dst *net.IPNet, gw net.IP) *netlink.Route
- func DeactivateVethPort(vethPort string) error
- func DelNousedOvsBrInterfaces(brName string) error
- func DelNousedOvsBrInterfacesLoop(brName string)
- func DelOvsBrsNousedInterfacesLoop()
- func DelVethFromOvs(ovsBridge, vethPort string) error
- func DestroyResidualBrintIntfcs()
- func GetBusInfo(ethName string) (string, error)
- func GetC0PodInfo() (*jason.Object, error)
- func GetContainerDir() (string, error)
- func GetDockerInfoByKey(key []string) ([]string, error)
- func GetLspciOutput(args []string) ([]byte, error)
- func GetOVSList() (string, error)
- func GetPciID(busInfo string) (string, error)
- func NetNSToPID(ns string) (int, error)
- func RouteAdd(route *netlink.Route) error
- func SumOfVirtioNetPci() int
- type Container
- type Dpdknic
- type Link
- func (self *Link) GetName() string
- func (self *Link) SetAddr(addr *netlink.Addr) bool
- func (self *Link) SetDown() bool
- func (self *Link) SetDynamicName() bool
- func (self *Link) SetMac(mac string) bool
- func (self *Link) SetMtu(mtu string) bool
- func (self *Link) SetName(name string)
- func (self *Link) SetUp() bool
- type LinkRepository
- func (self *LinkRepository) AddRange(links []netlink.Link)
- func (self *LinkRepository) FindLinkByMac(mac string) *Link
- func (self *LinkRepository) FindLinkByName(name string) *Link
- func (self *LinkRepository) FindLinkByPci(pci string) *Link
- func (self *LinkRepository) FindVfLinkByName(name string) *Link
- func (self *LinkRepository) GetPciEthMap(line string) (string, string, error)
- func (self *LinkRepository) Update(links []netlink.Link)
- type Machine
- func (self *Machine) FindLinkByMac(mac string) *Link
- func (self *Machine) FindLinkByName(name string) *Link
- func (self *Machine) FindLinkByPci(pci string) *Link
- func (self *Machine) FindVfLinkByName(name string) *Link
- func (self *Machine) GetCurrentNsLinks() []netlink.Link
- func (self *Machine) SetNetLink(nl base.NetLink)
- func (self *Machine) UpdateLinks()
- type Nicdevs
- type Pci
- type Pod
- func (self *Pod) AddLinkToContainer(container *Container, vfLink *Link, port *manager.Port, vmNs netns.NsHandle) error
- func (self *Pod) BindLinkByVethName(container *Container, port *manager.Port, vm *Machine, vethName string, ...) error
- func (self *Pod) DeleteLink(container *Container, portMac string) error
- func (self *Pod) FindLinkByMac(mac string) *Link
- func (self *Pod) GetCurrentNsLinks() []netlink.Link
- func (self *Pod) SetNameSpace(ns base.NameSpace)
- func (self *Pod) SetNetLink(netlink base.NetLink)
- func (self *Pod) UpdateLinks()
Constants ¶
View Source
const MaxRetryTimesOfFindLinkByName int = 10
View Source
const PCIPATH = "/sys/bus/pci"
View Source
const SysNetPath = "/sys/class/net"
Variables ¶
View Source
var AttachVethToPod = func(netNs string, port *manager.Port, vethName string) error { pod := NewTempPod() nameSpace4Pod := &implement.NameSpace{} pod.SetNameSpace(nameSpace4Pod) netLink4Pod := &implement.NetLink{} pod.SetNetLink(netLink4Pod) vmNs, _ := pod.NameSpace.Get() defer vmNs.Close() vm := NewMachine(vmNs) netLink4Machine := &implement.NetLink{} vm.SetNetLink(netLink4Machine) pid, errN := NetNSToPID(netNs) if errN != nil { klog.Errorf("Error moving to netns. Err: %v", errN) return errN } container := NewContainer(pid) netLink4Container := &implement.NetLink{} container.SetNetLink(netLink4Container) netNs4Container := &implement.NetNs{} container.SetNetNs(netNs4Container) err := pod.BindLinkByVethName(container, port, vm, vethName, vmNs) if err != nil { return fmt.Errorf("%v:bind-AddSelectedIntfToPod:pod.bindlink(containerID, port, vfLink)error", err) } return nil }
View Source
var DelOvsBrInterfaces = func(brName string, ifs []string) { klog.Infof("DelOvsBrInterfaces: delete %v from %s START", ifs, brName) for _, ifName := range ifs { err := DelVethFromOvs(brName, ifName) if err != nil { klog.Errorf("DelOvsBrInterfaces: DelVethFromOvs %s from %s FAILED, error: %v", brName, ifName, err) } klog.Infof("DelOvsBrInterfaces: DelVethFromOvs %s from %s SUCC", brName, ifName) } klog.Infof("DelOvsBrInterfaces: delete %v from %s FINI", ifs, brName) }
View Source
var DockerExec = func(containerId, program, para string) error { dockerCtl, _ := exec.LookPath("docker") dockerPsArgs := []string{"exec", containerId, program, string(para)} output, err := exec.Command(dockerCtl, dockerPsArgs...).CombinedOutput() if err != nil || strings.Contains(strings.ToUpper(string(output)), "ERROR") { klog.Infof("DockerExec-err:output :%v", string(output)) param := " docker exec " + containerId + " " + program + " " + para klog.Errorf("ERROR:" + dockerCtl + param + "\n OUTPUT:" + string(output) + "\n CAUSE:" + err.Error()) return fmt.Errorf("%v:dockerExec:exec.command() ERROR", err) } klog.Infof("DockerExec-suc:output :%v", string(output)) return nil }
View Source
var GetC0ImageName = func() string { agtCtx := cni.GetGlobalContext() var c0ImageName = "" for i := 0; i < 3; i++ { key := dbaccessor.GetKeyOfImageNameForC0(agtCtx.ClusterID, agtCtx.HostIP) c0ImageName, _ = adapter.ReadLeafFromDb(key) if c0ImageName != "" { klog.Infof("C0 image is %v", c0ImageName) break } time.Sleep(10 * time.Second) } if c0ImageName == "" { klog.Errorf("GetC0ContainerIdByImageName: GetC0ContainerIdByImageName error : c0 image empty!") } return c0ImageName }
View Source
var GetContainerIDByName = func() (s string, e error) { var c0ContainerID string c0ImageName := GetC0ImageName() if c0ImageName == "" { return "", errors.New("getContainerIdByName:Get c0 image error") } for i := 0; i <= 2; i++ { c0PodJSON, err := GetC0PodInfo() if err != nil { return "", err } containersList, errList := c0PodJSON.GetObjectArray("status", "containerStatuses") if errList != nil { return "", errList } for _, container := range containersList { imageName, _ := container.GetString("image") if imageName != c0ImageName { continue } _, errRunning := container.GetObject("state", "running") if errRunning != nil { klog.Warningf("GetContainerIdByName: C0 container is not running") break } c0ContainerID, _ = container.GetString("containerID") c0ContainerID = strings.TrimPrefix(c0ContainerID, "docker://") return c0ContainerID, nil } time.Sleep(5 * time.Second) } return "", errors.New("getContainerIdByName:Get c0 id error") }
View Source
var GetEthtoolOutputFunc func(ethName string) ([]byte, error)
View Source
var GetLspciOutputFunc func(args []string) ([]byte, error)
View Source
var GetPidFromDockerConf = func(containerId string) (string, error) { containerDir, err := GetContainerDir() if err != nil { klog.Errorf("GetPidFromDockerConf:GetContainerDir error! %v", err) return "", err } dockerConfPath := containerDir + "/" + containerId fileList, err := ioutil.ReadDir(dockerConfPath) if err != nil { klog.Errorf("GetPidFromDockerConf:ReadDir error! %v", err) return "", err } dockerConfFile := dockerConfPath + "/" + "config.json" for _, f := range fileList { rxConf := regexp.MustCompile(`^conf.*\.json$`) if rxConf.MatchString(f.Name()) { dockerConfFile = dockerConfPath + "/" + f.Name() } } dockerConf, err := ioutil.ReadFile(dockerConfFile) if err != nil { klog.Errorf("GetPidFromDockerConf:ReadFile error! %v", err) return "", err } dockerConfJSON, errJSON := jason.NewObjectFromBytes(dockerConf) if errJSON != nil { klog.Errorf("GetPidFromDockerConf:NewObjectFromBytes error! %v", errJSON) return "", errJSON } pidInt, errInt := dockerConfJSON.GetInt64("State", "Pid") klog.Infof("GetPidFromDockerConf:pid is %v", pidInt) if errInt != nil { klog.Errorf("GetPidFromDockerConf:GetInt64 error! %v", errJSON) return "", errInt } pidStr := strconv.FormatInt(pidInt, 10) return pidStr, nil }
c0
View Source
var ListNousedOvsBrInterfaces = func(ports []string) []string { nonusedIfs := make([]string, 0) for _, portName := range ports { if isInterfaceDetached(portName) { nonusedIfs = append(nonusedIfs, portName) } } return nonusedIfs }
View Source
var Nsenter = func(pid, program, para string) error { nsenterCtl, _ := exec.LookPath("nsenter") nsenterArgs := []string{"-t", pid, "--mount", "--uts", "--ipc", "--net", "--pid", program, para} output, err := exec.Command(nsenterCtl, nsenterArgs...).CombinedOutput() if err != nil { param := " nsenter -t " + pid + " --mount --uts --ipc --net --pid " + program + " " + para klog.Errorf("ERROR:" + nsenterCtl + param + "\n OUTPUT:" + string(output) + "\n CAUSE:" + err.Error()) return fmt.Errorf("%v:Nsenter:exec.command() ERROR", err) } return nil }
View Source
var RouteAddFunc func(route *netlink.Route) error
Functions ¶
func ActiveVethPort ¶
func AddVethToOvsWithVlanID ¶
func DeactivateVethPort ¶
func DelNousedOvsBrInterfacesLoop ¶
func DelNousedOvsBrInterfacesLoop(brName string)
func DelOvsBrsNousedInterfacesLoop ¶
func DelOvsBrsNousedInterfacesLoop()
func DelVethFromOvs ¶
func DestroyResidualBrintIntfcs ¶
func DestroyResidualBrintIntfcs()
func GetBusInfo ¶
func GetC0PodInfo ¶
func GetContainerDir ¶
func GetDockerInfoByKey ¶
func GetLspciOutput ¶
func GetOVSList ¶
func NetNSToPID ¶
func SumOfVirtioNetPci ¶
func SumOfVirtioNetPci() int
Types ¶
type Container ¶
type Container struct { ID string Pid int NameSpace netns.NsHandle Link *Link NetLink base.NetLink NetNs base.NetNs }
func NewContainer ¶
func (*Container) SetNetLink ¶
type Dpdknic ¶
type Dpdknic struct { BusInfo string `json:"bus_info"` Name string `json:"name"` IP string `json:"ip"` Mask string `json:"mask"` Gateway string `json:"gateway"` Mac string `json:"mac"` Function string `json:"function"` Accelerate string `json:"accelerate"` BusInfos []string `json:"bus_infos"` BondMode string `json:"bond_type"` Metadata interface{} `json:"metadata"` }
type Link ¶
func (*Link) SetDynamicName ¶
type LinkRepository ¶
type LinkRepository struct {
Links []*Link
}
func NewLinkRepository ¶
func NewLinkRepository() *LinkRepository
func (*LinkRepository) AddRange ¶
func (self *LinkRepository) AddRange(links []netlink.Link)
func (*LinkRepository) FindLinkByMac ¶
func (self *LinkRepository) FindLinkByMac(mac string) *Link
func (*LinkRepository) FindLinkByName ¶
func (self *LinkRepository) FindLinkByName(name string) *Link
func (*LinkRepository) FindLinkByPci ¶
func (self *LinkRepository) FindLinkByPci(pci string) *Link
To find link by pci
func (*LinkRepository) FindVfLinkByName ¶
func (self *LinkRepository) FindVfLinkByName(name string) *Link
func (*LinkRepository) GetPciEthMap ¶
func (self *LinkRepository) GetPciEthMap(line string) (string, string, error)
func (*LinkRepository) Update ¶
func (self *LinkRepository) Update(links []netlink.Link)
type Machine ¶
type Machine struct { NameSpace netns.NsHandle LinkRepo *LinkRepository NetLink base.NetLink }
func NewMachine ¶
func (*Machine) FindLinkByMac ¶
func (*Machine) FindLinkByName ¶
func (*Machine) FindLinkByPci ¶
func (*Machine) FindVfLinkByName ¶
func (*Machine) GetCurrentNsLinks ¶
func (*Machine) SetNetLink ¶
func (*Machine) UpdateLinks ¶
func (self *Machine) UpdateLinks()
type Pci ¶
func (*Pci) UnbindPath ¶
type Pod ¶
type Pod struct { Name string `json:"name"` ID string `json:"id"` K8sns string `json:"k8sns"` Podtype string `json:"podtype"` LinkRepo *LinkRepository NameSpace base.NameSpace NetLink base.NetLink }
func NewTempPod ¶
func NewTempPod() *Pod
func (*Pod) AddLinkToContainer ¶
func (*Pod) BindLinkByVethName ¶
func (*Pod) FindLinkByMac ¶
func (*Pod) GetCurrentNsLinks ¶
func (*Pod) SetNameSpace ¶
func (*Pod) SetNetLink ¶
func (*Pod) UpdateLinks ¶
func (self *Pod) UpdateLinks()
Click to show internal directories.
Click to hide internal directories.