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
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# IP адрес Unified Agent. При MODE=dev независимо от значения переменной логи отправляются на localhost
UNIFIED_AGENT_URL="http://130.193.58.218:22132"

# Режим работы: dev (локальный PostgreSQL) или prod (Yandex Cloud PostgreSQL)
MODE=prod
5 changes: 5 additions & 0 deletions .github/workflows/back_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Create .env file with MODE=dev
run: |
touch .env
echo "MODE=dev" >> .env

- name: Install apt package
run: |
sudo apt-get update \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:

- name: Start frontend
run: |
cd front/
sed -i 's/MODE=prod/MODE=dev/' .env
cd front/
sed -i '/^BASE_DOMAIN/d' .env
sed -i '/^ALLOWED_HOSTS/d' .env && printf "\nALLOWED_HOSTS=http://localhost,http://172.18.0.2,http://172.18.0.3" >> .env
docker compose up -d
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vk_auth.json
__init__.py
eslint.config.mjs
back/rabbitmq/rabbitmq/
.env
*.log
*.ini
front/rabbitmq/rabbitmq
front/rabbitmq/rabbitmq
!.env
3 changes: 2 additions & 1 deletion back/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ celery_concurrency=1
queue_names=queue1,queue2,queue3
exchange_name=default_exchange
RABBITMQ_DEFAULT_USER=user
RABBITMQ_DEFAULT_PASS=password
RABBITMQ_DEFAULT_PASS=password
CELERY_LOG_GROUP="e236kkv3il7sf922kato"
1 change: 1 addition & 0 deletions back/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
restart: always
env_file:
- .env
- ../.env
environment:
- celery_concurrency=${celery_concurrency}
- queue_names=${queue_names}
Expand Down
3 changes: 2 additions & 1 deletion back/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ 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.4
requests==2.34.0
29 changes: 26 additions & 3 deletions back/src/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os.path
import subprocess
import time

import dpkt

import logging
import logging_config
from ipmininet.ipnet import IPNet
from jobs import Jobs
from network import MiminetNetwork
Expand All @@ -13,6 +13,9 @@
from mininet.log import setLogLevel, info, error
from network_topology import MiminetTopology

logger = logging.getLogger(__name__)
logging_config.configure_logging(logger)


def emulate(
network: Network,
Expand All @@ -26,6 +29,15 @@ def emulate(
tuple: animation list and pcap files.
"""

start_ts = time.time()

logger.info(
"Emulation started",
extra={
"jobs_count": len(network.jobs) if getattr(network, "jobs", None) else 0
},
)

setLogLevel("info")

# Validate job limit
Expand All @@ -42,7 +54,6 @@ def emulate(
raise ValueError(
f"Превышен лимит! В сети максимальное количество команд sleep {MAX_TIME_SLEEP})."
)

if len(network.jobs) == 0:
return [], []

Expand Down Expand Up @@ -125,6 +136,9 @@ def emulate(
net.stop()

except Exception as e:

logger.error("Miminet configuration failed", extra={"error": str(e)})

error(f"An error occurred during mininet configuration: {str(e)}")
subprocess.call("mn -c", shell=True)

Expand All @@ -143,6 +157,15 @@ def emulate(
animation = group_packets_by_time(animation)
error("[emulator] Animation groups after time-grouping: %d\n" % len(animation))

duration_ms = int((time.time() - start_ts) * 1000)
logger.info(
"Emulation finished",
extra={
"pcaps_count": len(pcaps),
"duration_ms": duration_ms,
},
)

return animation, pcaps


Expand Down
Loading
Loading