Exemplo n.º 1
0
        /// <summary>
        /// Handles the not reachable route.
        /// </summary>
        /// <param name="nextHopId">The next hop identifier.</param>
        /// <param name="frameMessage">The frame message.</param>
        private void HandleNotReachableRoute(string nextHopId, DsrFrameMessage frameMessage)
        {
            var dsrTable = this.Table as DsrTable;

            // remove notreachable route
            dsrTable?.HandleError(this.Client.Id, nextHopId);

            // broadcast route error to neighbors - Neighbors remove every route with sender -> notreachable in path
            this.Client.BroadcastMessage(
                new DsrRouteErrorMessage()
            {
                Sender = this.Client.Id, NotReachableNode = nextHopId,
            });

            if (frameMessage != null)
            {
                // send route error to sender with back path in message
                // receiver removes every route with sender - notreachable in path
                this.SendMessage(
                    new DsrRouteErrorMessage()
                {
                    Sender           = this.Client.Id,
                    Receiver         = frameMessage.Sender,
                    Route            = frameMessage.Route,
                    NotReachableNode = nextHopId,
                    FailedMessage    = frameMessage.Data
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the new outgoing message.
        /// </summary>
        /// <param name="queuedMessage">The queued message.</param>
        private void HandleRouteDiscoveryForOutgoingMessage(NetSimQueuedMessage queuedMessage)
        {
            // search the route for message (also in cache)
            var searchedRoute = this.GetDsrRoute(queuedMessage.Message.Receiver);

            // if route found - send the message via the connection
            if (searchedRoute != null)
            {
                var sendMessage = queuedMessage.Message;

                // pack message in dsrframemessage and set found route
                var dsrFrame = new DsrFrameMessage()
                {
                    Data     = (NetSimMessage)sendMessage.Clone(),
                    Receiver = sendMessage.Receiver,
                    Sender   = sendMessage.Sender,
                    Route    = new List <string>(searchedRoute.Route),
                };

                // determine the next hop of the requested route
                var nextHopId = dsrFrame.GetNextHop(this.Client.Id);

                // lay message on wire - intial send
                if (this.IsConnectionReachable(nextHopId))
                {
                    this.Client.Connections[nextHopId].StartTransportMessage(dsrFrame, this.Client.Id, nextHopId);
                }
                else
                {
                    this.HandleNotReachableRoute(nextHopId, null);
                }
            }
            else
            {
                // if route not found and route discovery is not started for this message
                if (!queuedMessage.IsRouteDiscoveryStarted)
                {
                    // mark as started
                    queuedMessage.IsRouteDiscoveryStarted = true;

                    // broadcast to all neighbors
                    this.Client.BroadcastMessage(
                        new DsrRouteRequestMessage()
                    {
                        Sender    = this.Client.Id,
                        Receiver  = queuedMessage.Message.Receiver,
                        RequestId = this.CurrentRequestId,
                        Nodes     = { this.Client.Id }
                    },
                        false);

                    // increase route request id
                    this.CurrentRequestId++;
                }

                // and enqueue message again
                this.OutputQueue.Enqueue(queuedMessage);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone()
        {
            var clone = new DsrFrameMessage()
            {
                Route = new List <string>(this.Route),
                Data  = (NetSimMessage)this.Data.Clone()
            };

            return(this.CopyTo(clone));
        }