Exemplo n.º 1
0
        /**
         * Find neighbor connections within the range
         * return ArrayList of List<Connection> for left and right neighbors.
         */
        private Brunet.Collections.Pair <List <Connection>, List <Connection> > GetConnectionInfo(AHAddress t_addr, AHAddress start, AHAddress end, ConnectionList cl)
        {
            //this node is within the given range (start_addr, end_addr)
            List <Connection> left_con_list  = new List <Connection>();
            List <Connection> right_con_list = new List <Connection>();

            foreach (Connection c in cl)
            {
                AHAddress adr = (AHAddress)c.Address;
                //if(adr.IsBetweenFromLeft(t_addr, end) ) {
                if (InRange(adr, start, t_addr))
                {
                    left_con_list.Add(c);
                }
                //else if (adr.IsBetweenFromLeft(start, t_addr) ) {
                else if (InRange(adr, start, t_addr))
                {
                    right_con_list.Add(c);
                }
                else
                {
                    //Out of Range. Do nothing!
                }
            }
            //Make a compare and add it to ConnectionTable to sort by Address
            ConnectionLeftComparer left_cmp = new ConnectionLeftComparer(t_addr);

            left_con_list.Sort(left_cmp);
            ConnectionRightComparer right_cmp = new ConnectionRightComparer(t_addr);

            right_con_list.Sort(right_cmp);
            Brunet.Collections.Pair <List <Connection>, List <Connection> > ret = new Brunet.Collections.Pair <List <Connection>, List <Connection> >(left_con_list, right_con_list);
            return(ret);
        }
Exemplo n.º 2
0
        /**
         * Generates tree for bounded broadcast. Algorithm works as follows:
         * The goal is to broadcast to all nodes in range (start, end).
         * Given a range (a, b), determine all connections that belong to this range.
         * Let the left connections be l_1, l_2, ..... l_n.
         * Let the right connections be r_1, r_2, ... , r_n.
         * To left connection l_i assign the range [b_{i-1}, b_i).
         * To right connection r_i assign the range [r_i, r_{i-1}]
         * To the connection ln assign range [l_{n-1}, end)
         * To the connection rn assign range (start, r_{n-1}]
         */
        public override void GenerateTree(Channel q, MapReduceArgs mr_args)
        {
            ArrayList gen_list    = mr_args.GenArg as ArrayList;
            string    start_range = gen_list[0] as string;
            AHAddress start_addr  = (AHAddress)AddressParser.Parse(start_range);
            AHAddress end_addr;
            string    end_range;

            /// If users do not specify an end range, this method understands
            /// that users intend to broadcasting the whole range.
            /// Thus, the address of end range is set to (start_address - 2),
            /// the farthest address from the start_addr.
            if (gen_list.Count < 2)
            {
                BigInteger start_int = start_addr.ToBigInteger();
                BigInteger end_int   = start_int - 2;
                end_addr  = new AHAddress(end_int);
                end_range = end_addr.ToString();
            }
            else
            {
                end_range = gen_list[1] as string;
                end_addr  = (AHAddress)AddressParser.Parse(end_range);
            }
            Log("generating child tree, range start: {0}, range end: {1}.", start_range, end_range);
            //we are at the start node, here we go:
            ConnectionTable      tab     = _node.ConnectionTable;
            ConnectionList       structs = tab.GetConnections(ConnectionType.Structured);
            List <MapReduceInfo> retval  = new List <MapReduceInfo>();

            if (InRange(_this_addr, start_addr, end_addr))
            {
                if (structs.Count > 0)
                {
                    //make connection list in the range.
                    //left connection list is a list of neighbors which are in the range (this node, end of range)
                    //right connection list is a list of neighbors which are in the range (start of range, this node)
                    Brunet.Collections.Pair <List <Connection>, List <Connection> > cons = GetConnectionInfo(_this_addr, start_addr, end_addr, structs);
                    List <Connection> left_cons  = cons.First as List <Connection>;
                    List <Connection> right_cons = cons.Second as List <Connection>;
                    //PrintConnectionList(left_cons);
                    //PrintConnectionList(right_cons);
                    retval = GenerateTreeInRange(start_addr, end_addr, left_cons, true, mr_args);
                    List <MapReduceInfo> ret_right = GenerateTreeInRange(start_addr, end_addr, right_cons, false, mr_args);
                    retval.AddRange(ret_right);
                }
                else //this node is a leaf node.
                //MapReduceInfo mr_info = null;
                //retval.Add(mr_info);
                //Console.WriteLine("no connection in the range: return null info");
                {
                }
            }
            else // _node is out of range. Just pass it to the closest to the middle of range.
            {
                retval = GenerateTreeOutRange(start_addr, end_addr, mr_args);
            }
            q.Enqueue(retval.ToArray());
        }
Exemplo n.º 3
0
 /**
  * Find neighbor connections within the range
  * return ArrayList of List<Connection> for left and right neighbors.
  */
 private Brunet.Collections.Pair<List<Connection>,List<Connection>> GetConnectionInfo(AHAddress t_addr, AHAddress start, AHAddress end, ConnectionList cl) {
    
   //this node is within the given range (start_addr, end_addr)
   List<Connection> left_con_list = new List<Connection>();
   List<Connection> right_con_list = new List<Connection>();
   foreach(Connection c in cl) {
     AHAddress adr = (AHAddress)c.Address;
     //if(adr.IsBetweenFromLeft(t_addr, end) ) {
     if (InRange(adr, start, t_addr) ) {
       left_con_list.Add(c);
     }
     //else if (adr.IsBetweenFromLeft(start, t_addr) ) {
     else if (InRange(adr, start, t_addr) ) {
       right_con_list.Add(c);
     }
     else {
       //Out of Range. Do nothing!
     }
   }
   //Make a compare and add it to ConnectionTable to sort by Address
   ConnectionLeftComparer left_cmp = new ConnectionLeftComparer(t_addr);
   left_con_list.Sort(left_cmp);
   ConnectionRightComparer right_cmp = new ConnectionRightComparer(t_addr);
   right_con_list.Sort(right_cmp);
   Brunet.Collections.Pair<List<Connection>,List<Connection>> ret = new Brunet.Collections.Pair<List<Connection>,List<Connection>>(left_con_list, right_con_list);
   return ret;
 }