-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement functionality to connect RSU Health Monitor to multiple RSU…
…s(4) from same instance (#606) <!-- Thanks for the contribution, this is awesome. --> # PR Details ## Description Update the V2X Hub's RSU Health Monitor plugin supports monitoring the health status of multiple Roadside Units (RSUs) per V2X Hub instance. <!--- Describe your changes in detail --> ## Related Issue NA <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> ## Motivation and Context NA <!--- Why is this change required? What problem does it solve? --> ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Defect fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that cause existing functionality to change) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have added any new packages to the sonar-scanner.properties file - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. [V2XHUB Contributing Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md) - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed.
- Loading branch information
1 parent
ff9dd7c
commit c1759dd
Showing
10 changed files
with
320 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationException.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
namespace RSUHealthMonitor | ||
{ | ||
class RSUConfigurationException : public std::runtime_error | ||
{ | ||
public: | ||
using runtime_error::runtime_error; | ||
}; | ||
} |
128 changes: 128 additions & 0 deletions
128
src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
|
||
#include "RSUConfigurationList.h" | ||
|
||
namespace RSUHealthMonitor | ||
{ | ||
Json::Value RSUConfigurationList::parseJson(const std::string &rsuConfigsStr) const | ||
{ | ||
JSONCPP_STRING err; | ||
Json::Value root; | ||
auto length = static_cast<int>(rsuConfigsStr.length()); | ||
Json::CharReaderBuilder builder; | ||
std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); | ||
if (!reader->parse(rsuConfigsStr.c_str(), rsuConfigsStr.c_str() + length, &root, &err)) | ||
{ | ||
std::stringstream ss; | ||
ss << "Parse RSUs raw string error: " << err; | ||
throw RSUConfigurationException(ss.str().c_str()); | ||
} | ||
return root; | ||
} | ||
|
||
void RSUConfigurationList::parseRSUs(const std::string &rsuConfigsStr) | ||
{ | ||
auto json = parseJson(rsuConfigsStr); | ||
std::vector<RSUConfiguration> tempConfigs; | ||
RSUConfiguration config; | ||
auto rsuArray = json[RSUSKey]; | ||
if (!rsuArray.isArray()) | ||
{ | ||
throw RSUConfigurationException("RSUConfigurationList: Missing RSUS array."); | ||
} | ||
for (auto i = 0; i != rsuArray.size(); i++) | ||
{ | ||
if (rsuArray[i].isMember(RSUIpKey)) | ||
{ | ||
config.rsuIp = rsuArray[i][RSUIpKey].asString(); | ||
} | ||
else | ||
{ | ||
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU IP [" + std::string(RSUIpKey) + "] is required."; | ||
throw RSUConfigurationException(errMsg); | ||
} | ||
|
||
if (rsuArray[i].isMember(SNMPPortKey)) | ||
{ | ||
auto port = static_cast<uint16_t>(atoi(rsuArray[i][SNMPPortKey].asCString())); | ||
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: Invalid SNMP port number in string format."; | ||
port != 0 ? config.snmpPort = port : throw RSUConfigurationException(errMsg); | ||
} | ||
else | ||
{ | ||
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: SNMP port [" + std::string(SNMPPortKey) + "] is required."; | ||
throw RSUConfigurationException(errMsg); | ||
} | ||
|
||
if (rsuArray[i].isMember(AuthPassPhraseKey)) | ||
{ | ||
config.authPassPhrase = rsuArray[i][AuthPassPhraseKey].asString(); | ||
} | ||
else | ||
{ | ||
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: Authentication pass phrase [" + std::string(AuthPassPhraseKey) + "] is required."; | ||
throw RSUConfigurationException(errMsg); | ||
} | ||
|
||
if (rsuArray[i].isMember(UserKey)) | ||
{ | ||
config.user = rsuArray[i][UserKey].asString(); | ||
} | ||
else | ||
{ | ||
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: User [" + std::string(UserKey) + "] is required."; | ||
throw RSUConfigurationException(errMsg); | ||
} | ||
|
||
if (rsuArray[i].isMember(RSUMIBVersionKey)) | ||
{ | ||
auto rsuMIBVersionStr = rsuArray[i][RSUMIBVersionKey].asString(); | ||
config.mibVersion = strToMibVersion(rsuMIBVersionStr); | ||
} | ||
else | ||
{ | ||
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU MIB version [" + std::string(RSUMIBVersionKey) + "] is required."; | ||
throw RSUConfigurationException(errMsg); | ||
} | ||
tempConfigs.push_back(config); | ||
} | ||
// Only update RSU configurations when all configs are processed correctly. | ||
configs.clear(); | ||
configs.assign(tempConfigs.begin(), tempConfigs.end()); | ||
} | ||
|
||
RSUMibVersion RSUConfigurationList::strToMibVersion(std::string &mibVersionStr) const | ||
{ | ||
boost::trim_left(mibVersionStr); | ||
boost::trim_right(mibVersionStr); | ||
// Only support RSU MIB version 4.1 | ||
if (boost::iequals(mibVersionStr, RSU4_1_str)) | ||
{ | ||
return RSUMibVersion::RSUMIB_V_4_1; | ||
} | ||
else | ||
{ | ||
std::stringstream ss; | ||
ss << "Uknown RSU MIB version: " << mibVersionStr; | ||
throw RSUConfigurationException(ss.str().c_str()); | ||
} | ||
} | ||
|
||
std::vector<RSUConfiguration> RSUConfigurationList::getConfigs() const | ||
{ | ||
return configs; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &os, const RSUMibVersion &mib) | ||
{ | ||
const std::vector<std::string> nameMibs = {"UNKOWN MIB", | ||
"RSU4.1", | ||
"NTCIP1218"}; | ||
return os << nameMibs[static_cast<int>(mib)]; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &os, const RSUConfiguration &config) | ||
{ | ||
os << RSUIpKey << ": " << config.rsuIp << ", " << SNMPPortKey << ": " << config.snmpPort << ", " << UserKey << ": " << config.user << ", " << AuthPassPhraseKey << ": " << config.authPassPhrase << ", " << SecurityLevelKey << ": " << config.securityLevel << ", " << RSUMIBVersionKey << ": " << config.mibVersion; | ||
return os; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <jsoncpp/json/json.h> | ||
#include <boost/algorithm/string.hpp> | ||
#include "RSUConfigurationException.h" | ||
|
||
namespace RSUHealthMonitor | ||
{ | ||
static constexpr const char *RSUSKey = "RSUS"; | ||
static constexpr const char *RSUIpKey = "RSUIp"; | ||
static constexpr const char *SNMPPortKey = "SNMPPort"; | ||
static constexpr const char *UserKey = "User"; | ||
static constexpr const char *AuthPassPhraseKey = "AuthPassPhrase"; | ||
static constexpr const char *RSUMIBVersionKey = "RSUMIBVersion"; | ||
static constexpr const char *SecurityLevelKey = "SecurityLevel"; | ||
static constexpr const char *RSU4_1_str = "RSU4.1"; | ||
static constexpr const char *RSU1218_str = "RSU1218"; | ||
|
||
enum class RSUMibVersion | ||
{ | ||
UNKOWN_MIB_V = 0, | ||
RSUMIB_V_4_1 = 1, | ||
RSUMIB_V_1218 = 2 | ||
}; | ||
|
||
struct RSUConfiguration | ||
{ | ||
std::string rsuIp; | ||
uint16_t snmpPort; | ||
std::string user; | ||
std::string authPassPhrase; | ||
std::string securityLevel = "authPriv"; | ||
RSUMibVersion mibVersion; | ||
friend std::ostream &operator<<(std::ostream &os, const RSUConfiguration &config); | ||
}; | ||
|
||
class RSUConfigurationList | ||
{ | ||
private: | ||
std::vector<RSUConfiguration> configs; | ||
/*** | ||
* @brief Parse JSON string and return the corresponding JSON value. | ||
* @param rsuConfigsStr A JSON string includes all RSUs related configrations. | ||
* @return JSON::Value A JSON object that includes RSUS information. | ||
*/ | ||
Json::Value parseJson(const std::string &rsuConfigsStr) const; | ||
RSUMibVersion strToMibVersion(std::string &mibVersionStr) const; | ||
|
||
public: | ||
RSUConfigurationList() = default; | ||
~RSUConfigurationList() = default; | ||
/** | ||
* @brief Parse RSUs configrations in JSON string representation, and update the memeber of list of RSUConfiguration struct. | ||
* @param rsuConfigsStr A JSON string includes all RSUs related configrations. | ||
*/ | ||
void parseRSUs(const std::string &rsuConfigsStr); | ||
/** | ||
* @brief Get a list of RSUConfiguration struct. | ||
*/ | ||
std::vector<RSUConfiguration> getConfigs() const; | ||
}; | ||
|
||
} // namespace RSUHealthMonitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.