• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/gaf/gaf.h

00001 
00002 /*
00003  * gaf.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: gaf.h,v 1.4 2005/08/25 18:58:05 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 // Header file for grid-based adaptive fidelity algorithm 
00048 
00049 #ifndef ns_gaf_h
00050 #define ns_gaf_h
00051 
00052 #include <assert.h>
00053 #include "agent.h"
00054 #include "node.h"
00055 
00056 #define MAXQUEUE  1             // 1 = only my grid, 5 = all of my neighbos
00057 #define GN_UPDATE_INTERVAL 10   // how often to update neighbor list
00058 #define GAF_STARTUP_JITTER 1.0  // secs to jitter start of periodic activity
00059 #define GAF_NONSTART_JITTER 3.0
00060 #define MIN_DISCOVERY_TIME 1    // min interval to send discovery
00061 #define MAX_DISCOVERY_TIME 15   // max interval to send discovery
00062 #define MIN_SELECT_TIME 5       // start to tell your neighbor that
00063 #define MAX_SELECT_TIME 6       // you are the leader b/w, my need
00064                                 // to be set by apps. 
00065 #define MAX_DISCOVERY   10      // send selection after 10 time try
00066 #define MIN_LIFETIME    60
00067 #define GAF_LEADER_JITTER 3
00068 #define MIN_TURNOFFTIME 1
00069 
00070 class GAFAgent;
00071 
00072 typedef enum {
00073   GAF_DISCOVER, GAF_SELECT, GAF_DUTY
00074 } GafMsgType;
00075 
00076 typedef enum {
00077   GAF_FREE, GAF_LEADER, GAF_SLEEP
00078 } GafNodeState;
00079 
00080 /*
00081  * data structure for exchanging existence message and selection msg
00082  */
00083 
00084 struct DiscoveryMsg {
00085         u_int32_t gid;  // grid id
00086         u_int32_t nid;  // node id
00087         u_int32_t state; // what is my state
00088         u_int32_t ttl;  // My time to live
00089         u_int32_t stime;  // I may stay on this grid for only stime
00090 
00091 };
00092 
00093 
00094 // gaf header
00095 
00096 struct hdr_gaf {
00097         // needs to be extended
00098 
00099         int seqno_;
00100         GafMsgType type_;
00101 
00102         // Header access methods
00103         static int offset_; // required by PacketHeaderManager
00104         inline static int& offset() { return offset_; }
00105         inline static hdr_gaf* access(const Packet* p) {
00106                 return (hdr_gaf*) p->access(offset_);
00107         }
00108 };
00109 
00110 
00111 // GAFTimer is used for discovery phase
00112 
00113 class GAFDiscoverTimer : public TimerHandler {
00114 public: 
00115         GAFDiscoverTimer(GAFAgent *a) : TimerHandler(), a_(a) { }
00116 protected:
00117         virtual void expire(Event *);
00118         GAFAgent *a_;
00119 };
00120 
00121 // GAFSelectTimer is for the slecting phase
00122 
00123 class GAFSelectTimer : public TimerHandler {
00124 public:
00125         GAFSelectTimer(GAFAgent *a) : TimerHandler(), a_(a) { }
00126 protected:
00127         virtual void expire(Event *);
00128         GAFAgent *a_;
00129 };
00130 
00131 // GAFDutyTimer is for duty cycle. It is the place of adaptive fidelity
00132 // plays
00133 
00134 class GAFDutyTimer : public TimerHandler {
00135 public:
00136         GAFDutyTimer(GAFAgent *a) : TimerHandler(), a_(a) { }
00137 protected:
00138         inline void expire(Event *);
00139         GAFAgent *a_;
00140 };
00141 
00142 class GAFAgent : public Agent {
00143 public:
00144         GAFAgent(nsaddr_t id);
00145         virtual void recv(Packet *, Handler *);
00146         void timeout(GafMsgType);
00147         //void select_timeout(int);
00148 
00149         u_int32_t nodeid() {return nid_;}
00150         double myttl();
00151                 
00152 protected:
00153         int command(int argc, const char*const*argv);
00154         
00155 
00156         void node_on();
00157         void node_off();
00158         void duty_timeout();
00159         void send_discovery();
00160         void makeUpDiscoveryMsg(Packet *p);
00161         void processDiscoveryMsg(Packet *p);
00162         void schedule_wakeup(struct DiscoveryMsg);
00163         double beacon_; /* beacon period */
00164         void setGAFstate(GafNodeState);
00165         int randomflag_;
00166         GAFDiscoverTimer timer_;
00167         GAFSelectTimer stimer_;
00168         GAFDutyTimer dtimer_;
00169         int seqno_;
00170         int gid_;       // group id of this node
00171         int nid_;       // the node id of this node belongs to.
00172         Node *thisnode; // the node object where this agent resides
00173         int maxttl_;    // life of a node in the neighbor list
00174         
00175         GafNodeState    state_;
00176         int leader_settime_;
00177         int adapt_mobility_;  // control the use of 
00178                               // GAF-3: load balance with aggressive sleeping
00179                               // GAF-4:  load 3 + mobility adaption
00180 };
00181 
00182 /* assisting getting broadcast msg */
00183 
00184 class GAFPartner : public Connector {
00185 public:
00186         GAFPartner();
00187         void recv(Packet *p, Handler *h);
00188         
00189 protected:
00190         int command(int argc, const char*const*argv);
00191         ns_addr_t here_;
00192         int gafagent_;
00193         int mask_;
00194         int shift_;
00195 };
00196 
00197 
00198 
00199 #endif

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