src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/apps/ndn-consumer-window.cpp b/apps/ndn-consumer-window.cpp
index a4a6ad5..595842c 100644
--- a/apps/ndn-consumer-window.cpp
+++ b/apps/ndn-consumer-window.cpp
@@ -30,93 +30,92 @@
#include "ns3/ndn-data.hpp"
#include "ns3/ndn-interest.hpp"
-NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerWindow");
+NS_LOG_COMPONENT_DEFINE("ndn.ConsumerWindow");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (ConsumerWindow);
+NS_OBJECT_ENSURE_REGISTERED(ConsumerWindow);
TypeId
-ConsumerWindow::GetTypeId (void)
+ConsumerWindow::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::ConsumerWindow")
- .SetGroupName ("Ndn")
- .SetParent<Consumer> ()
- .AddConstructor<ConsumerWindow> ()
+ static TypeId tid =
+ TypeId("ns3::ndn::ConsumerWindow")
+ .SetGroupName("Ndn")
+ .SetParent<Consumer>()
+ .AddConstructor<ConsumerWindow>()
- .AddAttribute ("Window", "Initial size of the window",
- StringValue ("1"),
- MakeUintegerAccessor (&ConsumerWindow::GetWindow, &ConsumerWindow::SetWindow),
- MakeUintegerChecker<uint32_t> ())
+ .AddAttribute("Window", "Initial size of the window", StringValue("1"),
+ MakeUintegerAccessor(&ConsumerWindow::GetWindow, &ConsumerWindow::SetWindow),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("PayloadSize", "Average size of content object size (to calculate interest generation rate)",
- UintegerValue (1040),
- MakeUintegerAccessor (&ConsumerWindow::GetPayloadSize, &ConsumerWindow::SetPayloadSize),
- MakeUintegerChecker<uint32_t>())
+ .AddAttribute("PayloadSize",
+ "Average size of content object size (to calculate interest generation rate)",
+ UintegerValue(1040), MakeUintegerAccessor(&ConsumerWindow::GetPayloadSize,
+ &ConsumerWindow::SetPayloadSize),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("Size",
- "Amount of data in megabytes to request, relying on PayloadSize parameter (alternative to MaxSeq attribute)",
- DoubleValue (-1), // don't impose limit by default
- MakeDoubleAccessor (&ConsumerWindow::GetMaxSize, &ConsumerWindow::SetMaxSize),
- MakeDoubleChecker<double> ())
+ .AddAttribute("Size", "Amount of data in megabytes to request, relying on PayloadSize "
+ "parameter (alternative to MaxSeq attribute)",
+ DoubleValue(-1), // don't impose limit by default
+ MakeDoubleAccessor(&ConsumerWindow::GetMaxSize, &ConsumerWindow::SetMaxSize),
+ MakeDoubleChecker<double>())
- .AddAttribute ("MaxSeq",
- "Maximum sequence number to request (alternative to Size attribute, would activate only if Size is -1). "
- "The parameter is activated only if Size negative (not set)",
- IntegerValue (std::numeric_limits<uint32_t>::max ()),
- MakeUintegerAccessor (&ConsumerWindow::GetSeqMax, &ConsumerWindow::SetSeqMax),
- MakeUintegerChecker<uint32_t> ())
+ .AddAttribute("MaxSeq", "Maximum sequence number to request (alternative to Size attribute, "
+ "would activate only if Size is -1). "
+ "The parameter is activated only if Size negative (not set)",
+ IntegerValue(std::numeric_limits<uint32_t>::max()),
+ MakeUintegerAccessor(&ConsumerWindow::GetSeqMax, &ConsumerWindow::SetSeqMax),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("InitialWindowOnTimeout", "Set window to initial value when timeout occurs",
- BooleanValue (true),
- MakeBooleanAccessor (&ConsumerWindow::m_setInitialWindowOnTimeout),
- MakeBooleanChecker ())
+ .AddAttribute("InitialWindowOnTimeout", "Set window to initial value when timeout occurs",
+ BooleanValue(true),
+ MakeBooleanAccessor(&ConsumerWindow::m_setInitialWindowOnTimeout),
+ MakeBooleanChecker())
- .AddTraceSource ("WindowTrace",
- "Window that controls how many outstanding interests are allowed",
- MakeTraceSourceAccessor (&ConsumerWindow::m_window))
- .AddTraceSource ("InFlight",
- "Current number of outstanding interests",
- MakeTraceSourceAccessor (&ConsumerWindow::m_inFlight))
- ;
+ .AddTraceSource("WindowTrace",
+ "Window that controls how many outstanding interests are allowed",
+ MakeTraceSourceAccessor(&ConsumerWindow::m_window))
+ .AddTraceSource("InFlight", "Current number of outstanding interests",
+ MakeTraceSourceAccessor(&ConsumerWindow::m_inFlight));
return tid;
}
-ConsumerWindow::ConsumerWindow ()
- : m_payloadSize (1040)
- , m_inFlight (0)
+ConsumerWindow::ConsumerWindow()
+ : m_payloadSize(1040)
+ , m_inFlight(0)
{
}
void
-ConsumerWindow::SetWindow (uint32_t window)
+ConsumerWindow::SetWindow(uint32_t window)
{
m_initialWindow = window;
m_window = m_initialWindow;
}
uint32_t
-ConsumerWindow::GetWindow () const
+ConsumerWindow::GetWindow() const
{
return m_initialWindow;
}
uint32_t
-ConsumerWindow::GetPayloadSize () const
+ConsumerWindow::GetPayloadSize() const
{
return m_payloadSize;
}
void
-ConsumerWindow::SetPayloadSize (uint32_t payload)
+ConsumerWindow::SetPayloadSize(uint32_t payload)
{
m_payloadSize = payload;
}
double
-ConsumerWindow::GetMaxSize () const
+ConsumerWindow::GetMaxSize() const
{
if (m_seqMax == 0)
return -1.0;
@@ -125,28 +124,27 @@
}
void
-ConsumerWindow::SetMaxSize (double size)
+ConsumerWindow::SetMaxSize(double size)
{
m_maxSize = size;
- if (m_maxSize < 0)
- {
- m_seqMax = 0;
- return;
- }
+ if (m_maxSize < 0) {
+ m_seqMax = 0;
+ return;
+ }
m_seqMax = floor(1.0 + m_maxSize * 1024.0 * 1024.0 / m_payloadSize);
- NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax);
+ NS_LOG_DEBUG("MaxSeqNo: " << m_seqMax);
// std::cout << "MaxSeqNo: " << m_seqMax << "\n";
}
uint32_t
-ConsumerWindow::GetSeqMax () const
+ConsumerWindow::GetSeqMax() const
{
return m_seqMax;
}
void
-ConsumerWindow::SetSeqMax (uint32_t seqMax)
+ConsumerWindow::SetSeqMax(uint32_t seqMax)
{
if (m_maxSize < 0)
m_seqMax = seqMax;
@@ -154,31 +152,30 @@
// ignore otherwise
}
-
void
-ConsumerWindow::ScheduleNextPacket ()
+ConsumerWindow::ScheduleNextPacket()
{
- if (m_window == static_cast<uint32_t> (0))
- {
- Simulator::Remove (m_sendEvent);
+ if (m_window == static_cast<uint32_t>(0)) {
+ Simulator::Remove(m_sendEvent);
- NS_LOG_DEBUG ("Next event in " << (std::min<double> (0.5, m_rtt->RetransmitTimeout ().ToDouble (Time::S))) << " sec");
- m_sendEvent = Simulator::Schedule (Seconds (std::min<double> (0.5, m_rtt->RetransmitTimeout ().ToDouble (Time::S))),
- &Consumer::SendPacket, this);
+ NS_LOG_DEBUG(
+ "Next event in " << (std::min<double>(0.5, m_rtt->RetransmitTimeout().ToDouble(Time::S)))
+ << " sec");
+ m_sendEvent =
+ Simulator::Schedule(Seconds(
+ std::min<double>(0.5, m_rtt->RetransmitTimeout().ToDouble(Time::S))),
+ &Consumer::SendPacket, this);
+ }
+ else if (m_inFlight >= m_window) {
+ // simply do nothing
+ }
+ else {
+ if (m_sendEvent.IsRunning()) {
+ Simulator::Remove(m_sendEvent);
}
- else if (m_inFlight >= m_window)
- {
- // simply do nothing
- }
- else
- {
- if (m_sendEvent.IsRunning ())
- {
- Simulator::Remove (m_sendEvent);
- }
- m_sendEvent = Simulator::ScheduleNow (&Consumer::SendPacket, this);
- }
+ m_sendEvent = Simulator::ScheduleNow(&Consumer::SendPacket, this);
+ }
}
///////////////////////////////////////////////////
@@ -186,58 +183,58 @@
///////////////////////////////////////////////////
void
-ConsumerWindow::OnData (Ptr<const Data> contentObject)
+ConsumerWindow::OnData(Ptr<const Data> contentObject)
{
- Consumer::OnData (contentObject);
+ Consumer::OnData(contentObject);
m_window = m_window + 1;
- if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
+ if (m_inFlight > static_cast<uint32_t>(0))
+ m_inFlight--;
+ NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
void
-ConsumerWindow::OnNack (Ptr<const Interest> interest)
+ConsumerWindow::OnNack(Ptr<const Interest> interest)
{
- Consumer::OnNack (interest);
+ Consumer::OnNack(interest);
- if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
+ if (m_inFlight > static_cast<uint32_t>(0))
+ m_inFlight--;
- if (m_window > static_cast<uint32_t> (0))
- {
- // m_window = 0.5 * m_window;//m_window - 1;
- m_window = std::max<uint32_t> (0, m_window - 1);
- }
+ if (m_window > static_cast<uint32_t>(0)) {
+ // m_window = 0.5 * m_window;//m_window - 1;
+ m_window = std::max<uint32_t>(0, m_window - 1);
+ }
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
+ NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
void
-ConsumerWindow::OnTimeout (uint32_t sequenceNumber)
+ConsumerWindow::OnTimeout(uint32_t sequenceNumber)
{
- if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
+ if (m_inFlight > static_cast<uint32_t>(0))
+ m_inFlight--;
- if (m_setInitialWindowOnTimeout)
- {
- // m_window = std::max<uint32_t> (0, m_window - 1);
- m_window = m_initialWindow;
- }
+ if (m_setInitialWindowOnTimeout) {
+ // m_window = std::max<uint32_t> (0, m_window - 1);
+ m_window = m_initialWindow;
+ }
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
- Consumer::OnTimeout (sequenceNumber);
+ NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
+ Consumer::OnTimeout(sequenceNumber);
}
void
-ConsumerWindow::WillSendOutInterest (uint32_t sequenceNumber)
+ConsumerWindow::WillSendOutInterest(uint32_t sequenceNumber)
{
- m_inFlight ++;
- Consumer::WillSendOutInterest (sequenceNumber);
+ m_inFlight++;
+ Consumer::WillSendOutInterest(sequenceNumber);
}
-
} // namespace ndn
} // namespace ns3