From f2a51eb8e1dfd5b49146ba02fb2004a101f154d7 Mon Sep 17 00:00:00 2001 From: Arunima Chaudhuri Date: Tue, 23 Jan 2024 01:46:18 +0530 Subject: [PATCH] Introduce randomization for malicious nodes Signed-off-by: Arunima Chaudhuri --- DAS/simulator.py | 21 +++++++++++++++++---- DAS/visualizor.py | 20 ++++++++++---------- smallConf.py | 4 ++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index faffdff..00ba951 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -71,13 +71,26 @@ class Simulator: assignedRows = [] assignedCols = [] maliciousNodesCount = int((self.shape.maliciousNodes / 100) * self.shape.numberNodes) + remainingMaliciousNodes = maliciousNodesCount + for i in range(self.shape.numberNodes): - if i==0: + if i == 0: amImalicious_value = 0 - elif i < maliciousNodesCount+1: - amImalicious_value = 1 else: - amImalicious_value = 0 + if not self.config.randomizeMaliciousNodes: + # Assign based on predefined pattern when randomization is turned off + if i < maliciousNodesCount + 1: + amImalicious_value = 1 + else: + amImalicious_value = 0 + else: + # Randomly assign amImalicious_value when randomization is turned on + if remainingMaliciousNodes > 0 and random.random() < (self.shape.maliciousNodes / 100): + amImalicious_value = 1 + remainingMaliciousNodes -= 1 + else: + amImalicious_value = 0 + if self.config.evenLineDistribution: if i < int(lightVal/self.shape.vpn1): # First start with the light nodes start = i *self.shape.chi*self.shape.vpn1 diff --git a/DAS/visualizor.py b/DAS/visualizor.py index fb582e9..ab1e57f 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -12,7 +12,7 @@ def plotData(conf): else: xDes = conf["xdots"][-1] * 0.6 props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) - plt.text(xDes, conf["yaxismax"]/4, conf["textBox"], fontsize=10, verticalalignment='top', bbox=props) + plt.text(xDes, conf["yaxismax"]/3, conf["textBox"], fontsize=10, verticalalignment='top', bbox=props) if conf["type"] == "plot": for i in range(len(conf["data"])): plt.plot(conf["xdots"], conf["data"][i], conf["colors"][i], label=conf["labels"][i]) @@ -86,7 +86,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Percentage of Samples Received by Nodes" conf["type"] = "individual_bar" conf["legLoc"] = 1 @@ -108,7 +108,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Missing Samples" conf["type"] = "plot" conf["legLoc"] = 1 @@ -136,7 +136,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Nodes/validators ready" conf["type"] = "plot" conf["legLoc"] = 2 @@ -168,7 +168,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Sent data" conf["type"] = "plot" conf["legLoc"] = 2 @@ -198,7 +198,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Received data" conf["type"] = "plot" conf["legLoc"] = 2 @@ -228,7 +228,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Duplicated data" conf["type"] = "plot" conf["legLoc"] = 2 @@ -255,7 +255,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Row/Column distribution" conf["type"] = "grouped_bar" conf["legLoc"] = 2 @@ -280,7 +280,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Number of Messages Sent by Nodes" conf["type"] = "individual_bar" conf["legLoc"] = 1 @@ -300,7 +300,7 @@ class Visualizor: conf = {} text = str(result.shape).split("-") conf["textBox"] = "Block Size: "+text[1]+"\nNumber of nodes: "+text[3]\ - +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns" + +"\nFailure rate: "+text[7]+" \nNetwork degree: "+text[23]+"\nX: "+text[11]+" rows/columns"+"\nMalicious Nodes: "+text[27]+"%" conf["title"] = "Number of Messages Received by Nodes" conf["type"] = "individual_bar" conf["legLoc"] = 1 diff --git a/smallConf.py b/smallConf.py index e1c9125..e5f6ccd 100644 --- a/smallConf.py +++ b/smallConf.py @@ -59,6 +59,10 @@ failureRates = [0] # Percentage of nodes that are considered malicious maliciousNodes = [95] +# Parameter to determine whether to randomly assign malicious nodes or not +# If True, the malicious nodes will be assigned randomly; if False, a predefined pattern may be used +randomizeMaliciousNodes = True + # Block size in one dimension in segments. Block is blockSizes * blockSizes segments. blockSizes = [128]