5 * Created by Victor Grishchenko on 7/13/09.
6 * Copyright 2009-2012 TECHNISCHE UNIVERSITEIT DELFT. All rights reserved.
11 #include <gtest/gtest.h>
12 #include <glog/logging.h>
21 SimPacket(int from, int to, const SimPacket* toack, bool data) ;
30 /** very simplified; uplink is the bottleneck */
33 SimPeer (tint tt, tint lt, int qlen) : travtime(tt), latency(lt), queue_length(qlen) {}
40 queue<SimPacket> packet_queue;
41 queue<SimPacket> dropped_queue;
42 CongestionControl congc;
44 void send(SimPacket pck) {
45 if (packet_queue.size()==queue_length) {
46 dropped_queue.push(pck);
49 tint start = max(now,freetime);
50 tint done = pck.datatime ? start+travtime : start;
52 pck.arrivaltime = done + latency;
53 packet_queue.push(pck);
57 assert(!packet_queue.empty());
58 SimPacket ret = packet_queue.front();
63 tint next_recv_time () const {
64 return packet_queue.empty() ? NEVER : packet_queue.front().arrivaltime;
68 SimPacket rp = recv();
72 congc.RttSample(rp.arrivaltime-rp.acktime);
73 congc.OnCongestionEvent(CongestionControl::ACK_EV);
78 congc.OnCongestionEvent(CongestionControl::DATA_EV);
79 reply.acktime = reply.datatime;
81 if (!dropped_queue.empty() && dropped_queue.top().datatime<now+THR)
82 congc.OnCongestionEvent(CongestionControl::LOSS_EV);
83 if (congc.cwnd()>unackd) {
92 TEST(P2TP, TailDropTest) {
93 // two peers exchange packets over 100ms link with tail-drop discipline
94 // bw 1Mbits => travel time of 1KB is ~10ms
95 SimPeer a(10*MSEC,100*MSEC,20), b(10*MSEC,100*MSEC,20);
96 a.send(SimPacket(&b,now,0,0));
98 if (a.next_recv_time()<b.next_recv_time())
104 int main (int argc, char** argv) {
107 google::InitGoogleLogging(argv[0]);
108 testing::InitGoogleTest(&argc, argv);
109 return RUN_ALL_TESTS();