예제 #1
0
    def process_rerr_message(self, message):
        self.logger.debug("Processing RERR message %s" % message)

        message_type = message['type']
        sender = message['sender']
        dest_addr = message['dest_addr']
        dest_sequence = message['dest_sequence']

        # IF THERE IS ADDINTIONAL INFO IN THE PACKET, PROCESS THIS FIRST
        if message.get('op_info'):
            additional_info = message.get('op_info')

            for rt in additional_info:
                route = bd_connect.consult_target(rt['dest_addr'])
                if route:
                    if route[0].get('next_hop') == sender:
                        bd_connect.update_routing_table(
                            ('status', 0, 'ID', route[0].get('ID')))

        # Process message only if there is an active route
        # to the destination where next hop IP address is the same
        # as the sender IP address in the packet received.

        target = bd_connect.consult_target(dest_addr)
        if target:
            if target[0].get('next_hop') == sender:
                bd_connect.update_routing_table(
                    ('status', 0, 'ID', target[0].get('ID')))
                self.forward_rerr(message)
예제 #2
0
    def process_rrep(self, message):
        self.logger.debug("Processing RREP message %s" % message)

        sender = message["sender"]
        source_addr = message["source_addr"]
        hop_count = int(message["hop_cnt"]) + 1
        message['hop_cnt'] = str(hop_count)
        dest_addr = message["dest_addr"]
        dest_sequence = message["dest_sequence"]

        routing_list = (
            source_addr,
            sender,
            dest_sequence,
            hop_count,
            1,
            1,
        )

        if self.localhost == dest_addr:
            record = bd_connect.consult_target(source_addr)
            if record:
                if record[0].get('hop_count') > hop_count:
                    bd_connect.insert_routing_table(routing_list)
            else:
                bd_connect.insert_routing_table(routing_list)

            find_rt_end_time = time.time()
            final_time = find_rt_end_time - self.times_dict[source_addr]
            self.logger.info("Route to %s found in %s" %
                             (source_addr, final_time))

            for msg in self.message_pend_list:
                self.logger.debug("[process_rrep] Evaluating: %s" % msg)
                if msg['dest_addr'] == source_addr:
                    next_hop = sender
                    self.send(next_hop, msg)
                    self.message_pend_list.remove(msg)
        else:
            record = bd_connect.consult_target(source_addr)
            if record:
                bd_connect.update_routing_table(
                    ('status', 1, 'ID', record[0].get('ID')))
                bd_connect.update_routing_table(
                    ('target_seq_number', dest_sequence, 'ID',
                     record[0].get('ID')))
            else:
                bd_connect.insert_routing_table(routing_list)

            record = bd_connect.consult_target(dest_addr)
            self.forward_rrep(message, record[0].get('next_hop'))
예제 #3
0
    def process_user_message(self, message):
        source = message['source_addr']
        dest = message['dest_addr']
        data = message['data']

        if self.localhost == dest:
            self.logger.info('Message received: %s' % data)
        else:
            route = bd_connect.consult_target(dest)
            self.send(route[0].get('next_hop'), message)
예제 #4
0
    def process_neighbor_timeout(self, node):
        self.logger.debug("Timeout activated for %s" % node)

        target = bd_connect.consult_target(node)
        bd_connect.update_routing_table(
            ('status', 0, 'ID', target[0].get('ID')))

        next_hop_list = bd_connect.consult_next_hop(node)
        route_nh_list = []

        for rt in next_hop_list:
            obj = {}
            obj['dest_addr'] = rt['target_address']
            obj['dest_sequence'] = rt['target_seq_number']

            route_nh_list.append(obj)

        # Send RERR
        self.send_rerr(node, target[0].get('target_seq_number'), route_nh_list)
예제 #5
0
    def notify_network(self, msg):
        self.logger.debug("Notifying to nodes %s" % self.nodes)
        if self.nodes:
            #CONSULT NEIGHBOR IP ADDRESS IN BD ROUTING TABLE
            for ngh in self.nodes:
                message = {
                    'type': 'notify',
                    'source_addr': self.localhost,
                    'dest_addr': ngh,
                    'data': msg
                }
                target = bd_connect.consult_target(ngh)
                self.logger.debug("Record %s" % target)
                if target:
                    self.logger.info("Target %s found " % ngh)
                    self.send(target[0].get('next_hop'), message)
                else:
                    self.logger.info("Target %s not found" % ngh)

                    self.times_dict[ngh] = time.time()
                    self.send_rreq(ngh, -1)
                    self.message_pend_list.append(message)
예제 #6
0
    def process_hello_message(self, message):
        sender = message['sender']
        try:
            if sender in self.neighbors.keys():
                ngh = self.neighbors[sender]
                timer = ngh['timer']
                timer.cancel()
                timer = th.Timer(AODV_HELLO_TIMEOUT,
                                 self.process_neighbor_timeout, [sender])

                self.neighbors[sender] = {'neighbor': sender, 'timer': timer}

                timer.start()
            else:
                timer = th.Timer(AODV_HELLO_TIMEOUT,
                                 self.process_neighbor_timeout, [sender])

                self.neighbors[sender] = {'neighbor': sender, 'timer': timer}

                timer.start()
                self.logger.debug("Neighbor added: %s" % sender)

                if bd_connect.consult_target(sender):
                    #RESTART ROUTE LIFETIME (PENDING)
                    pass
                else:
                    route = (
                        sender,  #Target
                        sender,  #Next_hop
                        1,  #Target sequence number
                        1,  #Hop count
                        1,  #Status
                        1,  #Lifetime
                    )
                    bd_connect.insert_routing_table(route)

                    #RESTART ROUTE LIFETIME (PENDING)
        except:
            pass
예제 #7
0
    def process_rreq(self, message):
        self.logger.debug("Processing RREQ message %s" % message)
        message = message
        message_type = message['type']
        sender = message['sender']
        hop_count = int(message['hop_cnt']) + 1
        message['hop_cnt'] = str(hop_count)
        broadcast_id = int(message['broadcast_id'])
        dest_addr = message['dest_addr']
        dest_sequence = int(message['dest_sequence'])
        source_addr = message['source_addr']
        source_sequence = int(message['source_sequence'])

        routing_list = (
            source_addr,
            sender,
            dest_sequence,
            hop_count,
            1,  #Lifetime
            1,  #status
        )

        # Discard this RREQ if we have already received this before
        rt_record = bd_connect.consult_target(source_addr)

        if bd_connect.consult_duplicate((source_addr, broadcast_id)):
            self.logger.debug("RREQ duplicate found!")
            return
        elif rt_record:

            # 1. If originator sequence number in packet is bigger than destination sequence in routing table
            #    Update target sequence number in DB.
            #
            # 2. If originator sequence number and destination sequence number are equal, but hop count in DB
            #    is bigger than hop count in packet, update hop count in DB.
            #
            # 3. If detination sequence number is unknown (-1), update sequence number in DB.

            if int(rt_record[0].get("target_seq_number")) < source_sequence:
                bd_connect.update_routing_table(
                    ("target_seq_number", source_sequence, 'ID',
                     rt_record[0].get("ID")))

            elif int(rt_record[0].get("target_seq_number")) == source_sequence:
                if rt_record[0].get("hop_count") > hop_count:
                    bd_connect.update_routing_table(
                        ("hop_count", hop_count, 'ID', rt_record[0].get("ID")))
                    bd_connect.update_routing_table(
                        ("next_hop", sender, 'ID', rt_record[0].get("ID")))

            elif int(rt_record[0].get("target_seq_number") == -1):
                bd_connect.update_routing_table(
                    ("target_seq_number", source_sequence, 'ID',
                     rt_record[0].get("ID")))

        else:
            # If there's no route to destination, and originator is not the
            # same as node IP address, add entry
            if source_addr != self.localhost:
                bd_connect.insert_routing_table(routing_list)
                bd_connect.insert_rreq((source_addr, broadcast_id))

        # Check if localhost is the destination. If it is, generate and send an
        # RREP back.
        if (self.localhost == dest_addr):
            self.send_rrep(source_addr, sender, dest_addr, dest_addr, 0, 0)

        # Localhost is not the destination. Check if this node has a valid route
        # to the destination. If it does, generate and send back an
        # RREP.
        else:
            target = bd_connect.consult_target(dest_addr)
            self.logger.debug("[process_rreq] Target Record %s" % target)
            if (target):
                # Verify that the route is valid and has a higher seq number

                if target[0].get("target_seq_number") >= dest_sequence:
                    self.send_rrep(source_addr, sender, self.localhost,
                                   dest_addr,
                                   target[0].get("target_seq_number"),
                                   target[0].get("hop_count"))
            else:
                self.forward_rreq(message)