Example #1
0
def main():
    initialize()
    env = Environment()
    net = Network()
    nl = []
    # an instance that contains network stats
    stats = NetStats()

    for i in range(max_nodes-1):
        n = NodeClass(i, 0.2, 'coordbased', Sources(), net)
        nl.append(n)
    # declare coordinator
    c = CoordClass('coord', 0.3, 'coordbased', Sources(), net)
    # populate network with nodes
    nl.append(c)
    init_net_list(nl, net)
    init_node_protocol(nl)
    c.node.protocol.initCoord(nl)
    #activate(net, net.run())
    print "coord has been started"
    activate(c, c.run())
    print "coord ok, now initializing nodes"
    for ncls in nl:
        #initPhase(ncls.node)
        activate(ncls, ncls.run())
    # manual import of net's message queue to coord
    #c.node.protocol.incoming_messages = net.MSG_QUEUE
    # c.node.protocol.processRecvdMessage()
    simulate(until=maxSimTime)
    pdb.set_trace()
Example #2
0
 def setUp(self):
     """ initial setup"""
     self.net = Network()
     self.nc1 = NodeClass('simple_node_1', 0.1, 'coordbased', \
                         Sources(), self.net)
     self.nc2 = NodeClass('simple_node_2', 0.1, 'coordbased', \
                         Sources(), self.net)
     self.cc = CoordClass('coord', 0.1, 'coordbased', Sources(), self.net)
     self.li = [self.nc1, self.nc2, self.cc]
     self.nc1.node.protocol.initProtocol(self.li)
     self.nc2.node.protocol.initProtocol(self.li)
     self.cc.node.protocol.initProtocol(self.li)
     self.net.NodeList = self.li
Example #3
0
def main():
    initialize()
    env = Environment()
    net = Network()
    nl = []
    stats = NetStats()

    for i in range(max_nodes - 1):
        n = NodeClass(i, 0.2, 'coordbased', Sources(), net)
        nl.append(n)
    # declare coordinator
    c = CoordClass('coord', 0.3, 'coordbased', Sources(), net)
    nl.append(c)
    init_env(nl, env)
    init_net_list(nl, net)
    init_threading(nl, env)
    init_node_protocol(nl)
    c.node.protocol.initCoord(nl)
    activate(c, c.run())
    for ncls in nl:
        activate(ncls, ncls.run())
    simulate(until=maxSimTime)
Example #4
0
def main():
    initialize()
    env = Environment()
    net = Network()
    nl = []
    stats = NetStats()

    for i in range(max_nodes-1):
        n = NodeClass(i, 0.2, 'coordbased', Sources(), net)
        nl.append(n)
    # declare coordinator
    c = CoordClass('coord', 0.3, 'coordbased', Sources(), net)
    nl.append(c)
    init_env(nl, env)
    init_net_list(nl, net)
    init_threading(nl, env)
    init_node_protocol(nl)
    c.node.protocol.initCoord(nl)
    activate(c, c.run())
    for ncls in nl:
        activate(ncls, ncls.run())
    simulate(until=maxSimTime)
Example #5
0
class TestCoordClass(unittest.TestCase):
    
    def setUp(self):
        """ initial setup"""
        self.net = Network()
        self.nc1 = NodeClass('simple_node_1', 0.1, 'coordbased', \
                            Sources(), self.net)
        self.nc2 = NodeClass('simple_node_2', 0.1, 'coordbased', \
                            Sources(), self.net)
        self.cc = CoordClass('coord', 0.1, 'coordbased', Sources(), self.net)
        self.li = [self.nc1, self.nc2, self.cc]
        self.nc1.node.protocol.initProtocol(self.li)
        self.nc2.node.protocol.initProtocol(self.li)
        self.cc.node.protocol.initProtocol(self.li)
        self.net.NodeList = self.li


    def testRun(self):
        """ tests the run method. """
        self.cc.run()
        pass

    def testIncomingMsgs(self):
        """ tests the incomingMsgs method. """
        # wrong test
        initialize()
        activate(self.cc, self.cc.incomingMsgs())
        simulate(until=10)
        self.assertTrue(self.cc.busy_cpu)

    def test_sim(self):
        """ tests a real simple small simulation. """
        initialize()
        for node in self.li:
            activate(node, node.run())
            activate(node, node.incomingMsgs())
        self.net.run()
        simulate(until=10)
        self.assertTrue(self.cc.node.protocol.NodeList)
Example #6
0
 def setUp(self):
     """ initial setup for testing """
     # define network first
     self.net = Network()
     self.n1 = NodeClass(1, 0.1, 'coordbased', 'sources', self.net)
     self.n2 = NodeClass(2, 0.1, 'coordbased', 'sources', self.net)
     self.coordclass = CoordClass('coord', 0.1, 'coordbased', 'sources',
                                  self.net)
     self.coord = self.coordclass.node
     self.coord.protocol = CoordinatorProcess('coord', self.net)
     self.NodeList = [self.n1, self.n2, self.coordclass]
     # create a list with the nodes and the coordinator
     self.nl = [self.n1.node, self.n2.node, self.coord]
     # copy this list to network, too
     self.net.NodeList = self.nl
     # first of all, initialize protocol's nodelist
     self.n1.node.protocol.NodeList = self.n1.NodeList
     #self.coordclass.NodeList = self.NodeList
     self.coord.protocol.NodeList = self.NodeList