|
1 | 1 | #!/bin/python |
2 | | - |
| 2 | +import time |
3 | 3 | import networkx as nx |
4 | 4 | import logging, random |
5 | 5 | import pandas as pd |
|
9 | 9 | from DAS.results import * |
10 | 10 | from DAS.observer import * |
11 | 11 | from DAS.validator import * |
| 12 | +from dht import DHTNetwork |
12 | 13 |
|
13 | 14 | class Simulator: |
14 | 15 | """This class implements the main DAS simulator.""" |
@@ -177,6 +178,23 @@ def initNetwork(self): |
177 | 178 | self.logger.debug("Val %d : rowN %s", i, self.validators[i].rowNeighbors, extra=self.format) |
178 | 179 | self.logger.debug("Val %d : colN %s", i, self.validators[i].columnNeighbors, extra=self.format) |
179 | 180 |
|
| 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 | + |
180 | 198 | def initLogger(self): |
181 | 199 | """It initializes the logger.""" |
182 | 200 | logging.TRACE = 5 |
@@ -216,7 +234,7 @@ def printDiagnostics(self): |
216 | 234 | self.logger.debug("Column %d, Neighbor %d sent: %s" % (c, val.columnNeighbors[c][nc].node.ID, val.columnNeighbors[c][nc].received), extra=self.format) |
217 | 235 | 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) |
218 | 236 |
|
219 | | - def run(self): |
| 237 | + def runBlockBroadcasting(self): |
220 | 238 | """It runs the main simulation until the block is available or it gets stucked.""" |
221 | 239 | self.glob.checkRowsColumns(self.validators) |
222 | 240 | for i in range(0,self.shape.numberNodes): |
@@ -307,3 +325,6 @@ def run(self): |
307 | 325 | self.result.populate(self.shape, self.config, missingVector) |
308 | 326 | return self.result |
309 | 327 |
|
| 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 |
0 commit comments