Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion back/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ python-dotenv==1.1.1
marshmallow_dataclass==8.7.1
psutil==7.0.0
netaddr==1.3.0
ipmininet @ git+https://github.com/mimi-net/ipmininet.git@1.2.4
ipmininet @ git+https://github.com/mimi-net/ipmininet.git@1.2.5
16 changes: 15 additions & 1 deletion back/src/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import shlex
import time
from typing import Any, Callable, Dict, List

from ipmininet.host.config.dnsmasq import Dnsmasq
from ipmininet.router.config.dhcprelay import DHCPRelay
from mininet.log import info
from netaddr import EUI, AddrFormatError
from network_schema import Job
Expand Down Expand Up @@ -535,6 +535,19 @@ def dhcp_server(job: Job, job_host):
info(f"[dhcp_server] dnsmasq started on host={job_host.name}")


def dhcp_relay(job: Job, job_host):
dhcp_server_ip = job.arg_1
listening_ip = job.arg_2
daemon = DHCPRelay(
node=job_host,
dhcp_server_ip=dhcp_server_ip,
listening_ip=listening_ip,
)
job_host.build_daemon(daemon)
job_host.start_daemon(daemon)
info(f"dnsmasq --dhcp-relay={listening_ip},{dhcp_server_ip}")


class Jobs:
"""Class for representing various commands for working with miminet network"""

Expand Down Expand Up @@ -569,6 +582,7 @@ def __init__(self, job: Job, job_host: Any, **kwargs) -> None:
201: open_tcp_server_handler,
202: block_tcp_udp_port,
203: dhcp_server,
204: dhcp_relay,
}
self._job: Job = job
self._job_host = job_host
Expand Down
1 change: 1 addition & 0 deletions back/tests/test_json/dhcp_relay_no_client_answer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[{"data": {"id": "pkt_UI1QGK53", "label": "ARP-request\nWho has 192.168.10.2? Tell 192.168.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 192.168.10.3", "path": "edge_mnwcvu628bbw4u6v8di", "source": "router_1", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274672995385"}], [{"data": {"id": "pkt_048BOD85", "label": "ARP-request\nWho has 192.168.10.2? Tell 192.168.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 192.168.10.3", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "l2sw2", "target": "server_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673012501"}], [{"data": {"id": "pkt_FIPV4QO4", "label": "ARP-response\n192.168.10.2 at 00:00:00:00:00:02", "type": "packet"}, "config": {"type": "ARP-response\n192.168.10.2 at 00:00:00:00:00:02", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "server_1", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673027832"}], [{"data": {"id": "pkt_ZY0N0WW7", "label": "ARP-response\n192.168.10.2 at 00:00:00:00:00:02", "type": "packet"}, "config": {"type": "ARP-response\n192.168.10.2 at 00:00:00:00:00:02", "path": "edge_mnwcvu628bbw4u6v8di", "source": "l2sw2", "target": "router_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673043742"}], [{"data": {"id": "pkt_JW244TDV", "label": "ICMP echo-request\n192.168.10.3 > 192.168.10.2", "type": "packet"}, "config": {"type": "ICMP echo-request\n192.168.10.3 > 192.168.10.2", "path": "edge_mnwcvu628bbw4u6v8di", "source": "router_1", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673060126"}], [{"data": {"id": "pkt_WP9RYEH0", "label": "ICMP echo-request\n192.168.10.3 > 192.168.10.2", "type": "packet"}, "config": {"type": "ICMP echo-request\n192.168.10.3 > 192.168.10.2", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "l2sw2", "target": "server_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673076671"}], [{"data": {"id": "pkt_ISD5OLD5", "label": "ICMP echo-reply\n192.168.10.2 > 192.168.10.3", "type": "packet"}, "config": {"type": "ICMP echo-reply\n192.168.10.2 > 192.168.10.3", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "server_1", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673091814"}], [{"data": {"id": "pkt_BCYWGSZS", "label": "ICMP echo-reply\n192.168.10.2 > 192.168.10.3", "type": "packet"}, "config": {"type": "ICMP echo-reply\n192.168.10.2 > 192.168.10.3", "path": "edge_mnwcvu628bbw4u6v8di", "source": "l2sw2", "target": "router_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776274673107063"}]]
233 changes: 233 additions & 0 deletions back/tests/test_json/dhcp_relay_no_client_network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
"nodes": [
{
"classes":[
"l2_switch"
],
"config":{
"label":"l2sw1",
"stp":0,
"type":"l2_switch"
},
"data":{
"id":"l2sw1",
"label":"l2sw1"
},
"interface":[
{
"connect":"edge_mnwcvh8lkuozj9b2hw",
"id":"l2sw1_3",
"name":"l2sw1_3",
"type_connection":null,
"vlan":null
},
{
"id":"l2sw1_1",
"name":"l2sw1_1",
"connect":"edge_mnxf20jpi9lk28vbr2",
"vlan":null,
"type_connection":null
}
],
"position":{
"x":250,
"y":200
}
},
{
"classes":[
"l3_router"
],
"config":{
"default_gw":"",
"label":"router_1",
"type":"router"
},
"data":{
"id":"router_1",
"label":"router_1"
},
"interface":[
{
"connect":"edge_mnwcvh8lkuozj9b2hw",
"id":"iface_20417632",
"ip":"172.16.10.3",
"name":"iface_20417632",
"netmask":24
},
{
"connect":"edge_mnwcvu628bbw4u6v8di",
"id":"iface_13153444",
"ip":"192.168.10.3",
"name":"iface_13153444",
"netmask":24
}
],
"position":{
"x":350,
"y":100
}
},
{
"classes":[
"l2_switch"
],
"config":{
"label":"l2sw2",
"stp":0,
"type":"l2_switch"
},
"data":{
"id":"l2sw2",
"label":"l2sw2"
},
"interface":[
{
"connect":"edge_mnwcvu628bbw4u6v8di",
"id":"l2sw2_1",
"name":"l2sw2_1",
"type_connection":null,
"vlan":null
},
{
"connect":"edge_mnwcvw5j8b38v1xr5sj",
"id":"l2sw2_2",
"name":"l2sw2_2",
"type_connection":null,
"vlan":null
}
],
"position":{
"x":450,
"y":200
}
},
{
"classes":[
"server"
],
"config":{
"default_gw":"192.168.10.3",
"label":"server_1",
"type":"server"
},
"data":{
"id":"server_1",
"label":"server_1"
},
"interface":[
{
"connect":"edge_mnwcvw5j8b38v1xr5sj",
"id":"iface_16417632",
"ip":"192.168.10.2",
"name":"iface_16417632",
"netmask":24
}
],
"position":{
"x":450,
"y":300
}
},
{
"data":{
"id":"host_1",
"label":"host_1"
},
"position":{
"x":250,
"y":300
},
"classes":[
"host"
],
"config":{
"type":"host",
"label":"host_1",
"default_gw":""
},
"interface":[
{
"id":"iface_46653148",
"name":"iface_46653148",
"connect":"edge_mnxf20jpi9lk28vbr2"
}
]
}
],
"edges": [
{
"data":{
"id":"edge_mnwcvh8lkuozj9b2hw",
"source":"l2sw1",
"target":"router_1",
"loss_percentage":0,
"duplicate_percentage":0
}
},
{
"data":{
"id":"edge_mnwcvu628bbw4u6v8di",
"source":"router_1",
"target":"l2sw2",
"loss_percentage":0,
"duplicate_percentage":0
}
},
{
"data":{
"id":"edge_mnwcvw5j8b38v1xr5sj",
"source":"l2sw2",
"target":"server_1",
"loss_percentage":0,
"duplicate_percentage":0
}
},
{
"data":{
"id":"edge_mnxf20jpi9lk28vbr2",
"source":"host_1",
"target":"l2sw1",
"loss_percentage":0,
"duplicate_percentage":0
}
}
],
"jobs": [
{
"arg_1":"172.16.10.10",
"arg_2":"172.16.10.100",
"arg_3":"24",
"arg_4":"172.16.10.3",
"arg_5":"iface_16417632",
"host_id":"server_1",
"id":"c124a6208e0441478f7548a14003b8b5",
"job_id":203,
"level":3,
"print_cmd":"dhcp ip range: 172.16.10.10,172.16.10.100/24 gw:172.16.10.3"
},
{
"id":"406fa1c5e3794d36b40c920dc80f129e",
"job_id":1,
"print_cmd":"ping -c 1 192.168.10.2",
"arg_1":"192.168.10.2",
"level":2,
"host_id":"router_1"
},
{
"id":"2e320d269cf841aa977817f5f21fb14e",
"job_id":204,
"print_cmd":"dnsmasq --dhcp-relay=172.16.10.3,192.168.10.2", "arg_1":"192.168.10.2",
"arg_2":"172.16.10.3",
"level":2,
"host_id":"router_1"
}
],
"config": {
"zoom": 2,
"pan_x": 193,
"pan_y": 8
},
"pcap": [],
"packets": "[]"
}
1 change: 1 addition & 0 deletions back/tests/test_json/dhcp_relay_no_gateway_answer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[{"data": {"id": "pkt_57448WIK", "label": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "type": "packet"}, "config": {"type": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "path": "edge_mnxf20jpi9lk28vbr2", "source": "host_1", "target": "l2sw1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275940616600"}], [{"data": {"id": "pkt_HANS8A4M", "label": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "type": "packet"}, "config": {"type": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "path": "edge_mnym51eah6wx0v6s9h", "source": "l2sw1", "target": "router_2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275940632726"}], [{"data": {"id": "pkt_JIATC2IM", "label": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "path": "edge_mnym5331cjpgqzraqy4", "source": "router_2", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275940648266"}], [{"data": {"id": "pkt_VK4RTY1D", "label": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "l2sw2", "target": "server_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275940672473"}], [{"data": {"id": "pkt_R9BDLMKS", "label": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "path": "edge_mnym5331cjpgqzraqy4", "source": "router_2", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275941678060"}], [{"data": {"id": "pkt_AUHPWQY3", "label": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "l2sw2", "target": "server_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275941693430"}], [{"data": {"id": "pkt_EQY7NYFC", "label": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "path": "edge_mnym5331cjpgqzraqy4", "source": "router_2", "target": "l2sw2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275942702422"}], [{"data": {"id": "pkt_TJ0JAYUO", "label": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "type": "packet"}, "config": {"type": "ARP-request\nWho has 192.168.10.2? Tell 172.16.10.3", "path": "edge_mnwcvw5j8b38v1xr5sj", "source": "l2sw2", "target": "server_1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275942718230"}], [{"data": {"id": "pkt_WJ7SM6D5", "label": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "type": "packet"}, "config": {"type": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "path": "edge_mnxf20jpi9lk28vbr2", "source": "host_1", "target": "l2sw1", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275943572633"}], [{"data": {"id": "pkt_E8Z0HLZ3", "label": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "type": "packet"}, "config": {"type": "DHCP Discover\n0.0.0.0 > 255.255.255.255", "path": "edge_mnym51eah6wx0v6s9h", "source": "l2sw1", "target": "router_2", "loss_percentage": 0.0, "duplicate_percentage": 0.0}, "timestamp": "1776275943597792"}]]
Loading
Loading