39c39,40
< #include <unordered_map>
---
> #include <map>
> #include <set>
69c70
< class Interface : public EtherInt
---
> class Interface : public EtherInt, public Serializable
74c75
< double rate);
---
> double rate, unsigned id);
83c84
< void enqueue(EthPacketPtr packet);
---
> void enqueue(EthPacketPtr packet, unsigned senderId);
90,91c91,92
< void serialize(const std::string &base, CheckpointOut &cp) const;
< void unserialize(const std::string &base, CheckpointIn &cp);
---
> void serialize(CheckpointOut &cp) const;
> void unserialize(CheckpointIn &cp);
96a98,99
> const unsigned interfaceId;
>
97a101,169
> protected:
> struct PortFifoEntry : public Serializable
> {
> PortFifoEntry(EthPacketPtr pkt, Tick recv_tick, unsigned id)
> : packet(pkt), recvTick(recv_tick), srcId(id) {}
>
> EthPacketPtr packet;
> Tick recvTick;
> // id of the port that the packet has been received from
> unsigned srcId;
> ~PortFifoEntry()
> {
> packet = nullptr;
> recvTick = 0;
> srcId = 0;
> }
> void serialize(CheckpointOut &cp) const;
> void unserialize(CheckpointIn &cp);
> };
>
> class PortFifo : public Serializable
> {
> protected:
> struct EntryOrder {
> bool operator() (const PortFifoEntry& lhs,
> const PortFifoEntry& rhs) const
> {
> if (lhs.recvTick == rhs.recvTick)
> return lhs.srcId < rhs.srcId;
> else
> return lhs.recvTick < rhs.recvTick;
> }
> };
> std::set<PortFifoEntry, EntryOrder> fifo;
>
> const std::string objName;
> const unsigned _maxsize;
> unsigned _size;
>
> public:
> PortFifo(const std::string &name, int max)
> :objName(name), _maxsize(max), _size(0) {}
> ~PortFifo() {}
>
> const std::string name() { return objName; }
> // Returns the available capacity of the fifo.
> // It can return a negative value because in "push" function
> // we first push the received packet into the fifo and then
> // check if we exceed the available capacity (if avail() < 0)
> // and remove packets from the end of fifo
> int avail() const { return _maxsize - _size; }
>
> EthPacketPtr front() { return fifo.begin()->packet; }
> bool empty() const { return _size == 0; }
> unsigned size() const { return _size; }
>
> /**
> * Push a packet into the fifo
> * and sort the packets with same recv tick by port id
> */
> bool push(EthPacketPtr ptr, unsigned senderId);
> void pop();
> void clear();
> /**
> * Serialization stuff
> */
> void serialize(CheckpointOut &cp) const;
> void unserialize(CheckpointIn &cp);
> };
101c173
< PacketFifo outputFifo;
---
> PortFifo outputFifo;