From 1cf19745068d79468ed25874e73138fa76607e7c Mon Sep 17 00:00:00 2001 From: Chao Zhou <66908299+zc1023@users.noreply.github.com> Date: Tue, 27 Jun 2023 11:43:37 +0800 Subject: [PATCH 1/6] Add the preparation in Mainland China --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 7b0d65b39..1ed18b950 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,50 @@ including Blockchain, Botnet, and many other useful elements of the Internet. ## Getting Started +### Preparation in Mainland China + +**Notice: This part is only useful for computers in Mainland China. If your computer is not in this area or you use some special network configuration, please skip this part.** + +1. Add the pip proxy: + + ```bash + pip install --upgrade pip + pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple + ``` + +2. Add the dockerhub proxy: + +vim the docker config file. + +```bash +sudo vim /etc/docker/deamon.json +``` + +add the following config. +```python +{ + "registry-mirrors": [ + "https://docker.mirrors.ustc.edu.cn", + "https://dockerproxy.com", + "https://hub-mirror.c.163.com", + "https://mirror.baidubce.com", + "https://ccr.ccs.tencentyun.com" + ] +} +``` + +restart docker + +```bash +sudo systemctl daemon-reload +sudo systemctl restart docker +``` + + + + +### Examples + To get started with the emulator, install docker, docker-compose, and python3. Then, take a look at the [examples/](./examples/) folder for examples. Detailed explanation is provided in the README file, as well as in the comments of the code. To run an example: 1. Pick an example, say `A00-simple-peering`. From 6e844f4422d9b011f3b07f30ebc133d32f057e42 Mon Sep 17 00:00:00 2001 From: Chao Zhou <66908299+zc1023@users.noreply.github.com> Date: Fri, 21 Jul 2023 09:23:27 +0800 Subject: [PATCH 2/6] Update README.md fix a typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ed18b950..8878bed1b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ including Blockchain, Botnet, and many other useful elements of the Internet. vim the docker config file. ```bash -sudo vim /etc/docker/deamon.json +sudo vim /etc/docker/daemon.json ``` add the following config. From ebfddd12abfdd585e70e9b9faef6914bda5de9dd Mon Sep 17 00:00:00 2001 From: wonkr Date: Tue, 29 Aug 2023 00:11:07 -0400 Subject: [PATCH 3/6] fix issue #158 --- seedemu/compiler/Docker.py | 3 +++ test/SeedEmuTestCase.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/seedemu/compiler/Docker.py b/seedemu/compiler/Docker.py index 725485a47..9df513ce2 100644 --- a/seedemu/compiler/Docker.py +++ b/seedemu/compiler/Docker.py @@ -116,6 +116,8 @@ {nodeId}: build: ./{nodeId} container_name: {nodeName} + depends_on: + - {dependsOn} cap_add: - ALL sysctls: @@ -944,6 +946,7 @@ def _compileNode(self, node: Node) -> str: return DockerCompilerFileTemplates['compose_service'].format( nodeId = real_nodename, nodeName = name, + dependsOn = md5(image.getName().encode('utf-8')).hexdigest(), networks = node_nets, # privileged = 'true' if node.isPrivileged() else 'false', ports = ports, diff --git a/test/SeedEmuTestCase.py b/test/SeedEmuTestCase.py index 17d17bc77..608585bd9 100644 --- a/test/SeedEmuTestCase.py +++ b/test/SeedEmuTestCase.py @@ -157,7 +157,8 @@ def wait_until_all_containers_up(cls, total_containers:int) -> None: cur_container_count = len(cls.containers) - cls.container_count_before_up_container cls.printLog("current containers counts : ", cur_container_count) if cur_container_count == total_containers: - time.sleep(10) + # wait until the initial setting in containers such as bird configuration. + time.sleep(30) return True if time.time() - current_time > 300: cls.printLog("TimeExhausted: 5 min") From a1b8fccbfe9370f34b5417b1c487e42570440472 Mon Sep 17 00:00:00 2001 From: won Date: Tue, 29 Aug 2023 00:27:39 -0400 Subject: [PATCH 4/6] `docker-compose` command is changed to `docker compose - ` --- test/SeedEmuTestCase.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/SeedEmuTestCase.py b/test/SeedEmuTestCase.py index 608585bd9..ca629833f 100644 --- a/test/SeedEmuTestCase.py +++ b/test/SeedEmuTestCase.py @@ -90,7 +90,7 @@ def build_emulator(cls): log_file = os.path.join(cls.init_dir, cls.test_log, "build_log") f = open(log_file, 'w') - result = subprocess.run(["docker-compose", "build"], stderr=f, stdout=f) + result = subprocess.run(["docker", "compose", "build"], stderr=f, stdout=f) f.close() os.system("echo 'y' | docker system prune > /dev/null") os.chdir(cls.init_dir) @@ -103,7 +103,7 @@ def up_emulator(cls): @brief up all containers. """ os.chdir(os.path.join(cls.emulator_code_dir, cls.output_dir)) - os.system("docker-compose up > ../../test_log/containers_log &") + os.system("docker compose up > ../../test_log/containers_log &") os.chdir(cls.init_dir) @classmethod @@ -112,7 +112,7 @@ def down_emulator(cls): @brief down all containers. """ os.chdir(os.path.join(cls.emulator_code_dir, cls.output_dir)) - os.system("docker-compose down > /dev/null") + os.system("docker compose down > /dev/null") os.system("echo 'y' | docker system prune > /dev/null") os.chdir(cls.init_dir) From a137987ba711d2f451f0cd65a85cd485a70ff724 Mon Sep 17 00:00:00 2001 From: wonkr Date: Tue, 29 Aug 2023 09:34:36 -0400 Subject: [PATCH 5/6] docker-compose version compatibility --- test/SeedEmuTestCase.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/SeedEmuTestCase.py b/test/SeedEmuTestCase.py index ca629833f..196bf2a6f 100644 --- a/test/SeedEmuTestCase.py +++ b/test/SeedEmuTestCase.py @@ -17,6 +17,7 @@ class SeedEmuTestCase(ut.TestCase): test_log: str container_count_before_up_container: int container_count_after_up_container: int + docker_compose_version:int @classmethod def setUpClass(cls) -> None: @@ -42,6 +43,12 @@ def setUpClass(cls) -> None: cls.printLog("{} Start".format(sys.modules[cls.__module__].__name__)) cls.printLog("==============================") + # if system is using a docker-compose version 2, test is done with version2. + result = subprocess.run(["docker", "compose"]) + if result.returncode == 0: + docker_compose_version = 2 + else: + docker_compose_version = 1 cls.gen_emulation_files() cls.build_emulator() @@ -90,7 +97,11 @@ def build_emulator(cls): log_file = os.path.join(cls.init_dir, cls.test_log, "build_log") f = open(log_file, 'w') - result = subprocess.run(["docker", "compose", "build"], stderr=f, stdout=f) + if(cls.docker_compose_version == 1): + result = subprocess.run(["docker-compose", "build"], stderr=f, stdout=f) + else: + result = subprocess.run(["docker", "compose", "build"], stderr=f, stdout=f) + f.close() os.system("echo 'y' | docker system prune > /dev/null") os.chdir(cls.init_dir) @@ -103,7 +114,10 @@ def up_emulator(cls): @brief up all containers. """ os.chdir(os.path.join(cls.emulator_code_dir, cls.output_dir)) - os.system("docker compose up > ../../test_log/containers_log &") + if(cls.docker_compose_version == 1): + os.system("docker-compose up > ../../test_log/containers_log &") + else: + os.system("docker compose up > ../../test_log/containers_log &") os.chdir(cls.init_dir) @classmethod @@ -112,7 +126,11 @@ def down_emulator(cls): @brief down all containers. """ os.chdir(os.path.join(cls.emulator_code_dir, cls.output_dir)) - os.system("docker compose down > /dev/null") + if(cls.docker_compose_version == 1): + os.system("docker-compose down > /dev/null") + else: + os.system("docker compose down > /dev/null") + os.system("echo 'y' | docker system prune > /dev/null") os.chdir(cls.init_dir) From f611b1ab6371bf400d06bfbd0fba2921d80515aa Mon Sep 17 00:00:00 2001 From: KRW Date: Tue, 29 Aug 2023 09:46:43 -0400 Subject: [PATCH 6/6] Update SeedEmuTestCase.py change docker_compose_version to a class member variable. --- test/SeedEmuTestCase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SeedEmuTestCase.py b/test/SeedEmuTestCase.py index 196bf2a6f..0189d9ba6 100644 --- a/test/SeedEmuTestCase.py +++ b/test/SeedEmuTestCase.py @@ -46,9 +46,9 @@ def setUpClass(cls) -> None: # if system is using a docker-compose version 2, test is done with version2. result = subprocess.run(["docker", "compose"]) if result.returncode == 0: - docker_compose_version = 2 + cls.docker_compose_version = 2 else: - docker_compose_version = 1 + cls.docker_compose_version = 1 cls.gen_emulation_files() cls.build_emulator()