Data link type is on the capture not on the link

pull/565/head
Julien Duponchelle 9 years ago
parent 04a1b2df3b
commit 549a6280c0
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -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}

@ -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)

@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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

@ -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
}

@ -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")

Loading…
Cancel
Save