Exemple #1
0
        protected void ResetState(object contab, EventArgs arg)
        {
            ConnectionEventArgs cea = (ConnectionEventArgs)arg;
            ConnectionList      cel = cea.CList;
            //Here's the tranaction:
            AHState state = _state; //Only read of _state
            AHState old_state;
            AHState new_state;

            do
            {
                old_state = state;
                if (cel.MainType == ConnectionType.Structured)
                {
                    new_state = old_state.UpdateStructs(cel);
                }
                else if (cel.MainType == ConnectionType.Leaf)
                {
                    new_state = old_state.UpdateLeafs(cel);
                }
                else
                {
                    //we ignore this type:
                    new_state = old_state;
                }
                state = System.Threading.Interlocked.CompareExchange <AHState>(ref _state, new_state, old_state);
            }while(old_state != state);
        }
Exemple #2
0
        /**
         * You still need to Subscribe this.  This constructor DOES NOT
         * do that
         */
        public AHHandler(Node n)
        {
            _n = n;
            var stcons = _n.ConnectionTable.GetConnections(ConnectionType.Structured);
            var lfcons = _n.ConnectionTable.GetConnections(ConnectionType.Leaf);

            _state = new AHState((AHAddress)n.Address, stcons, lfcons);
            _n.ConnectionTable.ConnectionEvent    += this.ResetState;
            _n.ConnectionTable.DisconnectionEvent += this.ResetState;
        }
Exemple #3
0
            protected AHState(AHState old_state, ConnectionList leafs)
            {
                Leafs   = leafs;
                Structs = old_state.Structs;
                Local   = old_state.Local;

                _directional = old_state._directional;
                _greedy      = old_state._greedy;
                _annealing   = old_state._annealing;
            }
Exemple #4
0
        /**
         * Here we handle routing AHPackets
         */
        public void HandleData(MemBlock data, ISender ret_path, object st)
        {
            AHState state   = _state; //Read the state, it can't change after the read
            var     header  = new AHHeader(data);
            var     payload = data.Slice(header.Length);

            Connection next_con;
            //Check to see if we can use a Leaf connection:
            int dest_idx = state.Leafs.IndexOf(header.Destination);

            if (dest_idx >= 0)
            {
                next_con = state.Leafs[dest_idx];
            }
            else
            {
                var alg = state.GetRoutingAlgo(header);
                Pair <Connection, bool> result = alg.NextConnection(ret_path as Edge, header);
                if (result.Second)
                {
                    //Send a response exactly back to the node that sent to us
                    var resp_send = new AHSender(_n, ret_path, header.Source,
                                                 AHSender.DefaultTTLFor(_n.NetworkSize),
                                                 AHHeader.Options.Exact);
                    _n.HandleData(payload, resp_send, this);
                }
                next_con = result.First;
            }
            //Send it on:
            if (next_con != null)
            {
                //Now we do the sending:
                var new_packet = new CopyList(PType.Protocol.AH,
                                              header.IncrementHops(),
                                              payload);
                try {
                    next_con.Edge.Send(new_packet);
                }
                catch (EdgeException) {
                    //Just drop the packet...
                }
            }
        }
Exemple #5
0
 /**
  * You still need to Subscribe this.  This constructor DOES NOT
  * do that
  */
 public AHHandler(Node n) {
   _n = n;
   var stcons = _n.ConnectionTable.GetConnections(ConnectionType.Structured);
   var lfcons = _n.ConnectionTable.GetConnections(ConnectionType.Leaf);
   _state = new AHState((AHAddress)n.Address, stcons, lfcons);
   _n.ConnectionTable.ConnectionEvent += this.ResetState;
   _n.ConnectionTable.DisconnectionEvent += this.ResetState;
 }
Exemple #6
0
    protected AHState(AHState old_state, ConnectionList leafs) {
      Leafs = leafs;
      Structs = old_state.Structs;
      Local = old_state.Local;

      _directional = old_state._directional;
      _greedy = old_state._greedy;
      _annealing = old_state._annealing;
    }
Exemple #7
0
        public void HandleData(AHHeader header, ICopyable payload, ISender ret_path, object st)
        {
            AHState    state = _state; //Read the state, it can't change after the read
            Connection next_con;
            //Check to see if we can use a Leaf connection:
            int dest_idx = state.Leafs.IndexOf(header.Destination);

            if (dest_idx >= 0)
            {
                next_con = state.Leafs[dest_idx];
            }
            else
            {
                var alg = state.GetRoutingAlgo(header);
                Pair <Connection, bool> result = alg.NextConnection(ret_path as Edge, header);
                if (result.Second)
                {
                    //Send a response exactly back to the node that sent to us
                    var resp_send = new AHSender(_n, ret_path, header.Source,
                                                 AHSender.DefaultTTLFor(_n.NetworkSize),
                                                 AHHeader.Options.Exact, header.Hops);
                    MemBlock data = payload as MemBlock;
                    if (data == null)
                    {
                        // Try to get the shared BufferAllocator, useful when we don't know
                        // how big the data is, which in general is just as expensive as
                        // doing a CopyTo...
                        BufferAllocator ba = Interlocked.Exchange <BufferAllocator>(ref _ba, null);
                        if (ba != null)
                        {
                            try {
                                int length = payload.CopyTo(ba.Buffer, ba.Offset);
                                data = MemBlock.Reference(ba.Buffer, ba.Offset, length);
                                ba.AdvanceBuffer(length);
                            } catch (System.Exception x) {
                                throw new SendException(false, "could not write the packet, is it too big?", x);
                            } finally {
                                Interlocked.Exchange <BufferAllocator>(ref _ba, ba);
                            }
                        }
                        else
                        {
                            data = MemBlock.Copy(payload);
                        }
                    }
                    _n.HandleData(data, resp_send, this);
                }
                next_con = result.First;
            }
            //Send it on:
            if (next_con != null)
            {
                //Now we do the sending:
                var new_packet = new CopyList(PType.Protocol.AH,
                                              header.IncrementHops(),
                                              payload);
                try {
                    next_con.State.Edge.Send(new_packet);
                }
                catch (SendException) {
                    //Just drop the packet...
                }
            }
        }