• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/diffusion3/filters/rmst/rmst_filter.hh

00001 //
00002 // rmst_filter.hh  : RmstFilter Class
00003 // authors         : Fred Stann
00004 //
00005 // Include file for RmstFilter - Reliable Multi-Segment Transport
00006 //
00007 // Copyright (C) 2003 by the University of Southern California
00008 // $Id: rmst_filter.hh,v 1.3 2005/09/13 04:53:49 tomh Exp $
00009 //
00010 // This program is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public License,
00012 // version 2, as published by the Free Software Foundation.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License along
00020 // with this program; if not, write to the Free Software Foundation, Inc.,
00021 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00022 //
00023 // Linking this file statically or dynamically with other modules is making
00024 // a combined work based on this file.  Thus, the terms and conditions of
00025 // the GNU General Public License cover the whole combination.
00026 //
00027 // In addition, as a special exception, the copyright holders of this file
00028 // give you permission to combine this file with free software programs or
00029 // libraries that are released under the GNU LGPL and with code included in
00030 // the standard release of ns-2 under the Apache 2.0 license or under
00031 // otherwise-compatible licenses with advertising requirements (or modified
00032 // versions of such code, with unchanged license).  You may copy and
00033 // distribute such a system following the terms of the GNU GPL for this
00034 // file and the licenses of the other code concerned, provided that you
00035 // include the source code of that other code when and as the GNU GPL
00036 // requires distribution of source code.
00037 //
00038 // Note that people who make modified versions of this file are not
00039 // obligated to grant this special exception for their modified versions;
00040 // it is their choice whether to do so.  The GNU General Public License
00041 // gives permission to release a modified version without this exception;
00042 // this exception also makes it possible to release a modified version
00043 // which carries forward this exception.
00044 
00045 #ifndef RMST_FILTER_HH
00046 #define RMST_FILTER_HH
00047 
00048 #include <sys/types.h>
00049 #include <map>
00050 #include <list>
00051 #include "diffapp.hh"
00052 #include "rmst.hh"
00053 
00054 #define RMST_FILTER_PRIORITY 190
00055 
00056 // Union to convert pkt_num & rdm_id into a 64 bit key
00057 union LlToInt {
00058   int64_t ll_val_;
00059   int int_val_[2];
00060 };
00061 
00062 // Exploratory message log.  Keep track of the last hop of every
00063 // new exploratory message. Then when one is reinforced we can
00064 // identify the "back-channel" that is the reverse gradient from
00065 // sink to source.
00066 typedef struct _ExpLog{
00067   int rmst_no_;
00068   int32_t last_hop_;
00069 } ExpLog;
00070 typedef map<int64_t, ExpLog> Key2ExpLog;
00071 
00072 typedef struct _SendMsgData{
00073   int rmst_no_;
00074   int last_frag_sent_;
00075   int exp_base_;
00076 } SendMsgData;
00077 typedef list<SendMsgData> SendList;
00078 
00079 typedef struct _NakMsgData{
00080   int rmst_no_;
00081   int frag_no_;
00082 } NakMsgData;
00083 typedef list<NakMsgData> NakList;
00084 
00085 typedef list<int32_t> Blacklist;
00086 
00087 class RmstFilter;
00088 
00089 // Method to be called when a message matches rmst-filter attributes.
00090 class RmstFilterCallback: public FilterCallback {
00091 public:
00092   RmstFilter *app_;                     // initialzed in setupFilter
00093   void recv(Message *msg, handle h);
00094 };
00095 
00096 class RmstFilter : public DiffApp {
00097 public:
00098 #ifdef NS_DIFFUSION
00099   RmstFilter();
00100   int command(int argc, const char*const* argv);
00101 #else
00102   RmstFilter(int argc, char **argv);
00103 #endif // NS_DIFFUSION
00104   
00105   virtual ~RmstFilter(){};
00106   void run();
00107   void recv(Message *msg, handle h);
00108   int processTimer(int rmst_no, int timer_type);
00109 private:
00110   handle filter_handle_;     // filter handle
00111   RmstFilterCallback *fcb_;  // filter callback routine
00112   handle setupFilter();    // routine that adds filter
00113   handle stat_timer_handle_;
00114   // Message Processing
00115   bool processMessage(Message *msg);
00116   void processCtrlMessage(Message *msg);
00117   Rmst* syncLocalCache(Message *msg);
00118   void sendRmstToSink(Rmst *rmst_ptr);
00119   void sendAckToSource(Rmst *rmst_ptr);
00120   void sendExpReqUpstream(Rmst *rmst_ptr);
00121   void sendContToSource(Rmst *rmst_ptr);
00122   void setupNak(int rmst_id);
00123   void cleanUpRmst(Rmst *rmst_ptr);
00124   void processExpReq(Rmst *rmst_ptr, int frag_no);
00125   Key2ExpLog exp_map_;
00126   Int2Rmst rmst_map_;
00127   SendList send_list_;
00128   bool send_timer_active_;
00129   handle send_timer_handle_;
00130   int exp_gap_;
00131   NakList nak_list_;
00132   Blacklist black_list_;
00133   int rdm_id_;
00134   int pkt_count_;
00135   bool local_sink_;
00136   bool caching_mode_;
00137   u_int16_t local_sink_port_;
00138   NRAttrVec *interest_attrs_;
00139   struct timeval last_data_rec_;
00140   struct timeval last_sink_time_;
00141 };
00142 
00143 // Define Timer Types
00144 #define WATCHDOG_TIMER   1
00145 #define SEND_TIMER       2
00146 #define ACK_TIMER        3
00147 #define CLEANUP_TIMER    4
00148 
00149 // Define timer intervals. These intervals dictate how fast you send
00150 // packets through the sensor net, how often you check for holes,
00151 // how often you clean up cache residue, how frequently a source
00152 // prompts for a missing ACK. These parameters can be application
00153 // tuned. The send timer in particular can be altered depending on
00154 // the presence of a backpressure mechanism.
00155 // SEND_INTERVAL - Gap between initiating the sending of a fragment.
00156 // WATCHDOG_INTERVAL - How often we look for holes (missing fragments).
00157 // ACK_INTERVAL - How long we wait for an ACK after sending last fragment
00158 //                before re-sending the last fragment.
00159 // CLEANUP_INTERVAL - How often we clean up our cache.
00160 // The time is in milliseconds.
00161 #define SEND_INTERVAL 2000
00162 #define WATCHDOG_INTERVAL 10000
00163 #define ACK_INTERVAL 20000
00164 #define CLEANUP_INTERVAL 90000
00165 
00166 // Define time intervals used to make decisions.
00167 // These are application tunable.
00168 // These times are in seconds.
00169 #define RMST_BLACKLIST_WAIT 3600
00170 #define NAK_RESPONSE_WAIT 10
00171 #define NEXT_FRAG_WAIT 15
00172 #define ACK_WAIT 30
00173 #define LONG_CLEANUP_WAIT 90
00174 #define SHORT_CLEANUP_WAIT 30
00175 #define SINK_REFRESH_WAIT 120
00176 
00177 // Define the threshold at which a node blacklists an incoming link.
00178 // It is the percentage of upstream packets sent that are actually
00179 // received. If a node gets less than this percentage, the link
00180 // is blacklisted.
00181 #define BLACKLIST_THRESHOLD .60
00182 
00183 class RmstTimeout: public TimerCallback {
00184 public:
00185   RmstTimeout(RmstFilter *rmst_flt, int no, int type);
00186   int expire();
00187   RmstFilter *filter_;
00188   int rmst_no_;
00189   int timer_type_;
00190 };
00191 
00192 // Define Send Timer Actions
00193 #define DELETE_FROM_QUEUE    1
00194 #define SEND_NEXT_FRAG       2
00195 #define DO_NOTHING           3
00196 
00197 #endif // RMST_FILTER_HH

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