From 9ba34d62a9faed8fb782062c58c3d746ce56a107 Mon Sep 17 00:00:00 2001 From: Ido Barnea Date: Mon, 16 May 2016 16:25:21 +0300 Subject: json fixes --- src/flow_stat.cpp | 6 +++--- src/flow_stat.h | 14 +++++++------- src/stateless/rx/trex_stateless_rx_core.cpp | 12 ++++++++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/flow_stat.cpp b/src/flow_stat.cpp index 575e66e0..feb7276a 100644 --- a/src/flow_stat.cpp +++ b/src/flow_stat.cpp @@ -858,7 +858,7 @@ int CFlowStatRuleMgr::stop_stream(TrexStream * stream) { m_hw_id_map.unmap(hw_id); } else { CFlowStatUserIdInfoPayload *p_user_id_p = (CFlowStatUserIdInfoPayload *)p_user_id; - std::string json; + Json::Value json; m_api->get_rfc2544_info(&rfc2544_info, hw_id, hw_id, true); p_user_id_p->set_jitter(rfc2544_info.get_jitter()); rfc2544_info.get_latency_json(json); @@ -1043,14 +1043,14 @@ bool CFlowStatRuleMgr::dump_json(std::string & s_json, std::string & l_json, boo if (user_id_info->rfc2544_support()) { CFlowStatUserIdInfoPayload *user_id_info_p = (CFlowStatUserIdInfoPayload *)user_id_info; // payload object. Send also latency, jitter... - std::string lat_hist; + Json::Value lat_hist; if (user_id_info->is_hw_id()) { // if mapped to hw_id, take info from what we just got from rx core uint16_t hw_id = user_id_info->get_hw_id(); rfc2544_info[hw_id].get_latency_json(lat_hist); user_id_info_p->set_seq_err_cnt(rfc2544_info[hw_id].get_seq_err_cnt()); user_id_info_p->set_ooo_cnt(rfc2544_info[hw_id].get_ooo_cnt()); - l_data_section[str_user_id]["latency"]["histogram"] = lat_hist; + l_data_section[str_user_id]["latency"] = lat_hist; l_data_section[str_user_id]["latency"]["last_max"] = rfc2544_info[hw_id].get_last_max(); l_data_section[str_user_id]["jitter"] = rfc2544_info[hw_id].get_jitter(); } else { diff --git a/src/flow_stat.h b/src/flow_stat.h index e0e5fe5f..f239044d 100644 --- a/src/flow_stat.h +++ b/src/flow_stat.h @@ -65,11 +65,11 @@ class rfc2544_info_t_ { clear(); } - inline void get_latency_json(std::string & json) const { + inline void get_latency_json(Json::Value & json) const { json = m_latency; } - inline void set_latency_json(std::string json) { + inline void set_latency_json(Json::Value json) { m_latency = json; } @@ -106,7 +106,7 @@ class rfc2544_info_t_ { m_seq_error = 0; m_out_of_order = 0; m_jitter = 0; - m_latency = ""; + m_latency = Json::Value(""); } inline rfc2544_info_t_ operator+ (const rfc2544_info_t_ &t_in) { @@ -146,9 +146,9 @@ class rfc2544_info_t_ { uint64_t m_out_of_order; double m_jitter; dsec_t m_last_max_latency; - // json string of latency. In case of stop/start, we calculate latency graph from scratch, + // json latency object. In case of stop/start, we calculate latency graph from scratch, // so when stopping, we just "freeze" state for reporting by saving the json string - std::string m_latency; + Json::Value m_latency; }; class tx_per_flow_t_ { @@ -286,11 +286,11 @@ class CFlowStatUserIdInfoPayload : public CFlowStatUserIdInfo { m_seq_error_base = 0; m_out_of_order_base = 0; } - inline void get_latency_json(std::string & json) const { + inline void get_latency_json(Json::Value & json) const { json = m_rfc2544_info.m_latency; } - inline void set_latency_json(std::string json) { + inline void set_latency_json(Json::Value json) { m_rfc2544_info.m_latency = json; } diff --git a/src/stateless/rx/trex_stateless_rx_core.cpp b/src/stateless/rx/trex_stateless_rx_core.cpp index 72b0f749..4a7c0b29 100644 --- a/src/stateless/rx/trex_stateless_rx_core.cpp +++ b/src/stateless/rx/trex_stateless_rx_core.cpp @@ -101,8 +101,7 @@ void CRxCoreStateless::start() { while (true) { if (m_state == STATE_WORKING) { i++; - //??? need to calculate value for 10msec instead of 1000 - if (i == 1000) { + if (i == 100000) { // approx 10msec i = 0; periodic_check_for_cp_messages(); // m_state might change in here } @@ -327,12 +326,17 @@ int CRxCoreStateless::get_rx_stats(uint8_t port_id, rx_per_flow_t *rx_stats, int } int CRxCoreStateless::get_rfc2544_info(rfc2544_info_t *rfc2544_info, int min, int max, bool reset) { - std::string json; + std::string json_str; + Json::Value json; + Json::Reader reader; + for (int hw_id = min; hw_id <= max; hw_id++) { rfc2544_info[hw_id - min].set_err_cntrs(m_per_flow_seq_error[hw_id], m_per_flow_out_of_order[hw_id]); rfc2544_info[hw_id - min].set_jitter(m_per_flow_jitter[hw_id].get_jitter()); m_per_flow_hist[hw_id].update(); - m_per_flow_hist[hw_id].dump_json("", json); + m_per_flow_hist[hw_id].dump_json("", json_str); + // This is a hack. We need to make the dump_json return json object. + reader.parse( json_str.c_str(), json); rfc2544_info[hw_id - min].set_latency_json(json); rfc2544_info[hw_id - min].set_last_max(m_per_flow_last_max[hw_id].switchMax()); -- cgit 1.2.3-korg