Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

geo-routing.hh

Go to the documentation of this file.
00001 //
00002 // geo-routing.hh  : GEAR Include File
00003 // authors         : Yan Yu and Fabio Silva
00004 //
00005 // Copyright (C) 2000-2002 by the University of Southern California
00006 // Copyright (C) 2000-2002 by the University of California
00007 // $Id: geo-routing.hh,v 1.11 2002/11/26 22:45:37 haldar Exp $
00008 //
00009 // This program is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License,
00011 // version 2, as published by the Free Software Foundation.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License along
00019 // with this program; if not, write to the Free Software Foundation, Inc.,
00020 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021 //
00022 //
00023 
00024 #ifndef _GEO_ROUTING_HH_
00025 #define _GEO_ROUTING_HH_
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #include "config.h"
00029 #endif // HAVE_CONFIG_H
00030 
00031 #include <list>
00032 
00033 #ifdef HAVE_HASH_MAP
00034 #include <hash_map>
00035 #else
00036 #ifdef HAVE_EXT_HASH_MAP
00037 #include <ext/hash_map>
00038 #endif // HAVE_EXT_HASH_MAP
00039 #endif // HAVE_HASH_MAP
00040 
00041 #ifdef NS_DIFFUSION
00042 #include <mobilenode.h>
00043 #endif // NS_DIFFUSION
00044 
00045 #include "geo-attr.hh"
00046 #include "geo-tools.hh"
00047 
00048 #include "diffapp.hh"
00049 
00050 // Filter priorities for pre-processing and post-processing. The
00051 // gradient's filter priority has to be in between these two values in
00052 // order for GEAR to work properly
00053 #define GEOROUTING_PRE_FILTER_PRIORITY  8
00054 #define GEOROUTING_POST_FILTER_PRIORITY 2
00055 
00056 // Values used for defining timers
00057 #define BEACON_REQUEST_TIMER 150
00058 #define NEIGHBOR_TIMER       151
00059 
00060 // Energy values for GEAR
00061 #define GEO_INITIAL_ENERGY          1
00062 #define GEO_UNIT_ENERGY_FOR_SEND    0.001
00063 #define GEO_UNIT_ENERGY_FOR_RECV    0.001
00064 
00065 // Various beacon types
00066 enum geo_beacons {
00067   GEO_REQUEST = 1, // Beacon request. Nodes should send a beacon reply
00068                    // in response
00069   GEO_REPLY,       // Beacon reply. Sent in response to a beacon
00070                    // request. It also includes an heuristic value if
00071                    // requested on the beacon request
00072   GEO_UPDATE       // Includes updates to a particular heuristic value
00073                    // (for a given destination). It is send only if
00074                    // the new value is sufficiently different from the
00075                    // previous one
00076 };
00077 
00078 // Various actions taken when forwarding interests
00079 enum geo_actions {
00080   BROADCAST = 0,      // We are inside the target region, broadcast
00081                       // packet
00082   BROADCAST_SUPPRESS, // All our neighbors are outside the target
00083                       // region, we should not forward this interest
00084                       // message
00085   OUTSIDE_REGION      // We are still outside the target region,
00086                       // continue forwarding this interest message
00087                       // towards the region using unicast
00088 };
00089 
00090 #define GEO_BEACON_REPLY_PERIOD     100 // Sends at most one
00091                                         // beacon_reply message every
00092                                         // GEO_BEACON_REPLY_PERIOS
00093                                         // seconds
00094 #define GEO_NEIGHBOR_DELAY        30000 // In milli-seconds
00095 
00096 #define GEO_BEACON_REQUEST_CHECK_PERIOD 100000 // In milli-seconds
00097 #define GEO_NEIGHBOR_UPDATE                300 // In seconds
00098 #define GEO_NEIGHBOR_REQUEST_PERIOD (10 * GEO_NEIGHBOR_UPDATE) // In seconds
00099 
00100 #define GEO_NEIGHBOR_EXPIRED (5 * GEO_NEIGHBOR_UPDATE) // In seconds,
00101                                                        // this is how
00102                                                        // long a
00103                                                        // neighbor
00104                                                        // entry will
00105                                                        // last before
00106                                                        // being
00107                                                        // deleted
00108 
00109 
00110 
00111 
00112 
00113 // These values tell GEAR how much time to wait before sending a
00114 // beacon reply in response to a beacon request message
00115 #define GEO_BEACON_REPLY_DELAY   1500 // (msec) between receive and forward
00116 #define GEO_BEACON_REPLY_JITTER  1000 // (msec) jitter
00117 
00118 // These values tell GEAR how much to wait before sending a beacon
00119 // request or a beacon update message
00120 #define GEO_BEACON_DELAY   400 // (msec) between receive and forward
00121 #define GEO_BEACON_JITTER  200 // (msec) jitter
00122 
00123 #define INITIAL_ENERGY          1
00124 #define DEFAULT_VALID_PERIOD    10
00125 
00126 #define UNICAST_ORIGINAL 1
00127 #define BROADCAST_TYPE   2
00128 #define MAX_INT          10000
00129 
00130 #define MAX_PATH_LEN     200
00131 
00132 class Region {
00133 public:
00134   void operator= (Region p) {center_ = p.center_; radius_ = p.radius_;}
00135   void output()
00136   {
00137     center_.output();
00138     DiffPrint(DEBUG_IMPORTANT, "-%f", radius_);
00139   }
00140 
00141   GeoLocation center_;
00142   double radius_;
00143 };
00144 
00145 class GeoHeader {
00146 public:
00147   int16_t pkt_type_;  // BROADCAST or UNICAST_ORIGINAL
00148   int16_t path_len_;
00149   Region dst_region_;
00150 };
00151  
00152 class PktHeader {
00153 public:
00154   int32_t pkt_num_;
00155   int32_t rdm_id_;
00156   int32_t prev_hop_;
00157   int pkt_type_;
00158   int path_len_;
00159   Region dst_region_;
00160 };
00161 
00162 class NeighborEntry {
00163 public:
00164   NeighborEntry(int32_t id, double longitude, double latitude,
00165                 double remaining_energy) :
00166   id_(id), longitude_(longitude), latitude_(latitude),
00167   remaining_energy_(remaining_energy){
00168     valid_period_ = DEFAULT_VALID_PERIOD;
00169     GetTime(&tv_);
00170   }
00171 
00172   int32_t id_;
00173   double longitude_;
00174   double latitude_;
00175   double remaining_energy_;
00176   struct timeval tv_;
00177   double valid_period_; // in seconds
00178 };
00179 
00180 class GeoRoutingFilter;
00181 
00182 typedef list<NeighborEntry *> NeighborList;
00183 typedef list<PktHeader *> PacketList;
00184  
00185 class GeoFilterReceive : public FilterCallback {
00186 public:
00187   GeoFilterReceive(GeoRoutingFilter *app) : app_(app) {};
00188   void recv(Message *msg, handle h);
00189 
00190   GeoRoutingFilter *app_;
00191 };
00192 
00193 class GeoRoutingFilter : public DiffApp {
00194 public:
00195 #ifdef NS_DIFFUSION
00196   GeoRoutingFilter();
00197   int command(int argc, const char*const* argv);
00198 #else
00199   GeoRoutingFilter(int argc, char **argv);
00200 #endif // NS_DIFFUSION
00201 
00202   virtual ~GeoRoutingFilter()
00203   {
00204     // Nothing but exit
00205   };
00206 
00207   void run();
00208   void recv(Message *msg, handle h);
00209 
00210   // Timers
00211   void messageTimeout(Message *msg);
00212   void beaconTimeout();
00213   void neighborTimeout();
00214   
00215 protected:
00216   // General Variables
00217   handle pre_filter_handle_;
00218   handle post_filter_handle_;
00219   int pkt_count_;
00220   int rdm_id_;
00221 
00222   // Keep track when last beacon reply was sent
00223   struct timeval last_beacon_reply_tv_;
00224 
00225   // Keep track when last beacon request was sent
00226   struct timeval last_neighbor_request_tv_;
00227   
00228   // Statistical data: location and remaining energy level
00229   double geo_longitude_;
00230   double geo_latitude_;
00231   int num_pkt_sent_;
00232   int num_pkt_recv_;
00233   double initial_energy_;
00234   double unit_energy_for_send_;
00235   double unit_energy_for_recv_;
00236 
00237   // List of all known neighbors, containing their location and energy
00238   // information
00239   NeighborList neighbors_list_;
00240 
00241   // List of messages currently being processed
00242   PacketList message_list_;
00243 
00244   // Forwarding table
00245   HeuristicValueTable h_value_table_;
00246   LearnedCostTable learned_cost_table_;
00247   
00248   // Receive Callback for the filter
00249   GeoFilterReceive *filter_callback_;
00250 
00251   // Setup the filter
00252   handle setupPostFilter();
00253   handle setupPreFilter();
00254 
00255   // Message Processing functions
00256   void preProcessFilter(Message *msg);
00257   void postProcessFilter(Message *msg);
00258 
00259   // Message processing functions
00260   PktHeader * preProcessMessage(Message *msg);
00261   PktHeader * stripOutHeader(Message *msg);
00262   PktHeader * retrievePacketHeader(Message *msg);
00263   bool extractLocation(Message *msg,
00264                        float *longitude_min, float *longitude_max,
00265                        float *latitude_min, float *latitude_max);
00266   GeoHeader * restoreGeoHeader(PktHeader *pkt_header, Message *msg);
00267   void takeOutAttr(NRAttrVec *attrs, int32_t key);
00268 
00269   // Neighbors related functions
00270   NeighborEntry * findNeighbor(int32_t neighbor_id);
00271   void updateNeighbor(int32_t neighbor_id, double neighbor_longitude,
00272                       double neighbor_latitude, double neighbor_energy);
00273   bool checkNeighbors();
00274   void sendNeighborRequest();
00275 
00276   // Energy related functions
00277   double remainingEnergy() {return INITIAL_ENERGY;}
00278 
00279   // Cost estimation related functions
00280   double retrieveLearnedCost(int neighbor_id, GeoLocation dst);
00281   double estimateCost(int neighbor_id, GeoLocation dst);
00282 
00283   // Routing related functions
00284   int32_t findNextHop(GeoHeader *geo_header, bool greedy);
00285   int floodInsideRegion(GeoHeader *geo_header);
00286 
00287   double retrieveHeuristicValue(GeoLocation dst);
00288   void broadcastHeuristicValue(GeoLocation dst, double new_heuristic_value);
00289 
00290   // GetNodeLocation --> This will move to the library in the future
00291   void getNodeLocation(double *longitude, double *latitude);
00292 };
00293 
00294 class GeoMessageSendTimer : public TimerCallback {
00295 public:
00296   GeoMessageSendTimer(GeoRoutingFilter *agent, Message *msg) :
00297     agent_(agent), msg_(msg) {};
00298   ~GeoMessageSendTimer()
00299   {
00300     delete msg_;
00301   };
00302   int expire();
00303 
00304   GeoRoutingFilter *agent_;
00305   Message *msg_;
00306 };
00307 
00308 class GeoNeighborsTimer : public TimerCallback {
00309 public:
00310   GeoNeighborsTimer(GeoRoutingFilter *agent) : agent_(agent) {};
00311   ~GeoNeighborsTimer() {};
00312   int expire();
00313 
00314   GeoRoutingFilter *agent_;
00315 };
00316 
00317 class GeoBeaconRequestTimer : public TimerCallback {
00318 public:
00319   GeoBeaconRequestTimer(GeoRoutingFilter *agent) : agent_(agent) {};
00320   ~GeoBeaconRequestTimer() {};
00321   int expire();
00322 
00323   GeoRoutingFilter *agent_;
00324 };
00325 
00326 #endif // !_GEO_ROUTING_HH_

Generated on Tue Apr 20 12:14:18 2004 for NS2.26SourcesOriginal by doxygen 1.3.3