1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
// Copyright (c) 2001-2009 XORP, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2, June
// 1991 as published by the Free Software Foundation. Redistribution
// and/or modification of this program under the terms of any other
// version of the GNU General Public License is not permitted.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
// see the GNU General Public License, Version 2, a copy of which can be
// found in the XORP LICENSE.gpl file.
//
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net
#include "rip_module.h"
#include "libxorp/xorp.h"
#include "libxorp/xlog.h"
#include "libxorp/ipv4.hh"
#include "libxorp/ipv6.hh"
#include "packet_queue.hh"
template <typename A>
PacketQueue<A>::PacketQueue()
: _buffered_bytes(0), _max_buffered_bytes(64000), _drops(0)
{
}
template <typename A>
PacketQueue<A>::~PacketQueue()
{
flush_packets();
}
template <typename A>
void
PacketQueue<A>::enqueue_packet(const RipPacket<A>* pkt)
{
while (_buffered_bytes + pkt->data_bytes() >= _max_buffered_bytes
&& drop_old() == true) {
// XXX: Empty body
}
_buffered_bytes += pkt->data_bytes();
_ready_packets.push_back(pkt);
}
template <typename A>
bool
PacketQueue<A>::empty() const
{
return _ready_packets.empty();
}
template <typename A>
const RipPacket<A>*
PacketQueue<A>::head() const
{
if (_ready_packets.empty())
return 0;
return _ready_packets.front();
}
template <typename A>
void
PacketQueue<A>::pop_head()
{
if (_ready_packets.empty() == false) {
_buffered_bytes -= _ready_packets.front()->data_bytes();
delete _ready_packets.front();
_ready_packets.pop_front();
}
}
template <typename A>
bool
PacketQueue<A>::drop_old()
{
if (_ready_packets.empty() == false) {
typename QueueRep::iterator i = ++_ready_packets.begin();
if (i != _ready_packets.end()) {
XLOG_INFO("Dropping outbound RIP packet");
delete *i;
_ready_packets.erase(i);
_drops++;
return true;
}
}
return false;
}
template <typename A>
uint32_t
PacketQueue<A>::drop_count() const
{
return _drops;
}
template <typename A>
void
PacketQueue<A>::reset_drop_count()
{
_drops = 0;
}
template <typename A>
void
PacketQueue<A>::flush_packets()
{
while (_ready_packets.empty() == false) {
_buffered_bytes -= _ready_packets.front()->data_bytes();
delete _ready_packets.front();
_ready_packets.pop_front();
}
XLOG_ASSERT(_buffered_bytes == 0);
}
template <typename A>
void
PacketQueue<A>::set_max_buffered_bytes(uint32_t mbb)
{
_max_buffered_bytes = mbb;
}
template <typename A>
uint32_t
PacketQueue<A>::max_buffered_bytes() const
{
return _max_buffered_bytes;
}
template <typename A>
uint32_t
PacketQueue<A>::buffered_bytes() const
{
return _buffered_bytes;
}
// ----------------------------------------------------------------------------
// Instantiations
#ifdef INSTANTIATE_IPV4
template class PacketQueue<IPv4>;
#endif
#ifdef INSTANTIATE_IPV6
template class PacketQueue<IPv6>;
#endif
|