Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 0ccf674

Browse files
authored
Feat kind support map pinning v3 (#67)
* bpf: map pinning support * cleanup: comments in bpfWrapper.c * dpcnisyncer: basic signalling from CNI to DP * dpcnisyncer: delete BPFFS signalled from CNI * pool-manager: dp-cni-syncer cleanup * SyncServer: one server for all BPF map managers * pool-manager: remove map cleanup * dpcnisyncer: add clean up * Makefile: Add missing copyright tag * fixup: unit tests * fixup: static analysis * linter: add directive to ignore generated code * fixup: fuzzing test * Add missing protobuf dependency * syncer: explicit configuration * plugin: updates after rebase * bpfwrapper: use libxdp for redirect program * cleanup: dead/commented code * linter error: run clang format --------- Signed-off-by: Maryam Tahhan <[email protected]>
1 parent db2fd90 commit 0ccf674

File tree

29 files changed

+1212
-60
lines changed

29 files changed

+1212
-60
lines changed

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ clangformat:
2727
@echo
2828
-clang-format -i -style=file internal/bpf/*.c internal/bpf/*.h
2929
-clang-format -i -style=file internal/bpf/xdp-pass/*.c
30+
-clang-format -i -style=file internal/bpf/xdp-afxdp-redirect/*.c
3031
@echo
3132
@echo
3233

@@ -37,18 +38,22 @@ format: clangformat
3738
@echo
3839
@echo
3940

41+
buildxdp:
42+
@echo "****** Build xdp_pass ******"
43+
make -C ./internal/bpf/xdp-pass/
44+
@echo "****** Build xdp_afxdp_redirect ******"
45+
make -C ./internal/bpf/xdp-afxdp-redirect/
46+
@echo
47+
4048
buildc:
4149
@echo "****** Build BPF ******"
4250
@echo
4351
gcc ./internal/bpf/bpfWrapper.c -lxdp -c -o ./internal/bpf/bpfWrapper.o
4452
ar rs ./internal/bpf/libwrapper.a ./internal/bpf/bpfWrapper.o &> /dev/null
45-
@echo "****** Build xdp_pass ******"
46-
make -C ./internal/bpf/xdp-pass/
47-
@echo
4853
@echo
4954
@echo
5055

51-
builddp: buildc
56+
builddp: buildc buildxdp
5257
@echo "****** Build DP ******"
5358
@echo
5459
go build -o ./bin/afxdp-dp ./cmd/deviceplugin

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ Note: User 0 does not imply that the pod needs to be privileged.
407407

408408
UdsServerDisable is a Boolean configuration. If set to true, devices in this pool will not have the BPF app loaded onto the netdev. This means no UDS server is spun up when a device is allocated to a pod. By default, this is set to false.
409409

410+
#### BpfMapPinningEnable
411+
412+
BpfMapPinningEnable is a Boolean configuration. If set to true, will use BPF map pinning instead of a UDS to share an XSK map with a pod. By default, this is set to false. Should set UdsServerDisable to true when using this configuration.
413+
410414
#### UdsTimeout
411415

412416
UdsTimeout is an integer configuration. This value sets the amount of time, in seconds, that the UDS server will wait while there is no activity on the UDS. When this timeout limit is reached, the UDS server terminates and the UDS is deleted from the filesystem. This can be a useful setting, for example, in scenarios where large batches of pods are created together. Large batches of pods tend to take some time to spin up, so it might be beneficial to have the UDS server sit waiting a little longer for the pod to start. The maximum allowed value is 300 seconds (5 min). The minimum and default value is 30 seconds.

cmd/deviceplugin/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/intel/afxdp-plugins-for-kubernetes/constants"
2727
"github.com/intel/afxdp-plugins-for-kubernetes/internal/deviceplugin"
28+
"github.com/intel/afxdp-plugins-for-kubernetes/internal/dpcnisyncerserver"
2829
"github.com/intel/afxdp-plugins-for-kubernetes/internal/host"
2930
"github.com/intel/afxdp-plugins-for-kubernetes/internal/logformats"
3031
"github.com/intel/afxdp-plugins-for-kubernetes/internal/networking"
@@ -97,9 +98,16 @@ func main() {
9798
}
9899
logging.Infof("Host meets requirements")
99100

101+
//START THE SYNCER SERVER TODO CHECK BPF MAP
102+
dpCniSyncerServer, err := dpcnisyncerserver.NewSyncerServer()
103+
if err != nil {
104+
logging.Errorf("Error creating the DpCniSyncerServer")
105+
}
106+
logging.Debugf("DP<=>CNI grpc Syncer started")
107+
100108
// pool configs
101109
logging.Infof("Getting device pools")
102-
poolConfigs, err := deviceplugin.GetPoolConfigs(configFile, netHandler, hostHandler)
110+
poolConfigs, err := deviceplugin.GetPoolConfigs(configFile, netHandler, hostHandler, dpCniSyncerServer)
103111
if err != nil {
104112
logging.Warningf("Error getting device pools: %v", err)
105113
exit(constants.Plugins.DevicePlugin.ExitPoolError)

constants/constants.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ var (
8282
udsSockDir = "/tmp/afxdp_dp/" // host location where we place our uds sockets. If changing location remember to update daemonset mount point
8383
udsPodPath = "/tmp/afxdp.sock" // the uds filepath as it will appear in the end user application pod
8484

85+
/* BPF*/
86+
bpfMapPodPath = "/tmp/xsks_map"
87+
xsk_map = "/xsks_map"
88+
8589
udsDirFileMode = 0700 // permissions for the directory in which we create our uds sockets
8690

8791
/* Handshake*/
@@ -129,6 +133,8 @@ var (
129133
DeviceFile deviceFile
130134
/* DeviceFile contains constants related to the devicefile */
131135
EthtoolFilter ethtoolFilter
136+
/* Bpf contains constants related to the BPF Map pinning */
137+
Bpf bpf
132138
)
133139

134140
type cni struct {
@@ -213,6 +219,11 @@ type uds struct {
213219
Handshake handshake
214220
}
215221

222+
type bpf struct {
223+
BpfMapPodPath string
224+
Xsk_map string
225+
}
226+
216227
type handshake struct {
217228
Version string
218229
RequestVersion string
@@ -334,6 +345,11 @@ func init() {
334345
},
335346
}
336347

348+
Bpf = bpf{
349+
BpfMapPodPath: bpfMapPodPath,
350+
Xsk_map: xsk_map,
351+
}
352+
337353
EthtoolFilter = ethtoolFilter{
338354
EthtoolFilterRegex: ethtoolFilterRegex,
339355
}

deployments/daemonset-kind.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ data:
1313
{
1414
"name":"myPool",
1515
"mode":"primary",
16-
"UdsServerDisable": false,
16+
"UdsServerDisable": true,
17+
"BpfMapPinningEnable": true,
1718
"drivers":[
1819
{
1920
"name":"veth"
@@ -72,6 +73,8 @@ spec:
7273
volumeMounts:
7374
- name: unixsock
7475
mountPath: /tmp/afxdp_dp/
76+
- name: bpfmappinning
77+
mountPath: /var/run/afxdp_dp/
7578
mountPropagation: Bidirectional
7679
- name: devicesock
7780
mountPath: /var/lib/kubelet/device-plugins/
@@ -87,6 +90,9 @@ spec:
8790
- name: unixsock
8891
hostPath:
8992
path: /tmp/afxdp_dp/
93+
- name: bpfmappinning
94+
hostPath:
95+
path: /var/run/afxdp_dp/
9096
- name: devicesock
9197
hostPath:
9298
path: /var/lib/kubelet/device-plugins/

examples/cndp-0-0.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# A working example of BPF MAP PINNING
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: cndp-0-0
6+
annotations:
7+
k8s.v1.cni.cncf.io/networks: afxdp-network
8+
spec:
9+
containers:
10+
- name: cndp-0
11+
command: ["/bin/bash"]
12+
args: ["-c", "./jsonc_gen.sh -kp ; cndpfwd -c config.jsonc lb;"]
13+
image: quay.io/mtahhan/cndp-map-pinning:latest
14+
imagePullPolicy: IfNotPresent
15+
securityContext:
16+
privileged: true
17+
#capabilities:
18+
#add:
19+
# - NET_RAW
20+
# - IPC_LOCK
21+
# - BPF
22+
resources:
23+
requests:
24+
afxdp/myPool: '1'
25+
limits:
26+
afxdp/myPool: '1'

examples/nad_with_syncer.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# WARNING: This is an example definition only. Remove all comments before use.
2+
3+
apiVersion: "k8s.cni.cncf.io/v1"
4+
kind: NetworkAttachmentDefinition
5+
metadata:
6+
name: afxdp-network # Name of this network, pods will request this network by name
7+
annotations:
8+
k8s.v1.cni.cncf.io/resourceName: afxdp/myPool # Needs to match the device plugin pool name / resource type
9+
spec:
10+
config: '{
11+
"cniVersion": "0.3.0",
12+
"type": "afxdp", # CNI binary, leave as afxdp
13+
"mode": "primary", # CNI mode setting (required)
14+
"logFile": "afxdp-cni.log", # CNI log file location (optional)
15+
"logLevel": "debug", # CNI logging level (optional)
16+
"dpSyncer": true, # Sync with Device Plugin over gRPC MUST BE SET for bpf map pinning
17+
"ipam": { # CNI IPAM plugin and associated config (optional)
18+
"type": "host-local",
19+
"subnet": "192.168.1.0/24",
20+
"rangeStart": "192.168.1.200",
21+
"rangeEnd": "192.168.1.220",
22+
"routes": [
23+
{ "dst": "0.0.0.0/0" }
24+
],
25+
"gateway": "192.168.1.1"
26+
}
27+
}'

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ require (
66
github.com/containernetworking/cni v1.1.2
77
github.com/containernetworking/plugins v1.1.1
88
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
9+
github.com/golang/protobuf v1.5.3
910
github.com/google/gofuzz v1.1.0
1011
github.com/google/uuid v1.3.0
1112
github.com/intel/afxdp-plugins-for-kubernetes/pkg/goclient v0.0.0
1213
github.com/intel/afxdp-plugins-for-kubernetes/pkg/subfunctions v0.0.0
14+
github.com/moby/sys/mount v0.3.3
1315
github.com/pkg/errors v0.9.1
1416
github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1
1517
github.com/sirupsen/logrus v1.9.0
1618
github.com/stretchr/testify v1.8.1
1719
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
1820
golang.org/x/net v0.17.0
1921
google.golang.org/grpc v1.53.0
22+
google.golang.org/protobuf v1.30.0 // indirect
2023
gotest.tools v2.2.0+incompatible
2124
k8s.io/apimachinery v0.25.2
2225
k8s.io/kubelet v0.25.2

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,9 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
735735
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
736736
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
737737
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
738-
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
739738
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
739+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
740+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
740741
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
741742
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
742743
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -894,8 +895,12 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
894895
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
895896
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
896897
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
898+
github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs=
899+
github.com/moby/sys/mount v0.3.3/go.mod h1:PBaEorSNTLG5t/+4EgukEQVlAvVEc6ZjTySwKdqp5K0=
897900
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
898901
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
902+
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
903+
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
899904
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
900905
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
901906
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
@@ -1774,8 +1779,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
17741779
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
17751780
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
17761781
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
1777-
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
17781782
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
1783+
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
1784+
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
17791785
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
17801786
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
17811787
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

images/amd64.dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ COPY . /usr/src/afxdp_k8s_plugins
1717
WORKDIR /usr/src/afxdp_k8s_plugins
1818
RUN apt-get update \
1919
&& apt-get -y install --no-install-recommends libxdp-dev=1.3.1-1 \
20-
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends clang=1:14.0-55.6 \
21-
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends llvm=1:14.0-55.6 \
20+
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends clang=1:14.0-55.7~deb12u1 \
21+
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends llvm=1:14.0-55.7~deb12u1 \
2222
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends gcc-multilib=4:12.2.0-3 \
2323
&& make buildcni
2424

@@ -39,4 +39,5 @@ COPY --from=cnibuilder /usr/src/afxdp_k8s_plugins/bin/afxdp /afxdp/afxdp
3939
COPY --from=dpbuilder /usr/src/afxdp_k8s_plugins/bin/afxdp-dp /afxdp/afxdp-dp
4040
COPY --from=dpbuilder /usr/src/afxdp_k8s_plugins/images/entrypoint.sh /afxdp/entrypoint.sh
4141
COPY --from=dpbuilder /usr/src/afxdp_k8s_plugins/internal/bpf/xdp-pass/xdp_pass.o /afxdp/xdp_pass.o
42+
COPY --from=dpbuilder /usr/src/afxdp_k8s_plugins/internal/bpf/xdp-afxdp-redirect/xdp_afxdp_redirect.o /afxdp/xdp_afxdp_redirect.o
4243
ENTRYPOINT ["/afxdp/entrypoint.sh"]

0 commit comments

Comments
 (0)