Skip to content

Commit

Permalink
erdma using eri mac as pod-side veth hwaddr
Browse files Browse the repository at this point in the history
Signed-off-by: bingshen.wbs <[email protected]>
  • Loading branch information
BSWANG committed Jul 19, 2024
1 parent 3aba8b9 commit 527ec51
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 118 deletions.
1 change: 1 addition & 0 deletions pkg/eni/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (l *LocalIPResource) ToRPC() []*rpc.NetConf {
Trunk: false,
Vid: 0,
GatewayIP: l.ENI.GatewayIP.ToRPC(),
ERDMA: l.ENI.ERdma,

Check warning on line 107 in pkg/eni/local.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/local.go#L107

Added line #L107 was not covered by tests
},
Pod: nil,
IfName: "",
Expand Down
16 changes: 10 additions & 6 deletions plugin/datapath/policy_router_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,20 @@ func generateENICfgForPolicy(cfg *types.SetupConfig, link netlink.Link, table in
}

func (d *PolicyRoute) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
eni, err := netlink.LinkByIndex(cfg.ENIIndex)
if err != nil {
return err

Check warning on line 308 in plugin/datapath/policy_router_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/policy_router_linux.go#L308

Added line #L308 was not covered by tests
}

vethCfg := &veth.Veth{
IfName: cfg.ContainerIfName,
PeerName: cfg.HostVETHName,
MTU: cfg.MTU,
}
err := veth.Setup(vethCfg, netNS)
if cfg.ERDMA {
vethCfg.HwAddr = eni.Attrs().HardwareAddr

Check warning on line 317 in plugin/datapath/policy_router_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/policy_router_linux.go#L317

Added line #L317 was not covered by tests
}
err = veth.Setup(vethCfg, netNS)
if err != nil {
return err
}
Expand All @@ -319,6 +327,7 @@ func (d *PolicyRoute) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
}

err = netNS.Do(func(_ ns.NetNS) error {

// 2. add address for container interface
contLink, err := netlink.LinkByName(cfg.ContainerIfName)
if err != nil {
Expand All @@ -339,11 +348,6 @@ func (d *PolicyRoute) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
return fmt.Errorf("setup container, %w", err)
}

eni, err := netlink.LinkByIndex(cfg.ENIIndex)
if err != nil {
return err
}

if cfg.EnableNetworkPriority {
err = utils.SetEgressPriority(eni, cfg.NetworkPriority, cfg.ContainerIPNet)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions plugin/driver/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type SetupConfig struct {
GatewayIP *terwayTypes.IPSet
MTU int
ENIIndex int
ERDMA bool
ENIGatewayIP *terwayTypes.IPSet

// disable create peer for exclusiveENI
Expand Down
6 changes: 6 additions & 0 deletions plugin/driver/veth/veth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package veth

import (
"net"

"github.com/AliyunContainerService/terway/plugin/driver/utils"

"github.com/containernetworking/plugins/pkg/ip"
Expand All @@ -11,6 +13,7 @@ import (
type Veth struct {
IfName string // cont in netns
PeerName string
HwAddr net.HardwareAddr
MTU int
}

Expand Down Expand Up @@ -39,6 +42,9 @@ func Setup(cfg *Veth, netNS ns.NetNS) error {
},
PeerName: cfg.PeerName,
}
if cfg.HwAddr != nil {
v.HardwareAddr = cfg.HwAddr
}
err = utils.LinkAdd(v)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions plugin/terway/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func parseSetupConf(args *skel.CmdArgs, alloc *rpc.NetConf, conf *types.CNIConf,
deviceID int32
trunkENI bool
vid uint32
erdma bool

ingress uint64
egress uint64
Expand Down Expand Up @@ -302,6 +303,7 @@ func parseSetupConf(args *skel.CmdArgs, alloc *rpc.NetConf, conf *types.CNIConf,
}
trunkENI = alloc.GetENIInfo().GetTrunk()
vid = alloc.GetENIInfo().GetVid()
erdma = alloc.GetENIInfo().GetERDMA()
if alloc.GetENIInfo().GetGatewayIP() != nil {
eniGatewayIP, err = terwayTypes.ToIPSet(alloc.GetENIInfo().GetGatewayIP())
if err != nil {
Expand Down Expand Up @@ -357,6 +359,7 @@ func parseSetupConf(args *skel.CmdArgs, alloc *rpc.NetConf, conf *types.CNIConf,
GatewayIP: gatewayIP,
MTU: conf.MTU,
ENIIndex: int(deviceID),
ERDMA: erdma,
ENIGatewayIP: eniGatewayIP,
ServiceCIDR: serviceCIDR,
HostStackCIDRs: hostStackCIDRs,
Expand Down
234 changes: 122 additions & 112 deletions rpc/rpc.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions rpc/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ message ENIInfo {
bool Trunk = 2; // eni is trunk
uint32 Vid = 3; // vlan ID
IPSet GatewayIP = 4;
bool eRDMA = 5; // eni is eRDMA
}

message Route {
Expand Down

0 comments on commit 527ec51

Please sign in to comment.