Beispiel #1
0

class Receiver(simx.PyService):
    def __init__(self, name, node, service_input):
        super(Receiver, self).__init__(name, node, service_input, self)

    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):
Beispiel #2
0
    def recv(self,msg):
        
        #debug3.write("HelloHandlerPerson: Inside receive method")
        self.recv_function[msg.__class__.__name__](msg)
        #rf = random.choice([self.recv_hello, self.recv_reply])
        #rf(msg)

    def recv_HelloMessage(self,msg):    
        simx.debug3.write("HelloHandler received hello",msg)
        simx.output.write(self,100,'Received a hello')
        simx.output.write(self,200,"Random number:",
                     self.get_random().get_uniform() )
        #simulate some computation
        # x = int(random.expovariate(0.00001))
        # for i in xrange(x):
        #     j = math.sqrt(i)
        self.send_info(ReplyMessage(source_id=self.get_entity_id(),
                                    dest_id=msg.source_id),
                       simx.get_min_delay(), msg.source_id,eAddr_HelloHandlerPerson)

    def recv_ReplyMessage(self,msg):
        simx.debug3.write("HelloHandlerPerson::receive(Reply):",msg)
        simx.output.write(self,100,"Received a reply")

    def __str__(self):
        return "HelloHandler(%s)" %(self.get_entity_id())

# should we make this one call? i.e register_service and register_addr?
simx.register_service(HelloHandlerPerson)
simx.register_address("eAddr_HelloHandlerPerson",eAddr_HelloHandlerPerson)
Beispiel #3
0
    def recv(self, msg):
        self.recv_function[msg.__class__.__name__](msg)
    
    def recv_loc_msg(self, msg):
        assert(False)
        try:
            self.node.neighbor_pos[msg.id] = msg.loc
        except KeyError:
            print "Neighbor ", id, " does not exist for node ",self.node.get_id()
    
    def recv_loc_list_msg(self,msg):
        for node,location in msg.pos_info.iteritems():
            Gpos[node] = location

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

node_list=[]

class Node(simx.PyEntity):

    def __init__(self,ID, lp, entity_input, py_obj=None):
        if py_obj is None:
            py_obj = self
        super(Node,self).__init__(ID,lp,entity_input,py_obj)
        #simx.debug2.write("Node",self.get_id(),"is being created with input ",
        #                  entity_input.data_," at time ",self.get_now())
        self.attr = entity_input.data_
        self.gnode_id = self.attr['gnode_id']
        self.loc = Gpos[self.gnode_id]
        self.vel = (0.0,0.0) 
Beispiel #4
0
    def recv_loc_msg(self, msg):
        assert (False)
        try:
            self.node.neighbor_pos[msg.id] = msg.loc
        except KeyError:
            print "Neighbor ", id, " does not exist for node ", self.node.get_id(
            )

    def recv_loc_list_msg(self, msg):
        for node, location in msg.pos_info.iteritems():
            Gpos[node] = location


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

node_list = []


class Node(simx.PyEntity):
    def __init__(self, ID, lp, entity_input, py_obj=None):
        if py_obj is None:
            py_obj = self
        super(Node, self).__init__(ID, lp, entity_input, py_obj)
        #simx.debug2.write("Node",self.get_id(),"is being created with input ",
        #                  entity_input.data_," at time ",self.get_now())
        self.attr = entity_input.data_
        self.gnode_id = self.attr['gnode_id']
        self.loc = Gpos[self.gnode_id]
        self.vel = (0.0, 0.0)
Beispiel #5
0
    def recv_HelloMessage(self, msg):
        #print "person ",self.get_entity_id()," received hello from ", \
        #   msg.source_id, " at time ", simx.get_now()
        #simx.debug3.write("HelloHandler received hello",msg)
        #simx.output.write(self,100,'Received a hello')
        #simx.output.write(self,200,"Random number:",
        #             self.get_random().get_uniform() )
        #simulate some computation
        # x = int(random.expovariate(0.00001))
        # for i in xrange(x):
        #     j = math.sqrt(i)
        self.send_info(
            ReplyMessage(source_id=self.get_entity_id(),
                         dest_id=msg.source_id), simx.get_min_delay(),
            msg.source_id, eAddr_HelloHandlerPerson)

    def recv_ReplyMessage(self, msg):
        #simx.debug3.write("HelloHandlerPerson::receive(Reply):",msg)
        #simx.output.write(self,100,"Received a reply")
        #print "person ",self.get_entity_id()," received reply from ", \
        #    msg.source_id, " at time ", simx.get_now()
        pass

    def __str__(self):
        return "HelloHandler(%s)" % (self.get_entity_id())


# should we make this one call? i.e register_service and register_addr?
simx.register_service(HelloHandlerPerson)
simx.register_address("eAddr_HelloHandlerPerson", eAddr_HelloHandlerPerson)
Beispiel #6
0
addr_RECEIVER = 1000
class Receiver(simx.PyService):
    def __init__(self,name,node,service_input):
        super(Receiver,self).__init__(name,node,service_input,self)

    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)