Skip to content

Commit 9939089

Browse files
author
cortze
committed
add basic DHT network init to the DAS.simulator + add DHTClient to the Validator
1 parent 808f857 commit 9939089

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*.swp
22
*.pyc
33
results/*
4-
myenv*/
4+
*env*/
55
doc/_build
66
!results/plots.py
77
Frontend/

DAS/shape.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
class Shape:
44
"""This class represents a set of parameters for a specific simulation."""
55

6-
def __init__(self, blockSize, numberNodes, failureModel, failureRate, class1ratio, chi, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run):
6+
def __init__(self, blockSize, numberNodes, failureModel, failureRate, class1ratio, chi, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, k, alpha, run):
77
"""Initializes the shape with the parameters passed in argument."""
8+
# block-segment related parameters
89
self.run = run
910
self.numberNodes = numberNodes
1011
self.blockSize = blockSize
@@ -19,6 +20,9 @@ def __init__(self, blockSize, numberNodes, failureModel, failureRate, class1rati
1920
self.bwUplink1 = bwUplink1
2021
self.bwUplink2 = bwUplink2
2122
self.randomSeed = ""
23+
# DHT related parameters
24+
self.k = k
25+
self.alpha = alpha
2226

2327
def __repr__(self):
2428
"""Returns a printable representation of the shape"""
@@ -35,6 +39,8 @@ def __repr__(self):
3539
shastr += "-bwup1-"+str(self.bwUplink1)
3640
shastr += "-bwup2-"+str(self.bwUplink2)
3741
shastr += "-nd-"+str(self.netDegree)
42+
shastr += "-k-"+str(self.k)
43+
shastr += "-alpha-"+str(self.alpha)
3844
shastr += "-r-"+str(self.run)
3945
return shastr
4046

DAS/simulator.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/python
2-
2+
import time
33
import networkx as nx
44
import logging, random
55
import pandas as pd
@@ -9,6 +9,7 @@
99
from DAS.results import *
1010
from DAS.observer import *
1111
from DAS.validator import *
12+
from dht import DHTNetwork
1213

1314
class Simulator:
1415
"""This class implements the main DAS simulator."""
@@ -177,6 +178,23 @@ def initNetwork(self):
177178
self.logger.debug("Val %d : rowN %s", i, self.validators[i].rowNeighbors, extra=self.format)
178179
self.logger.debug("Val %d : colN %s", i, self.validators[i].columnNeighbors, extra=self.format)
179180

181+
def initDHTNetwork(self):
182+
""" Compose the DHT network based on the pre-initialized Validators """
183+
# compose the DHT networking layer
184+
self.logger.info("Initializing DHTNetwork... with %d nodes" % self.shape.numberNodes, extra=self.format)
185+
self.DHTNetwork = DHTNetwork(self.execID, self.shape.failureRate, self.config.stepDuration)
186+
187+
# initialize each of the routing tables
188+
startTime = time.time()
189+
_ = self.DHTNetwork.init_with_random_peers(self.config.numJobs, self.shape.numberNodes,
190+
self.shape.k, self.shape.alpha, self.shape.k, self.config.nilStepsToStopLookup)
191+
self.logger.info("DHT fast-init (%d jobs) done in %.2f secs", self.config.numJobs, time.time()-startTime, extra=self.format)
192+
193+
# add the initialized DHTClient back to the Validator
194+
for val in self.validators:
195+
val.addDHTClient(self.DHTNetwork.nodestore.get_node(val.ID))
196+
# the network should be ready to go :)
197+
180198
def initLogger(self):
181199
"""It initializes the logger."""
182200
logging.TRACE = 5
@@ -216,7 +234,7 @@ def printDiagnostics(self):
216234
self.logger.debug("Column %d, Neighbor %d sent: %s" % (c, val.columnNeighbors[c][nc].node.ID, val.columnNeighbors[c][nc].received), extra=self.format)
217235
self.logger.debug("Column %d, Neighbor %d has: %s" % (c, val.columnNeighbors[c][nc].node.ID, self.validators[val.columnNeighbors[c][nc].node.ID].getColumn(c)), extra=self.format)
218236

219-
def run(self):
237+
def runBlockBroadcasting(self):
220238
"""It runs the main simulation until the block is available or it gets stucked."""
221239
self.glob.checkRowsColumns(self.validators)
222240
for i in range(0,self.shape.numberNodes):
@@ -307,3 +325,6 @@ def run(self):
307325
self.result.populate(self.shape, self.config, missingVector)
308326
return self.result
309327

328+
def runBlockPublicationToDHT(self):
329+
"""It runs the main DHT simulation, where the block proposer has to send the segments to the XOR close enough nodes."""
330+
return

DAS/validator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def logIDs(self):
117117
self.logger.debug("Selected rows: "+str(self.rowIDs), extra=self.format)
118118
self.logger.debug("Selected columns: "+str(self.columnIDs), extra=self.format)
119119

120+
def addDHTClient(self, dhtClient):
121+
self.logger.debug("Adding new DHTClient...", extra=self.format)
122+
# double check that
123+
if dhtClient.ID != self.ID:
124+
self.logger.error("Received DHTClient with different ValidatorID: %d", dhtClient.ID, extra=self.format)
125+
# TODO: do we want to panic here if the IDs don't match?
126+
self.DHTClient = dhtClient
127+
120128
def initBlock(self):
121129
"""It initializes the block for the proposer."""
122130
if self.amIproposer == 0:

install_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ git submodule update --init
1717
# install requirements for DAS and py-dht and install the dht module from py-dht
1818
pip3 install -r DAS/requirements.txt
1919
pip3 install -r py-dht/requirements.txt
20-
pip3 install -e py-dht
20+
python -m pip install -e py-dht/

study.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ def runOnce(config, shape, execID):
3333
sim.initLogger()
3434
sim.initValidators()
3535
sim.initNetwork()
36-
result = sim.run()
36+
result = sim.runBlockBroadcasting()
3737
sim.logger.info("Shape: %s ... Block Available: %d in %d steps" % (str(sim.shape.__dict__), result.blockAvailable, len(result.missingVector)), extra=sim.format)
38+
if config.dhtSimulation:
39+
sim.logger.info("Shape: %s ... Setting up DHT Network" % (str(sim.shape.__dict__)), extra=sim.format)
40+
sim.initDHTNetwork()
41+
sim.runBlockPublicationToDHT()
42+
sim.logger.info("Shape: %s ... Finished up Block propagation on the DHT Network" % (str(sim.shape.__dict__)), extra=sim.format)
43+
# TODO: append the DHT results to the previous results
3844

3945
if config.dumpXML:
4046
result.dump()
@@ -79,7 +85,7 @@ def study():
7985

8086
logger.info("Starting simulations:", extra=format)
8187
start = time.time()
82-
results = Parallel(config.numJobs)(delayed(runOnce)(config, shape ,execID) for shape in config.nextShape())
88+
results = Parallel(config.numJobs)(delayed(runOnce)(config, shape, execID) for shape in config.nextShape())
8389
end = time.time()
8490
logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=format)
8591

0 commit comments

Comments
 (0)