Skip to content

Commit

Permalink
[feature] Added WiFi mesh integration #170
Browse files Browse the repository at this point in the history
Closes #170
  • Loading branch information
pandafy committed Jun 13, 2023
1 parent 82c9118 commit e363f0b
Show file tree
Hide file tree
Showing 26 changed files with 1,367 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ omit =
/*/__init__.py
/setup.py
/*/migrations/*
source = openwisp_network_topology
parallel = true
concurrency = multiprocessing
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
build:
name: Python==${{ matrix.python-version }} | ${{ matrix.django-version }}
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04

strategy:
fail-fast: false
Expand All @@ -26,6 +26,18 @@ jobs:
- django~=4.0.0

steps:
- name: Install system packages
run: |
sudo apt update &&
sudo apt -qq install \
sqlite3 \
gdal-bin \
libproj-dev \
libgeos-dev \
libspatialite-dev \
spatialite-bin \
libsqlite3-mod-spatialite
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
Expand All @@ -45,6 +57,9 @@ jobs:
- name: Install python system packages
run: pip install -U pip wheel setuptools

- name: Start InfluxDB and Redis container
run: docker-compose up -d influxdb redis

- name: Install test dependencies
run: |
pip install -U -r requirements-test.txt
Expand All @@ -59,7 +74,9 @@ jobs:

- name: Tests
run: |
coverage run --source=openwisp_network_topology runtests.py
coverage run runtests.py --parallel
WIFI_MESH=1 coverage run runtests.py
coverage combine
SAMPLE_APP=1 ./runtests.py --parallel --keepdb
- name: Upload Coverage
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage*
.cache
nosetests.xml
coverage.xml
Expand Down
72 changes: 71 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ Install sqlite:

.. code-block:: shell
sudo apt-get install sqlite3 libsqlite3-dev
sudo apt install -y sqlite3 libsqlite3-dev
# Install system dependencies for spatialite which is required
# to run tests for openwisp-network-topology integrations with
# openwisp-controller and openwisp-monitoring.
sudo apt install libspatialite-dev libsqlite3-mod-spatialite
Install your forked repo:

Expand All @@ -176,6 +180,14 @@ Install your forked repo:
cd openwisp-network-topology/
python setup.py develop
Start InfluxDB and Redis using Docker
(required by the test project to run tests for
`WiFi Mesh Integration <#openwisp_network_topology_wifi_mesh_integration>`_):

.. code-block:: shell
docker-compose up -d influxdb redis
Install test requirements:

.. code-block:: shell
Expand All @@ -196,7 +208,14 @@ Run tests with:

.. code-block:: shell
# Running tests without setting the "WIFI_MESH" environment
# variable will not run tests for WiFi Mesh integration.
# This is done to avoid slowing down the test suite by adding
# dependencies which are only used by the integration.
./runtests.py
# You can run the tests only for WiFi mesh integration using
# the following command
WIFI_MESH=1 ./runtests.py
Run qa tests:

Expand Down Expand Up @@ -446,6 +465,12 @@ This additional and optional module provides the following features:
- the management IP address of the related device is updated straightaway
- if OpenWISP Monitoring is enabled, the device checks are triggered (e.g.: ping)

- if `OpenWISP Monitoring <https://github.com/openwisp/openwisp-monitoring>`_
is installed and enabled, the system can automatically create topology
for the WiFi Mesh (802.11s) interfaces using the monitoring data provided by the agent.
You can enable this by setting `OPENWISP_NETWORK_TOPOLOGY_WIFI_MESH_INTEGRATION
<#openwisp_network_topology_wifi_mesh_integration>`_ to ``True``.

This integration makes the whole system a lot faster in detecting important events in the network.

In order to use this module simply add
Expand All @@ -464,6 +489,31 @@ In order to use this module simply add
'rest_framework',
]
If you have enabled WiFI Mesh integration, you will also need to update the
``CELERY_BEAT_SCHEDULE`` as follow:

.. code-block:: python
CELERY_BEAT_SCHEDULE = {
'create_mesh_topology': {
# This task generates the mesh topology from monitoring data
'task': 'openwisp_network_topology.integrations.device.tasks.create_mesh_topology',
# Execute this task every 5 minutes
'schedule': timedelta(minutes=5),
'args': (
# List of organization UUIDs. The mesh topology will be
# created only for devices belonging these organizations.
[
'4e002f97-eb01-4371-a4a8-857faa22fe5c',
'be88d4c4-599a-4ca2-a1c0-3839b4fdc315'
],
# The task won't use monitoring data reported
# before this time (in seconds)
6 * 60 # 6 minutes
),
},
}
If you are enabling this integration on a pre-existing system, use the
`create_device_nodes <#create-device-nodes>`_ management command to create
the relationship between devices and nodes.
Expand Down Expand Up @@ -586,6 +636,25 @@ When enabled, the API `endpoints <#list-of-endpoints>`_ will only allow authenti
who have the necessary permissions to access the objects which
belong to the organizations the user manages.

``OPENWISP_NETWORK_TOPOLOGY_WIFI_MESH_INTEGRATION``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

+--------------+---------------+
| **type**: | ``boolean`` |
+--------------+---------------+
| **default**: | ``False`` |
+--------------+---------------+

When enabled, network topology objects will be automatically created and
updated based on the WiFi mesh interfaces peer information supplied
by the monitoring agent.

**Note:** The network topology objects are created using the device monitoring data
collected by OpenWISP Monitoring. Thus, it requires
`integration with OpenWISP Controller and OpenWISP Monitoring
<#integration-with-openwisp-controller-and-openwisp-monitoring>`_ to be enabled
in the Django project.

Rest API
--------

Expand Down Expand Up @@ -1070,6 +1139,7 @@ Once you have created the models, add the following to your ``settings.py``:
TOPOLOGY_TOPOLOGY_MODEL = 'sample_network_topology.Topology'
# if you use the integration with OpenWISP Controller and/or OpenWISP Monitoring
TOPOLOGY_DEVICE_DEVICENODE_MODEL = 'sample_integration_device.DeviceNode'
TOPOLOGY_DEVICE_WIFIMESH_MODEL = 'sample_integration_device.WifiMesh'
Substitute ``sample_network_topology`` with the name you chose in step 1.

Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"

services:
influxdb:
image: influxdb:1.8-alpine
volumes:
- influxdb-data:/var/lib/influxdb
ports:
- "8086:8086"
environment:
INFLUXDB_DB: openwisp2
INFLUXDB_USER: openwisp
INFLUXDB_USER_PASSWORD: openwisp

redis:
image: redis:alpine
ports:
- "6379:6379"
entrypoint: redis-server --appendonly yes

volumes:
influxdb-data: {}
19 changes: 19 additions & 0 deletions openwisp_network_topology/integrations/device/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.contrib import admin
from swapper import load_model

from openwisp_network_topology.admin import TopologyAdmin

from . import settings as app_settings

WifiMesh = load_model('topology_device', 'WifiMesh')
Topology = load_model('topology', 'Topology')


class WifiMeshInlineAdmin(admin.StackedInline):
model = WifiMesh
extra = 0
max_num = 1


if app_settings.WIFI_MESH_INTEGRATION:
TopologyAdmin.inlines = TopologyAdmin.inlines + [WifiMeshInlineAdmin]
Loading

0 comments on commit e363f0b

Please sign in to comment.