Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync development branch #166

Merged
merged 10 commits into from
Dec 14, 2023
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/daemon.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`.
Expand Down
3 changes: 3 additions & 0 deletions seedemu/compiler/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
{nodeId}:
build: ./{nodeId}
container_name: {nodeName}
depends_on:
- {dependsOn}
cap_add:
- ALL
sysctls:
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 23 additions & 4 deletions test/SeedEmuTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
cls.docker_compose_version = 2
else:
cls.docker_compose_version = 1

cls.gen_emulation_files()
cls.build_emulator()
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -157,7 +175,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")
Expand Down