From 09047d2bf614d7794fb855923caa94cbfeb94ceb Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 10 Jan 2024 15:26:05 +0100 Subject: [PATCH 1/2] pceplib: add json string option to subgroup counter The created counters in pceplib library are structures with a string attribute which is used for further display. This string information is not formatted for json output. Add a second option in the create_subgroup_counter() creation API to provide the json attribute output. Create a json naming compatible with caml format for each subgroup counter used. Signed-off-by: Philippe Guibert --- pceplib/pcep_session_logic_counters.c | 193 +++++++++++++----------- pceplib/pcep_utils_counters.c | 10 +- pceplib/pcep_utils_counters.h | 27 ++-- pceplib/test/pcep_utils_counters_test.c | 24 +-- 4 files changed, 141 insertions(+), 113 deletions(-) diff --git a/pceplib/pcep_session_logic_counters.c b/pceplib/pcep_session_logic_counters.c index 6f6f2a0df465..b12b8ab0e072 100644 --- a/pceplib/pcep_session_logic_counters.c +++ b/pceplib/pcep_session_logic_counters.c @@ -36,30 +36,30 @@ void create_session_counters(pcep_session *session) struct counters_subgroup *rx_msg_subgroup = create_counters_subgroup( "RX Message counters", COUNTER_SUBGROUP_ID_RX_MSG, PCEP_TYPE_MAX + 1); - create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_OPEN, - "Message Open"); + create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_OPEN, "Message Open", + "messageOpen"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_KEEPALIVE, - "Message KeepAlive"); + "Message KeepAlive", "messageKeepalive"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_PCREQ, - "Message PcReq"); + "Message PcReq", "messagePcReq"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_PCREP, - "Message PcRep"); + "Message PcRep", "messagePcRep"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_PCNOTF, - "Message Notify"); + "Message Notify", "messageNotify"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_ERROR, - "Message Error"); + "Message Error", "messageError"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_CLOSE, - "Message Close"); + "Message Close", "messageClose"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_REPORT, - "Message Report"); + "Message Report", "messageReport"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_UPDATE, - "Message Update"); + "Message Update", "messageUpdate"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_INITIATE, - "Message Initiate"); + "Message Initiate", "messageInitiate"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_START_TLS, - "Message StartTls"); + "Message StartTls", "messageStartTls"); create_subgroup_counter(rx_msg_subgroup, PCEP_TYPE_MAX, - "Message Erroneous"); + "Message Erroneous", "messageErroneous"); struct counters_subgroup *tx_msg_subgroup = clone_counters_subgroup(rx_msg_subgroup, "TX Message counters", @@ -74,59 +74,61 @@ void create_session_counters(pcep_session *session) struct counters_subgroup *rx_obj_subgroup = create_counters_subgroup( "RX Object counters", COUNTER_SUBGROUP_ID_RX_OBJ, 100); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_OPEN, - "Object Open"); - create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_RP, - "Object RP"); + "Object Open", "objectOpen"); + create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_RP, "Object RP", + "objectRP"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_NOPATH, - "Object Nopath"); - create_subgroup_counter( - rx_obj_subgroup, - ((PCEP_OBJ_CLASS_ENDPOINTS << 4) | PCEP_OBJ_TYPE_ENDPOINT_IPV4), - "Object Endpoint IPv4"); - create_subgroup_counter( - rx_obj_subgroup, - ((PCEP_OBJ_CLASS_ENDPOINTS << 4) | PCEP_OBJ_TYPE_ENDPOINT_IPV6), - "Object Endpoint IPv6"); + "Object Nopath", "objectNopath"); + create_subgroup_counter(rx_obj_subgroup, + ((PCEP_OBJ_CLASS_ENDPOINTS << 4) | + PCEP_OBJ_TYPE_ENDPOINT_IPV4), + "Object Endpoint IPv4", "objectEndpointIPv4"); + create_subgroup_counter(rx_obj_subgroup, + ((PCEP_OBJ_CLASS_ENDPOINTS << 4) | + PCEP_OBJ_TYPE_ENDPOINT_IPV6), + "Object Endpoint IPv6", "objectEndpointIPv6"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_BANDWIDTH, - "Object Bandwidth"); + "Object Bandwidth", "objectBandwidth"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_METRIC, - "Object Metric"); + "Object Metric", "objectMetric"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_ERO, - "Object ERO"); + "Object ERO", "objectERO"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_RRO, - "Object RRO"); + "Object RRO", "objectRRO"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_LSPA, - "Object LSPA"); + "Object LSPA", "objectLSPA"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_IRO, - "Object IRO"); + "Object IRO", "objectIRO"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_SVEC, - "Object SVEC"); + "Object SVEC", "objectSVEC"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_NOTF, - "Object Notify"); + "Object Notify", "objectNotify"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_ERROR, - "Object Error"); + "Object Error", "objectError"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_CLOSE, - "Object Close"); + "Object Close", "objectClose"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_LSP, - "Object LSP"); + "Object LSP", "objectLSP"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_SRP, - "Object SRP"); + "Object SRP", "objectSRP"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_VENDOR_INFO, - "Object Vendor Info"); + "Object Vendor Info", "objectVendorInfo"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_INTER_LAYER, - "Object Inter-Layer"); + "Object Inter-Layer", "objectInterLayer"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_SWITCH_LAYER, - "Object Switch-Layer"); + "Object Switch-Layer", "objectSwitchLayer"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_REQ_ADAP_CAP, - "Object Requested Adap-Cap"); + "Object Requested Adap-Cap", + "objectRequestedAdapCap"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_SERVER_IND, - "Object Server-Indication"); + "Object Server-Indication", + "objectServerIndication"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_ASSOCIATION, - "Object Association"); + "Object Association", "objectAssociation"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_MAX, - "Object Unknown"); + "Object Unknown", "objectUnknown"); create_subgroup_counter(rx_obj_subgroup, PCEP_OBJ_CLASS_MAX + 1, - "Object Erroneous"); + "Object Erroneous", "objectErroneous"); struct counters_subgroup *tx_obj_subgroup = clone_counters_subgroup(rx_obj_subgroup, "TX Object counters", @@ -139,21 +141,22 @@ void create_session_counters(pcep_session *session) "RX RO Sub-Object counters", COUNTER_SUBGROUP_ID_RX_SUBOBJ, RO_SUBOBJ_UNKNOWN + 2); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_TYPE_IPV4, - "RO Sub-Object IPv4"); + "RO Sub-Object IPv4", "ROSubObjectIPv4"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_TYPE_IPV6, - "RO Sub-Object IPv6"); + "RO Sub-Object IPv6", "ROSubObjectIPv6"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_TYPE_LABEL, - "RO Sub-Object Label"); + "RO Sub-Object Label", "ROSubObjectLabel"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_TYPE_UNNUM, - "RO Sub-Object Unnum"); + "RO Sub-Object Unnum", "ROSubObjectUnnum"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_TYPE_ASN, - "RO Sub-Object ASN"); + "RO Sub-Object ASN", "ROSubObjectASN"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_TYPE_SR, - "RO Sub-Object SR"); + "RO Sub-Object SR", "ROSubObjectSR"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_UNKNOWN, - "RO Sub-Object Unknown"); + "RO Sub-Object Unknown", "ROSubObjectUnknown"); create_subgroup_counter(rx_subobj_subgroup, RO_SUBOBJ_UNKNOWN + 1, - "RO Sub-Object Erroneous"); + "RO Sub-Object Erroneous", + "ROSubObjectErroneous"); struct counters_subgroup *tx_subobj_subgroup = clone_counters_subgroup( rx_subobj_subgroup, "TX RO Sub-Object counters", @@ -168,28 +171,36 @@ void create_session_counters(pcep_session *session) PCEP_SR_SUBOBJ_NAI_UNKNOWN + 1); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_ABSENT, - "RO Sub-Object SR NAI absent"); + "RO Sub-Object SR NAI absent", + "ROSubObjectSRNAIAbsent"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_IPV4_NODE, - "RO Sub-Object SR NAI IPv4 Node"); + "RO Sub-Object SR NAI IPv4 Node", + "ROSubObjectSRNAIIPv4Node"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_IPV6_NODE, - "RO Sub-Object SR NAI IPv6 Node"); + "RO Sub-Object SR NAI IPv6 Node", + "ROSubObjectSRNAIIPv6Node"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_IPV4_ADJACENCY, - "RO Sub-Object SR NAI IPv4 Adj"); + "RO Sub-Object SR NAI IPv4 Adj", + "ROSubObjectSRNAIIPv4Adj"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_IPV6_ADJACENCY, - "RO Sub-Object SR NAI IPv6 Adj"); + "RO Sub-Object SR NAI IPv6 Adj", + "ROSubObjectSRNAIIPv6Adj"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_UNNUMBERED_IPV4_ADJACENCY, - "RO Sub-Object SR NAI Unnumbered IPv4 Adj"); + "RO Sub-Object SR NAI Unnumbered IPv4 Adj", + "ROSubObjectSRNAIUnnumberedIPv4Adj"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_LINK_LOCAL_IPV6_ADJACENCY, - "RO Sub-Object SR NAI Link Local IPv6 Adj"); + "RO Sub-Object SR NAI Link Local IPv6 Adj", + "ROSubObjectSRNAILinkLocalIPv6Adj"); create_subgroup_counter(rx_subobj_sr_nai_subgroup, PCEP_SR_SUBOBJ_NAI_UNKNOWN, - "RO Sub-Object SR NAI Unknown"); + "RO Sub-Object SR NAI Unknown", + "ROSubObjectSRNAIUnknown"); struct counters_subgroup *tx_subobj_sr_nai_subgroup = clone_counters_subgroup(rx_subobj_sr_nai_subgroup, @@ -204,56 +215,60 @@ void create_session_counters(pcep_session *session) PCEP_OBJ_TLV_TYPE_UNKNOWN + 1); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_NO_PATH_VECTOR, - "TLV No Path Vector"); + "TLV No Path Vector", "TLVNoPathVector"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_VENDOR_INFO, - "TLV Vendor Info"); + "TLV Vendor Info", "TLVVendorInfo"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_STATEFUL_PCE_CAPABILITY, - "TLV Stateful PCE Capability"); + "TLV Stateful PCE Capability", + "TLVStatefulPCCapability"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SYMBOLIC_PATH_NAME, - "TLV Symbolic Path Name"); + "TLV Symbolic Path Name", "TLVSymbolicPathName"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_IPV4_LSP_IDENTIFIERS, - "TLV IPv4 LSP Identifier"); + "TLV IPv4 LSP Identifier", + "TLVIPv4LSPIdentifier"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_IPV6_LSP_IDENTIFIERS, - "TLV IPv6 LSP Identifier"); + "TLV IPv6 LSP Identifier", + "TLVIPv6LSPIdentifier"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_LSP_ERROR_CODE, - "TLV LSP Error Code"); + "TLV LSP Error Code", "TLVLSPErrorCode"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_RSVP_ERROR_SPEC, - "TLV RSVP Error Spec"); + "TLV RSVP Error Spec", "TLVRSVPErrorSpec"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_LSP_DB_VERSION, - "TLV LSP DB Version"); + "TLV LSP DB Version", "TLVLSPDBVersion"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SPEAKER_ENTITY_ID, - "TLV Speaker Entity ID"); + "TLV Speaker Entity ID", "TLVSpeakerEntityId"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SR_PCE_CAPABILITY, - "TLV SR PCE Capability"); + "TLV SR PCE Capability", "TLVSRPCECapability"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE, - "TLV Path Setup Type"); + "TLV Path Setup Type", "TLVPathSetupType"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE_CAPABILITY, - "TLV Path Setup Type Capability"); + "TLV Path Setup Type Capability", + "TLVPathSetupTypeCapability"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SRPOLICY_POL_ID, - "TLV SR Policy PolId"); + "TLV SR Policy PolId", "TLVSRPolicyPolId"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SRPOLICY_POL_NAME, - "TLV SR Policy PolName"); + "TLV SR Policy PolName", "TLVSRPolicyPolName"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SRPOLICY_CPATH_ID, - "TLV SR Policy CpathId"); + "TLV SR Policy CpathId", "TLVSRPolicyCpathId"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_SRPOLICY_CPATH_PREFERENCE, - "TLV SR Policy CpathRef"); + "TLV SR Policy CpathRef", "TLVSRPolicyCpathRef"); create_subgroup_counter(rx_tlv_subgroup, PCEP_OBJ_TLV_TYPE_UNKNOWN, - "TLV Unknown"); + "TLV Unknown", "TLVUnknown"); struct counters_subgroup *tx_tlv_subgroup = clone_counters_subgroup( rx_tlv_subgroup, "TX TLV counters", COUNTER_SUBGROUP_ID_TX_TLV); @@ -265,28 +280,32 @@ void create_session_counters(pcep_session *session) "Events counters", COUNTER_SUBGROUP_ID_EVENT, MAX_COUNTERS); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_PCC_CONNECT, - "PCC connect"); + "PCC connect", "PCCConnect"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_PCE_CONNECT, - "PCE connect"); + "PCE connect", "PCEConnect"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_PCC_DISCONNECT, - "PCC disconnect"); + "PCC disconnect", "PCCDisconnect"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_PCE_DISCONNECT, - "PCE disconnect"); + "PCE disconnect", "PCEDisconnect"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_TIMER_KEEPALIVE, - "Timer KeepAlive expired"); + "Timer KeepAlive expired", + "timerKeepAliveExpired"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_TIMER_DEADTIMER, - "Timer DeadTimer expired"); + "Timer DeadTimer expired", + "timerDeadTimerExpired"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_TIMER_OPENKEEPWAIT, - "Timer OpenKeepWait expired"); + "Timer OpenKeepWait expired", + "timerOpenKeepWaitExpired"); create_subgroup_counter(events_subgroup, PCEP_EVENT_COUNTER_ID_TIMER_OPENKEEPALIVE, - "Timer OpenKeepAlive expired"); + "Timer OpenKeepAlive expired", + "timerOpenKeepAliveExpired"); /* * Create the parent counters group diff --git a/pceplib/pcep_utils_counters.c b/pceplib/pcep_utils_counters.c index badef9351a75..1ab341c69c51 100644 --- a/pceplib/pcep_utils_counters.c +++ b/pceplib/pcep_utils_counters.c @@ -139,7 +139,8 @@ clone_counters_subgroup(struct counters_subgroup *subgroup, if (counter != NULL) { create_subgroup_counter(cloned_subgroup, counter->counter_id, - counter->counter_name); + counter->counter_name, + counter->counter_name_json); } } @@ -180,7 +181,8 @@ bool add_counters_subgroup(struct counters_group *group, } bool create_subgroup_counter(struct counters_subgroup *subgroup, - uint32_t counter_id, const char *counter_name) + uint32_t counter_id, const char *counter_name, + const char *counter_name_json) { if (subgroup == NULL) { pcep_log( @@ -212,7 +214,9 @@ bool create_subgroup_counter(struct counters_subgroup *subgroup, counter->counter_id = counter_id; strlcpy(counter->counter_name, counter_name, sizeof(counter->counter_name)); - + if (counter_name_json) + strlcpy(counter->counter_name_json, counter_name_json, + sizeof(counter->counter_name_json)); subgroup->num_counters++; subgroup->counters[counter->counter_id] = counter; diff --git a/pceplib/pcep_utils_counters.h b/pceplib/pcep_utils_counters.h index 755c94eb0cd4..dfae02fb2ea1 100644 --- a/pceplib/pcep_utils_counters.h +++ b/pceplib/pcep_utils_counters.h @@ -55,18 +55,18 @@ extern "C" { * *events_subgroup = create_counters_subgroup("events counters", 4); * * Use message_id: PCEP_TYPE_OPEN=1 - * create_subgroup_counter(rx_subgroup, 1, "Message Open"); - * create_subgroup_counter(rx_subgroup, 2, "Message KeepAlive"); - * create_subgroup_counter(rx_subgroup, 3, "Message PcReq"); + * create_subgroup_counter(rx_subgroup, 1, "Message Open", "messageOpen"); + * create_subgroup_counter(rx_subgroup, 2, "Message KeepAlive", "messageKeepAlive"); + * create_subgroup_counter(rx_subgroup, 3, "Message PcReq", "messagePcReq"); * - * create_subgroup_counter(tx_subgroup, 1, "Message Open"); - * create_subgroup_counter(tx_subgroup, 2, "Message KeepAlive"); - * create_subgroup_counter(tx_subgroup, 3, "Message PcReq"); + * create_subgroup_counter(tx_subgroup, 1, "Message Open", "messageOpen"); + * create_subgroup_counter(tx_subgroup, 2, "Message KeepAlive", "messageKeepAlive"); + * create_subgroup_counter(tx_subgroup, 3, "Message PcReq", "messagePcReq"); * - * create_subgroup_counter(events_subgroup, 1, "PCC Connect"); - * create_subgroup_counter(events_subgroup, 2, "PCE Connect"); - * create_subgroup_counter(events_subgroup, 3, "PCC Disconnect"); - * create_subgroup_counter(events_subgroup, 4, "PCE Disconnect"); + * create_subgroup_counter(events_subgroup, 1, "PCC Connect", "PCConnect"); + * create_subgroup_counter(events_subgroup, 2, "PCE Connect", "PCEConnect"); + * create_subgroup_counter(events_subgroup, 3, "PCC Disconnect", "PCCDisconnect"); + * create_subgroup_counter(events_subgroup, 4, "PCE Disconnect", "PCEDisconnect"); * * struct counters_group *cntrs_group = create_counters_group("PCEP Counters", * 3); add_counters_subgroup(cntrs_group, rx_subgroup); @@ -81,6 +81,7 @@ extern "C" { struct counter { uint16_t counter_id; char counter_name[MAX_COUNTER_STR_LENGTH]; + char counter_name_json[MAX_COUNTER_STR_LENGTH]; uint32_t counter_value; }; @@ -142,13 +143,15 @@ clone_counters_subgroup(struct counters_subgroup *subgroup, const char *subgroup_name, uint16_t subgroup_id); /* - * Create a counter in a subgroup with the given counter_id and counter_name. + * Create a counter in a subgroup with the given counter_id and counter_name + * and counter_name_json. * The counter_id is 0-based. * Return true on success or false if subgroup is NULL, counter_id >= * MAX_COUNTERS, or if counter_name is NULL. */ bool create_subgroup_counter(struct counters_subgroup *subgroup, - uint32_t counter_id, const char *counter_name); + uint32_t counter_id, const char *counter_name, + const char *couter_name_json); /* * Delete the counters_group and recursively delete all subgroups and their diff --git a/pceplib/test/pcep_utils_counters_test.c b/pceplib/test/pcep_utils_counters_test.c index 2cad9a64438f..d3d5197b5308 100644 --- a/pceplib/test/pcep_utils_counters_test.c +++ b/pceplib/test/pcep_utils_counters_test.c @@ -106,17 +106,19 @@ void test_create_subgroup_counter() { uint16_t counter_id = 1; char counter_name[] = "my counter"; + char counter_name_json[] = "myCounter"; struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", 1, 2); - CU_ASSERT_FALSE( - create_subgroup_counter(NULL, counter_id, counter_name)); + CU_ASSERT_FALSE(create_subgroup_counter(NULL, counter_id, counter_name, + counter_name_json)); CU_ASSERT_FALSE(create_subgroup_counter(subgroup, counter_id + 1, counter_name)); - CU_ASSERT_FALSE(create_subgroup_counter(subgroup, counter_id, NULL)); + CU_ASSERT_FALSE( + create_subgroup_counter(subgroup, counter_id, NULL, NULL)); CU_ASSERT_EQUAL(subgroup->num_counters, 0); - CU_ASSERT_TRUE( - create_subgroup_counter(subgroup, counter_id, counter_name)); + CU_ASSERT_TRUE(create_subgroup_counter(subgroup, counter_id, + counter_name, counter_name_json)); CU_ASSERT_EQUAL(subgroup->num_counters, 1); delete_counters_subgroup(subgroup); @@ -146,7 +148,7 @@ void test_reset_group_counters() struct counters_group *group = create_counters_group("group", 10); struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", subgroup_id, 10); - create_subgroup_counter(subgroup, counter_id, "counter"); + create_subgroup_counter(subgroup, counter_id, "counter", "counter"); add_counters_subgroup(group, subgroup); struct counter *counter = subgroup->counters[counter_id]; @@ -164,7 +166,7 @@ void test_reset_subgroup_counters() uint16_t counter_id = 1; struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", 1, 10); - create_subgroup_counter(subgroup, counter_id, "counter"); + create_subgroup_counter(subgroup, counter_id, "counter", "counter"); struct counter *counter = subgroup->counters[counter_id]; counter->counter_value = 100; @@ -183,7 +185,7 @@ void test_increment_counter() struct counters_group *group = create_counters_group("group", 10); struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", subgroup_id, 10); - create_subgroup_counter(subgroup, counter_id, "counter"); + create_subgroup_counter(subgroup, counter_id, "counter", "counter"); add_counters_subgroup(group, subgroup); struct counter *counter = subgroup->counters[counter_id]; @@ -205,7 +207,7 @@ void test_increment_subgroup_counter() uint32_t counter_value = 100; struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", 1, 10); - create_subgroup_counter(subgroup, counter_id, "counter"); + create_subgroup_counter(subgroup, counter_id, "counter", "counter"); struct counter *counter = subgroup->counters[counter_id]; counter->counter_value = counter_value; @@ -225,7 +227,7 @@ void test_dump_counters_group_to_log() struct counters_group *group = create_counters_group("group", 10); struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", subgroup_id, 10); - create_subgroup_counter(subgroup, counter_id, "counter"); + create_subgroup_counter(subgroup, counter_id, "counter", "counter"); add_counters_subgroup(group, subgroup); CU_ASSERT_FALSE(dump_counters_group_to_log(NULL)); @@ -240,7 +242,7 @@ void test_dump_counters_subgroup_to_log() uint16_t counter_id = 1; struct counters_subgroup *subgroup = create_counters_subgroup("subgroup", subgroup_id, 10); - create_subgroup_counter(subgroup, counter_id, "counter"); + create_subgroup_counter(subgroup, counter_id, "counter", "counter"); CU_ASSERT_FALSE(dump_counters_subgroup_to_log(NULL)); CU_ASSERT_TRUE(dump_counters_subgroup_to_log(subgroup)); From dba04c2f3c13c9624267247386330a8ab231a3a0 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 10 Jan 2024 15:25:03 +0100 Subject: [PATCH 2/2] pathd: add 'show sr-te pcep session json' support Add support to dump sr-te pcep session in json output. > ubuntu2204# show sr-te pcep session > PCE q > PCE IP 192.0.2.40 port 4189 > PCC IP 192.0.2.10 port 4189 > PCC MSD 10 > Session Status UP > Precedence 10, best candidate > Confidence normal > Timer: KeepAlive config 30, pce-negotiated 70 > Timer: DeadTimer config 120, pce-negotiated 120 > Timer: PcRequest 30 > Timer: SessionTimeout Interval 30 > Timer: Delegation Timeout 10 > No TCP MD5 Auth > PCE SR Version draft07 > Next PcReq ID 5 > Next PLSP ID 2 > Connected for 171 seconds, since 2023-10-28 09:36:44 UTC > PCC Capabilities: [PCC Initiated LSPs] [Stateful PCE] [SR TE PST] > PCE Capabilities: [Stateful PCE] [SR TE PST] > PCEP Message Statistics > Sent Rcvd > Message Open: 2 1 > Message KeepAlive: 1 6 > Message PcReq: 4 0 > Message PcRep: 0 0 > Message Notify: 4 0 > Message Error: 0 5 > Message Close: 0 0 > Message Report: 5 0 > Message Update: 0 1 > Message Initiate: 0 0 > Message StartTls: 0 0 > Message Erroneous: 0 0 > Total: 16 13 > PCEP Sessions => Configured 1 ; Connected 1 > ubuntu2204# show sr-te pcep session json > { > "pcepSessions":[ > { > "pceName":"q", > "pceAddress":"192.0.2.40", > "pcePort":4189, > "pccAddress":"192.0.2.10", > "pccPort":4189, > "pccMsd":10, > "sessionStatus":"UP", > "bestMultiPce":true, > "precedence":10, > "confidence":"normal", > "keepaliveConfig":30, > "deadTimerConfig":120, > "pccPcepRequestTimerConfig":30, > "sessionTimeoutIntervalSec":30, > "delegationTimeout":10, > "tcpMd5Authentication":false, > "draft07":true, > "draft16AndRfc8408":false, > "nextPcRequestId":5, > "nextPLspId":2, > "sessionKeepalivePceNegotiatedSec":70, > "sessionDeadTimerPceNegotiatedSec":120, > "sessionConnectionDurationSec":177, > "sessionConnectionStartTimeUTC":"2023-10-28 09:36:44", > "pccCapabilities":" [PCC Initiated LSPs] [Stateful PCE] [SR TE PST]", > "pceCapabilities":" [Stateful PCE] [SR TE PST]", > "messageStatisticsReceived":{ > "messageOpen":1, > "messageKeepalive":6, > "messagePcReq":0, > "messagePcRep":0, > "messageNotify":0, > "messageError":5, > "messageClose":0, > "messageReport":0, > "messageUpdate":1, > "messageInitiate":0, > "messageStartTls":0, > "messageErroneous":0, > "total":13 > }, > "messageStatisticsSent":{ > "messageOpen":2, > "messageKeepalive":1, > "messagePcReq":4, > "messagePcRep":0, > "messageNotify":4, > "messageError":0, > "messageClose":0, > "messageReport":5, > "messageUpdate":0, > "messageInitiate":0, > "messageStartTls":0, > "messageErrneous":0, > "total":16 > } > } > ], > "pcepSessionsConfigured":1, > "pcepSessionsConnected":1 > } Signed-off-by: Philippe Guibert --- doc/user/pathd.rst | 2 +- pathd/path_pcep_cli.c | 295 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 277 insertions(+), 20 deletions(-) diff --git a/doc/user/pathd.rst b/doc/user/pathd.rst index ba4c209a0df8..2519ac491228 100644 --- a/doc/user/pathd.rst +++ b/doc/user/pathd.rst @@ -534,7 +534,7 @@ retrieved via PCEP a random number based name is generated. Display PCC information. -.. clicmd:: show sr-te pcep session [NAME] +.. clicmd:: show sr-te pcep session [NAME] [json] Display the information of a PCEP session, if not name is specified all the sessions will be displayed. diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index e0926ea62d81..47a811d144f1 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -43,6 +43,8 @@ #define DEFAULT_TIMER_SESSION_TIMEOUT_INTERVAL 30 #define DEFAULT_DELEGATION_TIMEOUT_INTERVAL 10 +#define BUFFER_PCC_PCE_SIZE 1024 + /* CLI Function declarations */ static int pcep_cli_debug_config_write(struct vty *vty); static int pcep_cli_debug_set_all(uint32_t flags, bool set); @@ -73,6 +75,9 @@ static void print_pcep_capabilities(char *buf, size_t buf_len, pcep_configuration *config); static void print_pcep_session(struct vty *vty, struct pce_opts *pce_opts, struct pcep_pcc_info *pcc_info); +static void print_pcep_session_json(struct vty *vty, struct pce_opts *pce_opts, + struct pcep_pcc_info *pcc_info, + json_object *json); static bool pcep_cli_pcc_has_pce(const char *pce_name); static void pcep_cli_add_pce_connection(struct pce_opts *pce_opts); static void pcep_cli_remove_pce_connection(struct pce_opts *pce_opts); @@ -1186,11 +1191,189 @@ static void print_pcep_capabilities(char *buf, size_t buf_len, } } +/* Internal util function to print a pcep session */ +static void print_pcep_session_json(struct vty *vty, struct pce_opts *pce_opts, + struct pcep_pcc_info *pcc_info, + json_object *json) +{ + char buf[BUFFER_PCC_PCE_SIZE] = {}; + int index = 0; + pcep_session *session; + struct pcep_config_group_opts *config_opts; + struct counters_group *group; + + /* PCE IP */ + if (IS_IPADDR_V4(&pce_opts->addr)) + json_object_string_addf(json, "pceAddress", "%pI4", + &pce_opts->addr.ipaddr_v4); + else if (IS_IPADDR_V6(&pce_opts->addr)) + json_object_string_addf(json, "pceAddress", "%pI6", + &pce_opts->addr.ipaddr_v6); + json_object_int_add(json, "pcePort", pce_opts->port); + + /* PCC IP */ + if (IS_IPADDR_V4(&pcc_info->pcc_addr)) + json_object_string_addf(json, "pccAddress", "%pI4", + &pcc_info->pcc_addr.ipaddr_v4); + else if (IS_IPADDR_V6(&pcc_info->pcc_addr)) + json_object_string_addf(json, "pccAddress", "%pI6", + &pcc_info->pcc_addr.ipaddr_v6); + + json_object_int_add(json, "pccPort", pcc_info->pcc_port); + json_object_int_add(json, "pccMsd", pcc_info->msd); + + if (pcc_info->status == PCEP_PCC_OPERATING) + json_object_string_add(json, "sessionStatus", "UP"); + else + json_object_string_add(json, "sessionStatus", + pcc_status_name(pcc_info->status)); + + json_object_boolean_add(json, "bestMultiPce", + pcc_info->is_best_multi_pce); + json_object_int_add(json, "precedence", + pcc_info->precedence > 0 ? pcc_info->precedence + : DEFAULT_PCE_PRECEDENCE); + json_object_string_add(json, "confidence", + pcc_info->previous_best ? "low" : "normal"); + + /* PCEPlib pcep session values, get a thread safe copy of the counters + */ + session = pcep_ctrl_get_pcep_session(pcep_g->fpt, pcc_info->pcc_id); + + /* Config Options values */ + config_opts = &pce_opts->config_opts; + json_object_int_add(json, "keepaliveConfig", + config_opts->keep_alive_seconds); + json_object_int_add(json, "deadTimerConfig", + config_opts->dead_timer_seconds); + json_object_int_add(json, "pccPcepRequestTimerConfig", + config_opts->pcep_request_time_seconds); + json_object_int_add(json, "sessionTimeoutIntervalSec", + config_opts->session_timeout_inteval_seconds); + json_object_int_add(json, "delegationTimeout", + config_opts->delegation_timeout_seconds); + json_object_boolean_add(json, "tcpMd5Authentication", + (strlen(config_opts->tcp_md5_auth) > 0)); + if (strlen(config_opts->tcp_md5_auth) > 0) + json_object_string_add(json, "tcpMd5AuthenticationString", + config_opts->tcp_md5_auth); + json_object_boolean_add(json, "draft07", !!config_opts->draft07); + json_object_boolean_add(json, "draft16AndRfc8408", + !config_opts->draft07); + + json_object_int_add(json, "nextPcRequestId", pcc_info->next_reqid); + /* original identifier used by the PCC for LSP instantiation */ + json_object_int_add(json, "nextPLspId", pcc_info->next_plspid); + + if (session != NULL) { + json_object_int_add(json, "sessionKeepalivePceNegotiatedSec", + session->pcc_config + .keep_alive_pce_negotiated_timer_seconds); + json_object_int_add(json, "sessionDeadTimerPceNegotiatedSec", + session->pcc_config + .dead_timer_pce_negotiated_seconds); + if (pcc_info->status == PCEP_PCC_SYNCHRONIZING || + pcc_info->status == PCEP_PCC_OPERATING) { + time_t current_time = time(NULL); + struct tm lt = { 0 }; + /* Just for the timezone */ + localtime_r(¤t_time, <); + gmtime_r(&session->time_connected, <); + json_object_int_add(json, "sessionConnectionDurationSec", + (uint32_t)(current_time - + session->time_connected)); + json_object_string_addf(json, + "sessionConnectionStartTimeUTC", + "%d-%02d-%02d %02d:%02d:%02d", + lt.tm_year + 1900, lt.tm_mon + 1, + lt.tm_mday, lt.tm_hour, + lt.tm_min, lt.tm_sec); + } + + /* PCC capabilities */ + buf[0] = '\0'; + + if (config_opts->pce_initiated) + index += csnprintfrr(buf, sizeof(buf), "%s", + PCEP_CLI_CAP_PCC_PCE_INITIATED); + else + index += csnprintfrr(buf, sizeof(buf), "%s", + PCEP_CLI_CAP_PCC_INITIATED); + print_pcep_capabilities(buf, sizeof(buf) - index, + &session->pcc_config); + json_object_string_add(json, "pccCapabilities", buf); + + /* PCE capabilities */ + buf[0] = '\0'; + print_pcep_capabilities(buf, sizeof(buf), &session->pce_config); + if (buf[0] != '\0') + json_object_string_add(json, "pceCapabilities", buf); + XFREE(MTYPE_PCEP, session); + } else { + json_object_string_add(json, "warningSession", + "Detailed session information not available."); + } + + /* Message Counters, get a thread safe copy of the counters */ + group = pcep_ctrl_get_counters(pcep_g->fpt, pcc_info->pcc_id); + + if (group != NULL) { + struct counters_subgroup *rx_msgs = + find_subgroup(group, COUNTER_SUBGROUP_ID_RX_MSG); + struct counters_subgroup *tx_msgs = + find_subgroup(group, COUNTER_SUBGROUP_ID_TX_MSG); + json_object *json_counter; + struct counter *tx_counter, *rx_counter; + + if (rx_msgs != NULL) { + json_counter = json_object_new_object(); + for (int i = 0; i < rx_msgs->max_counters; i++) { + rx_counter = rx_msgs->counters[i]; + + if (rx_counter && + rx_counter->counter_name_json[0] != '\0') + json_object_int_add( + json_counter, + rx_counter->counter_name_json, + rx_counter->counter_value); + } + json_object_int_add(json_counter, "total", + subgroup_counters_total(rx_msgs)); + json_object_object_add(json, "messageStatisticsReceived", + json_counter); + } + if (tx_msgs != NULL) { + json_counter = json_object_new_object(); + for (int i = 0; i < tx_msgs->max_counters; i++) { + tx_counter = tx_msgs->counters[i]; + + if (tx_counter && + tx_counter->counter_name_json[0] != '\0') + json_object_int_add( + json_counter, + tx_counter->counter_name_json, + tx_counter->counter_value); + } + json_object_int_add(json_counter, "total", + subgroup_counters_total(tx_msgs)); + json_object_object_add(json, "messageStatisticsSent", + json_counter); + } + pcep_lib_free_counters(group); + } else { + json_object_string_add(json, "messageStatisticsWarning", + "Counters not available."); + } + + XFREE(MTYPE_PCEP, pcc_info); +} + /* Internal util function to print a pcep session */ static void print_pcep_session(struct vty *vty, struct pce_opts *pce_opts, struct pcep_pcc_info *pcc_info) { char buf[1024]; + buf[0] = '\0'; vty_out(vty, "\nPCE %s\n", pce_opts->pce_name); @@ -1241,6 +1424,7 @@ static void print_pcep_session(struct vty *vty, struct pce_opts *pce_opts, /* Config Options values */ struct pcep_config_group_opts *config_opts = &pce_opts->config_opts; + if (session != NULL) { vty_out(vty, " Timer: KeepAlive config %d, pce-negotiated %d\n", config_opts->keep_alive_seconds, @@ -1356,34 +1540,66 @@ static void print_pcep_session(struct vty *vty, struct pce_opts *pce_opts, } static int path_pcep_cli_show_srte_pcep_session(struct vty *vty, - const char *pcc_peer) + const char *pcc_peer, bool uj) { struct pce_opts_cli *pce_opts_cli; struct pcep_pcc_info *pcc_info; + json_object *json = NULL; + + if (uj) + json = json_object_new_object(); /* Only show 1 PCEP session */ if (pcc_peer != NULL) { + if (json) + json_object_string_add(json, "pceName", pcc_peer); pce_opts_cli = pcep_cli_find_pce(pcc_peer); if (pce_opts_cli == NULL) { - vty_out(vty, "%% PCE [%s] does not exist.\n", pcc_peer); + if (json) { + json_object_string_addf(json, "warning", + "PCE [%s] does not exist.", + pcc_peer); + vty_json(vty, json); + } else + vty_out(vty, "%% PCE [%s] does not exist.\n", + pcc_peer); return CMD_WARNING; } if (!pcep_cli_pcc_has_pce(pcc_peer)) { - vty_out(vty, "%% PCC is not connected to PCE [%s].\n", - pcc_peer); + if (json) { + json_object_string_addf(json, "warning", + "PCC is not connected to PCE [%s].", + pcc_peer); + vty_json(vty, json); + } else + vty_out(vty, + "%% PCC is not connected to PCE [%s].\n", + pcc_peer); return CMD_WARNING; } pcc_info = pcep_ctrl_get_pcc_info(pcep_g->fpt, pcc_peer); if (pcc_info == NULL) { - vty_out(vty, - "%% Cannot retrieve PCEP session info for PCE [%s]\n", - pcc_peer); + if (json) { + json_object_string_addf(json, "warning", + "Cannot retrieve PCEP session info for PCE [%s].", + pcc_peer); + vty_json(vty, json); + } else + vty_out(vty, + "%% Cannot retrieve PCEP session info for PCE [%s]\n", + pcc_peer); return CMD_WARNING; } - print_pcep_session(vty, &pce_opts_cli->pce_opts, pcc_info); + if (json) { + print_pcep_session_json(vty, &pce_opts_cli->pce_opts, + pcc_info, json); + vty_json(vty, json); + } else + print_pcep_session(vty, &pce_opts_cli->pce_opts, + pcc_info); return CMD_SUCCESS; } @@ -1392,29 +1608,56 @@ static int path_pcep_cli_show_srte_pcep_session(struct vty *vty, struct pce_opts *pce_opts; int num_pcep_sessions_conf = 0; int num_pcep_sessions_conn = 0; + json_object *json_array = NULL, *json_entry = NULL; + + if (json) + json_array = json_object_new_array(); for (int i = 0; i < MAX_PCC; i++) { pce_opts = pce_connections_g.connections[i]; if (pce_opts == NULL) { continue; } + if (json) { + json_entry = json_object_new_object(); + json_object_string_add(json_entry, "pceName", + pce_opts->pce_name); + } pcc_info = pcep_ctrl_get_pcc_info(pcep_g->fpt, pce_opts->pce_name); if (pcc_info == NULL) { - vty_out(vty, - "%% Cannot retrieve PCEP session info for PCE [%s]\n", - pce_opts->pce_name); + if (json_entry) { + json_object_string_addf(json_entry, "warning", + "Cannot retrieve PCEP session info for PCE [%s].", + pce_opts->pce_name); + json_object_array_add(json_array, json_entry); + } else + vty_out(vty, + "%% Cannot retrieve PCEP session info for PCE [%s]\n", + pce_opts->pce_name); continue; } num_pcep_sessions_conn += pcc_info->status == PCEP_PCC_OPERATING ? 1 : 0; num_pcep_sessions_conf++; - print_pcep_session(vty, pce_opts, pcc_info); - } - - vty_out(vty, "PCEP Sessions => Configured %d ; Connected %d\n", - num_pcep_sessions_conf, num_pcep_sessions_conn); + if (json_entry) { + print_pcep_session_json(vty, pce_opts, pcc_info, + json_entry); + json_object_array_add(json_array, json_entry); + } else + print_pcep_session(vty, pce_opts, pcc_info); + } + if (json) { + json_object_object_add(json, "pcepSessions", json_array); + json_object_int_add(json, "pcepSessionsConfigured", + num_pcep_sessions_conf); + json_object_int_add(json, "pcepSessionsConnected", + num_pcep_sessions_conn); + vty_json(vty, json); + } else + vty_out(vty, "PCEP Sessions => Configured %d ; Connected %d\n", + num_pcep_sessions_conf, num_pcep_sessions_conn); return CMD_SUCCESS; } @@ -2091,14 +2334,27 @@ DEFPY(pcep_cli_show_srte_pcc, DEFPY(pcep_cli_show_srte_pcep_session, pcep_cli_show_srte_pcep_session_cmd, - "show sr-te pcep session [WORD]$pce", + "show sr-te pcep session WORD$pce [json$uj]", SHOW_STR "SR-TE info\n" "PCEP info\n" "Show PCEP Session information\n" - "PCE name\n") + "PCE name\n" + JSON_STR) +{ + return path_pcep_cli_show_srte_pcep_session(vty, pce, !!uj); +} + +DEFPY(pcep_cli_show_srte_pcep_sessions, + pcep_cli_show_srte_pcep_sessions_cmd, + "show sr-te pcep session [json$uj]", + SHOW_STR + "SR-TE info\n" + "PCEP info\n" + "Show PCEP Session information\n" + JSON_STR) { - return path_pcep_cli_show_srte_pcep_session(vty, pce); + return path_pcep_cli_show_srte_pcep_session(vty, NULL, !!uj); } DEFPY(pcep_cli_clear_srte_pcep_session, @@ -2172,5 +2428,6 @@ void pcep_cli_init(void) install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_pce_config_cmd); install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_pce_cmd); install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_session_cmd); + install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_sessions_cmd); install_element(ENABLE_NODE, &pcep_cli_clear_srte_pcep_session_cmd); }