Skip to content

Commit

Permalink
Merge pull request #375 from Telecominfraproject/ols-246-feat-cable-diag
Browse files Browse the repository at this point in the history
OLS-246: feat: add cable diagnostics command
  • Loading branch information
i-chvets authored Sep 18, 2024
2 parents a97d49a + b3deba5 commit 596cfd4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/RESTAPI/RESTAPI_device_commandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace OpenWifi {
{APCommands::Commands::script, false, true, &RESTAPI_device_commandHandler::Script, 60000ms},
{APCommands::Commands::powercycle, false, true, &RESTAPI_device_commandHandler::PowerCycle, 60000ms},
{APCommands::Commands::fixedconfig, false, true, &RESTAPI_device_commandHandler::FixedConfig, 120000ms},
{APCommands::Commands::cablediagnostics, false, true, &RESTAPI_device_commandHandler::CableDiagnostics, 120000ms},

};

Expand Down Expand Up @@ -1587,4 +1588,45 @@ namespace OpenWifi {
*ParsedBody_, *Request, *Response, timeout, nullptr, this,
Logger_);
}

void RESTAPI_device_commandHandler::CableDiagnostics(
const std::string &CMD_UUID, uint64_t CMD_RPC,
[[maybe_unused]] std::chrono::milliseconds timeout,
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {

if(UserInfo_.userinfo.userRole != SecurityObjects::ROOT &&
UserInfo_.userinfo.userRole != SecurityObjects::ADMIN) {
CallCanceled("CABLEDIAGNOSTICS", CMD_UUID, CMD_RPC, RESTAPI::Errors::ACCESS_DENIED);
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}

poco_debug(Logger_, fmt::format("CABLEDIAGNOSTICS({},{}): TID={} user={} serial={}", CMD_UUID,
CMD_RPC, TransactionId_, Requester(), SerialNumber_));

if(IsDeviceSimulated(SerialNumber_)) {
CallCanceled("CABLEDIAGNOSTICS", CMD_UUID, CMD_RPC, RESTAPI::Errors::SimulatedDeviceNotSupported);
return BadRequest(RESTAPI::Errors::SimulatedDeviceNotSupported);
}

GWObjects::CableDiagnostics PR;
if(!PR.from_json(ParsedBody_)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}

GWObjects::CommandDetails Cmd;
Cmd.SerialNumber = SerialNumber_;
Cmd.SubmittedBy = Requester();
Cmd.UUID = CMD_UUID;
Cmd.Command = uCentralProtocol::CABLEDIAGNOSTICS;
std::ostringstream os;
ParsedBody_->stringify(os);
Cmd.Details = os.str();
Cmd.RunAt = PR.when;
Cmd.ErrorCode = 0;
Cmd.WaitingForFile = 0;

return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::cablediagnostics, false, Cmd,
*ParsedBody_, *Request, *Response, timeout, nullptr, this,
Logger_);
}
} // namespace OpenWifi
2 changes: 2 additions & 0 deletions src/RESTAPI/RESTAPI_device_commandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace OpenWifi {
const GWObjects::DeviceRestrictions &R);
void FixedConfig(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);
void CableDiagnostics(const std::string &UUID, uint64_t RPC, std::chrono::milliseconds timeout,
const GWObjects::DeviceRestrictions &R);

static auto PathName() {
return std::list<std::string>{"/api/v1/device/{serialNumber}/{command}"};
Expand Down
11 changes: 11 additions & 0 deletions src/RESTObjects/RESTAPI_GWobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,4 +808,15 @@ namespace OpenWifi::GWObjects {
}
return false;
}

bool CableDiagnostics::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serial", serialNumber);
field_from_json(Obj, "when", when);
field_from_json(Obj, "ports", ports);
return true;
} catch (const Poco::Exception &E) {
}
return false;
}
} // namespace OpenWifi::GWObjects
7 changes: 7 additions & 0 deletions src/RESTObjects/RESTAPI_GWobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,13 @@ namespace OpenWifi::GWObjects {
std::string serialNumber;
std::string country;

bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct CableDiagnostics {
std::string serialNumber;
std::uint64_t when;
std::vector<std::string> ports;

bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
} // namespace OpenWifi::GWObjects
5 changes: 4 additions & 1 deletion src/framework/ow_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ namespace OpenWifi::RESTAPI::Protocol {
static const char *BANDWIDTH = "bandwidth";

static const char *FIXEDCONFIG = "fixedconfig";
static const char *CABLEDIAGNOSTICS = "cablediagnostics";
} // namespace OpenWifi::RESTAPI::Protocol

namespace OpenWifi::uCentralProtocol {
Expand Down Expand Up @@ -695,6 +696,7 @@ namespace OpenWifi::uCentralProtocol {
static const char *ACTIONS = "actions";

static const char *FIXEDCONFIG = "fixedconfig";
static const char *CABLEDIAGNOSTICS = "cablediagnostics";

} // namespace OpenWifi::uCentralProtocol

Expand Down Expand Up @@ -793,6 +795,7 @@ namespace OpenWifi::APCommands {
transfer,
powercycle,
fixedconfig,
cablediagnostics,
unknown
};

Expand All @@ -808,7 +811,7 @@ namespace OpenWifi::APCommands {
RESTAPI::Protocol::PING, RESTAPI::Protocol::SCRIPT,
RESTAPI::Protocol::RRM, RESTAPI::Protocol::CERTUPDATE,
RESTAPI::Protocol::TRANSFER, RESTAPI::Protocol::POWERCYCLE,
RESTAPI::Protocol::FIXEDCONFIG
RESTAPI::Protocol::FIXEDCONFIG, RESTAPI::Protocol::CABLEDIAGNOSTICS
};

inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; }
Expand Down

0 comments on commit 596cfd4

Please sign in to comment.