fix(marker): ride markers on NIO so they survive node restart and project reload

Mirror the packet-filter lifecycle: marker specs now live on the NIO
(next to filters), ride in link_data from controller to compute on
every NIO create/update, and are reapplied by _ubridge_apply_markers
in add_ubridge_udp_connection (bridge creation / node restart) and
update_ubridge_udp_connection (NIO update — following the preceding
reset_packet_filters so markers survive filter changes).

Changes:
- NIO / NIOUDP: _markers property + asdict
- schemas/compute/nios.py: UDPNIO.markers field
- base_manager.create_nio: nio.markers from settings
- PUT /nio routes (vpcs/qemu/docker): nio.markers update
- base_node: _ubridge_apply_markers(bridge_name, nio) iterates
  nio.markers, computes pcap path, calls _ubridge_add_marker_filter
  + MarkerManager.register; called after _ubridge_apply_filters
- controller udp_link: _get_node_markers + _markers_for_node (route
  by capture_node_id); markers in create() and update() link_data
- /markers/start,stop endpoints: mirror spec onto nio.markers so
  the marker survives a subsequent node stop/start without a PUT
- tests: add markers field to NIO data expectations

This covers:
- Node restart: NIO persists, add_ubridge_udp_connection re-applies
- Filter update: reset wipes markers, _ubridge_apply_markers re-adds
- Project reload: create() carries markers in link_data → create_nio
- Immediate create: endpoint sets nio.markers immediately
This commit is contained in:
YueGuobin committed 2026-07-16 00:39:51 +08:00
1 parent 540e1c5678
commit 7c90fa9e64
10 files changed
+123 -2

No files matched your search

+1
View File
@@ -356,6 +356,7 @@ class BaseManager:
raise ComputeError(f"Could not create an UDP connection to {rhost}:{rport}: {e}")
nio = NIOUDP(lport, rhost, rport)
nio.filters = nio_settings.get("filters", {})
nio.markers = nio_settings.get("markers", {})
nio.suspend = nio_settings.get("suspend", False)
elif nio_settings["type"] == "nio_tap":
tap_device = nio_settings["tap_device"]
+30
View File
@@ -1012,10 +1012,12 @@ class BaseNode:
await self._ubridge_send(f"bridge start {bridge_name}")
await self._ubridge_apply_filters(bridge_name, destination_nio.filters)
await self._ubridge_apply_markers(bridge_name, destination_nio)
async def update_ubridge_udp_connection(self, bridge_name, source_nio, destination_nio):
if destination_nio:
await self._ubridge_apply_filters(bridge_name, destination_nio.filters)
await self._ubridge_apply_markers(bridge_name, destination_nio)
async def ubridge_delete_bridge(self, name):
"""
@@ -1112,6 +1114,34 @@ class BaseNode:
await self._ubridge_send(f"bridge delete_packet_filter {bridge_name} {name}")
async def _ubridge_apply_markers(self, bridge_name, nio):
"""
(Re-)apply every traffic-insight marker carried by *nio* to the uBridge
bridge *bridge_name*. Called from ``add_ubridge_udp_connection`` (bridge
creation / node restart) and ``update_ubridge_udp_connection`` (NIO update
— the preceding ``_ubridge_apply_filters`` has already issued
``reset_packet_filters``, so we must re-add markers to survive the reset).
"""
from gns3server.compute.marker.marker_manager import MarkerManager
markers = nio.markers if hasattr(nio, 'markers') else {}
if not markers:
return
manager = MarkerManager.instance()
markers_dir = self.project.markers_working_directory()
for name, spec in markers.items():
bpf = spec.get("bpf", "")
tag = spec.get("tag")
link_id = spec.get("link_id", "")
pcap_path = os.path.join(
markers_dir, f"{self._id}_{link_id}_{name}.pcap"
)
await self._ubridge_add_marker_filter(bridge_name, name, bpf, pcap_path, tag)
manager.register(
str(self.project.id), self._id, name, link_id, tag
)
async def _add_ubridge_ethernet_connection(self, bridge_name, ethernet_interface, block_host_traffic=False):
"""
Creates a connection with an Ethernet interface in uBridge.
+22
View File
@@ -30,6 +30,7 @@ class NIO:
self._capturing = False
self._suspended = False
self._filters = {}
self._markers = {}
self._pcap_output_file = ""
self._pcap_data_link_type = ""
@@ -118,3 +119,24 @@ class NIO:
assert isinstance(new_filters, dict)
self._filters = new_filters
@property
def markers(self):
"""
Returns the traffic-insight markers for this NIO.
:returns: markers (dictionary: name -> {bpf, tag, link_id})
"""
return self._markers
@markers.setter
def markers(self, new_markers):
"""
Set the traffic-insight markers for this NIO.
:param new_markers: markers (dictionary: name -> {bpf, tag, link_id})
"""
assert isinstance(new_markers, dict)
self._markers = new_markers
+2 -1
View File
@@ -80,5 +80,6 @@ class NIOUDP(NIO):
"rport": self._rport,
"rhost": self._rhost,
"suspend": self._suspended,
"filters": self._filters
"filters": self._filters,
"markers": self._markers
}