From e3aee78c38a340f87013fc101d35cccb36219f5f Mon Sep 17 00:00:00 2001 From: hedi bouattour Date: Wed, 4 Oct 2023 12:13:12 +0000 Subject: [PATCH] vpp: pass hashconfig to vpp for service annotations --- calico-vpp-agent/services/service.go | 18 ++++------ calico-vpp-agent/services/service_handler.go | 8 ++--- calico-vpp-agent/services/service_server.go | 14 ++++---- vpplink/cnat.go | 14 ++++---- vpplink/generated/bindings/cnat/cnat.ba.go | 36 +++++++++++++------- vpplink/generated/generate.log | 5 +-- vpplink/generated/vpp_clone_current.sh | 1 + vpplink/types/cnat.go | 14 ++++---- 8 files changed, 60 insertions(+), 50 deletions(-) diff --git a/calico-vpp-agent/services/service.go b/calico-vpp-agent/services/service.go index 17096815..79b48fbd 100644 --- a/calico-vpp-agent/services/service.go +++ b/calico-vpp-agent/services/service.go @@ -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 } diff --git a/calico-vpp-agent/services/service_handler.go b/calico-vpp-agent/services/service_handler.go index 97da5955..11f11b4c 100644 --- a/calico-vpp-agent/services/service_handler.go +++ b/calico-vpp-agent/services/service_handler.go @@ -68,7 +68,6 @@ func getCnatLBType(lbType lbType) types.CnatLbType { return types.MaglevLB } return types.DefaultLB - } func getCnatVipDstPort(servicePort *v1.ServicePort, isNodePort bool) uint16 { @@ -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, } } diff --git a/calico-vpp-agent/services/service_server.go b/calico-vpp-agent/services/service_server.go index 95346028..aa20a690 100644 --- a/calico-vpp-agent/services/service_server.go +++ b/calico-vpp-agent/services/service_server.go @@ -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)) } diff --git a/vpplink/cnat.go b/vpplink/cnat.go index ef77de69..60684c3a 100644 --- a/vpplink/cnat.go +++ b/vpplink/cnat.go @@ -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" ) @@ -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 { diff --git a/vpplink/generated/bindings/cnat/cnat.ba.go b/vpplink/generated/bindings/cnat/cnat.ba.go index eae47fd2..c0f99de9 100644 --- a/vpplink/generated/bindings/cnat/cnat.ba.go +++ b/vpplink/generated/bindings/cnat/cnat.ba.go @@ -11,9 +11,12 @@ package cnat import ( "strconv" + _ "github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/ethernet_types" _ "github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/fib_types" interface_types "github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/interface_types" + ip "github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/ip" ip_types "github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/ip_types" + _ "github.com/projectcalico/vpp-dataplane/v3/vpplink/generated/bindings/mfib_types" api "go.fd.io/govpp/api" codec "go.fd.io/govpp/codec" ) @@ -27,7 +30,7 @@ const _ = api.GoVppAPIPackageIsVersion2 const ( APIFile = "cnat" APIVersion = "0.2.0" - VersionCrc = 0x8e6b2e7b + VersionCrc = 0xece555ea ) // CnatEndpointTupleFlags defines enum 'cnat_endpoint_tuple_flags'. @@ -233,14 +236,15 @@ type CnatSession struct { // CnatTranslation defines type 'cnat_translation'. type CnatTranslation struct { - Vip CnatEndpoint `binapi:"cnat_endpoint,name=vip" json:"vip,omitempty"` - ID uint32 `binapi:"u32,name=id" json:"id,omitempty"` - IPProto ip_types.IPProto `binapi:"ip_proto,name=ip_proto" json:"ip_proto,omitempty"` - IsRealIP uint8 `binapi:"u8,name=is_real_ip" json:"is_real_ip,omitempty"` - Flags uint8 `binapi:"u8,name=flags" json:"flags,omitempty"` - LbType CnatLbType `binapi:"cnat_lb_type,name=lb_type" json:"lb_type,omitempty"` - NPaths uint32 `binapi:"u32,name=n_paths" json:"-"` - Paths []CnatEndpointTuple `binapi:"cnat_endpoint_tuple[n_paths],name=paths" json:"paths,omitempty"` + Vip CnatEndpoint `binapi:"cnat_endpoint,name=vip" json:"vip,omitempty"` + ID uint32 `binapi:"u32,name=id" json:"id,omitempty"` + IPProto ip_types.IPProto `binapi:"ip_proto,name=ip_proto" json:"ip_proto,omitempty"` + IsRealIP uint8 `binapi:"u8,name=is_real_ip" json:"is_real_ip,omitempty"` + Flags uint8 `binapi:"u8,name=flags" json:"flags,omitempty"` + LbType CnatLbType `binapi:"cnat_lb_type,name=lb_type" json:"lb_type,omitempty"` + NPaths uint32 `binapi:"u32,name=n_paths" json:"-"` + FlowHashConfig ip.IPFlowHashConfigV2 `binapi:"ip_flow_hash_config_v2,name=flow_hash_config" json:"flow_hash_config,omitempty"` + Paths []CnatEndpointTuple `binapi:"cnat_endpoint_tuple[n_paths],name=paths" json:"paths,omitempty"` } // CnatGetSnatAddresses defines message 'cnat_get_snat_addresses'. @@ -860,7 +864,7 @@ type CnatTranslationDetails struct { func (m *CnatTranslationDetails) Reset() { *m = CnatTranslationDetails{} } func (*CnatTranslationDetails) GetMessageName() string { return "cnat_translation_details" } -func (*CnatTranslationDetails) GetCrcString() string { return "347e1f16" } +func (*CnatTranslationDetails) GetCrcString() string { return "1a5140b7" } func (*CnatTranslationDetails) GetMessageType() api.MessageType { return api.ReplyMessage } @@ -880,6 +884,7 @@ func (m *CnatTranslationDetails) Size() (size int) { size += 1 // m.Translation.Flags size += 1 // m.Translation.LbType size += 4 // m.Translation.NPaths + size += 4 // m.Translation.FlowHashConfig for j2 := 0; j2 < len(m.Translation.Paths); j2++ { var s2 CnatEndpointTuple _ = s2 @@ -916,6 +921,7 @@ func (m *CnatTranslationDetails) Marshal(b []byte) ([]byte, error) { buf.EncodeUint8(m.Translation.Flags) buf.EncodeUint8(uint8(m.Translation.LbType)) buf.EncodeUint32(uint32(len(m.Translation.Paths))) + buf.EncodeUint32(uint32(m.Translation.FlowHashConfig)) for j1 := 0; j1 < len(m.Translation.Paths); j1++ { var v1 CnatEndpointTuple // Paths if j1 < len(m.Translation.Paths) { @@ -948,6 +954,7 @@ func (m *CnatTranslationDetails) Unmarshal(b []byte) error { m.Translation.Flags = buf.DecodeUint8() m.Translation.LbType = CnatLbType(buf.DecodeUint8()) m.Translation.NPaths = buf.DecodeUint32() + m.Translation.FlowHashConfig = ip.IPFlowHashConfigV2(buf.DecodeUint32()) m.Translation.Paths = make([]CnatEndpointTuple, m.Translation.NPaths) for j1 := 0; j1 < len(m.Translation.Paths); j1++ { m.Translation.Paths[j1].DstEp.Addr.Af = ip_types.AddressFamily(buf.DecodeUint8()) @@ -1003,7 +1010,7 @@ type CnatTranslationUpdate struct { func (m *CnatTranslationUpdate) Reset() { *m = CnatTranslationUpdate{} } func (*CnatTranslationUpdate) GetMessageName() string { return "cnat_translation_update" } -func (*CnatTranslationUpdate) GetCrcString() string { return "cd5aedf5" } +func (*CnatTranslationUpdate) GetCrcString() string { return "f8d40bc5" } func (*CnatTranslationUpdate) GetMessageType() api.MessageType { return api.RequestMessage } @@ -1023,6 +1030,7 @@ func (m *CnatTranslationUpdate) Size() (size int) { size += 1 // m.Translation.Flags size += 1 // m.Translation.LbType size += 4 // m.Translation.NPaths + size += 4 // m.Translation.FlowHashConfig for j2 := 0; j2 < len(m.Translation.Paths); j2++ { var s2 CnatEndpointTuple _ = s2 @@ -1059,6 +1067,7 @@ func (m *CnatTranslationUpdate) Marshal(b []byte) ([]byte, error) { buf.EncodeUint8(m.Translation.Flags) buf.EncodeUint8(uint8(m.Translation.LbType)) buf.EncodeUint32(uint32(len(m.Translation.Paths))) + buf.EncodeUint32(uint32(m.Translation.FlowHashConfig)) for j1 := 0; j1 < len(m.Translation.Paths); j1++ { var v1 CnatEndpointTuple // Paths if j1 < len(m.Translation.Paths) { @@ -1091,6 +1100,7 @@ func (m *CnatTranslationUpdate) Unmarshal(b []byte) error { m.Translation.Flags = buf.DecodeUint8() m.Translation.LbType = CnatLbType(buf.DecodeUint8()) m.Translation.NPaths = buf.DecodeUint32() + m.Translation.FlowHashConfig = ip.IPFlowHashConfigV2(buf.DecodeUint32()) m.Translation.Paths = make([]CnatEndpointTuple, m.Translation.NPaths) for j1 := 0; j1 < len(m.Translation.Paths); j1++ { m.Translation.Paths[j1].DstEp.Addr.Af = ip_types.AddressFamily(buf.DecodeUint8()) @@ -1163,9 +1173,9 @@ func file_cnat_binapi_init() { api.RegisterMessage((*CnatSnatPolicyAddDelIfReply)(nil), "cnat_snat_policy_add_del_if_reply_e8d4e804") api.RegisterMessage((*CnatTranslationDel)(nil), "cnat_translation_del_3a91bde5") api.RegisterMessage((*CnatTranslationDelReply)(nil), "cnat_translation_del_reply_e8d4e804") - api.RegisterMessage((*CnatTranslationDetails)(nil), "cnat_translation_details_347e1f16") + api.RegisterMessage((*CnatTranslationDetails)(nil), "cnat_translation_details_1a5140b7") api.RegisterMessage((*CnatTranslationDump)(nil), "cnat_translation_dump_51077d14") - api.RegisterMessage((*CnatTranslationUpdate)(nil), "cnat_translation_update_cd5aedf5") + api.RegisterMessage((*CnatTranslationUpdate)(nil), "cnat_translation_update_f8d40bc5") api.RegisterMessage((*CnatTranslationUpdateReply)(nil), "cnat_translation_update_reply_e2fc8294") } diff --git a/vpplink/generated/generate.log b/vpplink/generated/generate.log index 7cc8602b..4183fb9a 100755 --- a/vpplink/generated/generate.log +++ b/vpplink/generated/generate.log @@ -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 diff --git a/vpplink/generated/vpp_clone_current.sh b/vpplink/generated/vpp_clone_current.sh index 8dfbb434..d96946f1 100755 --- a/vpplink/generated/vpp_clone_current.sh +++ b/vpplink/generated/vpp_clone_current.sh @@ -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^^^' diff --git a/vpplink/types/cnat.go b/vpplink/types/cnat.go index 61cfec8c..48ad82a1 100644 --- a/vpplink/types/cnat.go +++ b/vpplink/types/cnat.go @@ -69,11 +69,12 @@ 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 { @@ -81,12 +82,13 @@ func (n *CnatTranslateEntry) String() string { 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, ) }