00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
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
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
00117
00118
00119 typedef enum neg_threshold_type__ {
00120 NEG_ABSOLUTE,
00121 NEG_RELATIVE
00122 } neg_tht;
00123
00124
00125
00126
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
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