Skip to content

Commit

Permalink
bpfd: update to use xskmap program
Browse files Browse the repository at this point in the history
Still not fully working with bpfd as it seems to be loading
the program but not pinning the map.

Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Nov 2, 2023
1 parent 31c129c commit 6e43684
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ kind-label-nodes: ## Label the kind worker nodes with cndp="true"
kubectl label node ${KIND_CLUSTER_NAME}-worker cndp="true"
kubectl label node ${KIND_CLUSTER_NAME}-worker2 cndp="true"

.PHONY: kind-label-bpfd-cp
kind-label-bpfd-cp: ## Label the kind worker nodes with cndp="true"
kubectl label node ${KIND_CLUSTER_NAME}-control-plane cndp="true"

.PHONY: kind-load-images
kind-load-images: ## Load the image on the kind cluster
@echo "****** Loading AF_XDP DEVICE PLUGIN image ******"
Expand Down
4 changes: 2 additions & 2 deletions deployments/daemonset-kind-bpfd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ data:
"name":"myPool",
"mode":"primary",
"UdsServerDisable": true,
"BpfByteCodeImage": "quay.io/bpfd-bytecode/go-xdp-counter:latest",
"BpfByteCodeFunction": "xdp_stats",
"BpfByteCodeImage": "quay.io/mtahhan/xsk_def_xdp_prog:latest",
"BpfByteCodeFunction": "xsk_def_prog",
"drivers":[
{
"name":"veth"
Expand Down
25 changes: 9 additions & 16 deletions internal/bpfd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,17 @@ func (b *BpfdClient) GetBPFProgs() (*bpfdiov1alpha1.BpfProgramList, error) {
return bpfProgramList, nil
}

func (b *BpfdClient) SubmitXdpProg(iface, node, pm, image, sec string) (error, string) {
func (b *BpfdClient) SubmitXdpProg(iface, node, pm, image, sec string) (string, error) {
var (
name = node + "-" + pm + "-" + iface
interfaces []string
)
interfaces = append(interfaces, iface)

if len(image) == 0 || len(sec) == 0 {
return errors.New("BPF image or function is empty"), ""
return "", errors.New("BPF image or function is empty")
}

logging.Infof("IMAGE %s FUNCTION %s", image, sec)

// Create an XdpProgram resource
xdpProgram := &bpfdiov1alpha1.XdpProgram{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -133,35 +131,34 @@ func (b *BpfdClient) SubmitXdpProg(iface, node, pm, image, sec string) (error, s
},
}

logging.Infof("Submitting this xdp program %v \n", xdpProgram)

// Submit the XdpProgram resource to the API
_, err := b.xdpProgramsClient.Create(context.TODO(), xdpProgram, metav1.CreateOptions{})
if err != nil {
return errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err), ""
return "", errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err)
}

time.Sleep(time.Second)
err = b.checkProgStatus(name)
if err != nil {
return errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err), ""
return "", errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err)
}

bpfProgramList, err := b.GetBPFProgs()
if err != nil {
return errors.Wrapf(err, "Failed to get bpf prog resources: %v", err), ""
return "", errors.Wrapf(err, "Failed to get bpf prog resources: %v", err)
}

var xskmap string

// Try to get the xspmap path from the bpf program resource
if bpfProgramList != nil {
bpfProgName := node + "-" + pm + "-" + iface + "-" + node
bpfProgName := node + "-" + pm + "-" + iface + "-" + node + "-" + iface
for _, bpfProgram := range bpfProgramList.Items {
if bpfProgram.ObjectMeta.Name == bpfProgName {
logging.Infof("FOUND bpfProgram %v", bpfProgram)
if len(bpfProgram.Spec.Maps) == 0 {
logging.Errorf("NO MAPS FOUND for %s", bpfProgName)
return errors.New("Failed to find a map for the loaded bpf program"), ""
return "", errors.New("Failed to find a map for the loaded bpf program")
}
for m, path := range bpfProgram.Spec.Maps {
logging.Infof("map: %v", m)
Expand All @@ -172,7 +169,7 @@ func (b *BpfdClient) SubmitXdpProg(iface, node, pm, image, sec string) (error, s
}
}

return nil, xskmap
return xskmap, nil
}

// Delete XdpProgram
Expand Down Expand Up @@ -233,8 +230,6 @@ func (b *BpfdClient) checkProgStatus(name string) error {

// Try to check status for 10 seconds
for i := 0; i < 10; i++ {
logging.Info("CHECKING STATUS OF XDP PROG")

event, ok := <-xdpWatcher.ResultChan()
if !ok {
// channel closed
Expand All @@ -248,8 +243,6 @@ func (b *BpfdClient) checkProgStatus(name string) error {
return errors.New("Failed to get xdp prog object")
}

logging.Infof("\n%v", prog.Status)

// Get most recent condition
recentIdx := len(prog.Status.Conditions) - 1
condition := prog.Status.Conditions[recentIdx]
Expand Down
2 changes: 1 addition & 1 deletion internal/deviceplugin/poolManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (pm *PoolManager) Allocate(ctx context.Context,
}

if pm.BpfdClientEnable {
err, xskmap := pm.BpfdClient.SubmitXdpProg(device.Name(), pm.Node, pm.DevicePrefix, pm.BpfProg, pm.BpfSec)
xskmap, err := pm.BpfdClient.SubmitXdpProg(device.Name(), pm.Node, pm.DevicePrefix, pm.BpfProg, pm.BpfSec)
if err != nil {
logging.Errorf("Error SubmitXdpProg to bpfd %v", err)
return &response, err
Expand Down

0 comments on commit 6e43684

Please sign in to comment.