Skip to content

Commit

Permalink
vpp: pass hashconfig to vpp for service annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
hedibouattour committed Oct 4, 2023
1 parent ba374a0 commit e3aee78
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 50 deletions.
18 changes: 6 additions & 12 deletions calico-vpp-agent/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@

package services

import "github.com/projectcalico/vpp-dataplane/v3/vpplink/types"

type lbType string
type hashConfig string

const (
lbTypeECMP lbType = "ECMP"
lbTypeMaglev lbType = "Maglev"
lbTypeMaglevDSR lbType = "MaglevDSR"
hashConfigSrcport hashConfig = "srcport"
hashConfigDstport hashConfig = "dstport"
hashConfigSrcaddr hashConfig = "srcaddr"
hashConfigDstaddr hashConfig = "dstaddr"
hashConfigIproto hashConfig = "iproto"
hashConfigSymmetric hashConfig = "symmetric"
hashConfigReverse hashConfig = "reverse"
lbTypeECMP lbType = "ECMP"
lbTypeMaglev lbType = "Maglev"
lbTypeMaglevDSR lbType = "MaglevDSR"
)

type serviceInfo struct {
keepOriginalPacket bool
lbType lbType
hashConfig []hashConfig
hashConfig types.IPFlowHash
}
8 changes: 4 additions & 4 deletions calico-vpp-agent/services/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func getCnatLBType(lbType lbType) types.CnatLbType {
return types.MaglevLB
}
return types.DefaultLB

}

func getCnatVipDstPort(servicePort *v1.ServicePort, isNodePort bool) uint16 {
Expand Down Expand Up @@ -126,9 +125,10 @@ func buildCnatEntryForServicePort(servicePort *v1.ServicePort, service *v1.Servi
Port: getCnatVipDstPort(servicePort, isNodePort),
IP: serviceIP,
},
Backends: backends,
IsRealIP: isNodePort,
LbType: getCnatLBType(svcInfo.lbType),
Backends: backends,
IsRealIP: isNodePort,
LbType: getCnatLBType(svcInfo.lbType),
HashConfig: svcInfo.hashConfig,
}
}

Expand Down
14 changes: 7 additions & 7 deletions calico-vpp-agent/services/service_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ func (s *Server) ParseServiceAnnotations(annotations map[string]string, name str
for _, hc := range hashConfigList {
switch strings.TrimSpace(strings.ToLower(hc)) {
case "srcport":
svc.hashConfig = append(svc.hashConfig, hashConfigSrcport)
svc.hashConfig |= types.FlowHashSrcPort
case "dstport":
svc.hashConfig = append(svc.hashConfig, hashConfigDstport)
svc.hashConfig |= types.FlowHashDstPort
case "srcaddr":
svc.hashConfig = append(svc.hashConfig, hashConfigSrcaddr)
svc.hashConfig |= types.FlowHashSrcIP
case "dstaddr":
svc.hashConfig = append(svc.hashConfig, hashConfigDstaddr)
svc.hashConfig |= types.FlowHashDstIP
case "iproto":
svc.hashConfig = append(svc.hashConfig, hashConfigIproto)
svc.hashConfig |= types.FlowHashProto
case "reverse":
svc.hashConfig = append(svc.hashConfig, hashConfigReverse)
svc.hashConfig |= types.FlowHashReverse
case "symmetric":
svc.hashConfig = append(svc.hashConfig, hashConfigSymmetric)
svc.hashConfig |= types.FlowHashSymetric
default:
err = append(err, errors.Errorf("Unknown value %s for key %s", value, key))
}
Expand Down
14 changes: 8 additions & 6 deletions vpplink/cnat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/cnat"
"github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/interface_types"
"github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/ip"
"github.com/projectcalico/vpp-dataplane/v3/vpplink/types"
)

Expand Down Expand Up @@ -59,12 +60,13 @@ func (v *VppLink) CnatTranslateAdd(tr *types.CnatTranslateEntry) (uint32, error)

response, err := client.CnatTranslationUpdate(v.GetContext(), &cnat.CnatTranslationUpdate{
Translation: cnat.CnatTranslation{
Vip: types.ToCnatEndpoint(tr.Endpoint),
IPProto: types.ToVppIPProto(tr.Proto),
Paths: paths,
IsRealIP: BoolToU8(tr.IsRealIP),
Flags: uint8(cnat.CNAT_TRANSLATION_ALLOC_PORT),
LbType: cnat.CnatLbType(tr.LbType),
Vip: types.ToCnatEndpoint(tr.Endpoint),
IPProto: types.ToVppIPProto(tr.Proto),
Paths: paths,
IsRealIP: BoolToU8(tr.IsRealIP),
Flags: uint8(cnat.CNAT_TRANSLATION_ALLOC_PORT),
LbType: cnat.CnatLbType(tr.LbType),
FlowHashConfig: ip.IPFlowHashConfigV2(tr.HashConfig),
},
})
if err != nil {
Expand Down
36 changes: 23 additions & 13 deletions vpplink/generated/bindings/cnat/cnat.ba.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vpplink/generated/generate.log
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
VPP Version : 23.10-rc0~8-gb811f2187
VPP Version : 23.10-rc0~9-gfbdcaa4c1
Binapi-generator version : v0.8.0-dev
VPP Base commit : 32203ce45 gerrit:34726/3 interface: add buffer stats api
VPP Base commit : 4b39caada gerrit:34726/3 interface: add buffer stats api
------------------ Cherry picked commits --------------------
interface: Fix interface.api endianness
capo: Calico Policies plugin
acl: acl-plugin custom policies
cnat: [WIP] no k8s maglev from pods
pbl: Port based balancer
gerrit:39507/11 cnat: add flow hash config to cnat translation
gerrit:39387/5 cnat: add host tag to bitmap in cnat snat
gerrit:31449/13 cnat: Support offloaded check sums
gerrit:34726/3 interface: add buffer stats api
Expand Down
1 change: 1 addition & 0 deletions vpplink/generated/vpp_clone_current.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ git_clone_cd_and_reset "$1" a7dd04d73bf5abed944fb77a5e957bbad24e2750 # misc: Ini
git_cherry_pick refs/changes/26/34726/3 # 34726: interface: add buffer stats api | https://gerrit.fd.io/r/c/vpp/+/34726
git_cherry_pick refs/changes/49/31449/13 # 31449: cnat: Support offloaded check sums | https://gerrit.fd.io/r/c/vpp/+/31449/13
git_cherry_pick refs/changes/87/39387/5 # 39387: cnat: add host tag to bitmap in cnat snat | https://gerrit.fd.io/r/c/vpp/+/39387/2
git_cherry_pick refs/changes/07/39507/11 # 39507: cnat: add flow hash config to cnat translation | https://gerrit.fd.io/r/c/vpp/+/39507/11

# --------------- private plugins ---------------
# Generated with 'git format-patch --zero-commit -o ./patches/ HEAD^^^'
Expand Down
14 changes: 8 additions & 6 deletions vpplink/types/cnat.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,26 @@ func (e *CnatTranslateEntry) Key() string {
}

type CnatTranslateEntry struct {
Endpoint CnatEndpoint
Backends []CnatEndpointTuple
Proto IPProto
IsRealIP bool
LbType CnatLbType
Endpoint CnatEndpoint
Backends []CnatEndpointTuple
Proto IPProto
IsRealIP bool
LbType CnatLbType
HashConfig IPFlowHash
}

func (n *CnatTranslateEntry) String() string {
strLst := make([]string, 0, len(n.Backends))
for _, e := range n.Backends {
strLst = append(strLst, e.String())
}
return fmt.Sprintf("[%s real=%t lbtyp=%d vip=%s rw=%s]",
return fmt.Sprintf("[%s real=%t lbtyp=%d vip=%s rw=%s hashc=%+v]",
n.Proto.String(),
n.IsRealIP,
n.LbType,
n.Endpoint.String(),
strings.Join(strLst, ", "),
n.HashConfig,
)
}

Expand Down

0 comments on commit e3aee78

Please sign in to comment.