From bb5b09eed855f5b015d5f5826f7111a541ade9f9 Mon Sep 17 00:00:00 2001 From: Marcin Zyla Date: Thu, 18 May 2023 17:45:27 +0200 Subject: [PATCH 1/4] initial --- test/e2e/binapi/upf/upf.ba.go | 202 +++++++++++++++++++++++++++++- test/e2e/binapi/upf/upf_rpc.ba.go | 20 +++ test/e2e/upg_e2e.go | 81 ++++++++++++ upf/upf.api | 30 +++++ upf/upf_api.c | 83 ++++++++++++ upf/upf_cli.c | 2 - 6 files changed, 413 insertions(+), 5 deletions(-) diff --git a/test/e2e/binapi/upf/upf.ba.go b/test/e2e/binapi/upf/upf.ba.go index 50634ac..23a81c8 100644 --- a/test/e2e/binapi/upf/upf.ba.go +++ b/test/e2e/binapi/upf/upf.ba.go @@ -3,9 +3,9 @@ // Package upf contains generated bindings for API file upf.api. // // Contents: -// 2 enums +// 3 enums // 1 struct -// 44 messages +// 48 messages // package upf @@ -28,7 +28,7 @@ const _ = api.GoVppAPIPackageIsVersion2 const ( APIFile = "upf" APIVersion = "2.0.0" - VersionCrc = 0xcdb93693 + VersionCrc = 0xaf9ddd8 ) // UpfIpfixRecordFlags defines enum 'upf_ipfix_record_flags'. @@ -123,6 +123,36 @@ func (x UpfIpfixWhichFlags) String() string { return s } +// UpfNodeIDType defines enum 'upf_node_id_type'. +type UpfNodeIDType uint8 + +const ( + UPF_NODE_TYPE_IPv4 UpfNodeIDType = 0 + UPF_NODE_TYPE_IPv6 UpfNodeIDType = 1 + UPF_NODE_TYPE_FQDN UpfNodeIDType = 2 +) + +var ( + UpfNodeIDType_name = map[uint8]string{ + 0: "UPF_NODE_TYPE_IPv4", + 1: "UPF_NODE_TYPE_IPv6", + 2: "UPF_NODE_TYPE_FQDN", + } + UpfNodeIDType_value = map[string]uint8{ + "UPF_NODE_TYPE_IPv4": 0, + "UPF_NODE_TYPE_IPv6": 1, + "UPF_NODE_TYPE_FQDN": 2, + } +) + +func (x UpfNodeIDType) String() string { + s, ok := UpfNodeIDType_name[uint8(x)] + if ok { + return s + } + return "UpfNodeIDType(" + strconv.Itoa(int(x)) + ")" +} + // UpfL7Rule defines type 'upf_l7_rule'. type UpfL7Rule struct { ID uint32 `binapi:"u32,name=id" json:"id,omitempty"` @@ -587,6 +617,82 @@ func (m *UpfApplicationsDump) Unmarshal(b []byte) error { return nil } +// UpfGetNodeID defines message 'upf_get_node_id'. +type UpfGetNodeID struct{} + +func (m *UpfGetNodeID) Reset() { *m = UpfGetNodeID{} } +func (*UpfGetNodeID) GetMessageName() string { return "upf_get_node_id" } +func (*UpfGetNodeID) GetCrcString() string { return "51077d14" } +func (*UpfGetNodeID) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *UpfGetNodeID) Size() (size int) { + if m == nil { + return 0 + } + return size +} +func (m *UpfGetNodeID) Marshal(b []byte) ([]byte, error) { + if b == nil { + b = make([]byte, m.Size()) + } + buf := codec.NewBuffer(b) + return buf.Bytes(), nil +} +func (m *UpfGetNodeID) Unmarshal(b []byte) error { + return nil +} + +// UpfGetNodeIDReply defines message 'upf_get_node_id_reply'. +type UpfGetNodeIDReply struct { + Type uint8 `binapi:"u8,name=type" json:"type,omitempty"` + IP ip_types.Address `binapi:"address,name=ip" json:"ip,omitempty"` + FqdnLen uint8 `binapi:"u8,name=fqdn_len" json:"-"` + Fqdn []byte `binapi:"u8[fqdn_len],name=fqdn" json:"fqdn,omitempty"` +} + +func (m *UpfGetNodeIDReply) Reset() { *m = UpfGetNodeIDReply{} } +func (*UpfGetNodeIDReply) GetMessageName() string { return "upf_get_node_id_reply" } +func (*UpfGetNodeIDReply) GetCrcString() string { return "d2f43a0a" } +func (*UpfGetNodeIDReply) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *UpfGetNodeIDReply) Size() (size int) { + if m == nil { + return 0 + } + size += 1 // m.Type + size += 1 // m.IP.Af + size += 1 * 16 // m.IP.Un + size += 1 // m.FqdnLen + size += 1 * len(m.Fqdn) // m.Fqdn + return size +} +func (m *UpfGetNodeIDReply) Marshal(b []byte) ([]byte, error) { + if b == nil { + b = make([]byte, m.Size()) + } + buf := codec.NewBuffer(b) + buf.EncodeUint8(m.Type) + buf.EncodeUint8(uint8(m.IP.Af)) + buf.EncodeBytes(m.IP.Un.XXX_UnionData[:], 16) + buf.EncodeUint8(uint8(len(m.Fqdn))) + buf.EncodeBytes(m.Fqdn, 0) + return buf.Bytes(), nil +} +func (m *UpfGetNodeIDReply) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.Type = buf.DecodeUint8() + m.IP.Af = ip_types.AddressFamily(buf.DecodeUint8()) + copy(m.IP.Un.XXX_UnionData[:], buf.DecodeBytes(16)) + m.FqdnLen = buf.DecodeUint8() + m.Fqdn = make([]byte, m.FqdnLen) + copy(m.Fqdn, buf.DecodeBytes(len(m.Fqdn))) + return nil +} + // UpfNatPoolDetails defines message 'upf_nat_pool_details'. type UpfNatPoolDetails struct { Name []byte `binapi:"u8[64],name=name" json:"name,omitempty"` @@ -1883,6 +1989,88 @@ func (m *UpfPolicyDump) Unmarshal(b []byte) error { return nil } +// UpfSetNodeID defines message 'upf_set_node_id'. +type UpfSetNodeID struct { + Type uint8 `binapi:"u8,name=type" json:"type,omitempty"` + IP ip_types.Address `binapi:"address,name=ip" json:"ip,omitempty"` + FqdnLen uint8 `binapi:"u8,name=fqdn_len" json:"-"` + Fqdn []byte `binapi:"u8[fqdn_len],name=fqdn" json:"fqdn,omitempty"` +} + +func (m *UpfSetNodeID) Reset() { *m = UpfSetNodeID{} } +func (*UpfSetNodeID) GetMessageName() string { return "upf_set_node_id" } +func (*UpfSetNodeID) GetCrcString() string { return "d2f43a0a" } +func (*UpfSetNodeID) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *UpfSetNodeID) Size() (size int) { + if m == nil { + return 0 + } + size += 1 // m.Type + size += 1 // m.IP.Af + size += 1 * 16 // m.IP.Un + size += 1 // m.FqdnLen + size += 1 * len(m.Fqdn) // m.Fqdn + return size +} +func (m *UpfSetNodeID) Marshal(b []byte) ([]byte, error) { + if b == nil { + b = make([]byte, m.Size()) + } + buf := codec.NewBuffer(b) + buf.EncodeUint8(m.Type) + buf.EncodeUint8(uint8(m.IP.Af)) + buf.EncodeBytes(m.IP.Un.XXX_UnionData[:], 16) + buf.EncodeUint8(uint8(len(m.Fqdn))) + buf.EncodeBytes(m.Fqdn, 0) + return buf.Bytes(), nil +} +func (m *UpfSetNodeID) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.Type = buf.DecodeUint8() + m.IP.Af = ip_types.AddressFamily(buf.DecodeUint8()) + copy(m.IP.Un.XXX_UnionData[:], buf.DecodeBytes(16)) + m.FqdnLen = buf.DecodeUint8() + m.Fqdn = make([]byte, m.FqdnLen) + copy(m.Fqdn, buf.DecodeBytes(len(m.Fqdn))) + return nil +} + +// UpfSetNodeIDReply defines message 'upf_set_node_id_reply'. +type UpfSetNodeIDReply struct { + Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"` +} + +func (m *UpfSetNodeIDReply) Reset() { *m = UpfSetNodeIDReply{} } +func (*UpfSetNodeIDReply) GetMessageName() string { return "upf_set_node_id_reply" } +func (*UpfSetNodeIDReply) GetCrcString() string { return "e8d4e804" } +func (*UpfSetNodeIDReply) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +func (m *UpfSetNodeIDReply) Size() (size int) { + if m == nil { + return 0 + } + size += 4 // m.Retval + return size +} +func (m *UpfSetNodeIDReply) Marshal(b []byte) ([]byte, error) { + if b == nil { + b = make([]byte, m.Size()) + } + buf := codec.NewBuffer(b) + buf.EncodeInt32(m.Retval) + return buf.Bytes(), nil +} +func (m *UpfSetNodeIDReply) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.Retval = buf.DecodeInt32() + return nil +} + // UpfUpdateApp defines message 'upf_update_app'. type UpfUpdateApp struct { App []byte `binapi:"u8[64],name=app" json:"app,omitempty"` @@ -1995,6 +2183,8 @@ func file_upf_binapi_init() { api.RegisterMessage((*UpfApplicationL7RuleDump)(nil), "upf_application_l7_rule_dump_0b99fe11") api.RegisterMessage((*UpfApplicationsDetails)(nil), "upf_applications_details_72cd4b5d") api.RegisterMessage((*UpfApplicationsDump)(nil), "upf_applications_dump_51077d14") + api.RegisterMessage((*UpfGetNodeID)(nil), "upf_get_node_id_51077d14") + api.RegisterMessage((*UpfGetNodeIDReply)(nil), "upf_get_node_id_reply_d2f43a0a") api.RegisterMessage((*UpfNatPoolDetails)(nil), "upf_nat_pool_details_536a8c46") api.RegisterMessage((*UpfNatPoolDump)(nil), "upf_nat_pool_dump_51077d14") api.RegisterMessage((*UpfNwiAddDel)(nil), "upf_nwi_add_del_07485c64") @@ -2025,6 +2215,8 @@ func file_upf_binapi_init() { api.RegisterMessage((*UpfPolicyAddDelReply)(nil), "upf_policy_add_del_reply_e8d4e804") api.RegisterMessage((*UpfPolicyDetails)(nil), "upf_policy_details_8b4efe84") api.RegisterMessage((*UpfPolicyDump)(nil), "upf_policy_dump_51077d14") + api.RegisterMessage((*UpfSetNodeID)(nil), "upf_set_node_id_d2f43a0a") + api.RegisterMessage((*UpfSetNodeIDReply)(nil), "upf_set_node_id_reply_e8d4e804") api.RegisterMessage((*UpfUpdateApp)(nil), "upf_update_app_50f53737") api.RegisterMessage((*UpfUpdateAppReply)(nil), "upf_update_app_reply_e8d4e804") } @@ -2044,6 +2236,8 @@ func AllMessages() []api.Message { (*UpfApplicationL7RuleDump)(nil), (*UpfApplicationsDetails)(nil), (*UpfApplicationsDump)(nil), + (*UpfGetNodeID)(nil), + (*UpfGetNodeIDReply)(nil), (*UpfNatPoolDetails)(nil), (*UpfNatPoolDump)(nil), (*UpfNwiAddDel)(nil), @@ -2074,6 +2268,8 @@ func AllMessages() []api.Message { (*UpfPolicyAddDelReply)(nil), (*UpfPolicyDetails)(nil), (*UpfPolicyDump)(nil), + (*UpfSetNodeID)(nil), + (*UpfSetNodeIDReply)(nil), (*UpfUpdateApp)(nil), (*UpfUpdateAppReply)(nil), } diff --git a/test/e2e/binapi/upf/upf_rpc.ba.go b/test/e2e/binapi/upf/upf_rpc.ba.go index fb195ab..bb37f9d 100644 --- a/test/e2e/binapi/upf/upf_rpc.ba.go +++ b/test/e2e/binapi/upf/upf_rpc.ba.go @@ -19,6 +19,7 @@ type RPCService interface { UpfAppL7RuleAddDel(ctx context.Context, in *UpfAppL7RuleAddDel) (*UpfAppL7RuleAddDelReply, error) UpfApplicationL7RuleDump(ctx context.Context, in *UpfApplicationL7RuleDump) (RPCService_UpfApplicationL7RuleDumpClient, error) UpfApplicationsDump(ctx context.Context, in *UpfApplicationsDump) (RPCService_UpfApplicationsDumpClient, error) + UpfGetNodeID(ctx context.Context, in *UpfGetNodeID) (*UpfGetNodeIDReply, error) UpfNatPoolDump(ctx context.Context, in *UpfNatPoolDump) (RPCService_UpfNatPoolDumpClient, error) UpfNwiAddDel(ctx context.Context, in *UpfNwiAddDel) (*UpfNwiAddDelReply, error) UpfNwiDump(ctx context.Context, in *UpfNwiDump) (RPCService_UpfNwiDumpClient, error) @@ -34,6 +35,7 @@ type RPCService interface { UpfPfcpServerShow(ctx context.Context, in *UpfPfcpServerShow) (*UpfPfcpServerShowReply, error) UpfPolicyAddDel(ctx context.Context, in *UpfPolicyAddDel) (*UpfPolicyAddDelReply, error) UpfPolicyDump(ctx context.Context, in *UpfPolicyDump) (RPCService_UpfPolicyDumpClient, error) + UpfSetNodeID(ctx context.Context, in *UpfSetNodeID) (*UpfSetNodeIDReply, error) UpfUpdateApp(ctx context.Context, in *UpfUpdateApp) (*UpfUpdateAppReply, error) } @@ -167,6 +169,15 @@ func (c *serviceClient_UpfApplicationsDumpClient) Recv() (*UpfApplicationsDetail } } +func (c *serviceClient) UpfGetNodeID(ctx context.Context, in *UpfGetNodeID) (*UpfGetNodeIDReply, error) { + out := new(UpfGetNodeIDReply) + err := c.conn.Invoke(ctx, in, out) + if err != nil { + return nil, err + } + return out, nil +} + func (c *serviceClient) UpfNatPoolDump(ctx context.Context, in *UpfNatPoolDump) (RPCService_UpfNatPoolDumpClient, error) { stream, err := c.conn.NewStream(ctx) if err != nil { @@ -438,6 +449,15 @@ func (c *serviceClient_UpfPolicyDumpClient) Recv() (*UpfPolicyDetails, error) { } } +func (c *serviceClient) UpfSetNodeID(ctx context.Context, in *UpfSetNodeID) (*UpfSetNodeIDReply, error) { + out := new(UpfSetNodeIDReply) + err := c.conn.Invoke(ctx, in, out) + if err != nil { + return nil, err + } + return out, api.RetvalToVPPApiError(out.Retval) +} + func (c *serviceClient) UpfUpdateApp(ctx context.Context, in *UpfUpdateApp) (*UpfUpdateAppReply, error) { out := new(UpfUpdateAppReply) err := c.conn.Invoke(ctx, in, out) diff --git a/test/e2e/upg_e2e.go b/test/e2e/upg_e2e.go index b4245da..519e9cc 100644 --- a/test/e2e/upg_e2e.go +++ b/test/e2e/upg_e2e.go @@ -604,6 +604,87 @@ var _ = ginkgo.Describe("CLI debug commands", func() { // TODO: validate both binapi and CLI against each other var _ = ginkgo.Describe("UPG Binary API", func() { + ginkgo.Context("for node-id", func() { + f := framework.NewDefaultFramework(framework.UPGModeTDF, framework.UPGIPModeV4) + + CallSetNodeId := func(set_req *upf.UpfSetNodeID) (*upf.UpfSetNodeIDReply, error) { + set_reply := &upf.UpfSetNodeIDReply{} + set_err := f.VPP.ApiChannel.SendRequest(set_req).ReceiveReply(set_reply) + return set_reply, set_err + } + + CallGetNodeId := func() (*upf.UpfGetNodeIDReply, error) { + get_req := &upf.UpfGetNodeID{} + get_reply := &upf.UpfGetNodeIDReply{} + get_err := f.VPP.ApiChannel.SendRequest(get_req).ReceiveReply(get_reply) + return get_reply, get_err + } + + ginkgo.It("sets and retrieves the node-id", func() { + ipv4, _ := ip_types.ParseAddress("192.168.42.1") + ipv6, _ := ip_types.ParseAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334") + + fqdn_str := "upg.example.com" + fqdn := util.EncodeFQDN(fqdn_str) + fqdn_len := uint8(len(fqdn)) + + { + set_req := &upf.UpfSetNodeID{ + Type: uint8(upf.UPF_NODE_TYPE_IPv4), + IP: ipv4, + } + _, set_err := CallSetNodeId(set_req) + gomega.Expect(set_err).To(gomega.BeNil(), "upf_set_node_id") + + get_reply, get_err := CallGetNodeId() + gomega.Expect(get_err).To(gomega.BeNil(), "upf_get_node_id") + gomega.Expect(get_reply).To(gomega.Equal( + &upf.UpfGetNodeIDReply{ + Type: uint8(upf.UPF_NODE_TYPE_IPv4), + IP: ipv4, + FqdnLen: 0, + Fqdn: []byte{}, + }), "upf_get_node_id") + } + { + set_req := &upf.UpfSetNodeID{ + Type: uint8(upf.UPF_NODE_TYPE_IPv6), + IP: ipv6, + } + _, set_err := CallSetNodeId(set_req) + gomega.Expect(set_err).To(gomega.BeNil(), "upf_set_node_id") + + get_reply, get_err := CallGetNodeId() + gomega.Expect(get_err).To(gomega.BeNil(), "upf_get_node_id") + gomega.Expect(get_reply).To(gomega.Equal( + &upf.UpfGetNodeIDReply{ + Type: uint8(upf.UPF_NODE_TYPE_IPv6), + IP: ipv6, + FqdnLen: 0, + Fqdn: []byte{}, + }), "upf_get_node_id") + } + { + set_req := &upf.UpfSetNodeID{ + Type: uint8(upf.UPF_NODE_TYPE_FQDN), + Fqdn: fqdn, + } + _, set_err := CallSetNodeId(set_req) + gomega.Expect(set_err).To(gomega.BeNil(), "upf_set_node_id") + + get_reply, get_err := CallGetNodeId() + gomega.Expect(get_err).To(gomega.BeNil(), "upf_get_node_id") + gomega.Expect(get_reply).To(gomega.Equal( + &upf.UpfGetNodeIDReply{ + Type: uint8(upf.UPF_NODE_TYPE_FQDN), + IP: ip_types.Address{}, + FqdnLen: fqdn_len, + Fqdn: fqdn, + }), "upf_get_node_id") + } + }) + }) + ginkgo.Context("for policy based routing", func() { f := framework.NewDefaultFramework(framework.UPGModeTDF, framework.UPGIPModeV4) ginkgo.It("adds, removes and lists the routing policies", func() { diff --git a/upf/upf.api b/upf/upf.api index 77f580c..2ef6b66 100644 --- a/upf/upf.api +++ b/upf/upf.api @@ -343,3 +343,33 @@ define upf_pfcp_heartbeats_get_reply { u32 timeout; u32 retries; }; + +enum upf_node_id_type : u8 +{ + UPF_NODE_TYPE_IPv4 = 0, + UPF_NODE_TYPE_IPv6 = 1, + UPF_NODE_TYPE_FQDN = 2, +}; + +autoreply define upf_set_node_id { + u32 client_index; + u32 context; + u8 type; + vl_api_address_t ip; + u8 fqdn_len; + u8 fqdn[fqdn_len]; +}; + +define upf_get_node_id { + u32 client_index; + u32 context; +}; + +define upf_get_node_id_reply { + u32 client_index; + u32 context; + u8 type; + vl_api_address_t ip; + u8 fqdn_len; + u8 fqdn[fqdn_len]; +}; \ No newline at end of file diff --git a/upf/upf_api.c b/upf/upf_api.c index 7c42eba..d690216 100644 --- a/upf/upf_api.c +++ b/upf/upf_api.c @@ -892,6 +892,89 @@ vl_api_upf_pfcp_heartbeats_get_t_handler (vl_api_upf_pfcp_heartbeats_get_t * vl_api_send_msg (reg, (u8 *) rmp); } +/* API message handler */ +static void +vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t * mp) +{ + upf_main_t *sm = &upf_main; + vl_api_upf_set_node_id_reply_t *rmp = NULL; + + // if old was fqdn then free it + + switch (mp->type) + { + case NID_IPv4: + case NID_IPv6: + sm->node_id.type = mp->type; + ip_address_decode (&mp->ip, &sm->node_id.ip); + break; + + case NID_FQDN: + sm->node_id.type = NID_FQDN; + sm->node_id.fqdn = NULL; + vec_validate (sm->node_id.fqdn, 20); + memcpy (sm->node_id.fqdn, mp->fqdn, mp->fqdn_len); + break; + + default: + //TODO: error + break; + } + + + int rv = 0; + REPLY_MACRO (VL_API_UPF_SET_NODE_ID_REPLY); +} + +/* API message handler */ +static void +vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t * mp) +{ + vl_api_registration_t *reg; + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + vl_api_upf_get_node_id_reply_t *rmp = NULL; + upf_main_t *sm = &upf_main; + pfcp_node_id_t *node = &sm->node_id; + + + + switch (node->type) + { + case NID_IPv4: + case NID_IPv6: + { + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + + ip_address_encode (&ip_addr_46 (node), IP46_TYPE_ANY, &rmp->ip); + break; + } + case NID_FQDN: + { + u8 len; + len = strlen (node->fqdn); + + rmp = vl_msg_api_alloc (sizeof (*rmp) + len * sizeof (u8)); + clib_memset (rmp, 0, sizeof (*rmp) + len * sizeof (u8)); + + rmp->fqdn_len = len; + memcpy (rmp->fqdn, node->fqdn, rmp->fqdn_len); + break; + } + default: + ASSERT (false); + // TODO: return error + } + + rmp->type = node->type; + rmp->_vl_msg_id = htons (VL_API_UPF_GET_NODE_ID_REPLY + sm->msg_id_base); + rmp->context = mp->context; + + vl_api_send_msg (reg, (u8 *) rmp); +} #include diff --git a/upf/upf_cli.c b/upf/upf_cli.c index 2e0f73e..1368754 100644 --- a/upf/upf_cli.c +++ b/upf/upf_cli.c @@ -898,8 +898,6 @@ upf_show_node_id_command_fn (vlib_main_t * vm, vlib_cli_command_t * cmd) { upf_main_t *gtm = &upf_main; - u8 *type = 0; - vec_reset_length (type); vlib_cli_output (vm, "Node ID: %U", format_node_id, >m->node_id); return NULL; } From c95ac7290a318d501584a5c83a5ef984c439d2d5 Mon Sep 17 00:00:00 2001 From: Marcin Zyla Date: Thu, 18 May 2023 17:51:22 +0200 Subject: [PATCH 2/4] whitespace fix --- upf/upf_api.c | 99 +++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/upf/upf_api.c b/upf/upf_api.c index d690216..e354a65 100644 --- a/upf/upf_api.c +++ b/upf/upf_api.c @@ -52,7 +52,7 @@ /* API message handler */ static void -vl_api_upf_app_add_del_t_handler (vl_api_upf_app_add_del_t * mp) +vl_api_upf_app_add_del_t_handler (vl_api_upf_app_add_del_t *mp) { vl_api_upf_app_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -115,8 +115,8 @@ static void vl_api_upf_app_flow_timeout_set_t_handler } static void -send_upf_applications_details (vl_api_registration_t * reg, - u8 * app_name, u32 flags, u32 context) +send_upf_applications_details (vl_api_registration_t *reg, + u8 *app_name, u32 flags, u32 context) { vl_api_upf_applications_details_t *mp; upf_main_t *sm = &upf_main; @@ -157,8 +157,8 @@ static void vl_api_upf_applications_dump_t_handler } static void -send_upf_application_l7_rule_details (vl_api_registration_t * reg, - u32 id, u8 * regex, u32 context) +send_upf_application_l7_rule_details (vl_api_registration_t *reg, + u32 id, u8 *regex, u32 context) { vl_api_upf_application_l7_rule_details_t *mp; upf_main_t *sm = &upf_main; @@ -213,7 +213,7 @@ static void vl_api_upf_application_l7_rule_dump_t_handler /* API message handler */ static void -vl_api_upf_update_app_t_handler (vl_api_upf_update_app_t * mp) +vl_api_upf_update_app_t_handler (vl_api_upf_update_app_t *mp) { vl_api_upf_update_app_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -246,7 +246,7 @@ vl_api_upf_update_app_t_handler (vl_api_upf_update_app_t * mp) } static void -vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t * mp) +vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t *mp) { upf_main_t *sm = &upf_main; vl_api_upf_pfcp_reencode_reply_t *rmp; @@ -286,7 +286,7 @@ vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t * mp) } static void -vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t * mp) +vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t *mp) { upf_main_t *sm = &upf_main; vl_api_upf_pfcp_format_reply_t *rmp; @@ -328,8 +328,8 @@ vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t * mp) } static void -send_upf_nat_pool_details (vl_api_registration_t * reg, - upf_nat_pool_t * np, u32 context) +send_upf_nat_pool_details (vl_api_registration_t *reg, + upf_nat_pool_t *np, u32 context) { vl_api_upf_nat_pool_details_t *mp; upf_main_t *sm = &upf_main; @@ -387,7 +387,7 @@ static void vl_api_upf_nat_pool_dump_t_handler /* API message handler */ static void -vl_api_upf_policy_add_del_t_handler (vl_api_upf_policy_add_del_t * mp) +vl_api_upf_policy_add_del_t_handler (vl_api_upf_policy_add_del_t *mp) { vl_api_upf_policy_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -428,8 +428,8 @@ vl_api_upf_policy_add_del_t_handler (vl_api_upf_policy_add_del_t * mp) } static void -send_upf_policy_details (vl_api_registration_t * reg, - upf_forwarding_policy_t * fp, u32 context) +send_upf_policy_details (vl_api_registration_t *reg, + upf_forwarding_policy_t *fp, u32 context) { vl_api_upf_policy_details_t *mp; upf_main_t *sm = &upf_main; @@ -463,7 +463,7 @@ send_upf_policy_details (vl_api_registration_t * reg, /* API message handler */ static void -vl_api_upf_policy_dump_t_handler (vl_api_upf_policy_dump_t * mp) +vl_api_upf_policy_dump_t_handler (vl_api_upf_policy_dump_t *mp) { upf_main_t *sm = &upf_main; vl_api_registration_t *reg; @@ -483,7 +483,7 @@ vl_api_upf_policy_dump_t_handler (vl_api_upf_policy_dump_t * mp) /* API message handler */ static void -vl_api_upf_nwi_add_del_t_handler (vl_api_upf_nwi_add_del_t * mp) +vl_api_upf_nwi_add_del_t_handler (vl_api_upf_nwi_add_del_t *mp) { vl_api_upf_nwi_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -568,8 +568,7 @@ vl_api_upf_nwi_add_del_t_handler (vl_api_upf_nwi_add_del_t * mp) } static void -send_upf_nwi_details (vl_api_registration_t * reg, - upf_nwi_t * nwi, u32 context) +send_upf_nwi_details (vl_api_registration_t *reg, upf_nwi_t *nwi, u32 context) { vl_api_upf_nwi_details_t *mp; upf_main_t *sm = &upf_main; @@ -618,7 +617,7 @@ send_upf_nwi_details (vl_api_registration_t * reg, /* API message handler */ static void -vl_api_upf_nwi_dump_t_handler (vl_api_upf_nwi_dump_t * mp) +vl_api_upf_nwi_dump_t_handler (vl_api_upf_nwi_dump_t *mp) { upf_main_t *sm = &upf_main; vl_api_registration_t *reg; @@ -639,7 +638,7 @@ vl_api_upf_nwi_dump_t_handler (vl_api_upf_nwi_dump_t * mp) /* API message handler */ static void vl_api_upf_pfcp_endpoint_add_del_t_handler (vl_api_upf_pfcp_endpoint_add_del_t - * mp) + *mp) { vl_api_upf_pfcp_endpoint_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -680,8 +679,8 @@ vl_api_upf_pfcp_endpoint_add_del_t_handler (vl_api_upf_pfcp_endpoint_add_del_t } static void -send_upf_pfcp_endpoint_details (vl_api_registration_t * reg, - ip46_address_fib_t * key, u32 context) +send_upf_pfcp_endpoint_details (vl_api_registration_t *reg, + ip46_address_fib_t *key, u32 context) { vl_api_upf_pfcp_endpoint_details_t *mp; upf_main_t *sm = &upf_main; @@ -705,7 +704,7 @@ send_upf_pfcp_endpoint_details (vl_api_registration_t * reg, /* API message handler */ static void -vl_api_upf_pfcp_endpoint_dump_t_handler (vl_api_upf_pfcp_endpoint_dump_t * mp) +vl_api_upf_pfcp_endpoint_dump_t_handler (vl_api_upf_pfcp_endpoint_dump_t *mp) { upf_main_t *sm = &upf_main; vl_api_registration_t *reg; @@ -727,7 +726,7 @@ vl_api_upf_pfcp_endpoint_dump_t_handler (vl_api_upf_pfcp_endpoint_dump_t * mp) /* API message handler */ static void -vl_api_upf_pfcp_server_set_t_handler (vl_api_upf_pfcp_server_set_t * mp) +vl_api_upf_pfcp_server_set_t_handler (vl_api_upf_pfcp_server_set_t *mp) { vl_api_upf_pfcp_server_set_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -768,7 +767,7 @@ vl_api_upf_pfcp_server_set_t_handler (vl_api_upf_pfcp_server_set_t * mp) /* API message handler */ static void -vl_api_upf_pfcp_server_show_t_handler (vl_api_upf_pfcp_server_show_t * mp) +vl_api_upf_pfcp_server_show_t_handler (vl_api_upf_pfcp_server_show_t *mp) { vl_api_upf_pfcp_server_show_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -803,7 +802,7 @@ vl_api_upf_pfcp_server_show_t_handler (vl_api_upf_pfcp_server_show_t * mp) /* API message handler */ static void -vl_api_upf_pfcp_policer_set_t_handler (vl_api_upf_pfcp_policer_set_t * mp) +vl_api_upf_pfcp_policer_set_t_handler (vl_api_upf_pfcp_policer_set_t *mp) { vl_api_upf_pfcp_policer_set_reply_t *rmp = NULL; qos_pol_cfg_params_st *cfg = &pfcp_rate_cfg_main; @@ -819,7 +818,7 @@ vl_api_upf_pfcp_policer_set_t_handler (vl_api_upf_pfcp_policer_set_t * mp) /* API message handler */ static void -vl_api_upf_pfcp_policer_show_t_handler (vl_api_upf_pfcp_policer_show_t * mp) +vl_api_upf_pfcp_policer_show_t_handler (vl_api_upf_pfcp_policer_show_t *mp) { vl_api_upf_pfcp_policer_show_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -847,8 +846,8 @@ vl_api_upf_pfcp_policer_show_t_handler (vl_api_upf_pfcp_policer_show_t * mp) /* API message handler */ static void -vl_api_upf_pfcp_heartbeats_set_t_handler (vl_api_upf_pfcp_heartbeats_set_t * - mp) +vl_api_upf_pfcp_heartbeats_set_t_handler (vl_api_upf_pfcp_heartbeats_set_t + *mp) { vl_api_upf_pfcp_heartbeats_set_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -865,8 +864,8 @@ vl_api_upf_pfcp_heartbeats_set_t_handler (vl_api_upf_pfcp_heartbeats_set_t * /* API message handler */ static void -vl_api_upf_pfcp_heartbeats_get_t_handler (vl_api_upf_pfcp_heartbeats_get_t * - mp) +vl_api_upf_pfcp_heartbeats_get_t_handler (vl_api_upf_pfcp_heartbeats_get_t + *mp) { vl_api_upf_pfcp_heartbeats_get_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -894,7 +893,7 @@ vl_api_upf_pfcp_heartbeats_get_t_handler (vl_api_upf_pfcp_heartbeats_get_t * /* API message handler */ static void -vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t * mp) +vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t *mp) { upf_main_t *sm = &upf_main; vl_api_upf_set_node_id_reply_t *rmp = NULL; @@ -902,7 +901,7 @@ vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t * mp) // if old was fqdn then free it switch (mp->type) - { + { case NID_IPv4: case NID_IPv6: sm->node_id.type = mp->type; @@ -917,9 +916,9 @@ vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t * mp) break; default: - //TODO: error - break; - } + //TODO: error + break; + } int rv = 0; @@ -928,7 +927,7 @@ vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t * mp) /* API message handler */ static void -vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t * mp) +vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t *mp) { vl_api_registration_t *reg; reg = vl_api_client_index_to_registration (mp->client_index); @@ -942,32 +941,32 @@ vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t * mp) switch (node->type) - { + { case NID_IPv4: case NID_IPv6: { - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); - ip_address_encode (&ip_addr_46 (node), IP46_TYPE_ANY, &rmp->ip); - break; + ip_address_encode (&ip_addr_46 (node), IP46_TYPE_ANY, &rmp->ip); + break; } case NID_FQDN: { - u8 len; - len = strlen (node->fqdn); + u8 len; + len = strlen (node->fqdn); - rmp = vl_msg_api_alloc (sizeof (*rmp) + len * sizeof (u8)); - clib_memset (rmp, 0, sizeof (*rmp) + len * sizeof (u8)); + rmp = vl_msg_api_alloc (sizeof (*rmp) + len * sizeof (u8)); + clib_memset (rmp, 0, sizeof (*rmp) + len * sizeof (u8)); - rmp->fqdn_len = len; - memcpy (rmp->fqdn, node->fqdn, rmp->fqdn_len); - break; + rmp->fqdn_len = len; + memcpy (rmp->fqdn, node->fqdn, rmp->fqdn_len); + break; } default: ASSERT (false); // TODO: return error - } + } rmp->type = node->type; rmp->_vl_msg_id = htons (VL_API_UPF_GET_NODE_ID_REPLY + sm->msg_id_base); @@ -979,7 +978,7 @@ vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t * mp) #include static clib_error_t * -upf_api_hookup (vlib_main_t * vm) +upf_api_hookup (vlib_main_t *vm) { upf_main_t *gtm = &upf_main; From 5402a60928544220157fbc414a45b4aa15e8e548 Mon Sep 17 00:00:00 2001 From: Marcin Zyla Date: Fri, 19 May 2023 14:56:34 +0200 Subject: [PATCH 3/4] fixes + vscode --- .vscode/c_cpp_properties.json | 18 ++++ .vscode/settings.json | 9 ++ test/e2e/binapi/upf/upf.ba.go | 10 ++- test/e2e/binapi/upf/upf_rpc.ba.go | 2 +- test/e2e/upg_e2e.go | 137 ++++++++++++++++-------------- upf/upf.api | 1 + upf/upf_api.c | 88 +++++++++---------- 7 files changed, 155 insertions(+), 110 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..37127a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/../fpp-vpp/vpp/**" + ], + "defines": [], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++14", + "intelliSenseMode": "linux-clang-x64", + "configurationProvider": "ms-vscode.makefile-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e7dc140 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "editor.formatOnSave": false, + + "editor.indentSize": 2, + "editor.insertSpaces": true, + "editor.tabSize": 8, + + "editor.detectIndentation": false, +} \ No newline at end of file diff --git a/test/e2e/binapi/upf/upf.ba.go b/test/e2e/binapi/upf/upf.ba.go index 23a81c8..80eabe2 100644 --- a/test/e2e/binapi/upf/upf.ba.go +++ b/test/e2e/binapi/upf/upf.ba.go @@ -28,7 +28,7 @@ const _ = api.GoVppAPIPackageIsVersion2 const ( APIFile = "upf" APIVersion = "2.0.0" - VersionCrc = 0xaf9ddd8 + VersionCrc = 0x878c4e6 ) // UpfIpfixRecordFlags defines enum 'upf_ipfix_record_flags'. @@ -646,6 +646,7 @@ func (m *UpfGetNodeID) Unmarshal(b []byte) error { // UpfGetNodeIDReply defines message 'upf_get_node_id_reply'. type UpfGetNodeIDReply struct { + Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"` Type uint8 `binapi:"u8,name=type" json:"type,omitempty"` IP ip_types.Address `binapi:"address,name=ip" json:"ip,omitempty"` FqdnLen uint8 `binapi:"u8,name=fqdn_len" json:"-"` @@ -654,7 +655,7 @@ type UpfGetNodeIDReply struct { func (m *UpfGetNodeIDReply) Reset() { *m = UpfGetNodeIDReply{} } func (*UpfGetNodeIDReply) GetMessageName() string { return "upf_get_node_id_reply" } -func (*UpfGetNodeIDReply) GetCrcString() string { return "d2f43a0a" } +func (*UpfGetNodeIDReply) GetCrcString() string { return "4f226741" } func (*UpfGetNodeIDReply) GetMessageType() api.MessageType { return api.RequestMessage } @@ -663,6 +664,7 @@ func (m *UpfGetNodeIDReply) Size() (size int) { if m == nil { return 0 } + size += 4 // m.Retval size += 1 // m.Type size += 1 // m.IP.Af size += 1 * 16 // m.IP.Un @@ -675,6 +677,7 @@ func (m *UpfGetNodeIDReply) Marshal(b []byte) ([]byte, error) { b = make([]byte, m.Size()) } buf := codec.NewBuffer(b) + buf.EncodeInt32(m.Retval) buf.EncodeUint8(m.Type) buf.EncodeUint8(uint8(m.IP.Af)) buf.EncodeBytes(m.IP.Un.XXX_UnionData[:], 16) @@ -684,6 +687,7 @@ func (m *UpfGetNodeIDReply) Marshal(b []byte) ([]byte, error) { } func (m *UpfGetNodeIDReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) + m.Retval = buf.DecodeInt32() m.Type = buf.DecodeUint8() m.IP.Af = ip_types.AddressFamily(buf.DecodeUint8()) copy(m.IP.Un.XXX_UnionData[:], buf.DecodeBytes(16)) @@ -2184,7 +2188,7 @@ func file_upf_binapi_init() { api.RegisterMessage((*UpfApplicationsDetails)(nil), "upf_applications_details_72cd4b5d") api.RegisterMessage((*UpfApplicationsDump)(nil), "upf_applications_dump_51077d14") api.RegisterMessage((*UpfGetNodeID)(nil), "upf_get_node_id_51077d14") - api.RegisterMessage((*UpfGetNodeIDReply)(nil), "upf_get_node_id_reply_d2f43a0a") + api.RegisterMessage((*UpfGetNodeIDReply)(nil), "upf_get_node_id_reply_4f226741") api.RegisterMessage((*UpfNatPoolDetails)(nil), "upf_nat_pool_details_536a8c46") api.RegisterMessage((*UpfNatPoolDump)(nil), "upf_nat_pool_dump_51077d14") api.RegisterMessage((*UpfNwiAddDel)(nil), "upf_nwi_add_del_07485c64") diff --git a/test/e2e/binapi/upf/upf_rpc.ba.go b/test/e2e/binapi/upf/upf_rpc.ba.go index bb37f9d..68417ba 100644 --- a/test/e2e/binapi/upf/upf_rpc.ba.go +++ b/test/e2e/binapi/upf/upf_rpc.ba.go @@ -175,7 +175,7 @@ func (c *serviceClient) UpfGetNodeID(ctx context.Context, in *UpfGetNodeID) (*Up if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) UpfNatPoolDump(ctx context.Context, in *UpfNatPoolDump) (RPCService_UpfNatPoolDumpClient, error) { diff --git a/test/e2e/upg_e2e.go b/test/e2e/upg_e2e.go index 519e9cc..49f6aae 100644 --- a/test/e2e/upg_e2e.go +++ b/test/e2e/upg_e2e.go @@ -607,81 +607,92 @@ var _ = ginkgo.Describe("UPG Binary API", func() { ginkgo.Context("for node-id", func() { f := framework.NewDefaultFramework(framework.UPGModeTDF, framework.UPGIPModeV4) - CallSetNodeId := func(set_req *upf.UpfSetNodeID) (*upf.UpfSetNodeIDReply, error) { - set_reply := &upf.UpfSetNodeIDReply{} - set_err := f.VPP.ApiChannel.SendRequest(set_req).ReceiveReply(set_reply) - return set_reply, set_err + callSetNodeID := func(req *upf.UpfSetNodeID) (*upf.UpfSetNodeIDReply, error) { + reply := &upf.UpfSetNodeIDReply{} + err := f.VPP.ApiChannel.SendRequest(req).ReceiveReply(reply) + return reply, err } - CallGetNodeId := func() (*upf.UpfGetNodeIDReply, error) { - get_req := &upf.UpfGetNodeID{} - get_reply := &upf.UpfGetNodeIDReply{} - get_err := f.VPP.ApiChannel.SendRequest(get_req).ReceiveReply(get_reply) - return get_reply, get_err + callGetNodeID := func() (*upf.UpfGetNodeIDReply, error) { + req := &upf.UpfGetNodeID{} + reply := &upf.UpfGetNodeIDReply{} + err := f.VPP.ApiChannel.SendRequest(req).ReceiveReply(reply) + return reply, err } ginkgo.It("sets and retrieves the node-id", func() { ipv4, _ := ip_types.ParseAddress("192.168.42.1") ipv6, _ := ip_types.ParseAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334") - fqdn_str := "upg.example.com" - fqdn := util.EncodeFQDN(fqdn_str) - fqdn_len := uint8(len(fqdn)) + fqdnStr := "upg.example.com" + fqdn := util.EncodeFQDN(fqdnStr) + fqdnLen := uint8(len(fqdn)) - { - set_req := &upf.UpfSetNodeID{ - Type: uint8(upf.UPF_NODE_TYPE_IPv4), - IP: ipv4, - } - _, set_err := CallSetNodeId(set_req) - gomega.Expect(set_err).To(gomega.BeNil(), "upf_set_node_id") - - get_reply, get_err := CallGetNodeId() - gomega.Expect(get_err).To(gomega.BeNil(), "upf_get_node_id") - gomega.Expect(get_reply).To(gomega.Equal( - &upf.UpfGetNodeIDReply{ - Type: uint8(upf.UPF_NODE_TYPE_IPv4), - IP: ipv4, - FqdnLen: 0, - Fqdn: []byte{}, - }), "upf_get_node_id") + // pass 1: IPv4 + setReq := &upf.UpfSetNodeID{ + Type: uint8(upf.UPF_NODE_TYPE_IPv4), + IP: ipv4, } - { - set_req := &upf.UpfSetNodeID{ - Type: uint8(upf.UPF_NODE_TYPE_IPv6), - IP: ipv6, - } - _, set_err := CallSetNodeId(set_req) - gomega.Expect(set_err).To(gomega.BeNil(), "upf_set_node_id") - - get_reply, get_err := CallGetNodeId() - gomega.Expect(get_err).To(gomega.BeNil(), "upf_get_node_id") - gomega.Expect(get_reply).To(gomega.Equal( - &upf.UpfGetNodeIDReply{ - Type: uint8(upf.UPF_NODE_TYPE_IPv6), - IP: ipv6, - FqdnLen: 0, - Fqdn: []byte{}, - }), "upf_get_node_id") + _, setErr := callSetNodeID(setReq) + gomega.Expect(setErr).To(gomega.BeNil(), "upf_set_node_id") + + out, err := f.VPP.Ctl("show upf node-id") + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "show upf node-id") + gomega.Expect(out).To(gomega.ContainSubstring(ipv4.ToIP().String()), "expected node-id") + + getReply, getErr := callGetNodeID() + gomega.Expect(getErr).To(gomega.BeNil(), "upf_get_node_id") + gomega.Expect(getReply).To(gomega.Equal( + &upf.UpfGetNodeIDReply{ + Type: uint8(upf.UPF_NODE_TYPE_IPv4), + IP: ipv4, + FqdnLen: 0, + Fqdn: []byte{}, + }), "upf_get_node_id") + + // pass 2: IPv6 + setReq = &upf.UpfSetNodeID{ + Type: uint8(upf.UPF_NODE_TYPE_IPv6), + IP: ipv6, } - { - set_req := &upf.UpfSetNodeID{ - Type: uint8(upf.UPF_NODE_TYPE_FQDN), - Fqdn: fqdn, - } - _, set_err := CallSetNodeId(set_req) - gomega.Expect(set_err).To(gomega.BeNil(), "upf_set_node_id") - - get_reply, get_err := CallGetNodeId() - gomega.Expect(get_err).To(gomega.BeNil(), "upf_get_node_id") - gomega.Expect(get_reply).To(gomega.Equal( - &upf.UpfGetNodeIDReply{ - Type: uint8(upf.UPF_NODE_TYPE_FQDN), - IP: ip_types.Address{}, - FqdnLen: fqdn_len, - Fqdn: fqdn, - }), "upf_get_node_id") + _, setErr = callSetNodeID(setReq) + gomega.Expect(setErr).To(gomega.BeNil(), "upf_set_node_id") + + out, err = f.VPP.Ctl("show upf node-id") + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "show upf node-id") + gomega.Expect(out).To(gomega.ContainSubstring(ipv6.ToIP().String()), "expected node-id") + + getReply, getErr = callGetNodeID() + gomega.Expect(getErr).To(gomega.BeNil(), "upf_get_node_id") + gomega.Expect(getReply).To(gomega.Equal( + &upf.UpfGetNodeIDReply{ + Type: uint8(upf.UPF_NODE_TYPE_IPv6), + IP: ipv6, + FqdnLen: 0, + Fqdn: []byte{}, + }), "upf_get_node_id") + + // pass 3: FQDN + setReq = &upf.UpfSetNodeID{ + Type: uint8(upf.UPF_NODE_TYPE_FQDN), + Fqdn: fqdn, } + _, setErr = callSetNodeID(setReq) + gomega.Expect(setErr).To(gomega.BeNil(), "upf_set_node_id") + + out, err = f.VPP.Ctl("show upf node-id") + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "show upf node-id") + gomega.Expect(out).To(gomega.ContainSubstring(fqdnStr), "expected node-id") + + getReply, getErr = callGetNodeID() + gomega.Expect(getErr).To(gomega.BeNil(), "upf_get_node_id") + gomega.Expect(getReply).To(gomega.Equal( + &upf.UpfGetNodeIDReply{ + Type: uint8(upf.UPF_NODE_TYPE_FQDN), + IP: ip_types.Address{}, + FqdnLen: fqdnLen, + Fqdn: fqdn, + }), "upf_get_node_id") }) }) diff --git a/upf/upf.api b/upf/upf.api index 2ef6b66..adb8f37 100644 --- a/upf/upf.api +++ b/upf/upf.api @@ -368,6 +368,7 @@ define upf_get_node_id { define upf_get_node_id_reply { u32 client_index; u32 context; + i32 retval; u8 type; vl_api_address_t ip; u8 fqdn_len; diff --git a/upf/upf_api.c b/upf/upf_api.c index e354a65..027984e 100644 --- a/upf/upf_api.c +++ b/upf/upf_api.c @@ -52,7 +52,7 @@ /* API message handler */ static void -vl_api_upf_app_add_del_t_handler (vl_api_upf_app_add_del_t *mp) +vl_api_upf_app_add_del_t_handler (vl_api_upf_app_add_del_t * mp) { vl_api_upf_app_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -115,8 +115,8 @@ static void vl_api_upf_app_flow_timeout_set_t_handler } static void -send_upf_applications_details (vl_api_registration_t *reg, - u8 *app_name, u32 flags, u32 context) +send_upf_applications_details (vl_api_registration_t * reg, + u8 * app_name, u32 flags, u32 context) { vl_api_upf_applications_details_t *mp; upf_main_t *sm = &upf_main; @@ -157,8 +157,8 @@ static void vl_api_upf_applications_dump_t_handler } static void -send_upf_application_l7_rule_details (vl_api_registration_t *reg, - u32 id, u8 *regex, u32 context) +send_upf_application_l7_rule_details (vl_api_registration_t * reg, + u32 id, u8 * regex, u32 context) { vl_api_upf_application_l7_rule_details_t *mp; upf_main_t *sm = &upf_main; @@ -213,7 +213,7 @@ static void vl_api_upf_application_l7_rule_dump_t_handler /* API message handler */ static void -vl_api_upf_update_app_t_handler (vl_api_upf_update_app_t *mp) +vl_api_upf_update_app_t_handler (vl_api_upf_update_app_t * mp) { vl_api_upf_update_app_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -246,7 +246,7 @@ vl_api_upf_update_app_t_handler (vl_api_upf_update_app_t *mp) } static void -vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t *mp) +vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t * mp) { upf_main_t *sm = &upf_main; vl_api_upf_pfcp_reencode_reply_t *rmp; @@ -286,7 +286,7 @@ vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t *mp) } static void -vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t *mp) +vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t * mp) { upf_main_t *sm = &upf_main; vl_api_upf_pfcp_format_reply_t *rmp; @@ -328,8 +328,8 @@ vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t *mp) } static void -send_upf_nat_pool_details (vl_api_registration_t *reg, - upf_nat_pool_t *np, u32 context) +send_upf_nat_pool_details (vl_api_registration_t * reg, + upf_nat_pool_t * np, u32 context) { vl_api_upf_nat_pool_details_t *mp; upf_main_t *sm = &upf_main; @@ -387,7 +387,7 @@ static void vl_api_upf_nat_pool_dump_t_handler /* API message handler */ static void -vl_api_upf_policy_add_del_t_handler (vl_api_upf_policy_add_del_t *mp) +vl_api_upf_policy_add_del_t_handler (vl_api_upf_policy_add_del_t * mp) { vl_api_upf_policy_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -428,8 +428,8 @@ vl_api_upf_policy_add_del_t_handler (vl_api_upf_policy_add_del_t *mp) } static void -send_upf_policy_details (vl_api_registration_t *reg, - upf_forwarding_policy_t *fp, u32 context) +send_upf_policy_details (vl_api_registration_t * reg, + upf_forwarding_policy_t * fp, u32 context) { vl_api_upf_policy_details_t *mp; upf_main_t *sm = &upf_main; @@ -463,7 +463,7 @@ send_upf_policy_details (vl_api_registration_t *reg, /* API message handler */ static void -vl_api_upf_policy_dump_t_handler (vl_api_upf_policy_dump_t *mp) +vl_api_upf_policy_dump_t_handler (vl_api_upf_policy_dump_t * mp) { upf_main_t *sm = &upf_main; vl_api_registration_t *reg; @@ -483,7 +483,7 @@ vl_api_upf_policy_dump_t_handler (vl_api_upf_policy_dump_t *mp) /* API message handler */ static void -vl_api_upf_nwi_add_del_t_handler (vl_api_upf_nwi_add_del_t *mp) +vl_api_upf_nwi_add_del_t_handler (vl_api_upf_nwi_add_del_t * mp) { vl_api_upf_nwi_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -568,7 +568,8 @@ vl_api_upf_nwi_add_del_t_handler (vl_api_upf_nwi_add_del_t *mp) } static void -send_upf_nwi_details (vl_api_registration_t *reg, upf_nwi_t *nwi, u32 context) +send_upf_nwi_details (vl_api_registration_t * reg, upf_nwi_t * nwi, + u32 context) { vl_api_upf_nwi_details_t *mp; upf_main_t *sm = &upf_main; @@ -617,7 +618,7 @@ send_upf_nwi_details (vl_api_registration_t *reg, upf_nwi_t *nwi, u32 context) /* API message handler */ static void -vl_api_upf_nwi_dump_t_handler (vl_api_upf_nwi_dump_t *mp) +vl_api_upf_nwi_dump_t_handler (vl_api_upf_nwi_dump_t * mp) { upf_main_t *sm = &upf_main; vl_api_registration_t *reg; @@ -638,7 +639,7 @@ vl_api_upf_nwi_dump_t_handler (vl_api_upf_nwi_dump_t *mp) /* API message handler */ static void vl_api_upf_pfcp_endpoint_add_del_t_handler (vl_api_upf_pfcp_endpoint_add_del_t - *mp) + * mp) { vl_api_upf_pfcp_endpoint_add_del_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -679,8 +680,8 @@ vl_api_upf_pfcp_endpoint_add_del_t_handler (vl_api_upf_pfcp_endpoint_add_del_t } static void -send_upf_pfcp_endpoint_details (vl_api_registration_t *reg, - ip46_address_fib_t *key, u32 context) +send_upf_pfcp_endpoint_details (vl_api_registration_t * reg, + ip46_address_fib_t * key, u32 context) { vl_api_upf_pfcp_endpoint_details_t *mp; upf_main_t *sm = &upf_main; @@ -704,7 +705,7 @@ send_upf_pfcp_endpoint_details (vl_api_registration_t *reg, /* API message handler */ static void -vl_api_upf_pfcp_endpoint_dump_t_handler (vl_api_upf_pfcp_endpoint_dump_t *mp) +vl_api_upf_pfcp_endpoint_dump_t_handler (vl_api_upf_pfcp_endpoint_dump_t * mp) { upf_main_t *sm = &upf_main; vl_api_registration_t *reg; @@ -726,7 +727,7 @@ vl_api_upf_pfcp_endpoint_dump_t_handler (vl_api_upf_pfcp_endpoint_dump_t *mp) /* API message handler */ static void -vl_api_upf_pfcp_server_set_t_handler (vl_api_upf_pfcp_server_set_t *mp) +vl_api_upf_pfcp_server_set_t_handler (vl_api_upf_pfcp_server_set_t * mp) { vl_api_upf_pfcp_server_set_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -767,7 +768,7 @@ vl_api_upf_pfcp_server_set_t_handler (vl_api_upf_pfcp_server_set_t *mp) /* API message handler */ static void -vl_api_upf_pfcp_server_show_t_handler (vl_api_upf_pfcp_server_show_t *mp) +vl_api_upf_pfcp_server_show_t_handler (vl_api_upf_pfcp_server_show_t * mp) { vl_api_upf_pfcp_server_show_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -802,7 +803,7 @@ vl_api_upf_pfcp_server_show_t_handler (vl_api_upf_pfcp_server_show_t *mp) /* API message handler */ static void -vl_api_upf_pfcp_policer_set_t_handler (vl_api_upf_pfcp_policer_set_t *mp) +vl_api_upf_pfcp_policer_set_t_handler (vl_api_upf_pfcp_policer_set_t * mp) { vl_api_upf_pfcp_policer_set_reply_t *rmp = NULL; qos_pol_cfg_params_st *cfg = &pfcp_rate_cfg_main; @@ -818,7 +819,7 @@ vl_api_upf_pfcp_policer_set_t_handler (vl_api_upf_pfcp_policer_set_t *mp) /* API message handler */ static void -vl_api_upf_pfcp_policer_show_t_handler (vl_api_upf_pfcp_policer_show_t *mp) +vl_api_upf_pfcp_policer_show_t_handler (vl_api_upf_pfcp_policer_show_t * mp) { vl_api_upf_pfcp_policer_show_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -847,7 +848,7 @@ vl_api_upf_pfcp_policer_show_t_handler (vl_api_upf_pfcp_policer_show_t *mp) /* API message handler */ static void vl_api_upf_pfcp_heartbeats_set_t_handler (vl_api_upf_pfcp_heartbeats_set_t - *mp) + * mp) { vl_api_upf_pfcp_heartbeats_set_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -865,7 +866,7 @@ vl_api_upf_pfcp_heartbeats_set_t_handler (vl_api_upf_pfcp_heartbeats_set_t /* API message handler */ static void vl_api_upf_pfcp_heartbeats_get_t_handler (vl_api_upf_pfcp_heartbeats_get_t - *mp) + * mp) { vl_api_upf_pfcp_heartbeats_get_reply_t *rmp = NULL; upf_main_t *sm = &upf_main; @@ -893,42 +894,43 @@ vl_api_upf_pfcp_heartbeats_get_t_handler (vl_api_upf_pfcp_heartbeats_get_t /* API message handler */ static void -vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t *mp) +vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t * mp) { + int rv = 0; upf_main_t *sm = &upf_main; vl_api_upf_set_node_id_reply_t *rmp = NULL; - // if old was fqdn then free it + pfcp_node_id_t node_id = { 0 }; + node_id.type = mp->type; switch (mp->type) { case NID_IPv4: case NID_IPv6: - sm->node_id.type = mp->type; - ip_address_decode (&mp->ip, &sm->node_id.ip); + ip_address_decode (&mp->ip, &node_id.ip); break; case NID_FQDN: - sm->node_id.type = NID_FQDN; - sm->node_id.fqdn = NULL; - vec_validate (sm->node_id.fqdn, 20); - memcpy (sm->node_id.fqdn, mp->fqdn, mp->fqdn_len); + vec_validate (node_id.fqdn, mp->fqdn_len); + memcpy (node_id.fqdn, mp->fqdn, mp->fqdn_len); break; default: - //TODO: error + rv = VNET_API_ERROR_INVALID_VALUE; break; } + if (rv == 0) + vnet_upf_node_id_set (&node_id); - int rv = 0; REPLY_MACRO (VL_API_UPF_SET_NODE_ID_REPLY); } /* API message handler */ static void -vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t *mp) +vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t * mp) { + int rv = 0; vl_api_registration_t *reg; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) @@ -938,8 +940,6 @@ vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t *mp) upf_main_t *sm = &upf_main; pfcp_node_id_t *node = &sm->node_id; - - switch (node->type) { case NID_IPv4: @@ -964,13 +964,15 @@ vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t *mp) break; } default: - ASSERT (false); - // TODO: return error + rv = VNET_API_ERROR_INVALID_VALUE; + break; } rmp->type = node->type; + rmp->_vl_msg_id = htons (VL_API_UPF_GET_NODE_ID_REPLY + sm->msg_id_base); rmp->context = mp->context; + rmp->retval = ntohl (rv); vl_api_send_msg (reg, (u8 *) rmp); } @@ -978,7 +980,7 @@ vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t *mp) #include static clib_error_t * -upf_api_hookup (vlib_main_t *vm) +upf_api_hookup (vlib_main_t * vm) { upf_main_t *gtm = &upf_main; From 7ccb290bbe17a548e84beb423a4d3b4a8c187089 Mon Sep 17 00:00:00 2001 From: Marcin Zyla Date: Mon, 22 May 2023 17:37:03 +0200 Subject: [PATCH 4/4] cr round 2 --- test/e2e/upg_e2e.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/test/e2e/upg_e2e.go b/test/e2e/upg_e2e.go index 49f6aae..534be67 100644 --- a/test/e2e/upg_e2e.go +++ b/test/e2e/upg_e2e.go @@ -607,10 +607,9 @@ var _ = ginkgo.Describe("UPG Binary API", func() { ginkgo.Context("for node-id", func() { f := framework.NewDefaultFramework(framework.UPGModeTDF, framework.UPGIPModeV4) - callSetNodeID := func(req *upf.UpfSetNodeID) (*upf.UpfSetNodeIDReply, error) { + callSetNodeID := func(req *upf.UpfSetNodeID) error { reply := &upf.UpfSetNodeIDReply{} - err := f.VPP.ApiChannel.SendRequest(req).ReceiveReply(reply) - return reply, err + return f.VPP.ApiChannel.SendRequest(req).ReceiveReply(reply) } callGetNodeID := func() (*upf.UpfGetNodeIDReply, error) { @@ -633,15 +632,14 @@ var _ = ginkgo.Describe("UPG Binary API", func() { Type: uint8(upf.UPF_NODE_TYPE_IPv4), IP: ipv4, } - _, setErr := callSetNodeID(setReq) - gomega.Expect(setErr).To(gomega.BeNil(), "upf_set_node_id") + gomega.Expect(callSetNodeID(setReq)).To(gomega.Succeed(), "upf_set_node_id") out, err := f.VPP.Ctl("show upf node-id") gomega.Expect(err).NotTo(gomega.HaveOccurred(), "show upf node-id") gomega.Expect(out).To(gomega.ContainSubstring(ipv4.ToIP().String()), "expected node-id") - getReply, getErr := callGetNodeID() - gomega.Expect(getErr).To(gomega.BeNil(), "upf_get_node_id") + getReply, err := callGetNodeID() + gomega.Expect(err).To(gomega.BeNil(), "upf_get_node_id") gomega.Expect(getReply).To(gomega.Equal( &upf.UpfGetNodeIDReply{ Type: uint8(upf.UPF_NODE_TYPE_IPv4), @@ -655,15 +653,14 @@ var _ = ginkgo.Describe("UPG Binary API", func() { Type: uint8(upf.UPF_NODE_TYPE_IPv6), IP: ipv6, } - _, setErr = callSetNodeID(setReq) - gomega.Expect(setErr).To(gomega.BeNil(), "upf_set_node_id") + gomega.Expect(callSetNodeID(setReq)).To(gomega.Succeed(), "upf_set_node_id") out, err = f.VPP.Ctl("show upf node-id") gomega.Expect(err).NotTo(gomega.HaveOccurred(), "show upf node-id") gomega.Expect(out).To(gomega.ContainSubstring(ipv6.ToIP().String()), "expected node-id") - getReply, getErr = callGetNodeID() - gomega.Expect(getErr).To(gomega.BeNil(), "upf_get_node_id") + getReply, err = callGetNodeID() + gomega.Expect(err).To(gomega.BeNil(), "upf_get_node_id") gomega.Expect(getReply).To(gomega.Equal( &upf.UpfGetNodeIDReply{ Type: uint8(upf.UPF_NODE_TYPE_IPv6), @@ -677,15 +674,14 @@ var _ = ginkgo.Describe("UPG Binary API", func() { Type: uint8(upf.UPF_NODE_TYPE_FQDN), Fqdn: fqdn, } - _, setErr = callSetNodeID(setReq) - gomega.Expect(setErr).To(gomega.BeNil(), "upf_set_node_id") + gomega.Expect(callSetNodeID(setReq)).To(gomega.Succeed(), "upf_set_node_id") out, err = f.VPP.Ctl("show upf node-id") gomega.Expect(err).NotTo(gomega.HaveOccurred(), "show upf node-id") gomega.Expect(out).To(gomega.ContainSubstring(fqdnStr), "expected node-id") - getReply, getErr = callGetNodeID() - gomega.Expect(getErr).To(gomega.BeNil(), "upf_get_node_id") + getReply, err = callGetNodeID() + gomega.Expect(err).To(gomega.BeNil(), "upf_get_node_id") gomega.Expect(getReply).To(gomega.Equal( &upf.UpfGetNodeIDReply{ Type: uint8(upf.UPF_NODE_TYPE_FQDN),