filter_core.hh

Go to the documentation of this file.
00001 // 
00002 // filter_core.hh  : Diffusion definitions
00003 // authors         : Chalermek Intanagonwiwat and Fabio Silva
00004 //
00005 // Copyright (C) 2000-2003 by the University of Southern California
00006 // $Id: filter_core.hh,v 1.3 2005/09/13 04:53:47 tomh Exp $
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License,
00010 // version 2, as published by the Free Software Foundation.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License along
00018 // with this program; if not, write to the Free Software Foundation, Inc.,
00019 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020 //
00021 // Linking this file statically or dynamically with other modules is making
00022 // a combined work based on this file.  Thus, the terms and conditions of
00023 // the GNU General Public License cover the whole combination.
00024 //
00025 // In addition, as a special exception, the copyright holders of this file
00026 // give you permission to combine this file with free software programs or
00027 // libraries that are released under the GNU LGPL and with code included in
00028 // the standard release of ns-2 under the Apache 2.0 license or under
00029 // otherwise-compatible licenses with advertising requirements (or modified
00030 // versions of such code, with unchanged license).  You may copy and
00031 // distribute such a system following the terms of the GNU GPL for this
00032 // file and the licenses of the other code concerned, provided that you
00033 // include the source code of that other code when and as the GNU GPL
00034 // requires distribution of source code.
00035 //
00036 // Note that people who make modified versions of this file are not
00037 // obligated to grant this special exception for their modified versions;
00038 // it is their choice whether to do so.  The GNU General Public License
00039 // gives permission to release a modified version without this exception;
00040 // this exception also makes it possible to release a modified version
00041 // which carries forward this exception.
00042 
00043 #ifndef _FILTER_CORE_HH_
00044 #define _FILTER_CORE_HH_
00045 
00046 #ifdef HAVE_CONFIG_H
00047 #include "config.h"
00048 #endif // HAVE_CONFIG_H
00049 
00050 #include <assert.h>
00051 #include <math.h>
00052 #include <stdio.h>
00053 #include <signal.h>
00054 #include <float.h>
00055 #include <string.h>
00056 #include <stdlib.h>
00057 #include <time.h>
00058 
00059 #include "main/timers.hh"
00060 #include "main/message.hh"
00061 #include "main/filter.hh"
00062 #include "main/config.hh"
00063 #include "main/tools.hh"
00064 #include "main/iodev.hh"
00065 
00066 #ifdef IO_LOG
00067 #include "iolog.hh"
00068 #endif // IO_LOG
00069 
00070 #ifdef NS_DIFFUSION
00071 #include <tcl.h>
00072 #include "diffrtg.h"
00073 #else
00074 #include "main/hashutils.hh"
00075 #endif // NS_DIFFUSION
00076 
00077 #ifdef UDP
00078 #include "drivers/UDPlocal.hh"
00079 #ifdef WIRED
00080 #include "drivers/UDPwired.hh"
00081 #endif // WIRED
00082 #endif // UDP
00083 
00084 #ifdef USE_RPC
00085 #include "drivers/RPCio.hh"
00086 #endif // USE_RPC
00087 
00088 #ifdef USE_WINSNG2
00089 #include "drivers/WINSng2.hh"
00090 #endif // USE_WINSNG2
00091 
00092 #ifdef USE_MOTE_NIC
00093 #include "drivers/MOTEio.hh"
00094 #endif // USE_MOTE_NIC
00095 
00096 #ifdef USE_SMAC
00097 #include "drivers/SMAC.hh"
00098 #endif // USE_SMAC
00099 
00100 #ifdef USE_EMSTAR
00101 #include "drivers/emstar.hh"
00102 #endif // USE_EMSTAR
00103 
00104 #ifdef STATS
00105 #include "iostats.hh"
00106 #define STATS_ARGS "si:"
00107 #else
00108 #define STATS_ARGS ""
00109 #endif // STATS
00110 
00111 #ifdef IO_LOG
00112 #define IO_LOG_ARGS "l"
00113 #else
00114 #define IO_LOG_ARGS ""
00115 #endif // IO_LOG
00116 
00117 #define COMMAND_LINE_ARGS "f:hd:vt:p:" IO_LOG_ARGS STATS_ARGS
00118 
00119 class DiffusionCoreAgent;
00120 class HashEntry;
00121 class NeighborEntry;
00122 class DiffRoutingAgent;
00123 
00124 typedef list<NeighborEntry *> NeighborList;
00125 typedef list<Tcl_HashEntry *> HashList;
00126 typedef list<int32_t> BlackList;
00127 
00128 class DiffusionCoreAgent {
00129 public:
00130 #ifdef NS_DIFFUSION
00131   friend class DiffRoutingAgent;
00132   DiffusionCoreAgent(DiffRoutingAgent *diffrtg, int nodeid);
00133 #else
00134   DiffusionCoreAgent(int argc, char **argv);
00135   void usage(char *s);
00136   void run();
00137 #endif // NS_DIFFUSION
00138 
00139   void timeToStop();
00140   // Timer functions
00141   void neighborsTimeout();
00142   void filterTimeout();
00143 
00144 protected:
00145   float lon_;
00146   float lat_;
00147 
00148 #ifdef STATS
00149   DiffusionStats *stats_;
00150 #endif // STATS
00151 
00152   // Ids and counters
00153   int32_t my_id_;
00154   u_int16_t diffusion_port_;
00155   int pkt_count_;
00156   int random_id_;
00157 
00158   // Configuration options
00159   char *config_file_;
00160 
00161   // Lists
00162   DeviceList in_devices_;
00163   DeviceList out_devices_;
00164   DeviceList local_out_devices_;
00165   NeighborList neighbor_list_;
00166   FilterList filter_list_;
00167   BlackList black_list_;
00168   HashList hash_list_;
00169 
00170   // Data structures
00171   TimerManager *timers_manager_;
00172   //  EventQueue *eq_;
00173   Tcl_HashTable htable_;
00174 
00175   // Device-Independent send
00176   void sendMessageToLibrary(Message *msg, u_int16_t dst_agent_id);
00177   void sendPacketToLibrary(DiffPacket pkt, int len, u_int16_t dst);
00178 
00179   void sendMessageToNetwork(Message *msg);
00180   void sendPacketToNetwork(DiffPacket pkt, int len, int dst);
00181 
00182   // Receive functions
00183   void recvPacket(DiffPacket pkt);
00184   void recvMessage(Message *msg);
00185 
00186   // Hashing functions
00187   HashEntry * getHash(unsigned int, unsigned int);
00188   void putHash(unsigned int, unsigned int);
00189 
00190   // Neighbors functions
00191   void updateNeighbors(int id);
00192 
00193   // Message functions
00194   void processMessage(Message *msg);
00195   void processControlMessage(Message *msg);
00196   void logControlMessage(Message *msg, int command, int param1, int param2);
00197   bool restoreOriginalHeader(Message *msg);
00198 
00199   // Filter functions
00200   FilterList * getFilterList(NRAttrVec *attrs);
00201   FilterEntry * findFilter(int16_t handle, u_int16_t agent);
00202   FilterEntry * deleteFilter(int16_t handle, u_int16_t agent);
00203   bool addFilter(NRAttrVec *attrs, u_int16_t agent, int16_t handle,
00204          u_int16_t priority);
00205   FilterList::iterator findMatchingFilter(NRAttrVec *attrs,
00206                       FilterList::iterator filter_itr);
00207   u_int16_t getNextFilterPriority(int16_t handle, u_int16_t priority,
00208                   u_int16_t agent);
00209 
00210   // Send messages to modules
00211   void forwardMessage(Message *msg, FilterEntry *filter_entry);
00212   void sendMessage(Message *msg);
00213 };
00214 
00215 class NeighborsTimeoutTimer : public TimerCallback {
00216 public:
00217   NeighborsTimeoutTimer(DiffusionCoreAgent *agent) : agent_(agent) {};
00218   ~NeighborsTimeoutTimer() {};
00219   int expire();
00220 
00221   DiffusionCoreAgent *agent_;
00222 };
00223 
00224 class FilterTimeoutTimer : public TimerCallback {
00225 public:
00226   FilterTimeoutTimer(DiffusionCoreAgent *agent) : agent_(agent) {};
00227   ~FilterTimeoutTimer() {};
00228   int expire();
00229 
00230   DiffusionCoreAgent *agent_;
00231 };
00232 
00233 class DiffusionStopTimer : public TimerCallback {
00234 public:
00235   DiffusionStopTimer(DiffusionCoreAgent *agent) : agent_(agent) {};
00236   ~DiffusionStopTimer() {};
00237   int expire();
00238 
00239   DiffusionCoreAgent *agent_;
00240 };
00241 
00242 #endif // !_FILTER_CORE_HH_

Generated on Tue Mar 6 16:47:45 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6