Skip to content

Commit

Permalink
syncer: explicit configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Sep 7, 2023
1 parent 447b22d commit b6341fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/nad_with_syncer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
"mode": "primary", # CNI mode setting (required)
"logFile": "afxdp-cni.log", # CNI log file location (optional)
"logLevel": "debug", # CNI logging level (optional)
"dpSyncer": true, # Sync with Device Plugin over gRPC (optional)
"dpSyncer": true, # Sync with Device Plugin over gRPC MUST BE SET for bpf map pinning
"ipam": { # CNI IPAM plugin and associated config (optional)
"type": "host-local",
"subnet": "192.168.1.0/24",
Expand Down
1 change: 1 addition & 0 deletions internal/deviceplugin/poolManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (pm *PoolManager) Init(config PoolConfig) error {

logging.Debug("REGISTER MAP MANAGER WITH THE DP<=>CNI grpc Syncer")
pm.DpCniSyncerServer.RegisterMapManager(pm.Pbm)
pm.DpCniSyncerServer.BpfMapPinEnable = true
}

if len(pm.Devices) > 0 {
Expand Down
59 changes: 33 additions & 26 deletions internal/dpcnisyncerserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ var (

type SyncerServer struct {
pb.UnimplementedNetDevServer
mapManagers []bpf.PoolBpfMapManager
grpcServer *grpc.Server
mapManagers []bpf.PoolBpfMapManager
grpcServer *grpc.Server
BpfMapPinEnable bool
}

func (s *SyncerServer) RegisterMapManager(b bpf.PoolBpfMapManager) {
Expand All @@ -61,34 +62,39 @@ func (s *SyncerServer) RegisterMapManager(b bpf.PoolBpfMapManager) {
}

func (s *SyncerServer) DelNetDev(ctx context.Context, in *pb.DeleteNetDevReq) (*pb.DeleteNetDevResp, error) {
netDevName := in.GetName()

logging.Infof("Looking up Map Manager for %s", netDevName)
found := false
var pm bpf.PoolBpfMapManager
for _, mm := range s.mapManagers {
_, err := mm.Manager.GetBPFFS(netDevName)
if err == nil {
found = true
pm = mm
break

if s.BpfMapPinEnable {
netDevName := in.GetName()

logging.Infof("Looking up Map Manager for %s", netDevName)
found := false
var pm bpf.PoolBpfMapManager
for _, mm := range s.mapManagers {
_, err := mm.Manager.GetBPFFS(netDevName)
if err == nil {
found = true
pm = mm
break
}
}
}

if !found {
logging.Errorf("Could NOT find the map manager for device %s", netDevName)
return &pb.DeleteNetDevResp{Ret: -1}, errors.New("Could NOT find the map manager for device")
}
if !found {
logging.Errorf("Could NOT find the map manager for device %s", netDevName)
return &pb.DeleteNetDevResp{Ret: -1}, errors.New("Could NOT find the map manager for device")
}

logging.Infof("Map Manager found, deleting BPFFS for %s", netDevName)
err := pm.Manager.DeleteBPFFS(netDevName)
if err != nil {
logging.Errorf("Could NOT delete BPFFS for %s", netDevName)
return &pb.DeleteNetDevResp{Ret: -1}, errors.Wrapf(err, "Could NOT delete BPFFS for %s: %v", netDevName, err.Error())
logging.Infof("Map Manager found, deleting BPFFS for %s", netDevName)
err := pm.Manager.DeleteBPFFS(netDevName)
if err != nil {
logging.Errorf("Could NOT delete BPFFS for %s", netDevName)
return &pb.DeleteNetDevResp{Ret: -1}, errors.Wrapf(err, "Could NOT delete BPFFS for %s: %v", netDevName, err.Error())
}

logging.Infof("Network interface %s deleted", netDevName)
return &pb.DeleteNetDevResp{Ret: 0}, nil
}

logging.Infof("Network interface %s deleted", netDevName)
return &pb.DeleteNetDevResp{Ret: 0}, nil
return &pb.DeleteNetDevResp{Ret: -1}, errors.New("BPF Map pinning is not enabled")
}

func (s *SyncerServer) StopGRPCSyncer() {
Expand All @@ -108,7 +114,8 @@ func NewSyncerServer() (*SyncerServer, error) {
}

server := &SyncerServer{
grpcServer: grpc.NewServer(),
grpcServer: grpc.NewServer(),
BpfMapPinEnable: false,
}

lis, err := net.Listen(protocol, sockAddr)
Expand Down

0 comments on commit b6341fd

Please sign in to comment.