blob: 3add082cb0aba18e2ba64d9e5fdacb12a13f6d4e [file] [log] [blame]
Eric Newberry8821d3e2018-07-04 16:42:01 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011-2018 Regents of the University of California.
4 *
5 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
7 *
8 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20#include "ndn-consumer-pcon.hpp"
21
22NS_LOG_COMPONENT_DEFINE("ndn.ConsumerPcon");
23
24namespace ns3 {
25namespace ndn {
26
27NS_OBJECT_ENSURE_REGISTERED(ConsumerPcon);
28
29TypeId
30ConsumerPcon::GetTypeId()
31{
32 static TypeId tid =
33 TypeId("ns3::ndn::ConsumerPcon")
34 .SetGroupName("Ndn")
35 .SetParent<ConsumerWindow>()
36 .AddConstructor<ConsumerPcon>()
37
38 .AddAttribute("Beta", "TCP Multiplicative Decrease factor",
39 DoubleValue(0.5),
40 MakeDoubleAccessor(&ConsumerPcon::m_beta),
41 MakeDoubleChecker<double>())
42
43 .AddAttribute("AddRttSupress", "Minimum number of RTTs (1 + this factor) between window decreases",
44 DoubleValue(0.5), // This default value was chosen after manual testing
45 MakeDoubleAccessor(&ConsumerPcon::m_addRttSupress),
46 MakeDoubleChecker<double>())
47
48 .AddAttribute("ShouldReactToCongestionMarks", "If true, process received congestion marks",
49 BooleanValue(true),
50 MakeBooleanAccessor(&ConsumerPcon::m_shouldReactToCongestionMarks),
51 MakeBooleanChecker())
52
53 .AddAttribute("ShouldUseCwa", "If true, use Conservative Window Adaptation",
54 BooleanValue(true),
55 MakeBooleanAccessor(&ConsumerPcon::m_shouldUseCwa),
56 MakeBooleanChecker());
57
58 return tid;
59}
60
61ConsumerPcon::ConsumerPcon()
62 : m_ssthresh(std::numeric_limits<double>::max())
63 , m_highData(0)
64 , m_recPoint(0.0)
65{
66}
67
68void
69ConsumerPcon::OnData(shared_ptr<const Data> data)
70{
71 Consumer::OnData(data);
72
73 uint64_t sequenceNum = data->getName().get(-1).toSegment();
74
75 // Set highest received Data to sequence number
76 if (m_highData < sequenceNum) {
77 m_highData = sequenceNum;
78 }
79
80 if (data->getCongestionMark() > 0) {
81 if (m_shouldReactToCongestionMarks) {
82 NS_LOG_DEBUG("Received congestion mark: " << data->getCongestionMark());
83 WindowDecrease();
84 }
85 else {
86 NS_LOG_DEBUG("Ignored received congestion mark: " << data->getCongestionMark());
87 }
88 }
89 else {
90 WindowIncrease();
91 }
92
93 if (m_inFlight > static_cast<uint32_t>(0)) {
94 m_inFlight--;
95 }
96
97 NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
98
99 ScheduleNextPacket();
100}
101
102void
103ConsumerPcon::OnTimeout(uint32_t sequenceNum)
104{
105 WindowDecrease();
106
107 if (m_inFlight > static_cast<uint32_t>(0)) {
108 m_inFlight--;
109 }
110
111 NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
112
113 Consumer::OnTimeout(sequenceNum);
114}
115
116void
117ConsumerPcon::WindowIncrease()
118{
119 if (m_window < m_ssthresh) {
120 m_window += 1.0;
121 }
122 else {
123 m_window += (1.0 / m_window);
124 }
125
126 NS_LOG_DEBUG("Window size increased to " << m_window);
127}
128
129void
130ConsumerPcon::WindowDecrease()
131{
132 if (m_shouldUseCwa || m_highData > m_recPoint) {
133 const double diff = m_seq - m_highData;
134 assert(diff > 0);
135
136 m_recPoint = m_seq + (m_addRttSupress * diff);
137
138 m_ssthresh = m_window * m_beta;
139 m_window = m_ssthresh;
140
141 // Window size cannot be reduced below initial size
142 if (m_window < m_initialWindow) {
143 m_window = m_initialWindow;
144 }
145
146 NS_LOG_DEBUG("Window size decreased to " << m_window);
147 }
148 else {
149 NS_LOG_DEBUG("Window decrease suppressed, HighData: " << m_highData << ", RecPoint: " << m_recPoint);
150 }
151}
152
153} // namespace ndn
154} // namespace ns3