Skip to content

Commit

Permalink
modified: src/tmx/Asn_J2735/CMakeLists.txt
Browse files Browse the repository at this point in the history
	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
  • Loading branch information
jwillmartin committed Nov 8, 2023
1 parent c3da98c commit 5fd98df
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/tmx/Asn_J2735/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/tmx/TmxUtils/src/SNMPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/tmx/TmxUtils/src/SNMPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tmx/tmx.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/v2i-hub/ImmediateForwardPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
}
86 changes: 41 additions & 45 deletions src/v2i-hub/ImmediateForwardPlugin/src/ImmediateForwardPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ bool ImmediateForwardPlugin::UpdateUdpClientFromConfigSettings(uint clientIndex)
GetConfigValue<string>("SecurityLevel", _securityLevel);
GetConfigValue<string>("SNMPUser", _snmpUser);
GetConfigValue<string>("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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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<char> 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;
Expand All @@ -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<char> 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
Expand All @@ -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{
Expand All @@ -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<uint>(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<uint>(Key_SkippedInvalidUdpClient, ++_skippedInvalidUdpClient);
PLOG(logWARNING) << "UDP Client Invalid. Cannot send message. TmxType: " << _messageConfigMap[configIndex].TmxType;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5fd98df

Please sign in to comment.