Skip to content

Commit

Permalink
Add /unstable/controller/network endpoint
Browse files Browse the repository at this point in the history
Similar to /unstable/controller/network/{id}/member, it returns actual network objects,
instead of just network ids.
Also includes the total network count,
and each network has it's member counts in meta{}.
  • Loading branch information
laduke committed Feb 1, 2024
1 parent 1554bea commit 99223f0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions controller/EmbeddedNetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
// Control plane Endpoints
std::string controllerPath = "/controller";
std::string networkListPath = "/controller/network";
std::string networkListPath2 = "/unstable/controller/network";
std::string networkPath = "/controller/network/([0-9a-fA-F]{16})";
std::string oldAndBustedNetworkCreatePath = "/controller/network/([0-9a-fA-F]{10})______";
std::string memberListPath = "/controller/network/([0-9a-fA-F]{16})/member";
Expand Down Expand Up @@ -911,6 +912,48 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Get(networkListPath, networkListGet);
sv6.Get(networkListPath, networkListGet);

auto networkListGet2 = [&, setContent](const httplib::Request &req, httplib::Response &res) {
std::set<uint64_t> networkIds;
_db.networks(networkIds);

auto meta = json::object();
auto data = json::array();

for(std::set<uint64_t>::const_iterator nwid(networkIds.begin()); nwid != networkIds.end(); ++nwid) {
json network;
if (!_db.get(*nwid, network)) {
continue;
}

std::vector<json> memTmp;
if (_db.get(*nwid, network, memTmp)) {
uint64_t authorizedCount = 0;
uint64_t totalCount = memTmp.size();

for (auto m = memTmp.begin(); m != memTmp.end(); ++m) {
bool a = OSUtils::jsonBool((*m)["authorized"], 0);
if (a) { authorizedCount++; }
}

auto nwMeta = json::object();
nwMeta["totalMemberCount"] = totalCount;
nwMeta["authorizedMemberCount"] = authorizedCount;
network["meta"] = nwMeta;
}

data.push_back(network);
}
meta["networkCount"] = networkIds.size();

auto out = json::object();
out["data"] = data;
out["meta"] = meta;

setContent(req, res, out.dump());
};
s.Get(networkListPath2, networkListGet2);
sv6.Get(networkListPath2, networkListGet2);

auto networkGet = [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
Expand Down

0 comments on commit 99223f0

Please sign in to comment.