marker: drive uBridge enabled/pause/resume in real time

Wire gns3-server to uBridge's real-time marker controls (contract
../ubridge/doc/gns3server-integration.md §3.2), in three layers:

A. enabled reaches uBridge — _markers_for_node no longer drops disabled
   markers controller-side; it carries `enabled` in the NIO spec. apply
   installs every marker then issues `enable_packet_filter … off` for the
   disabled ones (base_node bridge / iou iol_bridge; old-ubridge errors
   downgrade to a warning so a toggle can't break link create).

B. instant per-filter toggle — apply records name→bridge so a new
   `_ubridge_set_marker_filter_state` can flip a running filter with
   `enable_packet_filter on|off` (iou overrides for iol_bridge + bay/unit).
   Each marker-capable node type gains PUT /markers/{name}; update_marker
   short-circuits to it when only `enabled` changes (no NIO rebuild, no pcap
   flush), falling back to reset+reapply if the route is unavailable.

C. global pause/resume — `_ubridge_marker_pause/resume` send `marker pause`
   / `marker resume` direct to the hypervisor (pause stops signal+pcap,
   resume instant, sink retained). Six node-type routes add POST
   /markers/pause|resume; project.pause_all/resume_all_markers fan out to
   each capture node (deduped, best-effort); REST exposes
   POST /projects/{id}/markers/pause|resume.

Toggling enabled and pause/resume are now both instant — only marker create
or a bpf change still go through reset+reapply.
This commit is contained in:
YueGuobin committed 2026-08-02 16:19:20 +08:00
1 parent 7368e4a65b
commit 3d06c4e22f
13 files changed
+404 -6

No files matched your search

+35 -5
View File
@@ -57,14 +57,17 @@ class UDPLink(Link):
def _markers_for_node(self, node):
"""
Marker specs (name -> {bpf, tag, link_id}) for the markers whose capture
side is ``node`` and that are enabled. Routed by capture_node_id so a
marker only rides the NIO of the node whose uBridge will host it.
Marker specs (name -> {bpf, tag, link_id, direction, enabled}) for the
markers whose capture side is ``node``. Routed by capture_node_id so a
marker only rides the NIO of the node whose uBridge will host it. A
disabled marker is included (installed then turned ``off`` at uBridge,
not dropped) so the UI can toggle it instantly without an NIO rebuild.
"""
return {
name: {"bpf": m["bpf"], "tag": m.get("tag"), "link_id": self._id, "direction": m.get("direction")}
name: {"bpf": m["bpf"], "tag": m.get("tag"), "link_id": self._id,
"direction": m.get("direction"), "enabled": m.get("enabled", True)}
for name, m in self._markers.items()
if m.get("enabled", True) and m.get("capture_node_id") == node.id
if m.get("capture_node_id") == node.id
}
def _get_node_markers(self, node1, node2):
@@ -457,6 +460,33 @@ class UDPLink(Link):
"Update it via the marker-definitions API instead."
)
# Instant toggle: when only `enabled` changes, send a single
# enable_packet_filter on|off to the capture node instead of rebuilding
# the whole NIO (no pcap flush, emitted counter preserved). Falls through
# to the full reset+reapply below if the compute route is unavailable.
only_enabled = (
enabled is not None
and bpf is None
and tag is None
and direction is _UNSET
and color is None
and highlight_duration is None
)
if only_enabled and self._created and not marker_info.get("inherited_from"):
capture_node_id = marker_info.get("capture_node_id")
side = next((s for s in self._nodes if str(s["node"].id) == str(capture_node_id)), None)
if side is not None:
try:
await side["node"].put(f"/markers/{name}", data={"enabled": enabled})
marker_info["enabled"] = enabled
self._project.emit_notification("link.updated", self.asdict())
self._project.dump()
return
except Exception:
# Old compute without the toggle route / node down: fall
# through to the full NIO reset+reapply below.
pass
if bpf is not None and bpf != marker_info["bpf"]:
result = validate_bpf_syntax(bpf)
if not result.get("valid"):