Exemplo n.º 1
0
        /// <summary>
        /// Handles the request route caching.
        /// </summary>
        /// <param name="repMessage">The request message.</param>
        public void HandleReplyRoute(AodvRouteReplyMessage repMessage)
        {
            // search for already cached route
            var route = (AodvTableEntry)this.GetRouteFor(repMessage.Sender);

            // add route if route doesn't exist
            if (route == null)
            {
                // add route to table
                this.AddRouteEntry(
                    repMessage.Sender,
                    repMessage.LastHop,
                    repMessage.HopCount + 1,
                    (AodvSequence)repMessage.ReceiverSequenceNr.Clone());
            }
            else
            {
                // if route exists check if sequencenr of request is newer - information in message is newer
                if (repMessage.ReceiverSequenceNr.CompareTo(route.SequenceNr) == 1)
                {
                    if (repMessage.HopCount + 1 < route.Metric)
                    {
                        // remove route and add new one
                        this.Entries.Remove(route);

                        // add new route
                        this.AddRouteEntry(
                            repMessage.Sender,
                            repMessage.LastHop,
                            repMessage.HopCount + 1,
                            (AodvSequence)repMessage.ReceiverSequenceNr.Clone());
                    }
                }
            }

            // handle active neighbour list of route
            route = (AodvTableEntry)this.GetRouteFor(repMessage.Sender);

            // add repmessage sender to active neighbours of route
            if (!route.ActiveNeighbours.ContainsKey(repMessage.Sender))
            {
                route.ActiveNeighbours.Add(repMessage.Sender, 0);
            }

            // add repmessage last hop to active neighbours of route
            if (!route.ActiveNeighbours.ContainsKey(repMessage.LastHop))
            {
                route.ActiveNeighbours.Add(repMessage.LastHop, 0);
            }
        }
Exemplo n.º 2
0
        private void IncomingAodvRouteReplyMessageHandler(NetSimMessage message)
        {
            AodvRouteReplyMessage repMessage = (AodvRouteReplyMessage)message;
            var aodvTable = this.Table as AodvTable;

            // handle the neighbour lsit update - inactive timer management
            this.UpdateNeighbourList(repMessage.Sender);
            this.UpdateNeighbourList(repMessage.LastHop);

            // save found route to table
            aodvTable?.HandleReplyRoute(repMessage);

            // check if the respone is not for this node . then forward
            if (!repMessage.Receiver.Equals(this.Client.Id))
            {
                // update reply message - increase hopcount and update last hop
                repMessage.LastHop   = this.Client.Id;
                repMessage.HopCount += 1;

                // forward message
                this.SendMessage(repMessage);
            }
        }
Exemplo n.º 3
0
        private void IncomingAodvRouteRequestMessageHandler(NetSimMessage message)
        {
            AodvTable aodvTable = (AodvTable)this.Table;
            AodvRouteRequestMessage reqMessage = (AodvRouteRequestMessage)message;

            // if this node was sender of request - or has already a cached version of request
            if (this.IsOwnRequest(reqMessage) || this.HasCachedRequest(reqMessage))
            {
                // ignore message and proceed
                return;
            }

            // add request to cache
            this.AddCachedRequest(reqMessage);

            // add reverse routing entry - if route doesn't exist or sequencenr is newer
            aodvTable.HandleRequestReverseRouteCaching(reqMessage);

            // update request message - increase hopcount and update last hop
            reqMessage.LastHop   = this.Client.Id;
            reqMessage.HopCount += 1;

            // check if message destination is current node
            if (reqMessage.Receiver.Equals(this.Client.Id))
            {
                // send back rrep mesage the reverse way
                var response = new AodvRouteReplyMessage()
                {
                    Receiver           = reqMessage.Sender,
                    Sender             = this.Client.Id,
                    ReceiverSequenceNr = (AodvSequence)this.CurrentSequence.Clone(),
                    LastHop            = this.Client.Id
                };

                // enqueue message for sending
                this.SendMessage(response);
            }
            else
            {
                // Check if route was cached
                var searchRoute = aodvTable.SearchCachedRoute(reqMessage);

                if (searchRoute != null)
                {
                    // send reply back to requester - send back rrep mesage the reverse way
                    var response = new AodvRouteReplyMessage()
                    {
                        Receiver           = reqMessage.Sender,
                        Sender             = searchRoute.Destination,
                        ReceiverSequenceNr = (AodvSequence)searchRoute.SequenceNr.Clone(),
                        HopCount           = searchRoute.Metric,
                        LastHop            = this.Client.Id
                    };

                    // enqueue message for sending
                    this.SendMessage(response);
                }
                else
                {
                    // forward message to outgoing messages
                    this.SendMessage(reqMessage);
                }
            }
        }