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); } } }
/// <summary> /// Determines whether the given dsr route request message is a own request. /// </summary> /// <param name="reqMessage">The request message.</param> /// <returns> /// <c>true</c> if is own request; otherwise, <c>false</c>. /// </returns> private bool IsOwnRequest(AodvRouteRequestMessage reqMessage) { return(reqMessage.Sender.Equals(this.Client.Id)); }
/// <summary> /// Determines whether this protocol instance has a cached request the specified request id. /// </summary> /// <param name="reqMessaged">The request messaged.</param> /// <returns> /// <c>true</c> if is cached request; otherwise, <c>false</c>. /// </returns> private bool HasCachedRequest(AodvRouteRequestMessage reqMessaged) { return(this.RequestCache .FirstOrDefault(r => r.Id.Equals(reqMessaged.Sender))?.HasCachedRequest(reqMessaged.RequestId) ?? false); }