Skip to content

Commit

Permalink
[web] topology visualization (#519)
Browse files Browse the repository at this point in the history
This is the first PR of OpenThread Network Manager.

In general, it implements a new module -- OTBR-REST, which is directly
embedded in OTBR-AGENT and provides RESTful API for a new feature of
WEB UI -- Topology Visualization.

Topology Visualization aims to collect diagnostic information of all
nodes in current network, visualize their relations and provide the
display of all the details.

The frontend part is implemented based on the frontend of OTBR-WEB for
the time being. We will then implement all the functionality OTBR-WEB
provides and transplant the frontend static file of OTBR-WEB in this
module.
  • Loading branch information
tttttangTH committed Sep 2, 2020
1 parent bc8825d commit ea9cd69
Show file tree
Hide file tree
Showing 41 changed files with 4,596 additions and 14 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ jobs:
run: script/test build check
- name: Codecov
uses: codecov/codecov-action@v1

rest-check:
runs-on: ubuntu-18.04
strategy:
matrix:
rest: ["rest", ""]
env:
BUILD_TARGET: check
OTBR_REST: ${{ matrix.rest }}
OTBR_COVERAGE: 1
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Bootstrap
run: tests/scripts/bootstrap.sh
- name: Run
run: script/test build check
- name: Codecov
uses: codecov/codecov-action@v1

script-check:
runs-on: ubuntu-18.04
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
path = third_party/openthread/repo
url = https://github.com/openthread/openthread.git
branch = master
[submodule "third_party/cJSON/repo"]
path = third_party/cJSON/repo
url = https://github.com/DaveGamble/cJSON.git
[submodule "third_party/http-parser/repo"]
path = third_party/http-parser/repo
url = https://github.com/nodejs/http-parser.git
[submodule "third_party/d3js/repo"]
path = third_party/d3js/repo
url = https://github.com/d3/d3.git
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ option(OTBR_DBUS "Build DBus support" OFF)
option(OTBR_OPENWRT "Build OpenWrt support" OFF)
option(OTBR_UNSECURE_JOIN "Enable unsecure joining" OFF)
option(OTBR_WEB "Build Web GUI" OFF)
option(OTBR_REST "Build Rest Server" OFF)


if(NOT CMAKE_C_STANDARD)
Expand Down Expand Up @@ -98,6 +99,12 @@ if(OTBR_DBUS)
)
endif()

if(OTBR_REST)
target_compile_definitions(otbr-config INTERFACE
OTBR_ENABLE_REST_SERVER=1
)
endif()

if(OTBR_WEB)
pkg_check_modules(JSONCPP jsoncpp REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
Expand Down
1 change: 1 addition & 0 deletions script/_otbr
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ otbr_install()
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DOTBR_DBUS=ON"
"-DOTBR_WEB=ON"
"-DOTBR_REST=ON"
"${otbr_options[@]}"
)

Expand Down
5 changes: 5 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ readonly QUIET=${QUIET:-1}

readonly OTBR_COVERAGE="${OTBR_COVERAGE:-0}"
readonly OTBR_MDNS="${OTBR_MDNS:-}"
readonly OTBR_REST="${OTBR_REST:-}"
readonly OTBR_OPTIONS="${OTBR_OPTIONS:-}"
readonly OTBR_TOP_SRCDIR="$PWD"
readonly OTBR_TOP_BUILDDIR="${BUILD_DIR}/otbr"
Expand Down Expand Up @@ -146,6 +147,9 @@ do_prepare()
if [[ ${OTBR_COVERAGE} == 1 ]]; then
otbr_options+=("-DOTBR_COVERAGE=ON")
fi
if [[ ${OTBR_REST} == "rest" ]]; then
otbr_options+=("-DOTBR_REST=ON")
fi
}

do_package()
Expand All @@ -154,6 +158,7 @@ do_package()
"-DBUILD_TESTING=OFF"
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DCMAKE_BUILD_TYPE=Release"
"-DOTBR_REST=ON"
"-DOTBR_WEB=ON"
${otbr_options[@]+"${otbr_options[@]}"}
)
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ endif()
if(OTBR_WEB)
add_subdirectory(web)
endif()

if(OTBR_REST)
add_subdirectory(rest)
endif()

1 change: 1 addition & 0 deletions src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_link_libraries(otbr-agent PRIVATE
$<$<BOOL:${OTBR_DBUS}>:otbr-dbus-server>
$<$<BOOL:${OTBR_MDNS}>:otbr-mdns>
$<$<BOOL:${OTBR_OPENWRT}>:otbr-ubus>
$<$<BOOL:${OTBR_REST}>:otbr-rest>
openthread-cli-ftd
openthread-ftd
openthread-posix
Expand Down
23 changes: 19 additions & 4 deletions src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@

#include "agent/agent_instance.hpp"
#include "agent/ncp.hpp"
#include "agent/ncp_openthread.hpp"
#include "common/code_utils.hpp"
#include "common/logging.hpp"
#include "common/types.hpp"

#include "agent/ncp_openthread.hpp"
#if OTBR_ENABLE_REST_SERVER
#include "rest/rest_web_server.hpp"
using otbr::rest::RestWebServer;
#endif
#if OTBR_ENABLE_DBUS_SERVER
#include "dbus/server/dbus_agent.hpp"
using otbr::DBus::DBusAgent;
Expand Down Expand Up @@ -98,13 +101,16 @@ static int Mainloop(otbr::AgentInstance &aInstance, const char *aInterfaceName)
#if OTBR_ENABLE_DBUS_SERVER
ControllerOpenThread * ncpOpenThread = reinterpret_cast<ControllerOpenThread *>(&aInstance.GetNcp());
std::unique_ptr<DBusAgent> dbusAgent = std::unique_ptr<DBusAgent>(new DBusAgent(aInterfaceName, ncpOpenThread));

dbusAgent->Init();
#else
(void)aInterfaceName;
#endif
#if OTBR_ENABLE_REST_SERVER
ControllerOpenThread *ncpOpenThreadRest = reinterpret_cast<ControllerOpenThread *>(&aInstance.GetNcp());
RestWebServer * restServer = RestWebServer::GetRestWebServer(ncpOpenThreadRest);
restServer->Init();
#endif
otbrLog(OTBR_LOG_INFO, "Border router agent started.");

// allow quitting elegantly
signal(SIGTERM, HandleSignal);

Expand All @@ -127,6 +133,10 @@ static int Mainloop(otbr::AgentInstance &aInstance, const char *aInterfaceName)
mainloop.mTimeout);
#endif

#if OTBR_ENABLE_REST_SERVER
restServer->UpdateFdSet(mainloop);
#endif

#if OTBR_ENABLE_OPENWRT
UbusUpdateFdSet(mainloop.mReadFdSet, mainloop.mMaxFd);
sThreadMutex.unlock();
Expand All @@ -149,6 +159,11 @@ static int Mainloop(otbr::AgentInstance &aInstance, const char *aInterfaceName)
sThreadMutex.lock();
UbusProcess(mainloop.mReadFdSet);
#endif

#if OTBR_ENABLE_REST_SERVER
restServer->Process(mainloop);
#endif

aInstance.Process(mainloop);

#if OTBR_ENABLE_DBUS_SERVER
Expand Down
1 change: 1 addition & 0 deletions src/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum otbrError
OTBR_ERROR_DBUS = -2, ///< DBus error.
OTBR_ERROR_MDNS = -3, ///< MDNS error.
OTBR_ERROR_OPENTHREAD = -4, ///< OpenThread error.
OTBR_ERROR_REST = -5 ///< Rest Server error.
};

namespace otbr {
Expand Down
48 changes: 48 additions & 0 deletions src/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

add_library( otbr-rest
rest_web_server.cpp
connection.cpp
resource.cpp
json.cpp
parser.cpp
request.cpp
response.cpp
)

target_link_libraries(otbr-rest
PUBLIC
http_parser
PRIVATE
cjson
otbr-config
otbr-utils
openthread-ftd
openthread-posix
)
Loading

0 comments on commit ea9cd69

Please sign in to comment.