• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/diffusion/iflist.h

00001 
00002 /*
00003  * iflist.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: iflist.h,v 1.5 2005/08/25 18:58:04 johnh Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 /**********************************************************/
00048 /* iflist.h : Chalermek Intanagonwiwat (USC/ISI) 06/25/99 */
00049 /**********************************************************/
00050 
00051 
00052 #ifndef ns_iflist_h
00053 #define ns_iflist_h
00054 
00055 #include <stdio.h>
00056 #include "config.h"
00057 
00058 #define INTF_INSERT(x,y)  x->InsertFront((Agent_List **)&x, (Agent_List *)y)
00059 #define INTF_REMOVE(x,y)  y->Remove(x,y)
00060 #define INTF_FIND(x,y)    x->Find((Agent_List **)&x, y)
00061 #define INTF_FREEALL(x)   x->FreeAll((Agent_List **)&x)
00062 #define INTF_UNION(x,y)   x->Union((Agent_List **)&x, (Agent_List *)y)
00063 
00064 #define AGENT_NEXT(x)     x->next
00065 #define FROM_NEXT(x)      (From_List *)(x->next)
00066 #define OUT_NEXT(x)       (Out_List *)(x->next)
00067 #define IN_NEXT(x)        (In_List *)(x->next)
00068 
00069 #define AGT_ADDR(x)       x->agent_addr
00070 #define NODE_ADDR(x)      x->agent_addr.addr_
00071 #define PORT(x)           x->agent_addr.port_
00072 #define RANK(x)           ((From_List *)x)->rank
00073 #define IS_SINK(x)        ((From_List *)x)->is_sink
00074 
00075 #define GRADIENT(x)       ((Out_List *)x)->gradient
00076 #define GRAD_TMOUT(x)     ((Out_List *)x)->timeout
00077 #define FROM_SLOT(x)      ((Out_List *)x)->from
00078 #define TO_SLOT(x)        ((Out_List *)x)->to
00079 #define NUM_DATA_SEND(x)       ((Out_List *)x)->num_data_send
00080 #define NUM_NEG_RECV(x)       ((Out_List *)x)->num_neg_recv
00081 #define NUM_POS_RECV(x)       ((Out_List *)x)->num_pos_recv
00082 
00083 #define NUM_POS_SEND(x)   ((In_List *)x)->num_pos_send
00084 #define NUM_NEG_SEND(x)   ((In_List *)x)->num_neg_send
00085 #define LAST_TS_NEW_SUB(x) ((In_List *)x)->last_ts_new_sub
00086 #define NEW_SUB_RECV(x)   ((In_List *)x)->new_sub_recv
00087 #define NEW_ORG_RECV(x)   ((In_List *)x)->new_org_recv
00088 #define OLD_ORG_RECV(x)   ((In_List *)x)->old_org_recv
00089 #define TOTAL_NEW_SUB_RECV(x)   ((In_List *)x)->total_new_sub_recv
00090 #define TOTAL_NEW_ORG_RECV(x)   ((In_List *)x)->total_new_org_recv
00091 #define TOTAL_OLD_ORG_RECV(x)   ((In_List *)x)->total_old_org_recv
00092 
00093 #define TOTAL_RECV(x)     ((In_List *)x)->total_received
00094 #define PREV_RECV(x)      ((In_List *)x)->prev_received
00095 #define NUM_LOSS(x)       ((In_List *)x)->num_loss
00096 #define AVG_DELAY(x)      ((In_List *)x)->avg_delay
00097 #define VAR_DELAY(x)      ((In_List *)x)->var_delay
00098 
00099 #define WHERE_TO_GO(x)    x->WhereToGo()
00100 #define FIND_MAX_IN(x)    x->FindMaxIn()
00101 #define CAL_RANGE(x)      x->CalRange()
00102 #define NORMALIZE(x)      x->NormalizeGradient()
00103 
00104 class Agent_List;
00105 
00106 
00107 class PrvCurPtr {
00108 public:
00109   Agent_List **prv;
00110   Agent_List *cur;
00111 };
00112 
00113 
00114 class Agent_List {
00115 public:
00116   ns_addr_t agent_addr;
00117   Agent_List *next;
00118 
00119   Agent_List() { 
00120     next = NULL; 
00121     agent_addr.addr_=0;
00122     agent_addr.port_=0;
00123   }
00124 
00125   virtual ~Agent_List () {}
00126   
00127   void InsertFront(Agent_List **, Agent_List *);
00128   void Remove(Agent_List **, Agent_List *);
00129   PrvCurPtr Find(Agent_List **, ns_addr_t);
00130   void FreeAll(Agent_List **);
00131   void Union(Agent_List **, Agent_List *);
00132 
00133   virtual void print();
00134 };
00135 
00136 
00137 class From_List : public Agent_List {
00138 public:
00139   int rank;
00140   bool  is_sink;
00141 
00142   From_List() : Agent_List() { rank = 0; is_sink = false; }
00143 
00144   virtual ~From_List () {}
00145 };
00146 
00147 
00148 class Out_List : public From_List {
00149 public:
00150   float gradient;
00151   double timeout;
00152   double   from;
00153   double   to;
00154   int   num_data_send;
00155   int   num_neg_recv;
00156   int   num_pos_recv;
00157 
00158   Out_List() : From_List() { gradient = 0; from=0.0; to=0.0; num_data_send=0; 
00159                              timeout = 0.0; num_neg_recv = 0; num_pos_recv=0;}
00160   virtual ~Out_List () {}
00161 
00162   Out_List *WhereToGo();
00163   void CalRange();
00164   void NormalizeGradient();
00165 };
00166 
00167 
00168 class In_List : public Agent_List {
00169 public:
00170   double avg_delay;
00171   double var_delay;
00172   int    total_received;
00173   int    prev_received;
00174   int    num_loss;
00175   int    num_neg_send;
00176   int    num_pos_send;
00177 
00178   int    total_new_org_recv;
00179   int    total_old_org_recv;
00180   int    total_new_sub_recv;
00181   int    new_org_recv;        // for simple mode. New original sample counter.
00182   int    old_org_recv;        // for simple mode. Old original sample counter.
00183   int    new_sub_recv;        // for simple mode. New subsample counter.
00184   double last_ts_new_sub;     // Last timestamp in receiving a new subsample.
00185 
00186   In_List() : Agent_List() { 
00187     avg_delay =0; 
00188     var_delay =0; 
00189     total_received=0;
00190     prev_received =0; 
00191     num_loss =0; 
00192     num_neg_send = 0;
00193     num_pos_send = 0;
00194 
00195     total_new_org_recv=0;
00196     total_old_org_recv=0;
00197     total_new_sub_recv=0; 
00198 
00199     new_org_recv=0;
00200     old_org_recv=0;
00201     new_sub_recv=0; 
00202 
00203     last_ts_new_sub = -1.0;
00204   }
00205 
00206   virtual ~In_List () {}
00207 
00208   In_List *FindMaxIn();
00209 };
00210 
00211 #endif
00212 
00213 
00214 
00215 /* Example 
00216 
00217 void main () {
00218 
00219   From_List *start, *cur;
00220 
00221   start=NULL;
00222 
00223   cur = new From_List;
00224   cur->agent_addr.addr_ =1;
00225   cur->agent_addr.port_ =1;
00226   INTF_INSERT(start,cur);
00227 
00228   cur = new From_List;
00229   cur->agent_addr.addr_ = 3;
00230   cur->agent_addr.port_ = 3;
00231   INTF_INSERT(start,cur);
00232 
00233   cur = new From_List;
00234   cur->agent_addr.addr_ = 5;
00235   cur->agent_addr.port_ = 5;
00236   INTF_INSERT(start,cur);
00237 
00238   start->print();
00239 
00240   PrvCurPtr RetVal;
00241   ns_addr_t fnd_addr;
00242 
00243   fnd_addr.addr_ = 1;
00244   fnd_addr.port_ = 1;
00245   RetVal= INTF_FIND(start, fnd_addr);
00246   INTF_REMOVE(RetVal.prv, RetVal.cur);
00247 
00248   start->print();
00249 
00250 }
00251 
00252 */
00253 
00254 

Generated on Tue Aug 10 2010 16:16:06 for ns-2.33 by  doxygen 1.7.1