Пример #1
0
        /// <summary>
        /// Handles the route maintenance.
        /// </summary>
        private void HandleRouteMaintenance()
        {
            // if neighbour list is emtpy - return
            if (this.Neighbours.Count == 0)
            {
                return;
            }

            AodvTable aodvTable = (AodvTable)this.Table;

            // after a period of time perform route maintaince via hello messages
            if (this.StepCounter % this.periodicHelloUpdateCounter == 0)
            {
                // broadcast send hello messages to every neighbours
                foreach (var neighborId in this.Neighbours.Keys)
                {
                    // enqueue the message for sending
                    this.SendMessage(
                        new AodvHelloMessage()
                    {
                        Sender           = this.Client.Id,
                        Receiver         = neighborId,
                        SenderSequenceNr = (AodvSequence)this.CurrentSequence.Clone()
                    });
                }
            }

            // decrease the neigbor response time (clone key list)
            foreach (string key in this.Neighbours.Keys.ToList())
            {
                this.Neighbours[key] -= 1;
            }

            // select neighbours where the inactive coutner is zero or less
            var inactiveNeighbours = this.Neighbours.Where(n => n.Value <= 0).Select(n => n.Key).ToList();

            // if a neighbour was for a period of time inactive (hellotimer * 2)
            if (inactiveNeighbours.Any())
            {
                foreach (var neighbourId in inactiveNeighbours)
                {
                    var routeErrorReceivers = aodvTable.HandleRouteMaintaince(neighbourId);

                    // enqueue route error messages for sending to route error receivers
                    routeErrorReceivers.ForEach(
                        receiver =>
                        this.SendMessage(
                            new AodvRouteErrorMessage()
                    {
                        Sender   = this.Client.Id,
                        Receiver = receiver,
                        UnReachableDestination           = neighbourId,
                        UnReachableDestinationSequenceNr = (AodvSequence)this.CurrentSequence.Clone()
                    }));

                    // remove the inactive neighbour
                    this.Neighbours.Remove(neighbourId);
                }
            }
        }
Пример #2
0
        private void IncomingAodvHelloMessageHandler(NetSimMessage message)
        {
            AodvHelloMessage helloMessage = (AodvHelloMessage)message;
            AodvTable        aodvTable    = (AodvTable)this.Table;

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

            // search for a route for hello message sender
            AodvTableEntry route = (AodvTableEntry)aodvTable.GetRouteFor(helloMessage.Sender);

            // create route for neighbour if not exists
            if (route == null)
            {
                aodvTable.AddRouteEntry(
                    helloMessage.Sender,
                    helloMessage.Sender,
                    1,
                    (AodvSequence)helloMessage.SenderSequenceNr.Clone());
            }
        }
Пример #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);
                }
            }
        }