mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
python: cleanup
This commit is contained in:
1 parent
930e3e890b
commit
c964d0e5df
3 files changed
+17
-15
No files matched your search
+1
-1
@@ -151,7 +151,7 @@ cdef void py_done_callback(bool done, vector[shared_ptr[Node]]* nodes, void *use
|
||||
h._v.second = n
|
||||
node_ids.append(h)
|
||||
cbs = <object>user_data
|
||||
if cbs['done']:
|
||||
if 'done' in cbs:
|
||||
cbs['done'](done, node_ids)
|
||||
ref.Py_DECREF(cbs)
|
||||
|
||||
|
||||
+12
-11
@@ -62,6 +62,7 @@ def getsTimesTest():
|
||||
|
||||
def getcb(v):
|
||||
print("found", v)
|
||||
return True
|
||||
|
||||
def donecb(ok, nodes):
|
||||
nonlocal lock, done, times
|
||||
@@ -109,7 +110,7 @@ def getsTimesTest():
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
parser = argparse.ArgumentParser(description='Create a dummy network interface for testing')
|
||||
parser = argparse.ArgumentParser(description='Run, test and benchmark a DHT network on a local virtual network with simulated packet loss and latency.')
|
||||
parser.add_argument('-i', '--ifname', help='interface name', default='ethdht')
|
||||
parser.add_argument('-n', '--node-num', help='number of dht nodes to run', type=int, default=32)
|
||||
parser.add_argument('-v', '--virtual-locs', help='number of virtual locations (node clusters)', type=int, default=8)
|
||||
@@ -131,7 +132,7 @@ if __name__ == '__main__':
|
||||
print("Launching", args.node_num, "nodes (", clusters, "clusters of", node_per_loc, "nodes)")
|
||||
|
||||
if args.virtual_locs > 1:
|
||||
cmd = ["/usr/bin/sudo", "python3", "dummy_if.py", "-i", args.ifname, "-n", str(clusters), '-l', str(args.loss), '-d', str(args.delay)]
|
||||
cmd = ["python3", "virtual_network_builder.py", "-i", args.ifname, "-n", str(clusters), '-l', str(args.loss), '-d', str(args.delay)]
|
||||
if not args.disable_ipv4:
|
||||
cmd.append('-4')
|
||||
if not args.disable_ipv6:
|
||||
@@ -156,16 +157,16 @@ if __name__ == '__main__':
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
for i in range(clusters):
|
||||
if procs[i]:
|
||||
procs[i].send_signal(signal.SIGINT);
|
||||
for p in procs:
|
||||
if p:
|
||||
p.send_signal(signal.SIGINT);
|
||||
bootstrap.resize(0)
|
||||
print('Removing dummy interfaces...')
|
||||
subprocess.call(["/usr/bin/sudo", "python3", "dummy_if.py", "-i", args.ifname, "-n", str(clusters), "-r"])
|
||||
for i in range(clusters):
|
||||
if procs[i]:
|
||||
print('Shuting down the virtual IP network.')
|
||||
subprocess.call(["python3", "virtual_network_builder.py", "-i", args.ifname, "-n", str(clusters), "-r"])
|
||||
for p in procs:
|
||||
if p:
|
||||
try:
|
||||
procs[i].wait()
|
||||
procs[i].release()
|
||||
p.wait()
|
||||
p.release()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -7,10 +7,10 @@ import argparse, subprocess
|
||||
from pyroute2 import IPDB, NetNS
|
||||
from pyroute2.netns.process.proxy import NSPopen
|
||||
|
||||
parser = argparse.ArgumentParser(description='Create a dummy network interface for testing')
|
||||
parser = argparse.ArgumentParser(description='Creates a virtual network topology for testing')
|
||||
parser.add_argument('-i', '--ifname', help='interface name', default='ethdht')
|
||||
parser.add_argument('-n', '--ifnum', type=int, help='interface number', default=1)
|
||||
parser.add_argument('-r', '--remove', help='remove instead of adding the interface', action="store_true")
|
||||
parser.add_argument('-n', '--ifnum', type=int, help='number of isolated interfaces to create', default=1)
|
||||
parser.add_argument('-r', '--remove', help='remove instead of adding network interfaces', action="store_true")
|
||||
parser.add_argument('-l', '--loss', help='simulated packet loss (percent)', type=int, default=0)
|
||||
parser.add_argument('-d', '--delay', help='simulated latency (ms)', type=int, default=0)
|
||||
parser.add_argument('-4', '--ipv4', help='Enable IPv4', action="store_true")
|
||||
@@ -26,6 +26,7 @@ ip = None
|
||||
try:
|
||||
ip = IPDB()
|
||||
if args.remove:
|
||||
# cleanup interfaces
|
||||
for ifn in range(args.ifnum):
|
||||
iface = args.ifname+str(ifn)
|
||||
if iface in ip.interfaces:
|
||||
Reference in new issue
Block a user