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 <thread>
27 #include "fd-net-device.h"
28 #include <net/netmap_user.h>
29 #include <atomic>
30 
31 namespace ns3 {
32 
44 {
45 public:
50  static TypeId GetTypeId (void);
51 
53  virtual ~NetDeviceQueueLock ();
54 
59  virtual void Start (void);
60 
65  virtual void Stop (void);
66 
72  virtual void Wake (void);
73 
81  virtual bool IsStopped (void) const;
82 
87  virtual void NotifyQueuedBytes (uint32_t bytes);
88 
93  virtual void NotifyTransmittedBytes (uint32_t bytes);
94 
95 private:
96  mutable std::mutex m_mutex;
97 };
98 
105 {
106 public:
108 
113  void SetBufferSize (uint32_t bufferSize);
114 
119  void SetNetmapIfp (struct netmap_if *nifp);
120 
121 private:
122  FdReader::Data DoRead (void);
123 
124  uint32_t m_bufferSize;
125  struct netmap_if *m_nifp;
126 };
127 
137 {
138 public:
143  static TypeId GetTypeId (void);
144 
145  NetmapNetDevice ();
146  virtual ~NetmapNetDevice ();
147 
152  uint32_t GetBytesInNetmapTxRing ();
153 
158  int GetSpaceInNetmapTxRing () const;
159 
165 
170  void SetNetmapInterfaceRepresentation (struct netmap_if *nifp);
171 
177  void SetTxRingsInfo (uint32_t nTxRings, uint32_t nTxRingsSlots);
178 
184  void SetRxRingsInfo (uint32_t nRxRings, uint32_t nRxRingsSlots);
185 
192  virtual ssize_t Write (uint8_t *buffer, size_t length);
193 
194 private:
196  void DoFinishStartingDevice (void);
197  void DoFinishStoppingDevice (void);
198 
203  virtual void SyncAndNotifyQueue ();
204 
205  struct netmap_if *m_nifp;
206  uint32_t m_nTxRings;
207  uint32_t m_nTxRingsSlots;
208  uint32_t m_nRxRings;
209  uint32_t m_nRxRingsSlots;
213  std::atomic<bool> m_syncAndNotifyQueueThreadRun;
215 };
216 
217 } // namespace ns3
218 
219 #endif /* NETMAP_NET_DEVICE_H */
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:85
A class that asynchronously reads from a file descriptor.
Network device transmission queue.
Network device transmission queue with lock.
static TypeId GetTypeId(void)
Get the type ID.
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.
std::mutex m_mutex
Mutex to serialize the operations performed on the queue.
virtual void Start(void)
Called by the device to start this device transmission queue.
virtual void Stop(void)
Called by the device to stop this device transmission queue.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue.
This class performs the actual data reading from the netmap ring.
FdReader::Data DoRead(void)
The read implementation.
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
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.
static TypeId GetTypeId(void)
Get the type ID.
void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
void SetNetmapInterfaceRepresentation(struct netmap_if *nifp)
Set the netmap interface representation.
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.
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.
void DoFinishStartingDevice(void)
Complete additional actions, if any, to spin up down the device.
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.
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(void)
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:74
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.