• Main Page
  • Classes
  • Files
  • File List

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

00001 
00002 /*
00003  * diff_rate.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: diff_rate.h,v 1.4 2005/08/25 18:58:03 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 /* diff_rate.h : Chalermek Intanagonwiwat (USC/ISI)  08/16/99   */
00049 /****************************************************************/
00050 
00051 // Important Note: Work still in progress !!!
00052 
00053 #ifndef ns_diff_rate_h
00054 #define ns_diff_rate_h
00055 
00056 #include <assert.h>
00057 #include <math.h>
00058 #include <stdio.h>
00059 #include <signal.h>
00060 #include <float.h>
00061 #include <stdlib.h>
00062 
00063 #include <tcl.h>
00064 
00065 #include "diff_header.h"
00066 #include "agent.h"
00067 #include "tclcl.h"
00068 #include "ip.h"
00069 #include "config.h"
00070 #include "packet.h"
00071 #include "trace.h"
00072 #include "random.h"
00073 #include "classifier.h"
00074 #include "node.h"
00075 #include "iflist.h"
00076 #include "hash_table.h"
00077 #include "arp.h"
00078 #include "mac.h"
00079 #include "ll.h"
00080 #include "dsr/path.h"
00081 
00082 
00083 //#define DEBUG_RATE
00084 
00085 typedef enum subsample_tx_type__ {
00086   BCAST_SUB,
00087   UNICAST_SUB
00088 } sub_t;
00089 
00090 
00091 typedef enum original_tx_type__ {
00092   BCAST_ORG,
00093   UNICAST_ORG
00094 } org_t;
00095 
00096 
00097 typedef enum pos_reinf_type__ {
00098   POS_HASH,
00099   POS_LAST,
00100   POS_ALL
00101 } pos_t;
00102 
00103 
00104 typedef enum pos_reinf_node_type__ {
00105   END_POS,
00106   INTM_POS
00107 } pos_ndt;
00108 
00109 
00110 typedef enum neg_window_type__ {
00111   NEG_COUNTER,
00112   NEG_TIMER
00113 } neg_wint;
00114 
00115 
00116 // For NEG_COUNTER Only, 
00117 // this threshold defines which neighbors will be negatively reinfoced.
00118 
00119 typedef enum neg_threshold_type__ {
00120   NEG_ABSOLUTE,
00121   NEG_RELATIVE
00122 } neg_tht;
00123 
00124 
00125 // For NEG_COUNTER Only,
00126 // The max counter defines when it is time to negatively reinforce.
00127 
00128 typedef enum neg_max_counter_type__ {
00129   NEG_FIXED_MAX,
00130   NEG_SCALE_MAX
00131 } neg_mxt;
00132 
00133 
00134 #define INTEREST_PERIODIC     5            // (sec) between interest 
00135 #define INTEREST_TIMEOUT      15           // (sec)  
00136 
00137 #define NEG_CHECK             2.0         // (sec) bw neg checks
00138 #define MAX_NEG_COUNTER       20           // (new original pkts) bw neg reinf
00139 #define PER_IIF               5            // new org data for scale max 
00140                                            // counter
00141 #define NEG_MIN_RATIO         0.1          // min ratio compared to the max iif
00142 #define MAX_DUP_DATA          0            // max dupplicate bw neg reinf
00143 
00144 
00145 class DiffusionRate;
00146 
00147 class GradientTimer : public TimerHandler {
00148 public:
00149   GradientTimer(DiffusionRate *a) : TimerHandler() 
00150   { 
00151       a_ = a; 
00152   }
00153   virtual void expire(Event *e=NULL);
00154 protected:
00155   DiffusionRate *a_;
00156 };
00157 
00158 
00159 class NegativeReinforceTimer : public TimerHandler {
00160 public:
00161   NegativeReinforceTimer(DiffusionRate *a) : TimerHandler() 
00162   { 
00163       a_ = a; 
00164   }
00165   virtual void expire(Event *e=NULL);
00166 protected:
00167   DiffusionRate *a_;
00168 };
00169 
00170 
00171 class DiffusionRate : public DiffusionAgent {
00172  public:
00173   DiffusionRate();
00174   void recv(Packet*, Handler*);
00175   int command(int argc, const char*const* argv);
00176 
00177  protected:
00178 
00179   bool DUP_SUP_;
00180 
00181   sub_t sub_type_;
00182   org_t org_type_;
00183   pos_t pos_type_;
00184   pos_ndt pos_node_type_;
00185   neg_wint neg_win_type_;
00186   neg_tht neg_thr_type_;
00187   neg_mxt neg_max_type_;
00188 
00189   Data_Hash_Table DataTable;
00190 
00191   GradientTimer *gradient_timer;
00192   NegativeReinforceTimer *neg_reinf_timer;
00193 
00194   int num_not_send_bcast_data;
00195   int num_data_bcast_send;
00196   int num_data_bcast_rcv;
00197   int num_neg_bcast_send;
00198   int num_neg_bcast_rcv;
00199 
00200   void reset();
00201   void consider_old(Packet *);
00202   void consider_new(Packet *);
00203   void Start();
00204 
00205   void DataReqAll(unsigned int dtype, int report_rate);
00206   void Print_IOlist();
00207   void FwdData(Packet *);
00208   void PosReinf(int dtype, nsaddr_t to_node, ns_addr_t info_sender, 
00209                       unsigned int info_seq);
00210   void ProcessPosReinf(Packet *pkt);
00211   void ProcessNegReinf(Packet *pkt);
00212   void UcastNeg(int dtype, ns_addr_t to);
00213   void BcastNeg(int dtype);
00214   void GenNeg(int dtype);
00215   void InterestHandle(Packet *pkt);
00216 
00217   void GradientTimeOut();
00218   void NegReinfTimeOut();
00219 
00220   void CheckNegCounter(int dtype);
00221   bool FwdSubsample(Packet *pkt);
00222   void FwdOriginal(Packet *pkt);
00223   void TriggerPosReinf(Packet *pkt, ns_addr_t forward_agent);
00224 
00225   friend class GradientTimer;
00226   friend class NegativeReinforceTimer;
00227 };
00228 
00229 
00230 sub_t ParseSubType(const char* str);
00231 org_t ParseOrgType(const char* str);
00232 pos_t ParsePosType(const char* str);
00233 pos_ndt ParsePosNodeType(const char* str);
00234 neg_wint ParseNegWinType(const char* str);
00235 neg_tht ParseNegThrType(const char* str);
00236 neg_mxt ParseNegMaxType(const char* str);
00237 
00238 #endif
00239 
00240 

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