filter_core.hh
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:7k
源码类别:

通讯编程

开发平台:

Visual C++

  1. // 
  2. // filter_core.hh  : Diffusion definitions
  3. // authors         : Chalermek Intanagonwiwat and Fabio Silva
  4. //
  5. // Copyright (C) 2000-2003 by the University of Southern California
  6. // $Id: filter_core.hh,v 1.3 2005/09/13 04:53:47 tomh Exp $
  7. //
  8. // This program is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU General Public License,
  10. // version 2, as published by the Free Software Foundation.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License along
  18. // with this program; if not, write to the Free Software Foundation, Inc.,
  19. // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  20. //
  21. // Linking this file statically or dynamically with other modules is making
  22. // a combined work based on this file.  Thus, the terms and conditions of
  23. // the GNU General Public License cover the whole combination.
  24. //
  25. // In addition, as a special exception, the copyright holders of this file
  26. // give you permission to combine this file with free software programs or
  27. // libraries that are released under the GNU LGPL and with code included in
  28. // the standard release of ns-2 under the Apache 2.0 license or under
  29. // otherwise-compatible licenses with advertising requirements (or modified
  30. // versions of such code, with unchanged license).  You may copy and
  31. // distribute such a system following the terms of the GNU GPL for this
  32. // file and the licenses of the other code concerned, provided that you
  33. // include the source code of that other code when and as the GNU GPL
  34. // requires distribution of source code.
  35. //
  36. // Note that people who make modified versions of this file are not
  37. // obligated to grant this special exception for their modified versions;
  38. // it is their choice whether to do so.  The GNU General Public License
  39. // gives permission to release a modified version without this exception;
  40. // this exception also makes it possible to release a modified version
  41. // which carries forward this exception.
  42. #ifndef _FILTER_CORE_HH_
  43. #define _FILTER_CORE_HH_
  44. #ifdef HAVE_CONFIG_H
  45. #include "config.h"
  46. #endif // HAVE_CONFIG_H
  47. #include <assert.h>
  48. #include <math.h>
  49. #include <stdio.h>
  50. #include <signal.h>
  51. #include <float.h>
  52. #include <string.h>
  53. #include <stdlib.h>
  54. #include <time.h>
  55. #include "main/timers.hh"
  56. #include "main/message.hh"
  57. #include "main/filter.hh"
  58. #include "main/config.hh"
  59. #include "main/tools.hh"
  60. #include "main/iodev.hh"
  61. #ifdef IO_LOG
  62. #include "iolog.hh"
  63. #endif // IO_LOG
  64. #ifdef NS_DIFFUSION
  65. #include <tcl.h>
  66. #include "diffrtg.h"
  67. #else
  68. #include "main/hashutils.hh"
  69. #endif // NS_DIFFUSION
  70. #ifdef UDP
  71. #include "drivers/UDPlocal.hh"
  72. #ifdef WIRED
  73. #include "drivers/UDPwired.hh"
  74. #endif // WIRED
  75. #endif // UDP
  76. #ifdef USE_RPC
  77. #include "drivers/RPCio.hh"
  78. #endif // USE_RPC
  79. #ifdef USE_WINSNG2
  80. #include "drivers/WINSng2.hh"
  81. #endif // USE_WINSNG2
  82. #ifdef USE_MOTE_NIC
  83. #include "drivers/MOTEio.hh"
  84. #endif // USE_MOTE_NIC
  85. #ifdef USE_SMAC
  86. #include "drivers/SMAC.hh"
  87. #endif // USE_SMAC
  88. #ifdef USE_EMSTAR
  89. #include "drivers/emstar.hh"
  90. #endif // USE_EMSTAR
  91. #ifdef STATS
  92. #include "iostats.hh"
  93. #define STATS_ARGS "si:"
  94. #else
  95. #define STATS_ARGS ""
  96. #endif // STATS
  97. #ifdef IO_LOG
  98. #define IO_LOG_ARGS "l"
  99. #else
  100. #define IO_LOG_ARGS ""
  101. #endif // IO_LOG
  102. #define COMMAND_LINE_ARGS "f:hd:vt:p:" IO_LOG_ARGS STATS_ARGS
  103. class DiffusionCoreAgent;
  104. class HashEntry;
  105. class NeighborEntry;
  106. class DiffRoutingAgent;
  107. typedef list<NeighborEntry *> NeighborList;
  108. typedef list<Tcl_HashEntry *> HashList;
  109. typedef list<int32_t> BlackList;
  110. class DiffusionCoreAgent {
  111. public:
  112. #ifdef NS_DIFFUSION
  113.   friend class DiffRoutingAgent;
  114.   DiffusionCoreAgent(DiffRoutingAgent *diffrtg, int nodeid);
  115. #else
  116.   DiffusionCoreAgent(int argc, char **argv);
  117.   void usage(char *s);
  118.   void run();
  119. #endif // NS_DIFFUSION
  120.   void timeToStop();
  121.   // Timer functions
  122.   void neighborsTimeout();
  123.   void filterTimeout();
  124. protected:
  125.   float lon_;
  126.   float lat_;
  127. #ifdef STATS
  128.   DiffusionStats *stats_;
  129. #endif // STATS
  130.   // Ids and counters
  131.   int32_t my_id_;
  132.   u_int16_t diffusion_port_;
  133.   int pkt_count_;
  134.   int random_id_;
  135.   // Configuration options
  136.   char *config_file_;
  137.   // Lists
  138.   DeviceList in_devices_;
  139.   DeviceList out_devices_;
  140.   DeviceList local_out_devices_;
  141.   NeighborList neighbor_list_;
  142.   FilterList filter_list_;
  143.   BlackList black_list_;
  144.   HashList hash_list_;
  145.   // Data structures
  146.   TimerManager *timers_manager_;
  147.   //  EventQueue *eq_;
  148.   Tcl_HashTable htable_;
  149.   // Device-Independent send
  150.   void sendMessageToLibrary(Message *msg, u_int16_t dst_agent_id);
  151.   void sendPacketToLibrary(DiffPacket pkt, int len, u_int16_t dst);
  152.   void sendMessageToNetwork(Message *msg);
  153.   void sendPacketToNetwork(DiffPacket pkt, int len, int dst);
  154.   // Receive functions
  155.   void recvPacket(DiffPacket pkt);
  156.   void recvMessage(Message *msg);
  157.   // Hashing functions
  158.   HashEntry * getHash(unsigned int, unsigned int);
  159.   void putHash(unsigned int, unsigned int);
  160.   // Neighbors functions
  161.   void updateNeighbors(int id);
  162.   // Message functions
  163.   void processMessage(Message *msg);
  164.   void processControlMessage(Message *msg);
  165.   void logControlMessage(Message *msg, int command, int param1, int param2);
  166.   bool restoreOriginalHeader(Message *msg);
  167.   // Filter functions
  168.   FilterList * getFilterList(NRAttrVec *attrs);
  169.   FilterEntry * findFilter(int16_t handle, u_int16_t agent);
  170.   FilterEntry * deleteFilter(int16_t handle, u_int16_t agent);
  171.   bool addFilter(NRAttrVec *attrs, u_int16_t agent, int16_t handle,
  172.  u_int16_t priority);
  173.   FilterList::iterator findMatchingFilter(NRAttrVec *attrs,
  174.   FilterList::iterator filter_itr);
  175.   u_int16_t getNextFilterPriority(int16_t handle, u_int16_t priority,
  176.   u_int16_t agent);
  177.   // Send messages to modules
  178.   void forwardMessage(Message *msg, FilterEntry *filter_entry);
  179.   void sendMessage(Message *msg);
  180. };
  181. class NeighborsTimeoutTimer : public TimerCallback {
  182. public:
  183.   NeighborsTimeoutTimer(DiffusionCoreAgent *agent) : agent_(agent) {};
  184.   ~NeighborsTimeoutTimer() {};
  185.   int expire();
  186.   DiffusionCoreAgent *agent_;
  187. };
  188. class FilterTimeoutTimer : public TimerCallback {
  189. public:
  190.   FilterTimeoutTimer(DiffusionCoreAgent *agent) : agent_(agent) {};
  191.   ~FilterTimeoutTimer() {};
  192.   int expire();
  193.   DiffusionCoreAgent *agent_;
  194. };
  195. class DiffusionStopTimer : public TimerCallback {
  196. public:
  197.   DiffusionStopTimer(DiffusionCoreAgent *agent) : agent_(agent) {};
  198.   ~DiffusionStopTimer() {};
  199.   int expire();
  200.   DiffusionCoreAgent *agent_;
  201. };
  202. #endif // !_FILTER_CORE_HH_