created Overlay node

parent bc94379c
from SystemEntity import SystemEntity
from Node import Node
import logging
logger = logging.getLogger(__name__)
......@@ -15,6 +14,7 @@ class Link(SystemEntity):
'''
SystemEntity.__init__(self,network)
self.logger = logging.getLogger(__name__ + "-" + str(link))
self.upNode = link[0]
self.downNode = link[1]
......@@ -39,10 +39,10 @@ class Link(SystemEntity):
:return:
'''
node = self.network.nodes.get(params[0])
node.enqueMessge((time, params[1]))
node.enqueMessage((time, params[1]))
pass
def enqueMessge(self,message):
def enqueMessage(self,message):
'''
:param message: (timestamp , payload) --- timestamp is the tick value at which node has inserted this message in queue
......@@ -54,7 +54,7 @@ class Link(SystemEntity):
self.messageQueue.append(message)
print("message enqued")
def dequeMessge(self):
def dequeMessage(self):
return self.messageQueue.pop(0)
def scheduleMessageDelievery(self,time,payload):
......@@ -65,7 +65,7 @@ class Link(SystemEntity):
def simulate(self,time):
# logger.info("simulating .. ")
# self.logger.info("simulating .. ")
'''
Process message first then process task in todo-list
......
......@@ -50,7 +50,7 @@ class Network():
def simulate(self,time):
logger.info("simulating .. ")
# logger.info("simulating .. ")
self.networkClockTime = time
# Note links should be simulated before nodes
# in order to receive the messge which is supposed to be received in this tick
......
from SystemEntity import SystemEntity
import logging
logger = logging.getLogger(__name__)
class Node(SystemEntity):
def __init__(self,id,network):
SystemEntity.__init__(self,network)
self.logger = logging.getLogger(__name__ + "-" + str(id))
self.id = id
self.adjacentNodes = []
self.messageQueue = []
'''make sure methods included here are not overriddenn'''
self.commands={"sendMessage":self.sendMessage,
}
def enqueMessge(self,message):
def enqueMessage(self,message):
'''
:param message: (timestamp , payload) --- timestamp is the tick value at which node has inserted this message in queue
......@@ -25,7 +26,7 @@ class Node(SystemEntity):
self.messageQueue.append(message)
print("message enqued")
def dequeMessge(self):
def dequeMessage(self):
return self.messageQueue.pop(0)
......@@ -37,15 +38,19 @@ class Node(SystemEntity):
:return:
'''
link = self.network.links.get((params[0],params[1]))
link.enqueMessge((time,params))
logger.info("Sending Message : " + str((time,params)))
link.enqueMessage((time,params))
self.logger.info("Sending : " + str((time,params)))
pass
def processMessage(self,time,payload):
print("fianlly reachec : " + str(payload))
print("fianlly reached : " + str(payload))
'''remove any extra headers like source and destination here '''
payload.pop(0) # removed source header
payload.pop(0) #removed destination header
def simulate(self,time):
# logger.info("simulating .. ")
# self.logger.info("simulating .. ")
'''
Process message first then process task in todo list
Here it is just intuition , i don`t what should be processing sequence
......@@ -56,8 +61,10 @@ class Node(SystemEntity):
'''
# todo process messages in queue
# generate tasks for todolist based on messges
for message in self.messageQueue:
self.processMessage(message[0],message[1]) # message : (time,(payload))
for message in list(self.messageQueue): #this creates adupliacte list and iterate over it while making changes to original queue
self.processMessage(message[0],list(message[1])) # message : (time,(payload))
self.logger.info("received : "+str(message))
self.dequeMessage()
# TODO : perform task from todolist which are relevant for current tick
......@@ -77,17 +84,13 @@ if __name__ == '__main__':
# node = Node('1')
# cmd = node.commands.get("sendMessage")
# cmd("1 ","2 "," : Hello world")
x = [1,2,3,4,5,6]
for i in list(x):
y= x.pop(0)
print(y)
from collections import defaultdict
# when accessing a key, if it has no value - create a list by default
d = defaultdict(list)
d["key"].append("a value")
d["key"].append("another value")
print(d)
x = d.pop("key2")
print(x)
print(d.get("key2"))
......
from Node import Node
import logging
class OverlayNode(Node):
def __init__(self,id,network):
Node.__init__(self,id,network)
self.commands.update({})
def processMessage(self,time,payload):
super(OverlayNode, self).processMessage(time,payload)
print("from overlay node : "+str(payload))
class A(object):
def __init__(self,id):
self.id = id
self.commands = {"sendMessage": self.sendMessage,
}
def sendMessage(self):
pass
def process(self,param):
print("from A " +str(param) )
param.pop(0)
param.pop(0)
class B(A):
def __init__(self,id):
A.__init__(self, id)
self.commands.update({"hello":self.working})
def working(self):
pass
def process(self,param):
super(B, self).process(param)
print("from B" + str(param))
if __name__ == '__main__':
l = (1,2,tuple(str('3|4|5').split('|')))
x = B(2)
print(x.commands)
x.process(list(l))
......@@ -8,9 +8,6 @@ logging.basicConfig(filename='ASim.log', level=logging.INFO)
logger = logging.getLogger(__name__)
def simulateThis(time):
logger.info("ticking time"+str(time))
if __name__ == '__main__':
metronome = TimeSimulator()
network = Network()
......
1 5 sendMessage 1 2 hello2
2 3 sendMessage 2 3 hello3
4 5 sendMessage 4 1 hello1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment