Commit d10cebea authored by THAKARE AKSHAY HARIBHAU's avatar THAKARE AKSHAY HARIBHAU

Merge branch 'netSim'

Global watch created , each loop is a tick of 1 millisecond

THe timer simmulates network and network simulates lisnks first
and then nodes as there may be amessage in current link which is to be delievered to node in current tick itself.
parents 30c170cc 1d7e6aa6
from SystemEntity import SystemEntity
import logging
logger = logging.getLogger(__name__)
class Network(SystemEntity):
def __init__(self):
#TODO need better datastructure store these
self.nodes = []
self.links = []
def setupNetwork(self):
# TODO add nodes
# TODO add links
pass
def simulate(self,time):
logger.info("simulating .. ")
# Note links should be simulated before nodes
# in order to receive the messge which is supposed to be received in this tick
for link in self.links:
link.simulate(time)
for node in self.nodes:
node.simulate(time)
pass
import SystemEntity
import logging
logger = logging.getLogger(__name__)
class Node(SystemEntity.SystemEntity):
def __init__(self,id):
self.id = id
def simulate(self,time):
logger.info("simulating .. ")
logger.info(" hello "+self.id)
pass
\ No newline at end of file
from TimeSimulator import TimeSimulator
from Network import Network
import logging
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()
metronome.startTicking(network.simulate)
pass
\ No newline at end of file
import logging
logger = logging.getLogger(__name__)
class SystemEntity(object):
def __init__(self):
self.todoList = []
def simulate(self,time):
pass
import logging
logger = logging.getLogger(__name__)
class TimeSimulator(object):
class __TimeSimulator:
def __init__(self):
self._systemTime = 0
def __str__(self):
# return repr(self) + str(self._systemTime)
return "Time : "+ str(self._systemTime)
def startTicking(self,callback):
for i in range(10):
self._systemTime = self._systemTime + 1
logger.info(self)
callback(self._systemTime)
instance = None
def __new__(cls): # __new__ always a classmethod
if not TimeSimulator.instance:
TimeSimulator.instance = TimeSimulator.__TimeSimulator()
return TimeSimulator.instance
def __getattr__(self, name):
return getattr(self.instance, name)
def __setattr__(self, name):
return setattr(self.instance, name)
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