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

通讯编程

开发平台:

Visual C++

  1. /*
  2. Copyright (c) 1997, 1998 Carnegie Mellon University.  All Rights
  3. Reserved. 
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. 3. The name of the author may not be used to endorse or promote products
  12. derived from this software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. The AODV code developed by the CMU/MONARCH group was optimized and tuned by Samir Das and Mahesh Marina, University of Cincinnati. The work was partially done in Sun Microsystems.
  24. */
  25. #ifndef __aodv_packet_h__
  26. #define __aodv_packet_h__
  27. //#include <config.h>
  28. //#include "aodv.h"
  29. #define AODV_MAX_ERRORS 100
  30. /* =====================================================================
  31.    Packet Formats...
  32.    ===================================================================== */
  33. #define AODVTYPE_HELLO   0x01
  34. #define AODVTYPE_RREQ    0x02
  35. #define AODVTYPE_RREP    0x04
  36. #define AODVTYPE_RERR    0x08
  37. #define AODVTYPE_RREP_ACK   0x10
  38. /*
  39.  * AODV Routing Protocol Header Macros
  40.  */
  41. #define HDR_AODV(p) ((struct hdr_aodv*)hdr_aodv::access(p))
  42. #define HDR_AODV_REQUEST(p)   ((struct hdr_aodv_request*)hdr_aodv::access(p))
  43. #define HDR_AODV_REPLY(p) ((struct hdr_aodv_reply*)hdr_aodv::access(p))
  44. #define HDR_AODV_ERROR(p) ((struct hdr_aodv_error*)hdr_aodv::access(p))
  45. #define HDR_AODV_RREP_ACK(p) ((struct hdr_aodv_rrep_ack*)hdr_aodv::access(p))
  46. /*
  47.  * General AODV Header - shared by all formats
  48.  */
  49. struct hdr_aodv {
  50.         u_int8_t        ah_type;
  51. /*
  52.         u_int8_t        ah_reserved[2];
  53.         u_int8_t        ah_hopcount;
  54. */
  55. // Header access methods
  56. static int offset_; // required by PacketHeaderManager
  57. inline static int& offset() { return offset_; }
  58. inline static hdr_aodv* access(const Packet* p) {
  59. return (hdr_aodv*) p->access(offset_);
  60. }
  61. };
  62. struct hdr_aodv_request {
  63.         u_int8_t        rq_type; // Packet Type
  64.         u_int8_t        reserved[2];
  65.         u_int8_t        rq_hop_count;   // Hop Count
  66.         u_int32_t       rq_bcast_id;    // Broadcast ID
  67.         nsaddr_t        rq_dst;         // Destination IP Address
  68.         u_int32_t       rq_dst_seqno;   // Destination Sequence Number
  69.         nsaddr_t        rq_src;         // Source IP Address
  70.         u_int32_t       rq_src_seqno;   // Source Sequence Number
  71.         double          rq_timestamp;   // when REQUEST sent;
  72. // used to compute route discovery latency
  73.   // This define turns on gratuitous replies- see aodv.cc for implementation contributed by
  74.   // Anant Utgikar, 09/16/02.
  75.   //#define RREQ_GRAT_RREP 0x80
  76.   inline int size() { 
  77.   int sz = 0;
  78.   /*
  79.    sz = sizeof(u_int8_t) // rq_type
  80.      + 2*sizeof(u_int8_t)  // reserved
  81.      + sizeof(u_int8_t) // rq_hop_count
  82.      + sizeof(double) // rq_timestamp
  83.      + sizeof(u_int32_t) // rq_bcast_id
  84.      + sizeof(nsaddr_t) // rq_dst
  85.      + sizeof(u_int32_t) // rq_dst_seqno
  86.      + sizeof(nsaddr_t) // rq_src
  87.      + sizeof(u_int32_t); // rq_src_seqno
  88.   */
  89.    sz = 7*sizeof(u_int32_t);
  90.    assert (sz >= 0);
  91. return sz;
  92.   }
  93. };
  94. struct hdr_aodv_reply {
  95.         u_int8_t        rp_type;        // Packet Type
  96.         u_int8_t        reserved[2];
  97.         u_int8_t        rp_hop_count;           // Hop Count
  98.         nsaddr_t        rp_dst;                 // Destination IP Address
  99.         u_int32_t       rp_dst_seqno;           // Destination Sequence Number
  100.         nsaddr_t        rp_src;                 // Source IP Address
  101.         double         rp_lifetime;            // Lifetime
  102.         double          rp_timestamp;           // when corresponding REQ sent;
  103. // used to compute route discovery latency
  104.   inline int size() { 
  105.   int sz = 0;
  106.   /*
  107.    sz = sizeof(u_int8_t) // rp_type
  108.      + 2*sizeof(u_int8_t)  // rp_flags + reserved
  109.      + sizeof(u_int8_t) // rp_hop_count
  110.      + sizeof(double) // rp_timestamp
  111.      + sizeof(nsaddr_t) // rp_dst
  112.      + sizeof(u_int32_t) // rp_dst_seqno
  113.      + sizeof(nsaddr_t) // rp_src
  114.      + sizeof(u_int32_t); // rp_lifetime
  115.   */
  116.    sz = 6*sizeof(u_int32_t);
  117.    assert (sz >= 0);
  118. return sz;
  119.   }
  120. };
  121. struct hdr_aodv_error {
  122.         u_int8_t        re_type;                // Type
  123.         u_int8_t        reserved[2];            // Reserved
  124.         u_int8_t        DestCount;                 // DestCount
  125.         // List of Unreachable destination IP addresses and sequence numbers
  126.         nsaddr_t        unreachable_dst[AODV_MAX_ERRORS];   
  127.         u_int32_t       unreachable_dst_seqno[AODV_MAX_ERRORS];   
  128.   inline int size() { 
  129.   int sz = 0;
  130.   /*
  131.    sz = sizeof(u_int8_t) // type
  132.      + 2*sizeof(u_int8_t)  // reserved
  133.      + sizeof(u_int8_t) // length
  134.      + length*sizeof(nsaddr_t); // unreachable destinations
  135.   */
  136.    sz = (DestCount*2 + 1)*sizeof(u_int32_t);
  137. assert(sz);
  138.         return sz;
  139.   }
  140. };
  141. struct hdr_aodv_rrep_ack {
  142. u_int8_t rpack_type;
  143. u_int8_t reserved;
  144. };
  145. // for size calculation of header-space reservation
  146. union hdr_all_aodv {
  147.   hdr_aodv          ah;
  148.   hdr_aodv_request  rreq;
  149.   hdr_aodv_reply    rrep;
  150.   hdr_aodv_error    rerr;
  151.   hdr_aodv_rrep_ack rrep_ack;
  152. };
  153. #endif /* __aodv_packet_h__ */