Ejemplo n.º 1
0
        private void OutgoingAodvRouteErrorMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            // get AodvHelloMessage instacne
            var errorMessage = (AodvRouteErrorMessage)queuedMessage.Message;

            // indicates that the error messages was broadcasted
            if (this.Client.Connections.ContainsKey(errorMessage.Receiver))
            {
                if (this.IsConnectionReachable(errorMessage.Receiver))
                {
                    // start message transport
                    this.Client.Connections[errorMessage.Receiver].StartTransportMessage(
                        errorMessage,
                        this.Client.Id,
                        errorMessage.Receiver);
                }
            }
            else
            {
                // error message sgets forwared among active path
                var nextHopId = this.Table.GetRouteFor(errorMessage.Receiver)?.NextHop;

                if (nextHopId != null && this.IsConnectionReachable(nextHopId))
                {
                    // start message transport
                    this.Client.Connections[nextHopId].StartTransportMessage(errorMessage, this.Client.Id, nextHopId);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the new outgoing message.
        /// </summary>
        /// <param name="queuedMessage">The queued message.</param>
        private void HandleRouteDiscoveryForOutgoingMessage(NetSimQueuedMessage queuedMessage)
        {
            // if route not found and route discovery is not started for this message
            if (!queuedMessage.IsRouteDiscoveryStarted)
            {
                // mark as started
                queuedMessage.IsRouteDiscoveryStarted = true;

                // increment SequenceNr every time a rreq gets sent
                this.CurrentSequence.SequenceNr += 2;

                // broadcast to all neighbors
                this.Client.BroadcastMessage(
                    new AodvRouteRequestMessage()
                {
                    Sender           = this.Client.Id,
                    Receiver         = queuedMessage.Message.Receiver,
                    RequestId        = this.CurrentRequestId,
                    SenderSequenceNr = (AodvSequence)this.CurrentSequence.Clone(),
                    LastHop          = this.Client.Id
                },
                    false);

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

            // and enqueue message again
            this.OutputQueue.Enqueue(queuedMessage);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        private void OutgoingAodvRouteRequestMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            // get dsr requestMessage instacne - note: the request message was alreay handled in incomings messages
            var requestMessage = (AodvRouteRequestMessage)queuedMessage.Message;

            // broadcast to all neighbors
            this.Client.BroadcastMessage(requestMessage, false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles the outgoing DSR message.
        /// Note: Messages handled in this methods where initially send from another node.
        /// </summary>
        /// <param name="queuedMessage">The queued message.</param>
        private void ForwardAodvMessage(NetSimQueuedMessage queuedMessage)
        {
            // searches a handler method with the messagehandler attribute and the
            // right message type and for incoming(false) or outgoing (true, default) messages.
            // e.g. IncomingAodvRouteRequestMessageHandler
            var method = this.handlerResolver.GetHandlerMethod(queuedMessage.Message.GetType());

            method?.Invoke(this, new object[] { queuedMessage });
        }
Ejemplo n.º 6
0
        private void OutgoingAodvHelloMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            // get AodvHelloMessage instacne
            var helloMessage = (AodvHelloMessage)queuedMessage.Message;

            if (this.IsConnectionReachable(helloMessage.Receiver))
            {
                // start message transport
                this.Client.Connections[helloMessage.Receiver].StartTransportMessage(
                    helloMessage,
                    this.Client.Id,
                    helloMessage.Receiver);
            }
        }
Ejemplo n.º 7
0
        private void OutgoingDsrRouteErrorMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            var errorMessage = (DsrRouteErrorMessage)queuedMessage.Message;

            // get the next hop id from the route info saved within this message
            string nextHopId = errorMessage.GetNextReverseHop(this.Client.Id);

            // if client has this connection (e.g. not deleted) and connection is not offline
            if (this.IsConnectionReachable(nextHopId))
            {
                // start message transport
                this.Client.Connections[nextHopId].StartTransportMessage(errorMessage, this.Client.Id, nextHopId);
            }
        }
Ejemplo n.º 8
0
        private void OutgoingDsrRouteReplyMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            var responseMessage = (DsrRouteReplyMessage)queuedMessage.Message;

            // get the next hop id from the route info saved within this message
            string nextHopId = responseMessage.GetNextReverseHop(this.Client.Id);

            if (this.IsConnectionReachable(nextHopId))
            {
                // start message transport
                this.Client.Connections[nextHopId].StartTransportMessage(responseMessage, this.Client.Id, nextHopId);
            }
            else
            {
                this.HandleNotReachableRoute(nextHopId, null);
            }
        }
Ejemplo n.º 9
0
        private void OutgoingAodvRouteReplyMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            var aodvTable       = (AodvTable)this.Table;
            var responseMessage = (AodvRouteReplyMessage)queuedMessage.Message;

            // get the next hop id from the route table (reverse route)
            string nextHopId = aodvTable.GetRouteFor(responseMessage.Receiver).NextHop;

            if (this.IsConnectionReachable(nextHopId))
            {
                // start message transport
                this.Client.Connections[nextHopId].StartTransportMessage(responseMessage, this.Client.Id, nextHopId);
            }
            else
            {
                this.HandleRouteError(nextHopId, responseMessage.Sender, responseMessage.Receiver);
            }
        }
Ejemplo n.º 10
0
        private void OutgoingDsrFrameMessageHandler(NetSimQueuedMessage queuedMessage)
        {
            // get dsr frame message instacne
            var frameMessage = (DsrFrameMessage)queuedMessage.Message;

            // get next hop from in frame message saved route info
            var nextHop = frameMessage.GetNextHop(this.Client.Id);

            if (this.IsConnectionReachable(nextHop))
            {
                // lay message "on" wire - start transmitting via connection
                this.Client.Connections[nextHop].StartTransportMessage(frameMessage, this.Client.Id, nextHop);
            }
            else
            {
                this.HandleNotReachableRoute(nextHop, frameMessage);
            }
        }