-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.cpp
40 lines (32 loc) · 973 Bytes
/
pipe.cpp
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
#include "pipe.h"
using namespace std;
Pipe::Pipe(simtime_picosec delay)
: EventSource("pipe"), _delay(delay)
{}
void
Pipe::receivePacket(Packet &pkt)
{
pkt.flow().logTraffic(pkt, *this, TrafficLogger::PKT_ARRIVE);
if (_inflight.empty()) {
// no packets currently inflight.
// need to notify the eventlist we've an event pending
EventList::Get().sourceIsPendingRel(*this, _delay);
}
_inflight.push_front(make_pair(EventList::Get().now() + _delay, &pkt));
}
void
Pipe::doNextEvent()
{
if (_inflight.size() == 0) {
return;
}
Packet *pkt = _inflight.back().second;
_inflight.pop_back();
pkt->flow().logTraffic(*pkt, *this, TrafficLogger::PKT_DEPART);
pkt->sendOn();
if (!_inflight.empty()) {
// notify the eventlist we've another event pending
simtime_picosec nexteventtime = _inflight.back().first;
EventList::Get().sourceIsPending(*this, nexteventtime);
}
}