mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-30 21:03:49 +02:00
Dynamips devices packet capture.
This commit is contained in:
parent
f99e834c37
commit
26f7195288
@ -15,7 +15,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
from ..web.route import Route
|
from ..web.route import Route
|
||||||
from ..schemas.dynamips_device import DEVICE_CREATE_SCHEMA
|
from ..schemas.dynamips_device import DEVICE_CREATE_SCHEMA
|
||||||
@ -184,51 +184,46 @@ class DynamipsDeviceHandler:
|
|||||||
yield from device.remove_nio(port_number)
|
yield from device.remove_nio(port_number)
|
||||||
response.set_status(204)
|
response.set_status(204)
|
||||||
|
|
||||||
# @Route.post(
|
@Route.post(
|
||||||
# r"/projects/{project_id}/dynamips/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/start_capture",
|
r"/projects/{project_id}/dynamips/devices/{device_id}/ports/{port_number:\d+}/start_capture",
|
||||||
# parameters={
|
parameters={
|
||||||
# "project_id": "UUID for the project",
|
"project_id": "UUID for the project",
|
||||||
# "vm_id": "UUID for the instance",
|
"device_id": "UUID for the instance",
|
||||||
# "adapter_number": "Adapter to start a packet capture",
|
"port_number": "Port on the device"
|
||||||
# "port_number": "Port on the adapter"
|
},
|
||||||
# },
|
status_codes={
|
||||||
# status_codes={
|
200: "Capture started",
|
||||||
# 200: "Capture started",
|
400: "Invalid request",
|
||||||
# 400: "Invalid request",
|
404: "Instance doesn't exist"
|
||||||
# 404: "Instance doesn't exist"
|
},
|
||||||
# },
|
description="Start a packet capture on a Dynamips device instance",
|
||||||
# description="Start a packet capture on a Dynamips VM instance",
|
input=DEVICE_CAPTURE_SCHEMA)
|
||||||
# input=VM_CAPTURE_SCHEMA)
|
def start_capture(request, response):
|
||||||
# def start_capture(request, response):
|
|
||||||
#
|
|
||||||
# dynamips_manager = Dynamips.instance()
|
|
||||||
# vm = dynamips_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
|
||||||
# slot_number = int(request.match_info["adapter_number"])
|
|
||||||
# port_number = int(request.match_info["port_number"])
|
|
||||||
# pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"])
|
|
||||||
# yield from vm.start_capture(slot_number, port_number, pcap_file_path, request.json["data_link_type"])
|
|
||||||
# response.json({"pcap_file_path": pcap_file_path})
|
|
||||||
#
|
|
||||||
# @Route.post(
|
|
||||||
# r"/projects/{project_id}/dynamips/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/stop_capture",
|
|
||||||
# parameters={
|
|
||||||
# "project_id": "UUID for the project",
|
|
||||||
# "vm_id": "UUID for the instance",
|
|
||||||
# "adapter_number": "Adapter to stop a packet capture",
|
|
||||||
# "port_number": "Port on the adapter (always 0)"
|
|
||||||
# },
|
|
||||||
# status_codes={
|
|
||||||
# 204: "Capture stopped",
|
|
||||||
# 400: "Invalid request",
|
|
||||||
# 404: "Instance doesn't exist"
|
|
||||||
# },
|
|
||||||
# description="Stop a packet capture on a Dynamips VM instance")
|
|
||||||
# def start_capture(request, response):
|
|
||||||
#
|
|
||||||
# dynamips_manager = Dynamips.instance()
|
|
||||||
# vm = dynamips_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
|
||||||
# slot_number = int(request.match_info["adapter_number"])
|
|
||||||
# port_number = int(request.match_info["port_number"])
|
|
||||||
# yield from vm.stop_capture(slot_number, port_number)
|
|
||||||
# response.set_status(204)
|
|
||||||
|
|
||||||
|
dynamips_manager = Dynamips.instance()
|
||||||
|
device = dynamips_manager.get_device(request.match_info["device_id"], project_id=request.match_info["project_id"])
|
||||||
|
port_number = int(request.match_info["port_number"])
|
||||||
|
pcap_file_path = os.path.join(device.project.capture_working_directory(), request.json["capture_file_name"])
|
||||||
|
yield from device.start_capture(port_number, pcap_file_path, request.json["data_link_type"])
|
||||||
|
response.json({"pcap_file_path": pcap_file_path})
|
||||||
|
|
||||||
|
@Route.post(
|
||||||
|
r"/projects/{project_id}/dynamips/devices/{device_id}/ports/{port_number:\d+}/stop_capture",
|
||||||
|
parameters={
|
||||||
|
"project_id": "UUID for the project",
|
||||||
|
"device_id": "UUID for the instance",
|
||||||
|
"port_number": "Port on the device"
|
||||||
|
},
|
||||||
|
status_codes={
|
||||||
|
204: "Capture stopped",
|
||||||
|
400: "Invalid request",
|
||||||
|
404: "Instance doesn't exist"
|
||||||
|
},
|
||||||
|
description="Stop a packet capture on a Dynamips device instance")
|
||||||
|
def start_capture(request, response):
|
||||||
|
|
||||||
|
dynamips_manager = Dynamips.instance()
|
||||||
|
device = dynamips_manager.get_device(request.match_info["device_id"], project_id=request.match_info["project_id"])
|
||||||
|
port_number = int(request.match_info["port_number"])
|
||||||
|
yield from device.stop_capture(port_number)
|
||||||
|
response.set_status(204)
|
||||||
|
@ -368,7 +368,7 @@ class ATMSwitch(Device):
|
|||||||
yield from nio.bind_filter("both", "capture")
|
yield from nio.bind_filter("both", "capture")
|
||||||
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||||
|
|
||||||
log.info('ATM switch "{name}" [{id}]: starting packet capture on {port}'.format(name=self._name,
|
log.info('ATM switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
|
||||||
@ -385,6 +385,6 @@ class ATMSwitch(Device):
|
|||||||
|
|
||||||
nio = self._nios[port_number]
|
nio = self._nios[port_number]
|
||||||
yield from nio.unbind_filter("both")
|
yield from nio.unbind_filter("both")
|
||||||
log.info('ATM switch "{name}" [{id}]: stopping packet capture on {port}'.format(name=self._name,
|
log.info('ATM switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
@ -149,7 +149,7 @@ class EthernetHub(Bridge):
|
|||||||
yield from nio.bind_filter("both", "capture")
|
yield from nio.bind_filter("both", "capture")
|
||||||
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||||
|
|
||||||
log.info('Ethernet hub "{name}" [{id}]: starting packet capture on {port}'.format(name=self._name,
|
log.info('Ethernet hub "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
|
||||||
@ -166,6 +166,6 @@ class EthernetHub(Bridge):
|
|||||||
|
|
||||||
nio = self._mappings[port_number]
|
nio = self._mappings[port_number]
|
||||||
yield from nio.unbind_filter("both")
|
yield from nio.unbind_filter("both")
|
||||||
log.info('Ethernet hub "{name}" [{id}]: stopping packet capture on {port}'.format(name=self._name,
|
log.info('Ethernet hub "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
@ -298,7 +298,7 @@ class EthernetSwitch(Device):
|
|||||||
yield from nio.bind_filter("both", "capture")
|
yield from nio.bind_filter("both", "capture")
|
||||||
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||||
|
|
||||||
log.info('Ethernet switch "{name}" [{id}]: starting packet capture on {port}'.format(name=self._name,
|
log.info('Ethernet switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
|
||||||
@ -315,6 +315,6 @@ class EthernetSwitch(Device):
|
|||||||
|
|
||||||
nio = self._nios[port_number]
|
nio = self._nios[port_number]
|
||||||
yield from nio.unbind_filter("both")
|
yield from nio.unbind_filter("both")
|
||||||
log.info('Ethernet switch "{name}" [{id}]: stopping packet capture on {port}'.format(name=self._name,
|
log.info('Ethernet switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
@ -272,7 +272,7 @@ class FrameRelaySwitch(Device):
|
|||||||
yield from nio.bind_filter("both", "capture")
|
yield from nio.bind_filter("both", "capture")
|
||||||
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
yield from nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||||
|
|
||||||
log.info('Frame relay switch "{name}" [{id}]: starting packet capture on {port}'.format(name=self._name,
|
log.info('Frame relay switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
|
||||||
@ -289,6 +289,6 @@ class FrameRelaySwitch(Device):
|
|||||||
|
|
||||||
nio = self._nios[port_number]
|
nio = self._nios[port_number]
|
||||||
yield from nio.unbind_filter("both")
|
yield from nio.unbind_filter("both")
|
||||||
log.info('Frame relay switch "{name}" [{id}]: stopping packet capture on {port}'.format(name=self._name,
|
log.info('Frame relay switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
port=port_number))
|
port=port_number))
|
||||||
|
@ -337,5 +337,5 @@ DEVICE_CAPTURE_SCHEMA = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["capture_file_name"]
|
"required": ["capture_file_name", "data_link_type"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user