/// <summary>
 /// Place a new message in the incoming-queue of this satellite.
 /// </summary>
 public void ReceiveMessage(Message.Message incomingMessage)
 {
     //Receive message with some probability
     if (RandomHelper.ReceiveData(_conf.LinkLayerReceptionProbability) && _inputQueue.Count < _conf.LinkBufferSize)
     {
         _statistics.LinkLayerAddReceivedMessage(incomingMessage);
         _inputQueue.Enqueue(new Message.Message(incomingMessage));
     }
     else
     {
         _statistics.LinkLayerAddDroppedMessage(incomingMessage);
     }
 }
        /// <summary>
        /// Send a message to another satellite.
        /// </summary>
        public LinkLayerResult SendMessage(Message.Message outgoingMessage, string nextHop)
        {
            var msg = new Message.Message(outgoingMessage); //Create copy of message

            //Dont forward messages with TTL == 0, pr. https://tools.ietf.org/html/rfc1812#section-4.2.2.9 / https://networkengineering.stackexchange.com/questions/10929/when-is-an-ipv4-ttl-decremented-and-what-is-the-drop-condition
            if (msg.Ttl <= 0)
            {
                _statistics.LinkLayerTtlExpired(msg);
                _logger.WriteLine("TTL reached 0 for " + msg.Type + " packet to " + msg.DestinationAddress + ", dropping packet.");
                return(new LinkLayerResult(LinkLayerResultType.TtlExpired));
            }

            msg.PreviousHop = _thisSatellite.LocalAddress;
            msg.DecrementTtl(); //Decrement TTL on egress part of router

            var neighbours     = GetAvailableLinks();
            var availableLinks = string.Join(", ", from item in neighbours.Values select item.LocalAddress);

            //If broadcast to all neighbours
            if (msg.DestinationAddress == SimulationConstants.BroadcastAddress || nextHop == SimulationConstants.BroadcastAddress)
            {
                _logger.WriteLine("Sending " + msg.Type + " broadcast packet. Destination: " + msg.DestinationAddress + ", Source: " + msg.SourceAddress + " Previous-hop: " + msg.PreviousHop + ", Next-hops: " + availableLinks);

                foreach (var link in neighbours)
                {
                    msg.AddPropagationDelay(_thisSatellite.Location, link.Value.Location);
                    link.Value.ReceiveNewMessage(new Message.Message(msg));
                }
            }
            else //Unicast towards specific neighbour (if available)
            {
                //If neighbour is not found, throw exception
                if (!neighbours.ContainsKey(nextHop))
                {
                    _logger.WriteLine("ERROR - LINK NOT FOUND. NextHop: " + nextHop + ", Available links: " + availableLinks);
                    return(new LinkLayerResult(new Message.Message(msg), nextHop));
                }

                _logger.WriteLine("Sending packet. Type: " + msg.Type + ", Destination: " + msg.DestinationAddress + ", Source: " + msg.SourceAddress + " Previous-hop: " + msg.PreviousHop + ", Next-hop: " + nextHop + ", Available links: " + availableLinks);
                msg.AddPropagationDelay(_thisSatellite.Location, neighbours[nextHop].Location);
                neighbours[nextHop].ReceiveNewMessage(new Message.Message(msg));
            }

            _statistics.LinkLayerAddSentMessage(msg);
            return(new LinkLayerResult(LinkLayerResultType.Success));
        }
예제 #3
0
 /// <summary>
 /// Place a message in this nodes queue (called from another satellite)
 /// </summary>
 /// <param name="msg">Message that other satellite wants to send to this satellite.</param>
 public void ReceiveNewMessage(Message.Message msg)
 {
     _linkLayer.ReceiveMessage(msg);
 }
예제 #4
0
 /// <summary>
 /// Send data message to other node
 /// </summary>
 /// <param name="msg">Message to transmit to other node.</param>
 public void SendMessage(Message.Message msg)
 {
     _networkLayer.SendDataMessage(msg);
 }