diff --git a/dp-core/vr_flow.c b/dp-core/vr_flow.c index d34b01ad1..4a8c146d2 100644 --- a/dp-core/vr_flow.c +++ b/dp-core/vr_flow.c @@ -1457,7 +1457,8 @@ vr_flow_req_destroy(vr_flow_req *req) vr_flow_req * vr_flow_req_get(vr_flow_req *ref_req) { - unsigned int hold_stat_size = vr_num_cpus * sizeof(uint32_t); + unsigned int hold_stat_size; + unsigned int num_cpus = vr_num_cpus; vr_flow_req *req = vr_zalloc(sizeof(*req)); if (!req) @@ -1470,12 +1471,16 @@ vr_flow_req_get(vr_flow_req *ref_req) req->fr_pcap_meta_data_size = 0; } + if (num_cpus > VR_FLOW_MAX_CPUS) + num_cpus = VR_FLOW_MAX_CPUS; + + hold_stat_size = num_cpus * sizeof(uint32_t); req->fr_hold_stat = vr_zalloc(hold_stat_size); if (!req->fr_hold_stat) { vr_free(req); return NULL; } - req->fr_hold_stat_size = hold_stat_size; + req->fr_hold_stat_size = num_cpus; return req; } @@ -1487,7 +1492,7 @@ void vr_flow_req_process(void *s_req) { int ret = 0; - unsigned int i; + unsigned int i, object = VR_FLOW_OBJECT_ID; bool need_destroy = false; uint64_t hold_count = 0; @@ -1516,7 +1521,7 @@ vr_flow_req_process(void *s_req) resp->fr_added = router->vr_flow_table_info->vfti_added; resp->fr_cpus = vr_num_cpus; /* we only have space for 64 stats block max when encoding */ - for (i = 0; ((i < vr_num_cpus) && (i < 64)); i++) { + for (i = 0; ((i < vr_num_cpus) && (i < VR_FLOW_MAX_CPUS)); i++) { resp->fr_hold_stat[i] = router->vr_flow_table_info->vfti_hold_count[i]; hold_count += resp->fr_hold_stat[i]; @@ -1524,6 +1529,7 @@ vr_flow_req_process(void *s_req) resp->fr_created = hold_count; + object = VR_FLOW_INFO_OBJECT_ID; break; case FLOW_OP_FLOW_SET: @@ -1536,7 +1542,7 @@ vr_flow_req_process(void *s_req) } send_response: - vr_message_response(VR_FLOW_OBJECT_ID, resp, ret); + vr_message_response(object, resp, ret); if (need_destroy) { vr_flow_req_destroy(resp); } diff --git a/dp-core/vr_sandesh.c b/dp-core/vr_sandesh.c index 5e9c95046..164bd14d9 100644 --- a/dp-core/vr_sandesh.c +++ b/dp-core/vr_sandesh.c @@ -33,8 +33,7 @@ struct sandesh_object_md sandesh_md[] = { .obj_type_string = "vr_mirror_req", }, [VR_FLOW_OBJECT_ID] = { - .obj_len = ((4 * sizeof(vr_flow_req)) + - (64 * sizeof(unsigned int))), + .obj_len = 4 * sizeof(vr_flow_req), .obj_type_string = "vr_flow_req", }, [VR_VRF_ASSIGN_OBJECT_ID] = { @@ -57,6 +56,11 @@ struct sandesh_object_md sandesh_md[] = { .obj_len = 4 * sizeof(vr_vxlan_req), .obj_type_string = "vr_vxlan_req", }, + [VR_FLOW_INFO_OBJECT_ID] = { + .obj_len = ((4 * sizeof(vr_flow_req)) + + (VR_FLOW_MAX_CPUS * sizeof(unsigned int))), + .obj_type_string = "vr_flow_req", + }, }; static unsigned int diff --git a/include/vr_message.h b/include/vr_message.h index fee428146..22c3b228c 100644 --- a/include/vr_message.h +++ b/include/vr_message.h @@ -27,6 +27,7 @@ #define VR_VRF_STATS_OBJECT_ID 9 #define VR_DROP_STATS_OBJECT_ID 10 #define VR_VXLAN_OBJECT_ID 11 +#define VR_FLOW_INFO_OBJECT_ID 13 #define VR_MESSAGE_PAGE_SIZE (4096 - 128) diff --git a/include/vr_sandesh.h b/include/vr_sandesh.h index 4fbf19bdc..f7f28e5b8 100644 --- a/include/vr_sandesh.h +++ b/include/vr_sandesh.h @@ -6,6 +6,8 @@ #ifndef __VR_SANDESH_H__ #define __VR_SANDESH_H__ +#define VR_FLOW_MAX_CPUS 128 + struct sandesh_object_md { unsigned int obj_len; char *obj_type_string; diff --git a/utils/flow.c b/utils/flow.c index 074c91013..98835736a 100644 --- a/utils/flow.c +++ b/utils/flow.c @@ -61,7 +61,8 @@ struct flow_table { unsigned int ft_flags; unsigned int ft_cpus; unsigned int ft_hold_oflows; - u_int32_t ft_hold_stat[64]; + unsigned int ft_hold_stat_count; + u_int32_t ft_hold_stat[128]; } main_table; int mem_fd; @@ -138,9 +139,9 @@ dump_table(struct flow_table *ft) printf("Entries: Created %lu Added %lu Processed %lu\n", ft->ft_created, ft->ft_added, ft->ft_processed); printf("(Created Flows/CPU: "); - for (i = 0; i < ft->ft_cpus; i++) { + for (i = 0; i < ft->ft_hold_stat_count; i++) { printf("%u", ft->ft_hold_stat[i]); - if (i != (ft->ft_cpus - 1)) + if (i != (ft->ft_hold_stat_count - 1)) printf(" "); } printf(")(oflows %u)\n", ft->ft_hold_oflows); @@ -477,9 +478,19 @@ flow_table_map(vr_flow_req *req) ft->ft_cpus = req->fr_cpus; if (req->fr_hold_stat && req->fr_hold_stat_size) { - for (i = 0; i < ft->ft_cpus; i++) { + ft->ft_hold_stat_count = req->fr_hold_stat_size; + for (i = 0; i < req->fr_hold_stat_size; i++) { + if (i == + (sizeof(ft->ft_hold_stat) / sizeof(ft->ft_hold_stat[0]))) { + ft->ft_hold_stat_count = i; + break; + } + ft->ft_hold_stat[i] = req->fr_hold_stat[i]; } + } else { + ft->ft_hold_stat_count = 0; + memset(ft->ft_hold_stat, 0, sizeof(ft->ft_hold_stat)); } return ft->ft_num_entries;