arc.h
Upload User: rubber
Upload Date: 2018-02-13
Package Size: 87k
Code Size: 11k
Development Platform:

Tcl-Tk

  1. #ifndef __arc_h__
  2. #define __arc_h__
  3. //#include <agent.h>
  4. //#include <packet.h>
  5. //#include <sys/types.h>
  6. //#include <cmu/list.h>
  7. //#include <scheduler.h>
  8. #include <cmu-trace.h>
  9. #include <priqueue.h>
  10. #include <arc/arc_rtable.h>
  11. #include <arc/arc_rqueue.h>
  12. #include <classifier/classifier-port.h>
  13. /*
  14.   Allows local repair of routes.
  15.   Local repair does not always work correct! Don't use it for now.
  16. */
  17. //#define ARC_LOCAL_REPAIR
  18. /*
  19.   Allows ARC to use link-layer (802.11) feedback in determining when
  20.   links are up/down.
  21. */
  22. #define ARC_LINK_LAYER_DETECTION
  23. /*
  24.   Causes ARC to apply a "smoothing" function to the link layer feedback
  25.   that is generated by 802.11.  In essence, it requires that RT_MAX_ERROR
  26.   errors occurs within a window of RT_MAX_ERROR_TIME before the link
  27.   is considered bad.
  28. */
  29. #define ARC_USE_LL_METRIC
  30. /*
  31.   Only applies if ARC_USE_LL_METRIC is defined.
  32.   Causes ARC to apply omniscient knowledge to the feedback received
  33.   from 802.11.  This may be flawed, because it does not account for
  34.   congestion.
  35. */
  36. //#define ARC_USE_GOD_FEEDBACK
  37. //My modification************************************************************//
  38. /*
  39.   To run simulations with different gateway discovery methods:
  40.   
  41.   1. PROACTIVE GATEWAY DISCOVERY METHOD
  42.   * Type "Agent/ARC set gw_discovery 0" before the creation of the nodes in 
  43.   * your Tcl file.
  44.   
  45.   2. HYBRID GATEWAY DISCOVERY METHOD
  46.   * Type "Agent/ARC set gw_discovery 1" before the creation of the nodes in
  47.   * your Tcl file.
  48.   
  49.   3. REACTIVE GATEWAY DISCOVERY METHOD
  50.   * Type "Agent/ARC set gw_discovery 2" before the creation of the nodes in
  51.   * your Tcl file.
  52.   */
  53. //#define DEQUE_AFTER_RREP_I
  54. //***************************************************************************//
  55. class ARC;
  56. #define ACTIVE_ROUTE_TIMEOUT    10      // seconds 
  57. #define BCAST_ID_SAVE           6 // seconds
  58. #define MY_ROUTE_TIMEOUT        10      // seconds
  59. // Should be set by the user using best guess (conservative) 
  60. #define NETWORK_DIAMETER        30      // hops
  61. // This should be somewhat related to arp timeout
  62. #define NODE_TRAVERSAL_TIME     0.03    // seconds (used in PerHopTime)
  63. #define REV_ROUTE_LIFE          6 // seconds
  64. // No. of times to do network-wide search before timing out for 
  65. // MAX_RREQ_TIMEOUT sec.        
  66. #define RREQ_RETRIES            2       // times
  67. // Various constants used for the expanding ring search
  68. #define TTL_START               1
  69. #define TTL_INCREMENT           2 
  70. #define TTL_THRESHOLD           7
  71. // The followings are used for the forward() function. Controls pacing.
  72. #define DELAY 1.0           // random delay - used for rebroadcasting RREQs
  73. #define NO_DELAY -1.0       // no delay 
  74. // think it should be 30 ms
  75. #define ARP_DELAY 0.01      // fixed delay to keep arp happy
  76. //My modification************************************************************//
  77. /*
  78.   The address of the default route is defined to -10.
  79.   All the gateways in the MANET have a common address ALL_MANET_GW_MULTICAST.
  80. */
  81. #define DEFAULT                  -10
  82. #define ALL_MANET_GW_MULTICAST   -20
  83. #define GWINFO_LIFETIME           10   // seconds
  84. #define RREQ_I_RETRIES            4    // times
  85. #define ADVERTISEMENT_ZONE        3    // hops, used for hybrid gw discovery
  86. #define ADVERTISEMENT_INTERVAL    5    // seconds, used for hybrid & proactive
  87. //***************************************************************************//
  88. // timeout after doing network-wide search RREQ_RETRIES times
  89. #define MAX_RREQ_TIMEOUT 10.0     // seconds
  90. // Must be larger than the time difference between a node propagates a route 
  91. // request and gets the route reply back.
  92. //#define RREP_WAIT_TIME     (3 * NODE_TRAVERSAL_TIME * NETWORK_DIAMETER) // ms
  93. //#define RREP_WAIT_TIME     (2 * REV_ROUTE_LIFE)  // seconds
  94. #define RREP_WAIT_TIME         1.0  // seconds
  95. #define LOCAL_REPAIR_WAIT_TIME  0.15     // seconds
  96. #define ID_NOT_FOUND    0x00
  97. #define ID_FOUND        0x01
  98. //#define INFINITY        0xff
  99. #define HELLO_INTERVAL          1               // second
  100. #define ALLOWED_HELLO_LOSS      3               // packets
  101. #define BAD_LINK_LIFETIME       3               // seconds
  102. #define MaxHelloInterval        (1.25 * HELLO_INTERVAL)
  103. #define MinHelloInterval        (0.75 * HELLO_INTERVAL)
  104. /* =====================================================================
  105.    Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)
  106.    ===================================================================== */
  107. class BroadcastTimer : public Handler {
  108.  public:
  109.   BroadcastTimer(ARC* a) : agent(a) {}
  110.   void handle(Event*);
  111.  private:
  112.   ARC    *agent;
  113.   Event intr;
  114. };
  115. class HelloTimer : public Handler {
  116.  public:
  117.   HelloTimer(ARC* a) : agent(a) {}
  118.   void handle(Event*);
  119.  private:
  120.   ARC    *agent;
  121.   Event intr;
  122. };
  123. class NeighborTimer : public Handler {
  124.  public:
  125.   NeighborTimer(ARC* a) : agent(a) {}
  126.   void handle(Event*);
  127.  private:
  128.   ARC    *agent;
  129.   Event intr;
  130. };
  131. class RouteCacheTimer : public Handler {
  132.  public:
  133.   RouteCacheTimer(ARC* a) : agent(a) {}
  134.   void handle(Event*);
  135.  private:
  136.   ARC    *agent;
  137.   Event intr;
  138. };
  139. class LocalRepairTimer : public Handler {
  140.  public:
  141.   LocalRepairTimer(ARC* a) : agent(a) {}
  142.   void handle(Event*);
  143.  private:
  144.   ARC    *agent;
  145.   Event intr;
  146. };
  147. //My modification************************************************************//
  148. /*
  149.   Implementing proactive and hybrid gateway discovery...
  150. */
  151. class AdvertisementTimer : public Handler {
  152.  public:
  153.   AdvertisementTimer(ARC* a) : agent(a) {}
  154.   void handle(Event*);
  155.  private:
  156.   ARC    *agent;
  157.   Event intr;
  158. };
  159. //***************************************************************************//
  160. /* =====================================================================
  161.    Broadcast ID Cache
  162.    ===================================================================== */
  163. class BroadcastID {
  164.   friend class ARC;
  165.  public:
  166.   BroadcastID(nsaddr_t i, u_int32_t b) { src = i; id = b;  }
  167.  protected:
  168.   LIST_ENTRY(BroadcastID) link;
  169.   nsaddr_t        src;
  170.   u_int32_t       id;
  171.   double          expire;         // now + BCAST_ID_SAVE s
  172. };
  173. LIST_HEAD(arc_bcache, BroadcastID);
  174. /* =====================================================================
  175.    The Routing Agent
  176.    ===================================================================== */
  177. class ARC: public Agent {
  178.   /*
  179.    * make some friends first 
  180.    */
  181.   
  182.   friend class arc_rt_entry;
  183.   friend class BroadcastTimer;
  184.   friend class HelloTimer;
  185.   friend class NeighborTimer;
  186.   friend class RouteCacheTimer;
  187.   friend class LocalRepairTimer;
  188.   //My modification***************************************//
  189.   /*
  190.     Implementing proactive and hybrid gateway discovery...
  191.   */
  192.   friend class AdvertisementTimer;
  193.   //******************************************************//
  194.   
  195.  public:
  196.   ARC(nsaddr_t id);
  197.   void recv(Packet *p, Handler *);
  198.   
  199.  protected:
  200.   int             command(int, const char *const *);
  201.   int             initialized() { return 1 && target_; }
  202.   
  203.   /*
  204.    * Route Table Management
  205.    */
  206.   void            rt_resolve(Packet *p);
  207.   void            rt_update(arc_rt_entry *rt, u_int32_t seqnum,
  208.     u_int16_t metric, nsaddr_t nexthop,
  209.     double expire_time);
  210.   void            rt_down(arc_rt_entry *rt);
  211.   void            local_rt_repair(arc_rt_entry *rt, Packet *p);
  212.   //My modification**********************************************************//
  213.   void print_routing_table();
  214.   arc_rt_entry* find_send_entry(arc_rt_entry *rt);
  215.   arc_rt_entry* find_fn_entry(void);
  216.   //*************************************************************************//
  217.  public:
  218.   void            rt_ll_failed(Packet *p);
  219.   void            handle_link_failure(nsaddr_t id);
  220.  protected:
  221.   void            rt_purge(void);
  222.   
  223.   void            enque(arc_rt_entry *rt, Packet *p);
  224.   Packet*         deque(arc_rt_entry *rt);
  225.   
  226.   /*
  227.    * Neighbor Management
  228.    */
  229.   void            nb_insert(nsaddr_t id);
  230.   ARC_Neighbor*       nb_lookup(nsaddr_t id);
  231.   void            nb_delete(nsaddr_t id);
  232.   void            nb_purge(void);
  233.   
  234.   
  235.   /*
  236.    * Broadcast ID Management
  237.    */
  238.   
  239.   void            id_insert(nsaddr_t id, u_int32_t bid);
  240.   bool         id_lookup(nsaddr_t id, u_int32_t bid);
  241.   void            id_purge(void);
  242.   
  243.   /*
  244.    * Packet TX Routines
  245.    */
  246.   void            forward(arc_rt_entry *rt, Packet *p, double delay);
  247.   void            sendHello(void);
  248.   //My modification**********************************************************//
  249.   /*
  250.     Added a field for flags to be able to distinguish between ordinary 
  251.     RREQ/RREP and RREQ_I/RREP_I.
  252.   */
  253.   void            sendRequest(nsaddr_t dst, u_int8_t flag);
  254.   void            sendReply(nsaddr_t ipdst, u_int32_t hop_count,
  255.     nsaddr_t rpdst, u_int32_t rpseq,
  256.     u_int32_t lifetime, double timestamp, 
  257.     u_int8_t flag);
  258.   /*
  259.     Implementing proactive and hybrid gateway discovery...
  260.   */
  261.   void            sendAdvertisement(int ttl);
  262.   //*************************************************************************//
  263.   void            sendError(Packet *p, bool jitter = true);
  264.   
  265.   /*
  266.    * Packet RX Routines
  267.    */
  268.   void            recvAODV(Packet *p);
  269.   void            recvHello(Packet *p);
  270.   void            recvRequest(Packet *p);
  271.   void            recvReply(Packet *p);
  272.   void            recvError(Packet *p);
  273.   //My modification**********************************************************//
  274.   /*
  275.     Implementing proactive gateway discovery...
  276.   */
  277.   void recvAdvertisement(Packet *p);
  278.   //*************************************************************************//
  279.   
  280.   /*
  281.    * History management
  282.    */
  283.   double  PerHopTime(arc_rt_entry *rt);
  284.   
  285.   
  286.   nsaddr_t        index;                  // IP Address of this node
  287.   u_int32_t       seqno;                  // Sequence Number
  288.   int             bid;                    // Broadcast ID
  289.   
  290.   //My modification**********************************************************//
  291.   /*
  292.     Implementing proactive and hybrid gateway discovery...
  293.   */
  294.   int gw_discovery;
  295.   int ad_bid;                  //Broadcast ID for advertisemens from GW
  296.   //*************************************************************************//
  297.   
  298.   arc_rtable         rthead;                 // routing table
  299.   arc_ncache         nbhead;                 // Neighbor Cache
  300.   arc_bcache         bihead;                 // Broadcast ID Cache
  301.   
  302.   /*
  303.    * Timers
  304.    */
  305.   BroadcastTimer  btimer;
  306.   HelloTimer      htimer;
  307.   NeighborTimer   ntimer;
  308.   RouteCacheTimer rtimer;
  309.   LocalRepairTimer lrtimer;
  310.   //My modification****************************************//
  311.   /*
  312.     Implementing proactive and hybrid gateway discovery...
  313.   */
  314.   AdvertisementTimer adtimer;
  315.   //*******************************************************//
  316.   
  317.   /*
  318.    * Routing Table
  319.    */
  320.   arc_rtable          rtable;
  321.   /*
  322.    *  A "drop-front" queue used by the routing layer to buffer
  323.    *  packets to which it does not have a route.
  324.    */
  325.   arc_rqueue         rqueue;
  326.   
  327.   /*
  328.    * A mechanism for logging the contents of the routing
  329.    * table.
  330.    */
  331.   Trace           *logtarget;
  332.   
  333.   /*
  334.    * A pointer to the network interface queue that sits
  335.    * between the "classifier" and the "link layer".
  336.    */
  337.   PriQueue        *ifqueue;
  338.   
  339.   //My modification**********************************************************//
  340.   /*
  341.     A pointer to a mobile node to be able to use base_stn() and 
  342.     set_base_stn(int addr) in mobilenode.h.
  343.   */
  344.   MobileNode *thisnode;
  345.   //*************************************************************************//
  346.   
  347.   /*
  348.    * Logging stuff
  349.    */
  350.   void            log_link_del(nsaddr_t dst);
  351.   void            log_link_broke(Packet *p);
  352.   void            log_link_kept(nsaddr_t dst);
  353.   /* for passing packets up to agents */
  354.   PortClassifier *dmux_;
  355. };
  356. #endif /* __arc_h__ */