mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
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:
13 files changed
+404
-6
No files matched your search
@@ -924,6 +924,41 @@ class Project:
|
||||
}
|
||||
return result
|
||||
|
||||
async def pause_all_markers(self):
|
||||
"""
|
||||
Pause marker signal+pcap emission on every node hosting a marker
|
||||
(``marker pause`` per capture node's uBridge). Node-deduplicated and
|
||||
best-effort: a node hosting markers on several links is paused once,
|
||||
and a node that is down or running an old compute is skipped.
|
||||
"""
|
||||
|
||||
seen = set()
|
||||
for link in list(self._links.values()):
|
||||
for info in link.markers.values():
|
||||
node_id = info.get("capture_node_id")
|
||||
if not node_id or node_id in seen:
|
||||
continue
|
||||
seen.add(node_id)
|
||||
try:
|
||||
await self.get_node(node_id).post("/markers/pause")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def resume_all_markers(self):
|
||||
"""Resume marker signal+pcap emission on every marker-hosting node."""
|
||||
|
||||
seen = set()
|
||||
for link in list(self._links.values()):
|
||||
for info in link.markers.values():
|
||||
node_id = info.get("capture_node_id")
|
||||
if not node_id or node_id in seen:
|
||||
continue
|
||||
seen.add(node_id)
|
||||
try:
|
||||
await self.get_node(node_id).post("/markers/resume")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@property
|
||||
def marker_definitions(self):
|
||||
"""
|
||||
|
||||
@@ -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"):
|
||||
|
||||
Reference in new issue
Block a user