2017-03-08 18:01:29 +01:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 Universita' degli Studi di Napoli Federico II
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* Author: Stefano Avallone <stefano.avallone@.unina.it>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ns3/abort.h"
|
|
|
|
|
#include "ns3/queue-limits.h"
|
|
|
|
|
#include "ns3/net-device-queue-interface.h"
|
|
|
|
|
#include "ns3/simulator.h"
|
2018-12-03 11:04:49 +01:00
|
|
|
#include "ns3/uinteger.h"
|
|
|
|
|
#include "ns3/queue-item.h"
|
2017-03-08 18:01:29 +01:00
|
|
|
|
|
|
|
|
namespace ns3 {
|
|
|
|
|
|
|
|
|
|
NS_LOG_COMPONENT_DEFINE ("NetDeviceQueueInterface");
|
|
|
|
|
|
2020-05-19 13:28:06 +02:00
|
|
|
TypeId
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueue::GetTypeId ()
|
2020-05-19 13:28:06 +02:00
|
|
|
{
|
|
|
|
|
static TypeId tid = TypeId ("ns3::NetDeviceQueue")
|
|
|
|
|
.SetParent<Object> ()
|
|
|
|
|
.SetGroupName("Network")
|
|
|
|
|
.AddConstructor<NetDeviceQueue> ()
|
|
|
|
|
;
|
|
|
|
|
return tid;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 18:01:29 +01:00
|
|
|
NetDeviceQueue::NetDeviceQueue ()
|
|
|
|
|
: m_stoppedByDevice (false),
|
2018-12-03 11:04:49 +01:00
|
|
|
m_stoppedByQueueLimits (false),
|
|
|
|
|
NS_LOG_TEMPLATE_DEFINE ("NetDeviceQueueInterface")
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeviceQueue::~NetDeviceQueue ()
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
2018-12-03 11:04:49 +01:00
|
|
|
|
2022-10-06 21:45:05 +00:00
|
|
|
m_queueLimits = nullptr;
|
2018-12-03 11:04:49 +01:00
|
|
|
m_wakeCallback.Nullify ();
|
2022-10-06 21:45:05 +00:00
|
|
|
m_device = nullptr;
|
2017-03-08 18:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueue::IsStopped () const
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
return m_stoppedByDevice || m_stoppedByQueueLimits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueue::Start ()
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
m_stoppedByDevice = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueue::Stop ()
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
m_stoppedByDevice = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueue::Wake ()
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
|
|
|
|
|
bool wasStoppedByDevice = m_stoppedByDevice;
|
|
|
|
|
m_stoppedByDevice = false;
|
|
|
|
|
|
|
|
|
|
// Request the queue disc to dequeue a packet
|
|
|
|
|
if (wasStoppedByDevice && !m_wakeCallback.IsNull ())
|
|
|
|
|
{
|
|
|
|
|
Simulator::ScheduleNow (&NetDeviceQueue::m_wakeCallback, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 11:04:49 +01:00
|
|
|
void
|
|
|
|
|
NetDeviceQueue::NotifyAggregatedObject (Ptr<NetDeviceQueueInterface> ndqi)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this << ndqi);
|
|
|
|
|
|
|
|
|
|
m_device = ndqi->GetObject<NetDevice> ();
|
|
|
|
|
NS_ABORT_MSG_IF (!m_device, "No NetDevice object was aggregated to the NetDeviceQueueInterface");
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 18:01:29 +01:00
|
|
|
void
|
|
|
|
|
NetDeviceQueue::SetWakeCallback (WakeCallback cb)
|
|
|
|
|
{
|
|
|
|
|
m_wakeCallback = cb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDeviceQueue::NotifyQueuedBytes (uint32_t bytes)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this << bytes);
|
|
|
|
|
if (!m_queueLimits)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_queueLimits->Queued (bytes);
|
|
|
|
|
if (m_queueLimits->Available () >= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_stoppedByQueueLimits = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDeviceQueue::NotifyTransmittedBytes (uint32_t bytes)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this << bytes);
|
|
|
|
|
if ((!m_queueLimits) || (!bytes))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_queueLimits->Completed (bytes);
|
|
|
|
|
if (m_queueLimits->Available () < 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bool wasStoppedByQueueLimits = m_stoppedByQueueLimits;
|
|
|
|
|
m_stoppedByQueueLimits = false;
|
|
|
|
|
// Request the queue disc to dequeue a packet
|
|
|
|
|
if (wasStoppedByQueueLimits && !m_wakeCallback.IsNull ())
|
|
|
|
|
{
|
|
|
|
|
Simulator::ScheduleNow (&NetDeviceQueue::m_wakeCallback, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDeviceQueue::ResetQueueLimits ()
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
if (!m_queueLimits)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_queueLimits->Reset ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDeviceQueue::SetQueueLimits (Ptr<QueueLimits> ql)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this << ql);
|
|
|
|
|
m_queueLimits = ql;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr<QueueLimits>
|
|
|
|
|
NetDeviceQueue::GetQueueLimits ()
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
return m_queueLimits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_OBJECT_ENSURE_REGISTERED (NetDeviceQueueInterface);
|
|
|
|
|
|
2018-09-18 15:50:02 +02:00
|
|
|
TypeId
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueueInterface::GetTypeId ()
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
static TypeId tid = TypeId ("ns3::NetDeviceQueueInterface")
|
|
|
|
|
.SetParent<Object> ()
|
|
|
|
|
.SetGroupName("Network")
|
|
|
|
|
.AddConstructor<NetDeviceQueueInterface> ()
|
2020-05-19 13:28:06 +02:00
|
|
|
.AddAttribute ("TxQueuesType",
|
|
|
|
|
"The type of transmission queues to be used",
|
|
|
|
|
TypeId::ATTR_CONSTRUCT,
|
|
|
|
|
TypeIdValue (NetDeviceQueue::GetTypeId ()),
|
|
|
|
|
MakeTypeIdAccessor (&NetDeviceQueueInterface::SetTxQueuesType),
|
|
|
|
|
MakeTypeIdChecker ())
|
2018-09-18 15:50:02 +02:00
|
|
|
.AddAttribute ("NTxQueues", "The number of device transmission queues",
|
|
|
|
|
TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT,
|
|
|
|
|
UintegerValue (1),
|
|
|
|
|
MakeUintegerAccessor (&NetDeviceQueueInterface::SetNTxQueues,
|
|
|
|
|
&NetDeviceQueueInterface::GetNTxQueues),
|
|
|
|
|
MakeUintegerChecker<uint16_t> (1, 65535))
|
2017-03-08 18:01:29 +01:00
|
|
|
;
|
|
|
|
|
return tid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeviceQueueInterface::NetDeviceQueueInterface ()
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
2018-09-18 15:50:02 +02:00
|
|
|
|
|
|
|
|
// the default select queue callback returns 0
|
|
|
|
|
m_selectQueueCallback = [] (Ptr<QueueItem> item) { return 0; };
|
2017-03-08 18:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeviceQueueInterface::~NetDeviceQueueInterface ()
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr<NetDeviceQueue>
|
2018-09-18 15:50:02 +02:00
|
|
|
NetDeviceQueueInterface::GetTxQueue (std::size_t i) const
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_ASSERT (i < m_txQueuesVector.size ());
|
|
|
|
|
return m_txQueuesVector[i];
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-18 15:50:02 +02:00
|
|
|
std::size_t
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueueInterface::GetNTxQueues () const
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_txQueuesVector.size ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueueInterface::DoDispose ()
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
2017-03-27 11:08:38 +02:00
|
|
|
|
2017-03-08 18:01:29 +01:00
|
|
|
m_txQueuesVector.clear ();
|
|
|
|
|
Object::DoDispose ();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 11:04:49 +01:00
|
|
|
void
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueueInterface::NotifyNewAggregate ()
|
2018-12-03 11:04:49 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this);
|
|
|
|
|
|
|
|
|
|
// Notify the NetDeviceQueue objects that an object was aggregated
|
|
|
|
|
for (auto& tx : m_txQueuesVector)
|
|
|
|
|
{
|
|
|
|
|
tx->NotifyAggregatedObject (this);
|
|
|
|
|
}
|
|
|
|
|
Object::NotifyNewAggregate ();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 13:28:06 +02:00
|
|
|
void
|
|
|
|
|
NetDeviceQueueInterface::SetTxQueuesType (TypeId type)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this << type);
|
|
|
|
|
|
|
|
|
|
NS_ABORT_MSG_IF (!m_txQueuesVector.empty (), "Cannot call SetTxQueuesType after creating device queues");
|
|
|
|
|
|
|
|
|
|
m_txQueues = ObjectFactory ();
|
|
|
|
|
m_txQueues.SetTypeId (type);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 18:01:29 +01:00
|
|
|
void
|
2018-09-18 15:50:02 +02:00
|
|
|
NetDeviceQueueInterface::SetNTxQueues (std::size_t numTxQueues)
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
NS_LOG_FUNCTION (this << numTxQueues);
|
|
|
|
|
NS_ASSERT (numTxQueues > 0);
|
|
|
|
|
|
2018-09-18 15:50:02 +02:00
|
|
|
NS_ABORT_MSG_IF (!m_txQueuesVector.empty (), "Cannot call SetNTxQueues after creating device queues");
|
2017-03-08 18:01:29 +01:00
|
|
|
|
2018-09-18 15:50:02 +02:00
|
|
|
// create the netdevice queues
|
|
|
|
|
for (std::size_t i = 0; i < numTxQueues; i++)
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
2020-05-19 13:28:06 +02:00
|
|
|
m_txQueuesVector.push_back (m_txQueues.Create ()->GetObject<NetDeviceQueue> ());
|
2017-03-08 18:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDeviceQueueInterface::SetSelectQueueCallback (SelectQueueCallback cb)
|
|
|
|
|
{
|
|
|
|
|
m_selectQueueCallback = cb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeviceQueueInterface::SelectQueueCallback
|
2022-10-06 21:33:49 +00:00
|
|
|
NetDeviceQueueInterface::GetSelectQueueCallback () const
|
2017-03-08 18:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_selectQueueCallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ns3
|