Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration parameters for RSUHealthMonitorPlugin #613

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/v2i-hub/RSUHealthMonitorPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
{
"key":"RSUConfigurationList",
"default":"{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }",
"default":"{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SecurityLevel\":\"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"},{ \"RSUIp\": \"192.168.00.XX\", \"SecurityLevel\":\"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"}] }",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is RSU Name or ID not the identifier? I think the RSU spec has snmp endpoints for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSUs specs does have RSU Name and ID. However, they usually have the same values across RSUs. We could use the RSUs specs, and that requires to update each individual RSUs setup either via SNMP request or some other ways. For the telematic tool purpose, I assume this is the least effort to meet the telematic requirement.

"description":"Configurations of the RSUs the V2X hub is connected to."
}
]
Expand Down
22 changes: 21 additions & 1 deletion src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ namespace RSUHealthMonitor
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU MIB version [" + std::string(RSUMIBVersionKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}

if (rsuArray[i].isMember(RSUIdentifierKey))
{
config.RSUIdentifier = rsuArray[i][RSUIdentifierKey].asString();
}
else
{
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU Identifier [" + std::string(RSUIdentifierKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}

if (rsuArray[i].isMember(SecurityLevelKey))
{
config.securityLevel = rsuArray[i][SecurityLevelKey].asString();
}
else
{
auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU Security Level [" + std::string(SecurityLevelKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}
tempConfigs.push_back(config);
}
// Only update RSU configurations when all configs are processed correctly.
Expand Down Expand Up @@ -122,7 +142,7 @@ namespace RSUHealthMonitor

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;
os << RSUIpKey << ": " << config.rsuIp << ", " << SNMPPortKey << ": " << config.snmpPort << ", " << UserKey << ": " << config.user << ", " << AuthPassPhraseKey << ": " << config.authPassPhrase << ", " << SecurityLevelKey << ": " << config.securityLevel << ", " << RSUMIBVersionKey << ": " << config.mibVersion << ", " << RSUIdentifierKey << ": " << config.RSUIdentifier;
return os;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace RSUHealthMonitor
static constexpr const char *SecurityLevelKey = "SecurityLevel";
static constexpr const char *RSU4_1_str = "RSU4.1";
static constexpr const char *RSU1218_str = "RSU1218";
static constexpr const char *RSUIdentifierKey = "RSUIdentifier";

enum class RSUMibVersion
{
Expand All @@ -31,8 +32,9 @@ namespace RSUHealthMonitor
uint16_t snmpPort;
std::string user;
std::string authPassPhrase;
std::string securityLevel = "authPriv";
std::string securityLevel;
RSUMibVersion mibVersion;
std::string RSUIdentifier;
friend std::ostream &operator<<(std::ostream &os, const RSUConfiguration &config);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace RSUHealthMonitor
for (auto rsuConfig : _rsuConfigListPtr->getConfigs())
{
auto rsuStatusJson = _rsuWorker->getRSUStatus(rsuConfig.mibVersion, rsuConfig.rsuIp, rsuConfig.snmpPort, rsuConfig.user, rsuConfig.authPassPhrase, rsuConfig.securityLevel, SEC_TO_MICRO);
rsuStatusJson[RSUIdentifierKey] = rsuConfig.RSUIdentifier;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we pulling this from the configuration, are we not setting this on the RSU?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to directly sent as part of the RSU status payload.

BroadcastRSUStatus(rsuStatusJson, rsuConfig.mibVersion);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,73 @@ namespace RSUHealthMonitor
TEST_F(test_RSUConfigurationList, parseAndGetConfigs)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"}] }";
rsuConfigList->parseRSUs(rsuConfigsStr);
ASSERT_EQ(2, rsuConfigList->getConfigs().size());
std::stringstream ss;
ss << rsuConfigList->getConfigs()[0];
std::string expected = "RSUIp: 192.168.XX.XX, SNMPPort: 161, User: authOnlyUser, AuthPassPhrase: dummy, SecurityLevel: authPriv, RSUMIBVersion: RSU4.1";
std::string expected = "RSUIp: 192.168.XX.XX, SNMPPort: 161, User: authOnlyUser, AuthPassPhrase: dummy, SecurityLevel: authPriv, RSUMIBVersion: RSU4.1, RSUIdentifier: NA";
ASSERT_EQ(expected, ss.str());
}
TEST_F(test_RSUConfigurationList, parseAndGetConfigs_MalformatJSON)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_RSUS)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"ERROR\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"ERROR\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"},{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"}] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_SNMPPORT)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort_Missing\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort_Missing\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_INVALID_SNMPPORT)
{
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.01.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"INVALID_PORT\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.01.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"INVALID_PORT\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_AuthPassPhrase)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase_Missing\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase_Missing\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_User)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User_Missing\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User_Missing\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_MibVersion)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion_Missing\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion_Missing\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}

TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Invalid_MibVersion)
{
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"INVALID_RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }";
std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"INVALID_RSU4.1\" ,\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\" }] }";
ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException);
ASSERT_EQ(0, rsuConfigList->getConfigs().size());
}
Expand Down
Loading