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 #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
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
00153 int32_t my_id_;
00154 u_int16_t diffusion_port_;
00155 int pkt_count_;
00156 int random_id_;
00157
00158
00159 char *config_file_;
00160
00161
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
00171 TimerManager *timers_manager_;
00172
00173 Tcl_HashTable htable_;
00174
00175
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
00183 void recvPacket(DiffPacket pkt);
00184 void recvMessage(Message *msg);
00185
00186
00187 HashEntry * getHash(unsigned int, unsigned int);
00188 void putHash(unsigned int, unsigned int);
00189
00190
00191 void updateNeighbors(int id);
00192
00193
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
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
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_