Skip to content

tools for creating network maps - #1174

Open
davidelang wants to merge 1 commit into
masterfrom
update-lldp-maps
Open

tools for creating network maps#1174
davidelang wants to merge 1 commit into
masterfrom
update-lldp-maps

Conversation

@davidelang

@davidelang davidelang commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

This script creates maps that show the network connectivity.


4 +

it is designed to be run from scale-network/swich-configuration/configs

5 +

it runs scripts/gather_lldp_map_data to the file map.parts

6 +

map.parts contains distilled lldp data showing what each device can hear

7 +

This includes a fixup defined in scripts/make_lldp_map.sed that should not be needed if the csv router definitions match their hostnames

8 +

There is also currently a bug in that the pi kiosk images don't set their hostnames via dhcp so they all show up as pi or pi-monitoring. they need to all get a unique name for the diagram

9 +

10 +

The format is:

11 +

host interface remote

12 +

13 +

scripts/make_lldp_map.py then takes this data and creates a .diag file

14 +

that can then be used by blockdiag to create the images.

15 +

you tell it which node to start with (the border router) and things external to that are shown as clouds

Copilot AI review requested due to automatic review settings March 6, 2026 21:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new WiFi scan “gather” utility under facts/aps/ to collect iwinfo status and iwinfo <iface> scan results from many OpenWrt APs over SSH, producing prefixed output intended for later analysis.

Changes:

  • Introduces facts/aps/gather-wifi-scans.py, a CLI tool that reads AP IPs from a CSV and sequentially SSHes into each AP to run iwinfo and per-radio scans.
  • Adds CSV column selection and regex-based row filtering, plus output-to-file and verbose progress reporting options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
Comment thread facts/aps/gather-wifi-scans.py Outdated
@davidelang davidelang changed the title tools for analyzing wifi network tools for creating network maps Mar 7, 2026
@davidelang
davidelang requested a review from Copilot March 7, 2026 01:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

for n in internal_starts:
levels[n] = 1
visited.add(n)
queue.append(n)

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

internal_starts are already enqueued via queue = deque(internal_starts) above, but this loop appends each n again, causing duplicate BFS work. Initialize queue empty and append inside the loop, or keep the deque(internal_starts) initialization and remove the queue.append(n) here.

Suggested change
queue.append(n)

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +84
# Identify external nodes: neighbors of starting with degree 1 (only connected to starting)
externals = [nb for nb in G.neighbors(starting) if G.degree(nb) == 1]

# Internal starting points: other neighbors of starting (not externals)
internal_starts = [nb for nb in G.neighbors(starting) if nb not in externals]

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

If starting_node is not present in the input data, G.neighbors(starting) will raise and the script exits with a traceback. Consider explicitly checking if starting not in G after parsing input and exiting with a clear error (or adding the starting node with no edges).

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +52
edges = [] # List of (A, B) pairs for later processing

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

edges is accumulated but never used (the graph is built from G directly). Removing this dead variable (and the append in the input loop) will reduce confusion and keep the script focused.

Copilot uses AI. Check for mistakes.

/usr/bin/blockdiag3 map.diag -T png -o map.png
/usr/bin/blockdiag3 map.diag -T svg -o map.svg
scripts/make_lldp_map.py br-mdf-01 map.parts

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

blockdiag is invoked here, but it does not appear to be provided by the repo's Nix devShell packages. If this script is expected to be runnable in the standard dev environment, consider adding blockdiag to the Nix shell (or documenting the required external dependency).

Suggested change
scripts/make_lldp_map.py br-mdf-01 map.parts
scripts/make_lldp_map.py br-mdf-01 map.parts
# Ensure required external dependency is available before generating diagrams.
if ! command -v blockdiag >/dev/null 2>&1; then
echo "Error: 'blockdiag' is required to generate network diagrams but is not installed or not in PATH." >&2
echo "Please install 'blockdiag' in your environment or add it to the Nix devShell packages." >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
do
echo "$name $line"
done
done |sed s/"\/"/-/g| tr "[A-Z]" "[a-z]" | while read host if p id rest; do name=`echo "$rest"|sed s/"^.* "//`; notname=`echo "$rest" |sed s/" [^ ]*$"//`; echo "$host $if $name"; done

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

This pipeline uses legacy backticks and unquoted expansions (e.g., name=echo "$rest"|...``), which is harder to read and can mis-handle values containing whitespace or backslashes. Prefer $(...), add `read -r`, and quote variables in these substitutions to make the parsing more robust.

Suggested change
done |sed s/"\/"/-/g| tr "[A-Z]" "[a-z]" | while read host if p id rest; do name=`echo "$rest"|sed s/"^.* "//`; notname=`echo "$rest" |sed s/" [^ ]*$"//`; echo "$host $if $name"; done
done |sed s/"\/"/-/g| tr "[A-Z]" "[a-z]" | while read -r host if p id rest; do name=$(echo "$rest" | sed 's/^.* //'); notname=$(echo "$rest" | sed 's/ [^ ]*$//'); echo "$host $if $name"; done

Copilot uses AI. Check for mistakes.
echo "$ip $line"
done
done |tee map.lldp
echo "There is also currently a bug in that the pi kiosk images don't set their hostnames via dhcp so they all show up as pi or pi-monitoring. they need to all get a unique name for the diagram. Manually edit map.parts"

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

This message instructs the user to manually edit map.parts, but the script immediately proceeds to generate the diagram in the next steps. Either pause/exit after printing this (so the user can edit before rendering) or reword the message to indicate they must re-run the later commands after editing.

Suggested change
echo "There is also currently a bug in that the pi kiosk images don't set their hostnames via dhcp so they all show up as pi or pi-monitoring. they need to all get a unique name for the diagram. Manually edit map.parts"
echo "There is also currently a bug in that the pi kiosk images don't set their hostnames via DHCP, so they all show up as pi or pi-monitoring. They need to all get a unique name for the diagram; if necessary, edit map.parts to correct the hostnames before (re)running the diagram-generation commands."

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,196 @@
#!/usr/bin/python3

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

The shebang uses an absolute /usr/bin/python3, which often doesn't exist in Nix/NixOS environments (Python is on PATH but not at that location). Use #!/usr/bin/env python3 (or invoke via python3 scripts/make_lldp_map.py ...) to make the script runnable in the repo’s typical tooling environments.

Suggested change
#!/usr/bin/python3
#!/usr/bin/env python3

Copilot uses AI. Check for mistakes.
#!/usr/bin/python3
import sys
import argparse
import networkx as nx

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

This script introduces a runtime dependency on networkx, but the repo's Nix devShell scalePython doesn't include it (only pytest/pylint/ipdb/jinja2/pandas). Either vendor/remove this dependency, document the required install, or add networkx to the Nix shell so scripts/make_lldp_map.py runs out-of-the-box.

Suggested change
import networkx as nx
try:
import networkx as nx
except ImportError:
sys.stderr.write(
"Error: The 'networkx' package is required to run make_lldp_map.py.\n"
"Install it with 'pip install networkx' or add it to the 'scalePython' Nix devShell.\n"
)
sys.exit(1)

Copilot uses AI. Check for mistakes.
#This goes through all switches in switchtypes, connects to them and gets a LLDP dump of what's connected to them.
#
# This script creates maps that show the network connectivity.
# it is designed to be run from scale-network/swich-configuration/configs

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

The run location in this comment appears to be wrong for this repo layout: there is switch-configuration/config/ but no switch-configuration/configs/, and the path is misspelled as swich-configuration. Update the comment so it points to the correct directory where switchtypes and scripts/ live.

Suggested change
# it is designed to be run from scale-network/swich-configuration/configs
# it is designed to be run from scale-network/switch-configuration/config

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants