A Discrete-Event Network Simulator
API
netmap-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 Universita' degli Studi di Napoli Federico II
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Pasquale Imputato <p.imputato@gmail.com>
19  */
20 
21 #ifndef NETMAP_NET_DEVICE_H
22 #define NETMAP_NET_DEVICE_H
23 
24 #include "ns3/net-device-queue-interface.h"
25 #include <mutex>
26 #include "fd-net-device.h"
27 #include <net/netmap_user.h>
28 #include <atomic>
29 
30 namespace ns3 {
31 
32 class SystemThread;
33 
45 {
46 public:
51  static TypeId GetTypeId (void);
52 
54  virtual ~NetDeviceQueueLock ();
55 
60  virtual void Start (void);
61 
66  virtual void Stop (void);
67 
73  virtual void Wake (void);
74 
82  virtual bool IsStopped (void) const;
83 
88  virtual void NotifyQueuedBytes (uint32_t bytes);
89 
94  virtual void NotifyTransmittedBytes (uint32_t bytes);
95 
96 private:
97  mutable std::mutex m_mutex;
98 };
99 
106 {
107 public:
109 
114  void SetBufferSize (uint32_t bufferSize);
115 
120  void SetNetmapIfp (struct netmap_if *nifp);
121 
122 private:
123  FdReader::Data DoRead (void);
124 
125  uint32_t m_bufferSize;
126  struct netmap_if *m_nifp;
127 };
128 
138 {
139 public:
144  static TypeId GetTypeId (void);
145 
146  NetmapNetDevice ();
147  virtual ~NetmapNetDevice ();
148 
153  uint32_t GetBytesInNetmapTxRing ();
154 
159  int GetSpaceInNetmapTxRing () const;
160 
166 
171  void SetNetmapInterfaceRepresentation (struct netmap_if *nifp);
172 
178  void SetTxRingsInfo (uint32_t nTxRings, uint32_t nTxRingsSlots);
179 
185  void SetRxRingsInfo (uint32_t nRxRings, uint32_t nRxRingsSlots);
186 
193  virtual ssize_t Write (uint8_t *buffer, size_t length);
194 
195 private:
197  void DoFinishStartingDevice (void);
198  void DoFinishStoppingDevice (void);
199 
204  virtual void SyncAndNotifyQueue ();
205 
206  struct netmap_if *m_nifp;
207  uint32_t m_nTxRings;
208  uint32_t m_nTxRingsSlots;
209  uint32_t m_nRxRings;
210  uint32_t m_nRxRingsSlots;
214  std::atomic<bool> m_syncAndNotifyQueueThreadRun;
216 };
217 
218 } // namespace ns3
219 
220 #endif /* NETMAP_NET_DEVICE_H */
ns3::NetmapNetDevice::NetmapNetDevice
NetmapNetDevice()
Definition: netmap-net-device.cc:184
ns3::NetmapNetDevice::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: netmap-net-device.cc:170
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::NetmapNetDeviceFdReader::SetBufferSize
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
Definition: netmap-net-device.cc:103
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::NetmapNetDevice::m_queue
Ptr< NetDeviceQueue > m_queue
NetDevice queue.
Definition: netmap-net-device.h:211
ns3::NetmapNetDeviceFdReader
This class performs the actual data reading from the netmap ring.
Definition: netmap-net-device.h:106
ns3::NetDeviceQueueLock::m_mutex
std::mutex m_mutex
Mutex to serialize the operations performed on the queue.
Definition: netmap-net-device.h:97
ns3::NetmapNetDevice::m_totalQueuedBytes
uint32_t m_totalQueuedBytes
Total queued bytes.
Definition: netmap-net-device.h:212
ns3::NetmapNetDevice
a NetDevice to read/write network traffic from/into a netmap file descriptor.
Definition: netmap-net-device.h:138
ns3::NetmapNetDevice::SetNetDeviceQueue
void SetNetDeviceQueue(Ptr< NetDeviceQueue > queue)
Set the NetDeviceQueue.
Definition: netmap-net-device.cc:266
ns3::NetmapNetDevice::m_nRxRings
uint32_t m_nRxRings
Number of receiver rings.
Definition: netmap-net-device.h:209
ns3::NetmapNetDevice::DoFinishStoppingDevice
void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
Definition: netmap-net-device.cc:229
ns3::NetmapNetDevice::SyncAndNotifyQueue
virtual void SyncAndNotifyQueue()
This function syncs netmap ring and notifies netdevice queue.
Definition: netmap-net-device.cc:312
ns3::NetmapNetDeviceFdReader::m_bufferSize
uint32_t m_bufferSize
size of the read buffer
Definition: netmap-net-device.h:125
ns3::NetDeviceQueueLock::Start
virtual void Start(void)
Called by the device to start this device transmission queue.
Definition: netmap-net-device.cc:57
ns3::NetmapNetDeviceFdReader::NetmapNetDeviceFdReader
NetmapNetDeviceFdReader()
Definition: netmap-net-device.cc:96
ns3::NetmapNetDeviceFdReader::DoRead
FdReader::Data DoRead(void)
The read implementation.
Definition: netmap-net-device.cc:117
ns3::NetDeviceQueueLock::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: netmap-net-device.cc:32
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::NetmapNetDevice::~NetmapNetDevice
virtual ~NetmapNetDevice()
Definition: netmap-net-device.cc:198
ns3::NetmapNetDevice::m_nRxRingsSlots
uint32_t m_nRxRingsSlots
Number of slots in the receiver rings.
Definition: netmap-net-device.h:210
ns3::NetmapNetDevice::DoFinishStartingDevice
void DoFinishStartingDevice(void)
Complete additional actions, if any, to spin up down the device.
Definition: netmap-net-device.cc:218
ns3::NetmapNetDevice::GetSpaceInNetmapTxRing
int GetSpaceInNetmapTxRing() const
Get the number of slots currently available in the netmap transmission ring.
Definition: netmap-net-device.cc:300
ns3::NetDeviceQueue
Network device transmission queue.
Definition: net-device-queue-interface.h:57
ns3::NetDeviceQueueLock::IsStopped
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
Definition: netmap-net-device.cc:48
ns3::NetmapNetDevice::Write
virtual ssize_t Write(uint8_t *buffer, size_t length)
The function Writes a packet into the netmap transmission ring.
Definition: netmap-net-device.cc:354
ns3::NetmapNetDevice::m_nifp
struct netmap_if * m_nifp
Netmap interface representation.
Definition: netmap-net-device.h:206
ns3::NetDeviceQueueLock::~NetDeviceQueueLock
virtual ~NetDeviceQueueLock()
Definition: netmap-net-device.cc:44
ns3::NetmapNetDevice::m_syncAndNotifyQueueThreadRun
std::atomic< bool > m_syncAndNotifyQueueThreadRun
Running flag of the flow control thread.
Definition: netmap-net-device.h:214
ns3::NetmapNetDevice::m_nTxRingsSlots
uint32_t m_nTxRingsSlots
Number of slots in the transmission rings.
Definition: netmap-net-device.h:208
ns3::NetmapNetDevice::SetTxRingsInfo
void SetTxRingsInfo(uint32_t nTxRings, uint32_t nTxRingsSlots)
Set the netmap transmission rings info.
Definition: netmap-net-device.cc:282
ns3::FdNetDevice
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:85
ns3::NetmapNetDevice::m_nTxRings
uint32_t m_nTxRings
Number of transmission rings.
Definition: netmap-net-device.h:207
ns3::NetDeviceQueueLock::NetDeviceQueueLock
NetDeviceQueueLock()
Definition: netmap-net-device.cc:41
ns3::NetDeviceQueueLock::Wake
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue.
Definition: netmap-net-device.cc:73
ns3::FdReader
A class that asynchronously reads from a file descriptor.
Definition: unix-fd-reader.h:48
ns3::NetmapNetDevice::SetRxRingsInfo
void SetRxRingsInfo(uint32_t nRxRings, uint32_t nRxRingsSlots)
Set the netmap receiver rings info.
Definition: netmap-net-device.cc:291
ns3::NetmapNetDevice::SetNetmapInterfaceRepresentation
void SetNetmapInterfaceRepresentation(struct netmap_if *nifp)
Set the netmap interface representation.
Definition: netmap-net-device.cc:274
ns3::NetmapNetDevice::m_syncAndNotifyQueuePeriod
uint8_t m_syncAndNotifyQueuePeriod
The period of time in us after which the device syncs the netmap ring and notifies queue status.
Definition: netmap-net-device.h:215
ns3::NetDeviceQueueLock
Network device transmission queue with lock.
Definition: netmap-net-device.h:45
ns3::NetmapNetDevice::DoCreateFdReader
Ptr< FdReader > DoCreateFdReader(void)
Create the FdReader object.
Definition: netmap-net-device.cc:206
ns3::NetDeviceQueueLock::Stop
virtual void Stop(void)
Called by the device to stop this device transmission queue.
Definition: netmap-net-device.cc:65
ns3::NetmapNetDevice::GetBytesInNetmapTxRing
uint32_t GetBytesInNetmapTxRing()
Get the number of bytes currently in the netmap transmission ring.
Definition: netmap-net-device.cc:241
ns3::NetDeviceQueueLock::NotifyTransmittedBytes
virtual void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
Definition: netmap-net-device.cc:89
ns3::NetmapNetDeviceFdReader::m_nifp
struct netmap_if * m_nifp
Netmap interface representation.
Definition: netmap-net-device.h:126
ns3::NetmapNetDeviceFdReader::SetNetmapIfp
void SetNetmapIfp(struct netmap_if *nifp)
Set netmap interface representation.
Definition: netmap-net-device.cc:110
ns3::FdReader::Data
A structure representing data read.
Definition: unix-fd-reader.h:77
fd-net-device.h
ns3::NetmapNetDevice::m_syncAndNotifyQueueThread
Ptr< SystemThread > m_syncAndNotifyQueueThread
Thread used to perform the flow control.
Definition: netmap-net-device.h:213
ns3::NetDeviceQueueLock::NotifyQueuedBytes
virtual void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue.
Definition: netmap-net-device.cc:81