model: add queue length congestion detection and signaling

add PCON consumer app

refs #4578

Change-Id: I1b04e3d123510b1ed6134a708c2710ebbb217167
diff --git a/model/ndn-net-device-transport.cpp b/model/ndn-net-device-transport.cpp
index 32abaa6..17880d2 100644
--- a/model/ndn-net-device-transport.cpp
+++ b/model/ndn-net-device-transport.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2011-2016  Regents of the University of California.
+/*
+ * Copyright (c) 2011-2018  Regents of the University of California.
  *
  * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
  * contributors.
@@ -27,6 +27,8 @@
 #include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/data.hpp>
 
+#include "ns3/queue.h"
+
 NS_LOG_COMPONENT_DEFINE("ndn.NetDeviceTransport");
 
 namespace ns3 {
@@ -49,6 +51,14 @@
   this->setLinkType(linkType);
   this->setMtu(m_netDevice->GetMtu()); // Use the MTU of the netDevice
 
+  // Get send queue capacity for congestion marking
+  PointerValue txQueueAttribute;
+  if (m_netDevice->GetAttributeFailSafe("TxQueue", txQueueAttribute)) {
+    Ptr<ns3::QueueBase> txQueue = txQueueAttribute.Get<ns3::QueueBase>();
+    // must be put into bytes mode queue
+    this->setSendQueueCapacity(txQueue->GetMaxBytes());
+  }
+
   NS_LOG_FUNCTION(this << "Creating an ndnSIM transport instance for netDevice with URI"
                   << this->getLocalUri());
 
@@ -64,6 +74,19 @@
   NS_LOG_FUNCTION_NOARGS();
 }
 
+ssize_t
+NetDeviceTransport::getSendQueueLength()
+{
+  PointerValue txQueueAttribute;
+  if (m_netDevice->GetAttributeFailSafe("TxQueue", txQueueAttribute)) {
+    Ptr<ns3::QueueBase> txQueue = txQueueAttribute.Get<ns3::QueueBase>();
+    return txQueue->GetNBytes();
+  }
+  else {
+    return nfd::face::QUEUE_UNSUPPORTED;
+  }
+}
+
 void
 NetDeviceTransport::doClose()
 {
diff --git a/model/ndn-net-device-transport.hpp b/model/ndn-net-device-transport.hpp
index 09a08ed..e68382d 100644
--- a/model/ndn-net-device-transport.hpp
+++ b/model/ndn-net-device-transport.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2011-2016  Regents of the University of California.
+/*
+ * Copyright (c) 2011-2018  Regents of the University of California.
  *
  * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
  * contributors.
@@ -54,6 +54,9 @@
   Ptr<NetDevice>
   GetNetDevice() const;
 
+  virtual ssize_t
+  getSendQueueLength() final;
+
 private:
   virtual void
   doClose() override;