Ejemplo n.º 1
0
        private void IncomingDsrRouteReplyMessageHandler(NetSimMessage message)
        {
            DsrTable             dsrTable   = this.Table as DsrTable;
            DsrRouteReplyMessage repMessage = (DsrRouteReplyMessage)message;

            // handle route caching
            dsrTable?.HandleReplyRouteCaching(repMessage, this.Client.Id);

            // check if the respone is for this node
            if (repMessage.Receiver.Equals(this.Client.Id))
            {
                // save found route to table
                dsrTable?.HandleResponse(repMessage);
            }
            else
            {
                // forward message
                this.SendMessage(repMessage);
            }
        }
Ejemplo n.º 2
0
        private void IncomingDsrRouteErrorMessageHandler(NetSimMessage message)
        {
            DsrTable             dsrTable     = this.Table as DsrTable;
            DsrRouteErrorMessage errorMessage = (DsrRouteErrorMessage)message;

            // delete the (cached) routes defined by the error message from table
            dsrTable?.HandleError(errorMessage.Sender, errorMessage.NotReachableNode);

            // check if the respone is for this node
            if (errorMessage.Receiver.Equals(this.Client.Id))
            {
                // check if error has failed message
                if (errorMessage.FailedMessage != null)
                {
                    // try to retransmit the failed message - start route discovery again
                    this.SendMessage(errorMessage.FailedMessage);
                }
            }
            else
            {
                // forward message
                this.SendMessage(errorMessage);
            }
        }
Ejemplo n.º 3
0
        private void IncomingDsrRouteRequestMessageHandler(NetSimMessage message)
        {
            DsrTable dsrTable = (DsrTable)this.Table;
            DsrRouteRequestMessage reqMessage = (DsrRouteRequestMessage)message;

            // if duplicate
            if (this.HasCachedRequest(reqMessage))
            {
                // ignore message and proceed
                return;
            }

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

            // add this node id to message Route
            reqMessage.Nodes.Add(this.Client.Id);

            // if this node was sender of request - ignore
            if (this.IsOwnRequest(reqMessage))
            {
                return;
            }

            // cache route
            dsrTable.HandleRequestRouteCaching(reqMessage);

            // check if message destination is current node (me)
            if (reqMessage.Receiver.Equals(this.Client.Id))
            {
                // send back rrep mesage the reverse way with found route
                var response = new DsrRouteReplyMessage()
                {
                    Receiver = reqMessage.Sender,
                    Sender   = this.Client.Id,
                    Route    = new List <string>(reqMessage.Nodes)
                };

                // enqueue message for sending
                this.SendMessage(response);

                return;
            }
            else
            {
                // Check if route to the end destination for request is cached
                var route = this.Table.GetRouteFor(reqMessage.Receiver);

                if (route != null)
                {
                    var dsrRoute = (DsrTableEntry)route;

                    var newRoute = new List <string>(reqMessage.Nodes);

                    // remove last entry
                    newRoute.RemoveAt(newRoute.Count - 1);

                    // add cached route entries
                    newRoute.AddRange(dsrRoute.Route);

                    // send back rrep mesage the reverse way with found route
                    // note: sender is the orig. receiver of the req
                    var response = new DsrRouteReplyMessage()
                    {
                        Receiver = reqMessage.Sender,
                        Sender   = reqMessage.Receiver,
                        Route    = newRoute
                    };

                    // enqueue message for sending
                    this.SendMessage(response);

                    return;
                }
            }

            // forward message to outgoing messages
            this.SendMessage(reqMessage);
        }