diff --git a/gns3server/controller/link.py b/gns3server/controller/link.py index a7b295cd..dbfb1cfa 100644 --- a/gns3server/controller/link.py +++ b/gns3server/controller/link.py @@ -94,4 +94,4 @@ class Link: "adapter_number": side["adapter_number"], "port_number": side["port_number"] }) - return {"vms": res, "link_id": self._id, "data_link_type": self._data_link_type} + return {"vms": res, "link_id": self._id} diff --git a/gns3server/controller/udp_link.py b/gns3server/controller/udp_link.py index 4b9a9876..1ff91ef3 100644 --- a/gns3server/controller/udp_link.py +++ b/gns3server/controller/udp_link.py @@ -24,8 +24,8 @@ from .link import Link class UDPLink(Link): - def __init__(self, project, data_link_type="DLT_EN10MB"): - super().__init__(project, data_link_type) + def __init__(self, project): + super().__init__(project) self._capture_vm = None @asyncio.coroutine @@ -80,14 +80,14 @@ class UDPLink(Link): yield from vm2.delete("/adapters/{adapter_number}/ports/{port_number}/nio".format(adapter_number=adapter_number2, port_number=port_number2)) @asyncio.coroutine - def start_capture(self): + def start_capture(self, data_link_type="DLT_EN10MB"): """ Start capture on a link """ self._capture_vm = self._choose_capture_side() data = { "capture_file_name": self.capture_file_name(), - "data_link_type": self._data_link_type + "data_link_type": data_link_type } yield from self._capture_vm["vm"].post("/adapters/{adapter_number}/ports/{port_number}/start_capture".format(adapter_number=self._capture_vm["adapter_number"], port_number=self._capture_vm["port_number"]), data=data) diff --git a/gns3server/handlers/api/controller/link_handler.py b/gns3server/handlers/api/controller/link_handler.py index f7234c31..329ba65b 100644 --- a/gns3server/handlers/api/controller/link_handler.py +++ b/gns3server/handlers/api/controller/link_handler.py @@ -16,7 +16,7 @@ # along with this program. If not, see . from ....web.route import Route -from ....schemas.link import LINK_OBJECT_SCHEMA +from ....schemas.link import LINK_OBJECT_SCHEMA, LINK_CAPTURE_SCHEMA from ....controller.project import Project from ....controller import Controller @@ -63,13 +63,14 @@ class LinkHandler: 204: "Capture started", 400: "Invalid request" }, - description="Start capture on a link instance") + input=LINK_CAPTURE_SCHEMA, + description="Start capture on a link instance. By default we consider it as an ethernet link") def start_capture(request, response): controller = Controller.instance() project = controller.getProject(request.match_info["project_id"]) link = project.getLink(request.match_info["link_id"]) - yield from link.start_capture() + yield from link.start_capture(request.json.get("data_link_type", "DLT_EN10MB")) response.set_status(204) @classmethod diff --git a/gns3server/schemas/link.py b/gns3server/schemas/link.py index 16fb7384..f344852a 100644 --- a/gns3server/schemas/link.py +++ b/gns3server/schemas/link.py @@ -28,10 +28,6 @@ LINK_OBJECT_SCHEMA = { "maxLength": 36, "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" }, - "data_link_type": { - "description": "PCAP data link type (http://www.tcpdump.org/linktypes.html)", - "enum": ["DLT_ATM_RFC1483", "DLT_EN10MB", "DLT_FRELAY", "DLT_C_HDLC"] - }, "vms": { "description": "List of the VMS", "type": "array", @@ -62,3 +58,17 @@ LINK_OBJECT_SCHEMA = { "required": ["vms"], "additionalProperties": False } + + +LINK_CAPTURE_SCHEMA = { + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "Request validation to start a packet capture on a link", + "type": "object", + "properties": { + "data_link_type": { + "description": "PCAP data link type (http://www.tcpdump.org/linktypes.html)", + "enum": ["DLT_ATM_RFC1483", "DLT_EN10MB", "DLT_FRELAY", "DLT_C_HDLC"] + } + }, + "additionalProperties": False +} diff --git a/tests/controller/test_link.py b/tests/controller/test_link.py index 8e66423e..80ab7a05 100644 --- a/tests/controller/test_link.py +++ b/tests/controller/test_link.py @@ -57,7 +57,6 @@ def test_json(async_run, project, compute): async_run(link.addVM(vm2, 1, 3)) assert link.__json__() == { "link_id": link.id, - "data_link_type": "DLT_EN10MB", "vms": [ { "vm_id": vm1.id, @@ -72,6 +71,7 @@ def test_json(async_run, project, compute): ] } + def test_capture_filename(project, compute, async_run): vm1 = VM(project, compute, name="Hello@") vm2 = VM(project, compute, name="w0.rld")