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

A standardized procedure was created using bandwidth measurement as an example. #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
docker_image := net-env
docker_file := dockers/Dockerfile

all: net-env

net-env:
docker pull ubuntu:20.04
docker build . --build-arg UID=$(shell id -u) --build-arg GUID=$(shell id -g) -f $(docker_file) -t ${docker_image}

41 changes: 41 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
branches:
include:
- "*"
exclude:
- upstream/*


pool:
vmImage: 'ubuntu-latest'

steps:

- checkout: self

- script: make
displayName: 'build network measure environment'

- script: cd /home ; sudo wget https://github.com/OpenNetLab/OpenNetLab-P2P-Measurment/blob/v-wangyif/std-process-pitch/machines.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not use file in a personal repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In that case, I need to submit a PR of the json file first, because the pipeline needs to download the test file from outside.

displayName: 'make network measure environment'

- script: docker run -v /home:/app -w /app --net=host --name net_evals net-env:latest python3 /home/onl/bwmur/bwmursever.py && docker run -v /home:/app -w /app --net=host --name net_evalc net-env:latest python3 /home/onl/bwmur/bwmurclient.py
displayName: 'Run test'


- script: docker image tag net-env:latest opennetlab.azurecr.io/net-env:latest
displayName: 'Tag network environment image'

- task: Docker@2
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
containerRegistry: 'opennetlab Azure registry'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that possible the name to OpenNetLab Azure Registry? Should we also change Azure side?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Similar to the challenge environment, we use opennetlab Azure registry.
image

repository: 'net-env'
command: 'push'
tags: 'latest'
displayName: "Push net-env image"
86 changes: 86 additions & 0 deletions bwmur/bwmurclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import paramiko
import time
import random
import json
import os
import sys
from scp import SCPClient
import numpy as np
import copy
import time

socket_timeout_sec = 240
machines_file = "machines.json"
sever_port = "8000"
sever_ip = "127.0.0.1"
recv_wd = "/home"

sever_run_cmd = [
"iperf3 -s -p %s -i 1 -1" % (
sever_port)]
client_run_cmd = [
"iperf3 -c %s -p %s" % (
sever_ip, sever_port)]

def get_datetime():
now = int(round(time.time() * 1000))
ret = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now / 1000))
return ret


def get_bw(name):
global sever_ip
global sever_port
with open(machines_file, 'r') as f:
machines = json.loads(f.read())
if name not in machines:
raise ValueError("Not find such mahcine")
sever_ip = machines[name]["host"]
sever_port = machines[name]["bw_port"]
print(machines[name]["host"])
print(sever_ip)



def get_ssh(name):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
with open(machines_file, 'r') as f:
machines = json.loads(f.read())
if name not in machines:
raise ValueError("Not find such mahcine")

client.connect(hostname=machines[name]["host"], port=machines[name]["ssh_port"], username=machines[name]["user"],
password=machines[name]["pwd"])


return client

def BWmeasure(matches_num):
try:
output =" "
get_bw("recv_%d" % (matches_num))
client_run_cmd = ["iperf3 -c %s -p %s" % (sever_ip, sever_port)]
status = os.popen(" ".join(client_run_cmd)).read()
print(" ".join(client_run_cmd))
cmd = client_run_cmd
doc = open('clientbwlog.txt', 'a+')
doc.seek(0)
doc.truncate()
doc.write(status)
doc.close()
netctr = get_ssh("netctr")
print("start scp")
scp_client = SCPClient(netctr.get_transport(), socket_timeout=30.0)
scp_client.put("clientbwlog.txt", "%s/." % (recv_wd))
scp_client.close()


except Exception as e:
print(get_datetime(), "run_measure", e)

finally:
print("measure finish")

if __name__ == "__main__":
BWmeasure(1)
94 changes: 94 additions & 0 deletions bwmur/bwmursever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import paramiko
import time
import random
import json
import os
import sys
from scp import SCPClient
import numpy as np
import copy
import time

socket_timeout_sec = 240
machines_file = "machines.json"
sever_port = "8000"
sever_ip = "0.0.0.0"
recv_wd = "/home/wang/testnet/"

sever_run_cmd = [
"iperf3 -s -p %s -i 1 -1" % (
sever_port)]
client_run_cmd = [
"iperf3 -c %s -p %s" % (
sever_ip, sever_port)]

def get_datetime():
now = int(round(time.time() * 1000))
ret = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now / 1000))
return ret


def get_bw(name):
global sever_ip
global sever_port
with open(machines_file, 'r') as f:
machines = json.loads(f.read())
if name not in machines:
raise ValueError("Not find such mahcine")

#print("iperf")
#print(machines[name]["host"])
#print(machines[name]["bw_port"])
sever_ip = machines[name]["host"]
sever_port = machines[name]["bw_port"]



def get_ssh(name):
client = paramiko.SSHClient()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need to use paramiko?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At that time, SCP was used for data transmission and SSH was needed.

client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
with open(machines_file, 'r') as f:
machines = json.loads(f.read())
if name not in machines:
raise ValueError("Not find such mahcine")

client.connect(hostname=machines[name]["host"], port=machines[name]["ssh_port"], username=machines[name]["user"],
password=machines[name]["pwd"])

#print(machines[name]["host"])
#print(machines[name]["ssh_port"])
#print(machines[name]["user"])

return client

def BWmeasure(matches_num):
#print(get_datetime(), "start measure")
try:
output =" "
get_bw("recv_%d" % (matches_num))
sever_run_cmd = ["iperf3 -s -p %s -i 1 -1" % (sever_port)]
status = os.popen(" ".join(sever_run_cmd)).read()
cmd = sever_run_cmd
doc = open('severbwlog.txt', 'a+')
doc.seek(0)
doc.truncate()
doc.write(status)
doc.close()
netctr = get_ssh("netctr")
'''
At present, the method of uploading files through SCP is not adopted.
print("start scp")
scp_client = SCPClient(netctr.get_transport(), socket_timeout=30.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not start SCP to collect results

scp_client.put("severbwlog.txt", "%s/." % (recv_wd))
scp_client.close()
'''


except Exception as e:
print(get_datetime(), "run_measure", e)

finally:
print("measure finish")

if __name__ == "__main__":
BWmeasure(1)
14 changes: 14 additions & 0 deletions bwmur/tests/machines.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{

"recv_1" : {
"host" : "127.0.0.1",
"bw_port" : "8000",
},
"netctr" : {
"host" : "127.0.0.1",
"ssh_port" : "22",
"user" : "",
"pwd" : ""
}

}
33 changes: 33 additions & 0 deletions bwmur/tests/test_bwmeasure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os, json, pytest, subprocess, time
from tempfile import NamedTemporaryFile


cur_dir = os.path.dirname(os.path.abspath(__file__))


def check_bws():
file_path = cur_dir + "/../bwmursever.py"
cmds = ["python3",file_path]
cmds = (" ".join(cmds))
subprocess.Popen(cmds,shell = True)
#os.system(cmds)


def check_bwc():
file_path = cur_dir + "/../bwmurclient.py"
cmdc = ["python3",file_path]
cmdc = (" ".join(cmdc))
#cmd_result = subprocess.Popen(cmdc,shell = True).stdout.read()
cmd_result = os.popen(cmdc).read()
print(cmd_result)
assert "scp" in cmd_result



def test_bw():
check_bws()
print("OK")
check_bwc()
Loading