From 5fd98df86a746d09f152154d8a637bd3cf470444 Mon Sep 17 00:00:00 2001 From: jwillmartin Date: Wed, 8 Nov 2023 17:03:11 +0800 Subject: [PATCH] modified: src/tmx/Asn_J2735/CMakeLists.txt modified: src/tmx/TmxUtils/src/SNMPClient.cpp modified: src/tmx/TmxUtils/src/SNMPClient.h modified: src/tmx/tmx.doxyfile modified: src/v2i-hub/ImmediateForwardPlugin/manifest.json modified: src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.cpp modified: src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.h --- src/tmx/Asn_J2735/CMakeLists.txt | 2 +- src/tmx/TmxUtils/src/SNMPClient.cpp | 4 +- src/tmx/TmxUtils/src/SNMPClient.h | 6 +- src/tmx/tmx.doxyfile | 2 +- .../ImmediateForwardPlugin/manifest.json | 5 ++ .../src/ImmediateForwardPlugin.cpp | 86 +++++++++---------- .../src/ImmediateForwardPlugin.h | 1 + 7 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/tmx/Asn_J2735/CMakeLists.txt b/src/tmx/Asn_J2735/CMakeLists.txt index f2eb0056d..601044461 100644 --- a/src/tmx/Asn_J2735/CMakeLists.txt +++ b/src/tmx/Asn_J2735/CMakeLists.txt @@ -41,4 +41,4 @@ ENDFOREACH () UNSET (LIBRARY_NAME) UNSET (SAEJ2735_SPEC) -SET (ASN_J2735_LIBRARIES "asn_j2735_r2023" PARENT_SCOPE) +SET (ASN_J2735_LIBRARIES "asn_j2735_r2020" PARENT_SCOPE) diff --git a/src/tmx/TmxUtils/src/SNMPClient.cpp b/src/tmx/TmxUtils/src/SNMPClient.cpp index 33e136e59..fbbb35dc2 100644 --- a/src/tmx/TmxUtils/src/SNMPClient.cpp +++ b/src/tmx/TmxUtils/src/SNMPClient.cpp @@ -4,7 +4,7 @@ namespace tmx::utils { // Client defaults to SNMPv3 snmp_client::snmp_client(const std::string& ip, const int& port, const std::string& community, - const std::string &snmp_user, const std::string &securityLevel, const std::string &authPassPhrase, int snmp_version, int timeout) + const std::string &snmp_user, const std::string &securityLevel, const std::string &authPassPhrase, uint8_t snmp_version, int timeout) : ip_(ip), port_(port), community_(community),snmp_version_(snmp_version), timeout_(timeout) { @@ -14,7 +14,7 @@ namespace tmx::utils { PLOG(logINFO) << "Target device NTCIP port: " << port_; // Bring the IP address and port of the target SNMP device in the required form, which is "IPADDRESS:PORT": - std::string ip_port_string = ip_ + ":" + std::to_string(port_); + std::string ip_port_string = ip_ + ":" + std::to_string(port_); char* ip_port = &ip_port_string[0]; // Initialize SNMP session parameters diff --git a/src/tmx/TmxUtils/src/SNMPClient.h b/src/tmx/TmxUtils/src/SNMPClient.h index 7231d489f..b709c3430 100644 --- a/src/tmx/TmxUtils/src/SNMPClient.h +++ b/src/tmx/TmxUtils/src/SNMPClient.h @@ -67,7 +67,7 @@ class snmp_client std::string community_ = "public"; /* net-snmp version definition: SNMP_VERSION_1:0 SNMP_VERSION_2c:1 SNMP_VERSION_2u:2 SNMP_VERSION_3:3 https://github.com/net-snmp/net-snmp/blob/master/include/net-snmp/library/snmp.h */ - int snmp_version_ = 3; // default to 3 since previous versions not compatable currently + uint8_t snmp_version_ = SNMP_VERSION_3; // default to 3 since previous versions not compatable currently /*Time after which the the snmp request times out*/ int timeout_ = 10000; @@ -77,11 +77,11 @@ class snmp_client * @param ip The ip ,as a string, for the tsc_client_service to establish an snmp communication with. * @param port Target port as integer on the host for snmp communication. * @param community The community id as a string. Defaults to "public" if unassigned. - * @param snmp_version The snmp_version as defined in net-snmp.Default to 0 if unassigned. + * @param snmp_version The snmp_version as defined in net-snmp. Default to 0 if unassigned. * net-snmp version definition: SNMP_VERSION_1:0 SNMP_VERSION_2c:1 SNMP_VERSION_2u:2 SNMP_VERSION_3:3" * @param timeout The time in microseconds after which an snmp session request expires. Defaults to 100 if unassigned * **/ - snmp_client(const std::string& ip, const int& port, const std::string& community, const std::string &snmp_user, const std::string &securityLevel, const std::string &authPassPhrase, int snmp_version = 0, int timeout = 100); + snmp_client(const std::string& ip, const int& port, const std::string& community, const std::string &snmp_user, const std::string &securityLevel, const std::string &authPassPhrase, uint8_t snmp_version, int timeout = 100); /* Disable default copy constructor*/ snmp_client() = delete; diff --git a/src/tmx/tmx.doxyfile b/src/tmx/tmx.doxyfile index 2613a0b65..4e72c5532 100644 --- a/src/tmx/tmx.doxyfile +++ b/src/tmx/tmx.doxyfile @@ -1935,7 +1935,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = SAEJ2735_SPEC=2023 +PREDEFINED = SAEJ2735_SPEC=2020 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The diff --git a/src/v2i-hub/ImmediateForwardPlugin/manifest.json b/src/v2i-hub/ImmediateForwardPlugin/manifest.json index 88497c831..0f6111367 100644 --- a/src/v2i-hub/ImmediateForwardPlugin/manifest.json +++ b/src/v2i-hub/ImmediateForwardPlugin/manifest.json @@ -86,6 +86,11 @@ "key":"SecurityLevel", "default":"authNoPriv", "description":"SNMP Access Control. Usage: noAuthNoPriv, authNoPriv, or authPriv." + }, + { + "key":"SNMPVersion", + "default":"3", + "description":"Set SNMP version to use." } ] } \ No newline at end of file diff --git a/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.cpp b/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.cpp index 50dddcb3c..6d9416c68 100644 --- a/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.cpp +++ b/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.cpp @@ -212,6 +212,7 @@ bool ImmediateForwardPlugin::UpdateUdpClientFromConfigSettings(uint clientIndex) GetConfigValue("SecurityLevel", _securityLevel); GetConfigValue("SNMPUser", _snmpUser); GetConfigValue("AuthPassPhrase", _authPassPhrase); + GetConfigValue("SNMPVersion", _snmpVersion); // Take the lock while shared data is accessed. // A lock_guard will unlock when it goes out of scope (even if an exception occurs). @@ -253,9 +254,9 @@ bool ImmediateForwardPlugin::UpdateUdpClientFromConfigSettings(uint clientIndex) _rsuIp = addr[0]; _snmpPort = stoul(addr[1]); PLOG(logINFO) << "Create SNMP Client to connect to RSU. RSU IP: " << _rsuIp << ",\tRSU Port: " << _snmpPort << - "\tSNMP User: " << _snmpUser << ",\tSecurity Level: " << _securityLevel << ",\tAuthentication Passphrase: " << _authPassPhrase << endl; + "\tSNMP User: " << _snmpUser << ",\tSecurity Level: " << _securityLevel << ",\tAuthentication Passphrase: " << _authPassPhrase << "\tSNMP Version: " << _snmpVersion << endl; // update SNMPClientList with the creation of a new SNMPClient with given params - _SNMPClientList[clientIndex].push_back(new snmp_client(_rsuIp, _snmpPort, "public", _snmpUser, _securityLevel, _authPassPhrase, 3, 10000)); // updated + _SNMPClientList[clientIndex].push_back(new snmp_client(_rsuIp, _snmpPort, "public", _snmpUser, _securityLevel, _authPassPhrase, _snmpVersion, 10000)); // updated PLOG(logDEBUG) << "Client added to list"; } else @@ -459,7 +460,7 @@ void ImmediateForwardPlugin::SendMessageToRadio(IvpMessage *msg) auto type_INT = tmx::utils::snmp_response_obj::response_type::INTEGER; auto type_STR = tmx::utils::snmp_response_obj::response_type::STRING; - auto snmpRsuMode = snmp_client(_rsuIp, _snmpPort, "public", _snmpUser, _securityLevel, _authPassPhrase, 3, 10000); + auto snmpRsuMode = snmp_client(_rsuIp, _snmpPort, "public", _snmpUser, _securityLevel, _authPassPhrase, _snmpVersion, 10000); tmx::utils::snmp_response_obj modeMessage; modeMessage.type = type_INT; modeMessage.val_int = 2; @@ -487,11 +488,6 @@ void ImmediateForwardPlugin::SendMessageToRadio(IvpMessage *msg) _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.1", tmx::utils::request_type::GET, maxIFMs); // The following commands are reflective of NTCIP spec, NOT the current spec. - tmx::utils::snmp_response_obj msgEnableObj; - msgEnableObj.type = type_INT; - msgEnableObj.val_int = 1; // should always be set to enable - _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.4", request, msgEnableObj); - tmx::utils::snmp_response_obj msgIndexObj; msgIndexObj.type = type_INT; msgIndexObj.val_int = 0; // needs updating @@ -508,20 +504,17 @@ void ImmediateForwardPlugin::SendMessageToRadio(IvpMessage *msg) channelObj.val_int = stoi(_messageConfigMap[configIndex].Channel); _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.3", request, channelObj); + tmx::utils::snmp_response_obj msgEnableObj; + msgEnableObj.type = type_INT; + msgEnableObj.val_int = 1; // should always be set to enable + _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.4", request, msgEnableObj); + tmx::utils::snmp_response_obj statusObj; statusObj.type = type_INT; statusObj.val_int = 1; _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.5", request, statusObj); - // //Payload - removed per updated NTCIP 1218 spec as of 11/06/23 - // tmx::utils::snmp_response_obj payloadObj; - // payloadObj.type = type_STR; - // std::vector payloadVector(payloadbyte.begin(), payloadbyte.end()); - // payloadObj.val_string = payloadVector; - // _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.8", request, payloadObj); - - // TBD if needed in the final IFT update, listed for convienence - + // TBD if needed in the final IFM update, listed for convienence // TODO: add parameter for message priority tmx::utils::snmp_response_obj priorityObj; priorityObj.type = type_INT; @@ -535,6 +528,12 @@ void ImmediateForwardPlugin::SendMessageToRadio(IvpMessage *msg) optionsObj.val_string = bits0_3; _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.7", request, optionsObj); + // //Payload - removed per updated NTCIP 1218 spec as of 11/06/23 + // tmx::utils::snmp_response_obj payloadObj; + // payloadObj.type = type_STR; + // std::vector payloadVector(payloadbyte.begin(), payloadbyte.end()); + // payloadObj.val_string = payloadVector; + // _SNMPClientList[_messageConfigMap[configIndex].ClientIndex][i]->process_snmp_request("1.3.6.1.4.1.1206.4.2.18.4.2.1.8", request, payloadObj); // Current DRSC Spec // rsuIFMIndex iso.0.15628.4.1.5.1.1 RsuTableIndex @@ -553,7 +552,7 @@ void ImmediateForwardPlugin::SendMessageToRadio(IvpMessage *msg) // Status 1.3.6.1.4.1.1206.4.2.18.4.2.1.5 RowStatus // Priority 1.3.6.1.4.1.1206.4.2.18.4.2.1.6 int32 // Options 1.3.6.1.4.1.1206.4.2.18.4.2.1.7 (used to enabled signed or encrypted messages + protocol, 4 bit binary) - // Payload - 1.3.6.1.4.1.1206.4.2.18.4.2.1.8 octet string + // Payload - 1.3.6.1.4.1.1206.4.2.18.4.2.1.8 octet string // ***removed from standard } else{ @@ -564,38 +563,35 @@ void ImmediateForwardPlugin::SendMessageToRadio(IvpMessage *msg) } // Send the message using the configured UDP client. + os << "Version=0.7" << "\n"; + os << "Type=" << _messageConfigMap[configIndex].SendType << "\n" << "PSID=" << _messageConfigMap[configIndex].Psid << "\n"; + if (_messageConfigMap[configIndex].Channel.empty()) + os << "Priority=7" << "\n" << "TxMode=CONT" << "\n" << "TxChannel=" << msg->dsrcMetadata->channel << "\n"; else - { - os << "Version=0.7" << "\n"; - os << "Type=" << _messageConfigMap[configIndex].SendType << "\n" << "PSID=" << _messageConfigMap[configIndex].Psid << "\n"; - if (_messageConfigMap[configIndex].Channel.empty()) - os << "Priority=7" << "\n" << "TxMode=CONT" << "\n" << "TxChannel=" << msg->dsrcMetadata->channel << "\n"; - else - os << "Priority=7" << "\n" << "TxMode=CONT" << "\n" << "TxChannel=" << _messageConfigMap[configIndex].Channel << "\n"; - os << "TxInterval=0" << "\n" << "DeliveryStart=\n" << "DeliveryStop=\n"; - os << "Signature="<< (signState == 1 ? "True" : "False") << "\n" << "Encryption=False\n"; - os << "Payload=" << payloadbyte << "\n"; + os << "Priority=7" << "\n" << "TxMode=CONT" << "\n" << "TxChannel=" << _messageConfigMap[configIndex].Channel << "\n"; + os << "TxInterval=0" << "\n" << "DeliveryStart=\n" << "DeliveryStop=\n"; + os << "Signature="<< (signState == 1 ? "True" : "False") << "\n" << "Encryption=False\n"; + os << "Payload=" << payloadbyte << "\n"; - string message = os.str(); // finalized message to send to clients + string message = os.str(); // finalized message to send to clients - for (uint i = 0; i < _udpClientList[_messageConfigMap[configIndex].ClientIndex].size(); i++) - { - //cout << message << endl; + for (uint i = 0; i < _udpClientList[_messageConfigMap[configIndex].ClientIndex].size(); i++) + { + //cout << message << endl; - if (_udpClientList[_messageConfigMap[configIndex].ClientIndex][i] != NULL) - { - PLOG(logDEBUG2) << _logPrefix << "Sending - TmxType: " << _messageConfigMap[configIndex].TmxType << ", SendType: " << _messageConfigMap[configIndex].SendType - << ", PSID: " << _messageConfigMap[configIndex].Psid << ", Client: " << _messageConfigMap[configIndex].ClientIndex - << ", Channel: " << (_messageConfigMap[configIndex].Channel.empty() ? ::to_string( msg->dsrcMetadata->channel) : _messageConfigMap[configIndex].Channel) - << ", Port: " << _udpClientList[_messageConfigMap[configIndex].ClientIndex][i]->GetPort(); + if (_udpClientList[_messageConfigMap[configIndex].ClientIndex][i] != NULL) + { + PLOG(logDEBUG2) << _logPrefix << "Sending - TmxType: " << _messageConfigMap[configIndex].TmxType << ", SendType: " << _messageConfigMap[configIndex].SendType + << ", PSID: " << _messageConfigMap[configIndex].Psid << ", Client: " << _messageConfigMap[configIndex].ClientIndex + << ", Channel: " << (_messageConfigMap[configIndex].Channel.empty() ? ::to_string( msg->dsrcMetadata->channel) : _messageConfigMap[configIndex].Channel) + << ", Port: " << _udpClientList[_messageConfigMap[configIndex].ClientIndex][i]->GetPort(); - _udpClientList[_messageConfigMap[configIndex].ClientIndex][i]->Send(message); // sending message to client - } - else - { - SetStatus(Key_SkippedInvalidUdpClient, ++_skippedInvalidUdpClient); - PLOG(logWARNING) << "UDP Client Invalid. Cannot send message. TmxType: " << _messageConfigMap[configIndex].TmxType; - } + _udpClientList[_messageConfigMap[configIndex].ClientIndex][i]->Send(message); // sending message to client + } + else + { + SetStatus(Key_SkippedInvalidUdpClient, ++_skippedInvalidUdpClient); + PLOG(logWARNING) << "UDP Client Invalid. Cannot send message. TmxType: " << _messageConfigMap[configIndex].TmxType; } } } diff --git a/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.h b/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.h index 41b863a99..d68f36f64 100644 --- a/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.h +++ b/src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.h @@ -77,6 +77,7 @@ class ImmediateForwardPlugin : public tmx::utils::PluginClient std::string _securityLevel; std::string _snmpUser; std::string _authPassPhrase; + uint8_t _snmpVersion; unsigned int signState; unsigned int snmpState;