Beispiel #1
0
        targetId = random.randrange(count)
        offset = int(exponential(1) + min_delay)
        #print "node ",self.get_entity_id()," sending message with offset ",\
        #    offset," at time ",simx.get_now(), "to target ", targetId
        self.send_info(None, offset, ('n', targetId), addr_RECEIVER)


simx.register_service(Receiver)
simx.register_address("addr_RECEIVER", addr_RECEIVER)


class Node(simx.PyEntity):
    def __init__(self, ID, lp, entity_input, py_obj=None):
        super(Node, self).__init__(ID, lp, entity_input, self)
        self.install_service(Receiver, addr_RECEIVER)
        #print "node ",ID," being created"


simx.init("phold")
simx.set_end_time(500000)
simx.set_min_delay(1)
simx.init_env()

for i in xrange(count):
    simx.create_entity(('n', i), Node)

for i in xrange(count):
    simx.schedule_event(0, ('n', i), addr_RECEIVER, None)

simx.run()
Beispiel #2
0
# Free Software Foundation. Accordingly, this library is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt for more details.

import simx
from Person import *
from HelloHandler import *

random.seed(0)

num_entities = 32
end_time = 1000000

# initialize
simx.init("helloworldv2")
simx.set_end_time(end_time)
simx.set_min_delay(1)
simx.init_env()

# create Persons
for i in xrange(num_entities):
    simx.create_entity(('p', i), Person)


# create a message generation process
class MessageGen(simx.Process):
    """
    Schedule simple message sending and receiving
    """
    def run(self):
        for evt_time in xrange(1, end_time / 2 - 1):
Beispiel #3
0
        plt.show()
    
    def run(self):
        while(simx.get_now() < end_time):
            plt.clf()
            nx.draw_networkx_edges(G,Gpos,nodelist=[ncenter],alpha=0.4,edge_color='grey')
            nx.draw_networkx_nodes(G,Gpos,node_size=80,nodelist=p.keys(),node_color=p.values(),cmap=plt.cm.Reds_r)
            plt.xlim(-0.05,1.05)
            plt.ylim(-0.05,1.05)
            plt.axis('off')
            plt.draw()
            self.sleep(update_interval)


simx.init("consensus")
simx.set_end_time(end_time)
simx.set_min_delay(min_delay)
#simx.set_log_level("debug3")
simx.init_env()

for i in xrange(num_nodes):
    simx.create_entity(('n',i),Node,ent_data=({'gnode_id':i}))
    node_list.append(simx.get_entity(('n',i)))

#quit()
    
simx.get_controller().install_service(Receiver,eAddr_RECVR)
simx.schedule_process(Updater())

#only rank 0 does the plotting
if plot == True:
Beispiel #4
0
            " at time ", simx.get_now()
        
        
        bp = self.os.create_process(BarProcess)
        # waits for Bar process to finish before resuming
        self.waitfor(bp)

        print "Foo process ",id(self)," on node",self.os.get_entity_id(), \
            "returned from waitfor. Acquired resource ",self.resource, \
            " at time ", simx.get_now()



#initialize
simx.init("ossim")
simx.set_end_time(1000)
simx.set_min_delay(1)
simx.set_log_level("debug3")
simx.init_env()

num_nodes = 1

#create nodes
for i in xrange(num_nodes):
    simx.create_entity(('n',i), os.Node,ent_data=({'num_cores':1}))

num_processes = 1
#on each node create foo processes
for i in xrange(num_nodes):
    node = simx.get_entity(('n',i))
    # the node might not live in this memory space
Beispiel #5
0
    """
    Just another process
    """
    def __init__(self, id_):
        self.id_ = id_

    def run(self):
        print "foo process: ", self.id_, " Time: ", simx.get_now()
        #if id == 0:
        #    self.spawn(fooprocess(id+1))
        self.sleep(2)
        print "foo process: ", self.id_, " wake up at time:", simx.get_now()

    def end(self):
        print "foo process: ", self.id_, " ends here"


simx.init("cd")

simx.set_min_delay(1)
simx.set_end_time(100)
simx.set_log_level("debug3")

simx.init_env()

for i in range(1):
    cd = CountDown(i, 10)
    simx.schedule_process(cd)

simx.run()
Beispiel #6
0
import simx
from Person import *
from HelloHandler import *

# initialize
simx.init("helloworld")
simx.set_end_time(1024)
simx.set_min_delay(1)
simx.init_env()

# create Persons
person_list = []
num_persons = 1024
for i in xrange(num_persons):
    simx.create_entity(('p', i), Person)
    person_list.append(('p', i))

#schedule events
for evt_time in range(1, end_time):
    hello_rcvr = random.choice(person_list)
    reply_rcvr = random.choice(person_list)
    simx.schedule_event(evt_time, hello_rcvr, eAddr_HelloHandlerPerson,
                        HelloMessage(source_id=reply_rcvr))

#Run the simulation
simx.run()
Beispiel #7
0
    def recv(self, msg):
        targetId = random.randrange(count)
        offset = int(exponential(1) + min_delay)
        #print "node ",self.get_entity_id()," sending message with offset ",\
        #    offset," at time ",simx.get_now(), "to target ", targetId
        self.send_info(None,offset,('n',targetId),
                       addr_RECEIVER)
                       
simx.register_service(Receiver)
simx.register_address("addr_RECEIVER",addr_RECEIVER)
        
class Node(simx.PyEntity):
    def __init__(self,ID,lp,entity_input,py_obj=None):
        super(Node,self).__init__(ID,lp,entity_input,self)
        self.install_service(Receiver, addr_RECEIVER)
        #print "node ",ID," being created"


simx.init("phold")
simx.set_end_time(500000)
simx.set_min_delay(1)
simx.init_env()
        
for i in xrange(count):
    simx.create_entity(('n',i),Node)

for i in xrange(count):
    simx.schedule_event(0,('n',i),addr_RECEIVER,None)

simx.run()