2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
31 #ifndef __DEV_PKTFIFO_HH__
32 #define __DEV_PKTFIFO_HH__
38 #include "dev/etherpkt.hh"
39 #include "sim/serialize.hh"
45 typedef std::list<EthPacketPtr> fifo_list;
46 typedef fifo_list::iterator iterator;
49 std::list<EthPacketPtr> fifo;
55 explicit PacketFifo(int max) : _maxsize(max), _size(0), _reserved(0) {}
56 virtual ~PacketFifo() {}
58 int packets() const { return fifo.size(); }
59 int maxsize() const { return _maxsize; }
60 int size() const { return _size; }
61 int reserved() const { return _reserved; }
62 int avail() const { return _maxsize - _size - _reserved; }
63 bool empty() const { return size() <= 0; }
64 bool full() const { return avail() <= 0; }
66 int reserve(int len = 0)
73 iterator begin() { return fifo.begin(); }
74 iterator end() { return fifo.end(); }
76 EthPacketPtr front() { return fifo.front(); }
78 bool push(EthPacketPtr ptr)
81 assert(_reserved <= ptr->length);
82 assert(ptr->slack == 0);
83 if (avail() < ptr->length - _reserved)
97 EthPacketPtr &packet = fifo.front();
98 _size -= packet->length;
99 _size -= packet->slack;
107 for (iterator i = begin(); i != end(); ++i)
114 void remove(iterator i)
116 EthPacketPtr &packet = *i;
117 if (i != fifo.begin()) {
120 assert(prev != fifo.end());
121 (*prev)->slack += packet->length;
123 _size -= packet->length;
124 _size -= packet->slack;
132 bool copyout(void *dest, int offset, int len);
134 int countPacketsBefore(iterator end)
136 iterator i = fifo.begin();
147 int countPacketsAfter(iterator i)
149 iterator end = fifo.end();
162 * Serialization stuff
165 void serialize(const std::string &base, std::ostream &os);
166 void unserialize(const std::string &base,
167 Checkpoint *cp, const std::string §ion);
170 #endif // __DEV_PKTFIFO_HH__