Example #1
0
        /// <summary>
        /// Sends a netgram using a supplied route
        /// </summary>
        /// <param name="route">The route to send with</param>
        /// <param name="content">The content to of the netgram to send</param>
        private void _sendWithRoute(Route route, NetgramContent content)
        {
            var  destination = content.Destination;
            byte portId;
            Mac  mac;

            if (destination.IsGlobalBroadcast())
            {
                // global broadcast
                content.Header.Destination = Address.GlobalBroadcast;
                portId = 255;
                mac    = Mac.Broadcast;
            }
            else if (destination.IsDirectedlyConnectedBroadcast())
            {
                // broadcast on all directly connected networks
                content.Header.Destination = null;
                portId = 255;
                mac    = Mac.Broadcast;
            }
            else if (route.NextHop.IsBroadcast())
            {
                // directly attached network
                content.Header.Destination = null;
                portId = route.PortId;
                mac    = destination.Mac;
            }
            else
            {
                // not directly attached
                content.Header.Destination = destination;
                portId = route.PortId;
                mac    = route.NextHop;
            }

            OutboundNetgram netgram = new OutboundNetgram();

            netgram.PortId      = portId;
            netgram.Destination = mac;
            netgram.Content     = content;
            if (_portManager != null)
            {
                _portManager.SendNetgram(netgram);
            }
        }
Example #2
0
        /// <summary>
        /// Sends an appgram
        /// </summary>
        /// <param name="appgram">The appgram to send</param>
        public void SendAppgram(OutboundAppgram appgram)
        {
            Contract.Requires(appgram != null);
            Contract.Requires(appgram.Destination != null);
            Contract.Requires(appgram.Content != null);

            var header = new NetgramHeader();

            header.Destination      = null;
            header.Source           = null;
            header.HopCount         = 64;
            header.IsNetworkMessage = false;
            header.ExpectingReply   = appgram.ExpectingReply;
            header.Priority         = appgram.Priority;
            var content = new NetgramContent(appgram.Destination, header, appgram.Content);

            lock (_lock)
            {
                _send(content);
            }
        }
Example #3
0
        /// <summary>
        /// Sends a netgram containing either a network message or an appgram
        /// </summary>
        /// <param name="content">The netgram content to send</param>
        private void _send(NetgramContent content)
        {
            var   destination = content.Destination;
            Route route       = null;

            if (destination.IsGlobalBroadcast() || destination.IsDirectedlyConnectedBroadcast())
            {
                // don't need a route, since we are globally broadcasting
                _sendWithRoute(null, content);
            }
            else if ((route = _table.GetRoute(destination.Network)) != null)
            {
                // we have a route to the destination network, which we can use
                _sendWithRoute(route, content);
            }
            else
            {
                // we currently have no route to the network, so we
                // need to enqueue the netgram and search for this network
                _netgramQueue.AddLast(content);
                _queueNetworkSearch(destination.Network);
            }
        }