From ef4e32ed53a3a0793f42a0451448b62429e879bc Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 7 Mar 2023 13:24:11 +0100 Subject: [PATCH] introduce node classes Signed-off-by: Csaba Kiraly --- DAS/shape.py | 18 +++++++++++++----- DAS/simulator.py | 3 ++- DAS/validator.py | 21 ++++++++++++++++----- config_example.py | 16 +++++++++++----- study.py | 2 +- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/DAS/shape.py b/DAS/shape.py index 7b24f6e..b707e51 100644 --- a/DAS/shape.py +++ b/DAS/shape.py @@ -3,16 +3,20 @@ class Shape: """This class represents a set of parameters for a specific simulation.""" - def __init__(self, blockSize, numberValidators, failureRate, chi, netDegree, bwUplink, run): + def __init__(self, blockSize, numberValidators, failureRate, class1ratio, chi1, chi2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run): """Initializes the shape with the parameters passed in argument.""" self.run = run self.numberValidators = numberValidators self.blockSize = blockSize self.failureRate = failureRate self.netDegree = netDegree - self.chi = chi + self.class1ratio = class1ratio + self.chi1 = chi1 + self.chi2 = chi2 + self.bwUplinkProd = bwUplinkProd + self.bwUplink1 = bwUplink1 + self.bwUplink2 = bwUplink2 self.randomSeed = "" - self.bwUplink = bwUplink def __repr__(self): """Returns a printable representation of the shape""" @@ -20,8 +24,12 @@ class Shape: shastr += "bs-"+str(self.blockSize) shastr += "-nbv-"+str(self.numberValidators) shastr += "-fr-"+str(self.failureRate) - shastr += "-chi-"+str(self.chi) - shastr += "-bwu-"+str(self.bwUplink) + shastr += "-c1r-"+str(self.class1ratio) + shastr += "-chi1-"+str(self.chi1) + shastr += "-chi2-"+str(self.chi2) + shastr += "-bwupprod-"+str(self.bwUplinkProd) + shastr += "-bwup1-"+str(self.bwUplink1) + shastr += "-bwup2-"+str(self.bwUplink2) shastr += "-nd-"+str(self.netDegree) shastr += "-r-"+str(self.run) return shastr diff --git a/DAS/simulator.py b/DAS/simulator.py index f0195cd..2d6e635 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -126,7 +126,8 @@ class Simulator: self.result = Result(self.shape) for val in self.validators: val.shape.failureRate = shape.failureRate - val.shape.chi = shape.chi + val.shape.chi1 = shape.chi1 + val.shape.chi2 = shape.chi2 # In GossipSub the initiator might push messages without participating in the mesh. # proposerPublishOnly regulates this behavior. If set to true, the proposer is not diff --git a/DAS/validator.py b/DAS/validator.py index 6a1b80a..71e5791 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -55,11 +55,17 @@ class Validator: self.sendQueue = deque() self.amIproposer = amIproposer self.logger = logger - if self.shape.chi < 1: + if self.shape.chi1 < 1 or self.shape.chi2 < 1: self.logger.error("Chi has to be greater than 0", extra=self.format) - elif self.shape.chi > self.shape.blockSize: + elif self.shape.chi1 > self.shape.blockSize or self.shape.chi2 > self.shape.blockSize: self.logger.error("Chi has to be smaller than %d" % blockSize, extra=self.format) else: + if self.amIproposer: + self.chi = 1 # not used + elif self.ID <= shape.numberValidators * shape.class1ratio: + self.chi = shape.chi1 + else: + self.chi = shape.chi2 if amIproposer: self.rowIDs = range(shape.blockSize) self.columnIDs = range(shape.blockSize) @@ -69,11 +75,11 @@ class Validator: if rows: self.rowIDs = rows else: - self.rowIDs = random.sample(range(self.shape.blockSize), self.shape.chi) + self.rowIDs = random.sample(range(self.shape.blockSize), self.chi) if columns: self.columnIDs = columns else: - self.columnIDs = random.sample(range(self.shape.blockSize), self.shape.chi) + self.columnIDs = random.sample(range(self.shape.blockSize), self.chi) self.rowNeighbors = collections.defaultdict(dict) self.columnNeighbors = collections.defaultdict(dict) @@ -86,7 +92,12 @@ class Validator: # Set uplink bandwidth. In segments (~560 bytes) per timestep (50ms?) # 1 Mbps ~= 1e6 / 20 / 8 / 560 ~= 11 # TODO: this should be a parameter - self.bwUplink = shape.bwUplink if not self.amIproposer else 2200 # approx. 10Mbps and 200Mbps + if self.amIproposer: + self.bwUplink = shape.bwUplinkProd + elif self.ID <= shape.numberValidators * shape.class1ratio: + self.bwUplink = shape.bwUplink1 + else: + self.bwUplink = shape.bwUplink2 self.repairOnTheFly = True self.sendLineUntil = (self.shape.blockSize + 1) // 2 # stop sending on a p2p link if at least this amount of samples passed diff --git a/config_example.py b/config_example.py index 59d8fef..b718528 100644 --- a/config_example.py +++ b/config_example.py @@ -15,6 +15,7 @@ if needed. import logging import itertools +import numpy as np from DAS.shape import Shape dumpXML = 1 @@ -44,12 +45,17 @@ blockSizes = range(32,65,16) # Per-topic mesh neighborhood size netDegrees = range(6, 9, 2) +class1ratios = np.arange(0, 1, .2) + # Number of rows and columns a validator is interested in -chis = range(4, 9, 2) +chis1 = range(1, 5, 2) +chis2 = range(10, 30, 20) # Set uplink bandwidth. In segments (~560 bytes) per timestep (50ms?) # 1 Mbps ~= 1e6 / 20 / 8 / 560 ~= 11 -bwUplinks = [11, 110] +bwUplinksProd = [2200] +bwUplinks1 = [2200] +bwUplinks2 = [110] # Set to True if you want your run to be deterministic, False if not deterministic = False @@ -58,9 +64,9 @@ deterministic = False randomSeed = "DAS" def nextShape(): - for run, fr, chi, blockSize, nv, netDegree, bwUplink in itertools.product( - runs, failureRates, chis, blockSizes, numberValidators, netDegrees, bwUplinks): + for run, fr, class1ratio, chi1, chi2, blockSize, nv, netDegree, bwUplinkProd, bwUplink1, bwUplink2 in itertools.product( + runs, failureRates, class1ratios, chis1, chis2, blockSizes, numberValidators, netDegrees, bwUplinksProd, bwUplinks1, bwUplinks2): # Network Degree has to be an even number if netDegree % 2 == 0: - shape = Shape(blockSize, nv, fr, chi, netDegree, bwUplink, run) + shape = Shape(blockSize, nv, fr, class1ratio, chi1, chi2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run) yield shape diff --git a/study.py b/study.py index 2503895..3efd83e 100644 --- a/study.py +++ b/study.py @@ -40,7 +40,7 @@ def study(): print("You need to pass a configuration file in parameter") exit(1) - shape = Shape(0, 0, 0, 0, 0, 0, 0) + shape = Shape(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) sim = Simulator(shape, config) sim.initLogger() results = []