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
3 changes: 2 additions & 1 deletion back/src/net_utils/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ipmininet.ipovs_switch import IPOVSSwitch

from network_schema import Node, NodeInterface
from node_types import NodeType


def setup_vlans(net: IPNet, nodes: list[Node]) -> None:
Expand All @@ -15,7 +16,7 @@ def setup_vlans(net: IPNet, nodes: list[Node]) -> None:
"""

for node in nodes:
if node.config.type == "l2_switch":
if node.config.type == NodeType.SWITCH:
switch = net.get(node.data.id)
add_bridge(switch, node.interface)

Expand Down
3 changes: 2 additions & 1 deletion back/src/net_utils/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ipmininet.ipnet import IPNet

from network_schema import Node
from node_types import NodeType


def setup_vtep_interfaces(net: IPNet, nodes: list[Node]) -> None:
Expand All @@ -14,7 +15,7 @@ def setup_vtep_interfaces(net: IPNet, nodes: list[Node]) -> None:
nodes (list[Node]): A list of nodes to configure.
"""
for node in nodes:
if node.config.type == "router":
if node.config.type == NodeType.ROUTER:
router = net.get(node.data.id)

# Configure VXLAN network interfaces (connection_type == 1)
Expand Down
14 changes: 10 additions & 4 deletions back/src/network_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ipmininet.router.config import RouterConfig
from network_schema import Network, Node, NodeConfig, NodeInterface
from pkt_parser import is_ipv4_address
from node_types import NodeType


class MiminetTopology(IPTopo):
Expand Down Expand Up @@ -46,14 +47,17 @@ def __handle_node(self, node: Node):
node_type: str = config.type # network device type
node_id: str = node.data.id # network device name(label)

if node_type == "l2_switch":
if node_type == NodeType.SWITCH:
self.__handle_l2_switch(node_id, config)
elif node_type in ("host", "server"):
elif node_type in (NodeType.HOST, NodeType.SERVER):
self.__handle_host_or_server(node_id, config)
elif node_type == "l1_hub":
elif node_type == NodeType.HUB:
self.__handle_l1_hub(node_id)
elif node_type == "router":
elif node_type == NodeType.ROUTER:
self.__handle_router(node_id, config)
else:
print(f"Unknown node type: {node_type}")
return

def __handle_l2_switch(self, node_id: str, config: NodeConfig):
assert config.stp in (0, 1, 2), "Incorrect STP mode"
Expand Down Expand Up @@ -126,6 +130,8 @@ def build(self, *args, **kwargs):
interfaces = []

for node in self.__network.nodes:
if node.config.type == "textbox":
continue
# Caches node by ID for quick lookup later
self.__id_to_node[node.data.id] = node

Expand Down
13 changes: 13 additions & 0 deletions back/src/node_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from enum import Enum


class NodeType(str, Enum):
"""
Types of all functional network nodes
"""

HOST = "host"
SERVER = "server"
SWITCH = "l2_switch"
HUB = "l1_hub"
ROUTER = "router"
28 changes: 25 additions & 3 deletions back/src/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import os
import signal

from marshmallow import Schema
import marshmallow_dataclass

from node_types import NodeType
from celery_app import (
app,
SEND_NETWORK_RESPONSE_EXCHANGE,
Expand All @@ -13,6 +16,25 @@
from network_schema import Network
from emulator import emulate

_network_schema: Schema | None = None


def _filter_unknown_nodes(data: dict) -> dict:
allowed = set(NodeType)
data["nodes"] = [
node
for node in data.get("nodes", [])
if node.get("config", {}).get("type") in allowed
]
return data


def get_network_schema() -> Schema:
global _network_schema
if _network_schema is None:
_network_schema = marshmallow_dataclass.class_schema(Network)()
return _network_schema


def run_miminet(network_json: str):
"""Load network from JSON and start emulation safely.
Expand All @@ -31,9 +53,9 @@ def run_miminet(network_json: str):
print("Set default handler to SIGCHLD")
signal.signal(signal.SIGCHLD, signal.SIG_IGN)

jnet = json.loads(network_json)
network_schema = marshmallow_dataclass.class_schema(Network)()
network_json = network_schema.load(jnet, unknown="include")
jnet = _filter_unknown_nodes(json.loads(network_json))
schema = get_network_schema()
network_json = schema.load(jnet, unknown="include")

for _ in range(4):
try:
Expand Down
2 changes: 1 addition & 1 deletion front/.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ POSTGRES_HOST=172.18.0.4
# YANDEX_POSTGRES_SSLMODE=verify-full

# Режим работы: dev (локальный PostgreSQL) или prod (Yandex Cloud PostgreSQL)
MODE=prod
MODE=dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😠😠😠😠😠😠😠😠😠😠😠 надо этот файл в .gitignore добавить

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По-хорошему он там должен был быть уже давно (изначально), текущие .env с примерной конфигурацией стоит оставить с MODE=dev и переименовать во что-то, вроде example.env. Занести в .gitignore и не трогать продовый .env

4 changes: 4 additions & 0 deletions front/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
delete_job,
save_host_config,
save_hub_config,
save_textbox_config,
save_router_config,
save_server_config,
save_switch_config,
Expand Down Expand Up @@ -234,6 +235,9 @@ def get_database_uri(mode):
app.add_url_rule(
"/host/hub_save_config", methods=["GET", "POST"], view_func=save_hub_config
)
app.add_url_rule(
"/host/textbox_save_config", methods=["GET", "POST"], view_func=save_textbox_config
)
app.add_url_rule(
"/host/switch_save_config", methods=["GET", "POST"], view_func=save_switch_config
)
Expand Down
34 changes: 34 additions & 0 deletions front/src/configurators.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,40 @@ def _configure(self):
return {"message": "Конфигурация обновлена", "nodes": self._nodes}


class TextboxConfigurator(AbstractDeviceConfigurator):
def __init__(self):
super().__init__(device_type="textbox")

def _conf_content_update(self):
label = get_data(f"config_{self._device_type}_content")
fontsize = get_data("config_textbox_font_size")
font_color = get_data("config_textbox_font_color")
font_style = get_data("config_textbox_font_style")
font_weight = get_data("config_textbox_font_weight")

if label:
self._device_node["config"]["label"] = label
self._device_node["data"]["label"] = self._device_node["config"]["label"]

if fontsize:
self._device_node["config"]["tb_fontsize"] = int(fontsize)

if font_color:
self._device_node["config"]["color"] = font_color

if font_style:
self._device_node["config"]["fontstyle"] = font_style

if font_weight:
self._device_node["config"]["fontweight"] = font_weight

def _configure(self):
self._conf_prepare()
self._conf_content_update()

return {"message": "Конфигурация обновлена", "nodes": self._nodes}


class SwitchConfigurator(AbstractDeviceConfigurator):
def __init__(self):
super().__init__(device_type="switch")
Expand Down
7 changes: 7 additions & 0 deletions front/src/miminet_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
HostConfigurator,
SwitchConfigurator,
HubConfigurator,
TextboxConfigurator,
ServerConfigurator,
RouterConfigurator,
EdgeConfigurator,
Expand Down Expand Up @@ -187,6 +188,7 @@ def build_error(error_type: str, cmd: str) -> str:
router = RouterConfigurator()
server = ServerConfigurator()
edge = EdgeConfigurator()
textbox = TextboxConfigurator()

# --- Jobs ---

Expand Down Expand Up @@ -518,6 +520,11 @@ def save_router_config():
return router.configure()


@login_required
def save_textbox_config():
return textbox.configure()


@login_required
def save_server_config():
return server.configure()
Expand Down
39 changes: 37 additions & 2 deletions front/src/static/assets/css/workspace.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
display: block;
margin-bottom: 10px;
padding: 10px;
width: 130px;
width: 170px;
background-color: white;
border-radius: 7px;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);
Expand All @@ -63,13 +63,14 @@
display: block;
max-height: calc(80vh - 140px);
padding: 10px;
width: 130px;
width: 170px;
background-color: white;
border-radius: 7px;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);
text-align: center;
color: #222;
overflow-y: auto;
margin-bottom: 10px;
}

.ws-menu-settings-name {
Expand Down Expand Up @@ -107,4 +108,38 @@
font-weight: 500;
color: #222;
}

.side-menu-header {
position: relative;
text-align: center;
padding: 6px 28px;
}

.side-menu-header span {
font-size: inherit;
user-select: none;
}

.side-menu-arrow {
position: absolute;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
font-size: 1.2rem;
color: #6c757d;
opacity: 0.6;
}

.side-menu-arrow.left {
left: 6px;
}

.side-menu-arrow.right {
right: 6px;
}

.side-menu-arrow:hover {
color: #000;
opacity: 1;
}
Comment on lines +112 to +144
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С новым side menu мне кажется очень крутая идея 👍 Учитывая что скорее всего ещё новые устройства появлятья будут

}
Loading