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