src/routing/aodv/aodv-rqueue.h
author Borovkova Elena <borovkovaes@iitp.ru>
Thu, 16 Jul 2009 18:25:49 +0400
changeset 5597 8e4c7f2aaead
parent 5591 e0448da5da14
child 5601 82c874729b6c
permissions -rw-r--r--
mothods, classes and members renamed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     2
/*
5591
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
     3
 * Copyright (c) 2009 IITP RAS
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     4
 *
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     7
 * published by the Free Software Foundation;
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     8
 *
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    12
 * GNU General Public License for more details.
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    13
 *
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    17
 *
5591
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    18
 * Based on 
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    19
 *      NS-2 AODV model developed by the CMU/MONARCH group and optimized and
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    20
 *      tuned by Samir Das and Mahesh Marina, University of Cincinnati;
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    21
 * 
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    22
 *      AODV-UU implementation by Erik Nordström of Uppsala University
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    23
 *      http://core.it.uu.se/core/index.php/AODV-UU
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    24
 *
5591
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    25
 * Authors: Elena Borovkova <borovkovaes@iitp.ru>
e0448da5da14 AODV copyright changed to IITP
Pavel Boyko <boyko@iitp.ru>
parents: 5561
diff changeset
    26
 *          Pavel Boyko <boyko@iitp.ru>
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    27
 */
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    28
#ifndef __aodv_rqueue_h__
5561
f74c7723afd3 AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents: 5543
diff changeset
    29
#define __aodv_rqueue_h__
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    30
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    31
#include "ns3/ipv4-header.h"
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    32
#include "ns3/nstime.h"
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    33
#include "ns3/packet.h"
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    34
#include <vector>
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    35
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    36
namespace ns3 {
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    37
namespace aodv {
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    38
5540
098f6cc13fc5 AODV rqueue fixes
Pavel Boyko <boyko@iitp.ru>
parents: 5539
diff changeset
    39
/// The maximum number of packets that we allow a routing protocol to buffer.
5541
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    40
#define AODV_RTQ_MAX_LEN 64
5540
098f6cc13fc5 AODV rqueue fixes
Pavel Boyko <boyko@iitp.ru>
parents: 5539
diff changeset
    41
/// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
5541
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    42
#define AODV_RTQ_TIMEOUT 30
5542
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    43
/**
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    44
 * \ingroup aodv
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    45
 * \brief AODV Queue Entry
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    46
 */
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    47
struct QueueEntry
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    48
{
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    49
  Ptr<Packet> m_packet;
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    50
  Ipv4Header m_header;
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    51
  /// Expire time for queue entry
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    52
  Time m_expire;
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    53
  /// c-tor
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    54
  QueueEntry(Ptr<Packet> pa, Ipv4Header const & h, Time exp = Seconds(0)) : m_packet(pa), m_header(h), m_expire(exp) {}
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    55
  /**
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    56
   * Compare queue entries
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    57
   * \return true if equal
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    58
   */
5541
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    59
  bool operator==(QueueEntry const & o) const
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    60
  {
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    61
    return ((m_packet == o.m_packet)/*&& header == o.header*/ && (m_expire == o.m_expire));
5541
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    62
  }
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    63
};
5542
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    64
/**
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    65
 * \ingroup aodv
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    66
 * \brief AODV Queue
1b504e63a1b1 aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5541
diff changeset
    67
 */
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    68
class AodvQueue
5540
098f6cc13fc5 AODV rqueue fixes
Pavel Boyko <boyko@iitp.ru>
parents: 5539
diff changeset
    69
{
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    70
public:
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    71
  /// Default c-tor
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    72
  AodvQueue ();
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    73
  /// Push entry in queue.
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    74
  void Enqueue (QueueEntry & entry);
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    75
  /// Returns a entry from the head of the queue.
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    76
  QueueEntry Dequeue ();
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    77
  /// Return first found (the earliest) entry for given destination
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    78
  bool Dequeue (Ipv4Address dst, QueueEntry & entry);
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    79
  /// Finds whether a packet with destination dst exists in the queue
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    80
  bool Find (Ipv4Address dst);
5541
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    81
  /// Number of entries
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    82
  uint32_t GetSize ();
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    83
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    84
private:
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    85
  std::vector<QueueEntry> m_queue;
5540
098f6cc13fc5 AODV rqueue fixes
Pavel Boyko <boyko@iitp.ru>
parents: 5539
diff changeset
    86
  /// Remove and return first entry from queue
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    87
  QueueEntry RemoveHead();
5541
06d67178ae33 Unit test for rqueue added
Pavel Boyko <boyko@iitp.ru>
parents: 5540
diff changeset
    88
  /// Remove all expired entries
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    89
  void Purge();
5540
098f6cc13fc5 AODV rqueue fixes
Pavel Boyko <boyko@iitp.ru>
parents: 5539
diff changeset
    90
  /// Notify that packet is dropped from queue by timeout
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    91
  void Drop (QueueEntry e);
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    92
  /// Maximum number of entries in queue
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    93
  uint32_t m_maxSize;
5543
be0a97484ad4 comments added
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5542
diff changeset
    94
  /// Life time of queue entry in queue
5597
8e4c7f2aaead mothods, classes and members renamed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5591
diff changeset
    95
  Time m_timeout;
5539
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    96
};
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    97
}}
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    98
93ea956223ba AODV queue added
sunnmy@localhost
parents:
diff changeset
    99
#endif /* __aodv_rqueue_h__ */