Skip to content

Commit 546f545

Browse files
committed
vpp: cnat performance
Signed-off-by: Nathan Skrzypczak <[email protected]>
1 parent fa5cbd2 commit 546f545

File tree

6 files changed

+68
-55
lines changed

6 files changed

+68
-55
lines changed

calico-vpp-agent/cmd/calico_vpp_dataplane.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ var (
5555
log *logrus.Logger
5656
)
5757

58-
func Go(f func(t *tomb.Tomb) error) {
58+
func Go(f func(t *tomb.Tomb) error, name string) {
5959
if t.Alive() {
60+
log.Infof("STARTING %s", name)
6061
t.Go(func() error {
6162
err := f(&t)
6263
if err != nil {
6364
log.Warnf("Tomb function errored with %s", err)
6465
}
66+
log.Infof("STOPPED %s", name)
6567
return err
6668
})
6769
}
@@ -160,7 +162,7 @@ func main() {
160162
serviceServer.SetBGPConf(bgpConf)
161163

162164
watchDog := watchdog.NewWatchDog(log.WithFields(logrus.Fields{"component": "watchDog"}), &t)
163-
Go(policyServer.ServePolicy)
165+
Go(policyServer.ServePolicy, "policyServer.ServePolicy")
164166
felixConfig := watchDog.Wait(policyServer.FelixConfigChan, "Waiting for FelixConfig to be provided by the calico pod")
165167
ourBGPSpec := watchDog.Wait(policyServer.GotOurNodeBGPchan, "Waiting for bgp spec to be provided on node add")
166168
if ourBGPSpec != nil {
@@ -173,7 +175,7 @@ func main() {
173175
}
174176

175177
if *config.GetCalicoVppFeatureGates().MultinetEnabled {
176-
Go(netWatcher.WatchNetworks)
178+
Go(netWatcher.WatchNetworks, "netWatcher.WatchNetworks")
177179
watchDog.Wait(netWatcher.InSync, "Waiting for networks to be listed and synced")
178180
}
179181

@@ -182,20 +184,20 @@ func main() {
182184
connectivityServer.SetFelixConfig(felixConfig.(*felixconfig.Config))
183185
}
184186

185-
Go(routeWatcher.WatchRoutes)
186-
Go(linkWatcher.WatchLinks)
187-
Go(bgpConfigurationWatcher.WatchBGPConfiguration)
188-
Go(prefixWatcher.WatchPrefix)
189-
Go(peerWatcher.WatchBGPPeers)
190-
Go(connectivityServer.ServeConnectivity)
191-
Go(routingServer.ServeRouting)
192-
Go(serviceServer.ServeService)
193-
Go(cniServer.ServeCNI)
194-
Go(prometheusServer.ServePrometheus)
187+
Go(routeWatcher.WatchRoutes, "routeWatcher.WatchRoutes")
188+
Go(linkWatcher.WatchLinks, "linkWatcher.WatchLinks")
189+
Go(bgpConfigurationWatcher.WatchBGPConfiguration, "bgpConfigurationWatcher.WatchBGPConfiguration")
190+
Go(prefixWatcher.WatchPrefix, "prefixWatcher.WatchPrefix")
191+
Go(peerWatcher.WatchBGPPeers, "peerWatcher.WatchBGPPeers")
192+
Go(connectivityServer.ServeConnectivity, "connectivityServer.ServeConnectivity")
193+
Go(routingServer.ServeRouting, "routingServer.ServeRouting")
194+
Go(serviceServer.ServeService, "serviceServer.ServeService")
195+
Go(cniServer.ServeCNI, "cniServer.ServeCNI")
196+
Go(prometheusServer.ServePrometheus, "prometheusServer.ServePrometheus")
195197

196198
// watch LocalSID if SRv6 is enabled
197199
if *config.GetCalicoVppFeatureGates().SRv6Enabled {
198-
Go(localSIDWatcher.WatchLocalSID)
200+
Go(localSIDWatcher.WatchLocalSID, "localSIDWatcher.WatchLocalSID")
199201
}
200202

201203
log.Infof("Agent started")

calico-vpp-agent/cni/cni_server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ func (s *Server) cniServerEventLoop(t *tomb.Tomb) error {
373373
for {
374374
select {
375375
case <-t.Dying():
376-
break
376+
s.log.Warnf("CNI server asked to stop")
377+
return nil
377378
case evt := <-s.cniEventChan:
378379
switch evt.Type {
379380
case common.FelixConfChanged:
@@ -482,12 +483,14 @@ func (s *Server) ServeCNI(t *tomb.Tomb) error {
482483
}
483484

484485
s.log.Infof("CNI Server returned")
486+
s.grpcServer.Stop()
487+
s.log.Infof("GRPC stopped")
485488

486-
s.grpcServer.GracefulStop()
487489
err = syscall.Unlink(config.CNIServerSocket)
488490
if err != nil {
489491
return err
490492
}
493+
s.log.Infof("Socket CNI unlink")
491494

492495
return nil
493496
}

vpplink/cnat.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ package vpplink
1818
import (
1919
"fmt"
2020
"net"
21+
"github.com/pkg/errors"
2122

2223
"github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/cnat"
2324
"github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/interface_types"
2425
"github.com/projectcalico/vpp-dataplane/v3/vpplink/types"
2526
)
2627

2728
const (
28-
FeatureArcCnatInput = "ip?-unicast cnat-input-ip?"
29-
FeatureArcCnatOutput = "ip?-output cnat-output-ip?"
30-
FeatureArcSnat = "ip?-unicast cnat-snat-ip?"
29+
FeatureArcCnatLookup = "ip?-unicast cnat-lookup-ip?"
30+
FeatureArcCnatInput = "ip?-unicast cnat-input-ip?"
31+
FeatureArcCnatOutput = "ip?-output cnat-output-ip?"
32+
FeatureArcCnatWriteBack = "ip?-output cnat-writeback-ip?"
33+
FeatureArcSnat = "ip?-unicast cnat-snat-ip?"
3134
)
3235

3336
const InvalidID = ^uint32(0)
@@ -124,6 +127,14 @@ func (v *VppLink) CnatDelSnatPrefix(prefix *net.IPNet) error {
124127
}
125128

126129
func (v *VppLink) CnatEnableFeatures(swIfIndex uint32) (err error) {
130+
err = v.EnableFeatureArc46(swIfIndex, FeatureArcCnatLookup)
131+
if err != nil {
132+
return errors.Wrap(err, "Error enabling arc dnat in")
133+
}
134+
err = v.EnableFeatureArc46(swIfIndex, FeatureArcCnatWriteBack)
135+
if err != nil {
136+
return errors.Wrap(err, "Error enabling arc dnat out")
137+
}
127138
err = v.EnableFeatureArc46(swIfIndex, FeatureArcCnatInput)
128139
if err != nil {
129140
return fmt.Errorf("enabling arc dnat input failed: %w", err)

vpplink/generated/generate.log

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
VPP Version : 23.06-rc0~206-gbc006bb5a
1+
VPP Version : 23.06-rc0~211-gf559a7816
22
Binapi-generator version : govpp v0.8.0-dev
3-
VPP Base commit : 28d74a396 gerrit:34726/3 interface: add buffer stats api
3+
VPP Base commit : 004ebac6a gerrit:34726/3 interface: add buffer stats api
44
------------------ Cherry picked commits --------------------
55
capo: Calico Policies plugin
66
acl: acl-plugin custom policies
77
cnat: [WIP] no k8s maglev from pods
88
pbl: Port based balancer
9+
gerrit:34552/8 cnat: add single lookup
10+
gerrit:29748/5 cnat: remove rwlock on ts
11+
gerrit:32821/6 cnat: add ip/client bihash
12+
gerrit:34108/5 cnat: flag to disable rsession
13+
gerrit:31449/10 cnat: dont compute offloaded cksums
914
gerrit:34726/3 interface: add buffer stats api
1015
-------------------------------------------------------------
Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,30 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Nathan Skrzypczak <[email protected]>
3-
Date: Mon, 8 Mar 2021 19:00:04 +0100
3+
Date: Fri, 7 Apr 2023 16:57:30 +0200
44
Subject: [PATCH 2/4] cnat: [WIP] no k8s maglev from pods
55

6-
Type: improvement
7-
8-
Change-Id: If0702dbc51c308f0bb0ed16149c293d7adf9a984
6+
Change-Id: Id262a97986b6de01a42019287377486787f2e606
97
Signed-off-by: Nathan Skrzypczak <[email protected]>
108
---
11-
src/plugins/cnat/cnat_node_feature.c | 8 +++++++-
12-
1 file changed, 7 insertions(+), 1 deletion(-)
9+
src/plugins/cnat/cnat_node_feature.c | 5 ++++-
10+
1 file changed, 4 insertions(+), 1 deletion(-)
1311

1412
diff --git a/src/plugins/cnat/cnat_node_feature.c b/src/plugins/cnat/cnat_node_feature.c
15-
index 76aa89398..fd3b90a1a 100644
13+
index f6d4850f8..f2b65b2ff 100644
1614
--- a/src/plugins/cnat/cnat_node_feature.c
1715
+++ b/src/plugins/cnat/cnat_node_feature.c
18-
@@ -43,6 +43,7 @@ cnat_input_feature_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
19-
int session_not_found, cnat_session_t *session)
20-
{
21-
vlib_combined_counter_main_t *cntm = &cnat_translation_counters;
22-
+ cnat_snat_policy_main_t *cpm = &cnat_snat_policy_main;
23-
const cnat_translation_t *ct = NULL;
24-
ip4_header_t *ip4 = NULL;
25-
ip_protocol_t iproto;
26-
@@ -53,6 +54,9 @@ cnat_input_feature_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
27-
index_t cti;
28-
u8 trace_flags = 0;
16+
@@ -112,7 +112,10 @@ cnat_input_feature_new_flow_inline (vlib_main_t *vm, vlib_buffer_t *b,
17+
clib_host_to_net_u16 (trk0->ct_ep[VLIB_TX].ce_port) :
18+
rw->tuple.port[VLIB_TX];
2919

20+
- if (trk0->ct_flags & CNAT_TRK_FLAG_NO_NAT)
3021
+ u32 in_if = vnet_buffer (b)->sw_if_index[VLIB_RX];
31-
+ int ispod;
32-
+
33-
/* By default follow arc default next */
34-
vnet_feature_next (&next0, b);
35-
36-
@@ -127,7 +131,9 @@ cnat_input_feature_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
37-
session->value.cs_port[VLIB_RX] = udp0->src_port;
38-
session->value.flags = 0;
39-
40-
- if (trk0->ct_flags & CNAT_TRK_FLAG_NO_NAT)
41-
+ ispod = clib_bitmap_get (
42-
+ cpm->interface_maps[CNAT_SNAT_IF_MAP_INCLUDE_POD], in_if);
43-
+ if (trk0->ct_flags & CNAT_TRK_FLAG_NO_NAT && !ispod)
44-
{
45-
const dpo_id_t *dpo0;
46-
const load_balance_t *lb1;
22+
+ int ispod = clib_bitmap_get (
23+
+ cnat_snat_policy_main.interface_maps[CNAT_SNAT_IF_MAP_INCLUDE_POD], in_if);
24+
+ if (trk0->ct_flags & CNAT_TRK_FLAG_NO_NAT && !ispod)
25+
{
26+
const dpo_id_t *dpo0;
27+
const load_balance_t *lb1;
4728
--
4829
2.39.2
4930

vpplink/generated/vpp_clone_current.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,20 @@ git_clone_cd_and_reset "$1" 156d452750ab37a51984938bf4a8ab0e16650d82
9696

9797
git_cherry_pick refs/changes/26/34726/3 # 34726: interface: add buffer stats api | https://gerrit.fd.io/r/c/vpp/+/34726
9898

99+
git_cherry_pick refs/changes/49/31449/10 # 31449: cnat: dont compute offloaded cksums | https://gerrit.fd.io/r/c/vpp/+/31449
100+
git_cherry_pick refs/changes/08/34108/5 # 34108: cnat: flag to disable rsession | https://gerrit.fd.io/r/c/vpp/+/34108
101+
git_cherry_pick refs/changes/21/32821/6 # 32821: cnat: add ip/client bihash | https://gerrit.fd.io/r/c/vpp/+/32821
102+
git_cherry_pick refs/changes/48/29748/5 # 29748: cnat: remove rwlock on ts | https://gerrit.fd.io/r/c/vpp/+/29748
103+
git_cherry_pick refs/changes/52/34552/8 # 34552: cnat: add single lookup | https://gerrit.fd.io/r/c/vpp/+/34552
104+
99105
# --------------- private plugins ---------------
100106
# Generated with 'git format-patch --zero-commit -o ./patches/ HEAD^^^'
101107
git_apply_private 0001-pbl-Port-based-balancer.patch
102108
git_apply_private 0002-cnat-WIP-no-k8s-maglev-from-pods.patch
103109
git_apply_private 0003-acl-acl-plugin-custom-policies.patch
104110
git_apply_private 0004-capo-Calico-Policies-plugin.patch
111+
112+
113+
# git cp 236423e261385e58556b75c9f9eb56006a2b9d67 # perf WIP
114+
# git cp 7603fd367739e74c47349a1dd9662c78dcf9377d # capo+cnat
115+

0 commit comments

Comments
 (0)