A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
32namespace ns3
33{
34
35/**
36 * \ingroup fd-net-device
37 *
38 * \brief Network device transmission queue with lock
39 *
40 * This class stores information about a single transmission queue
41 * of a network device that is exposed to queue discs. This class extends
42 * the NetDeviceQueue base class by introducing a lock for methods which
43 * require mutual exclusion on data access in emulation.
44 */
46{
47 public:
48 /**
49 * \brief Get the type ID.
50 * \return the object TypeId
51 */
52 static TypeId GetTypeId();
53
55 virtual ~NetDeviceQueueLock();
56
57 /**
58 * Called by the device to start this device transmission queue.
59 * This is the analogous to the netif_tx_start_queue function of the Linux kernel.
60 */
61 virtual void Start();
62
63 /**
64 * Called by the device to stop this device transmission queue.
65 * This is the analogous to the netif_tx_stop_queue function of the Linux kernel.
66 */
67 virtual void Stop();
68
69 /**
70 * Called by the device to wake the queue disc associated with this
71 * device transmission queue. This is done by invoking the wake callback.
72 * This is the analogous to the netif_tx_wake_queue function of the Linux kernel.
73 */
74 virtual void Wake();
75
76 /**
77 * \brief Get the status of the device transmission queue.
78 * \return true if the device transmission queue is stopped.
79 *
80 * Called by queue discs to enquire about the status of a given transmission queue.
81 * This is the analogous to the netif_xmit_stopped function of the Linux kernel.
82 */
83 virtual bool IsStopped() const;
84
85 /**
86 * \brief Called by the netdevice to report the number of bytes queued to the device queue
87 * \param bytes number of bytes queued to the device queue
88 */
89 virtual void NotifyQueuedBytes(uint32_t bytes);
90
91 /**
92 * \brief Called by the netdevice to report the number of bytes it is going to transmit
93 * \param bytes number of bytes the device is going to transmit
94 */
95 virtual void NotifyTransmittedBytes(uint32_t bytes);
96
97 private:
98 mutable std::mutex m_mutex; //!< Mutex to serialize the operations performed on the queue
99};
100
101/**
102 * \ingroup fd-net-device
103 *
104 * \brief This class performs the actual data reading from the netmap ring.
105 */
107{
108 public:
110
111 /**
112 * \brief Set size of the read buffer.
113 * \param bufferSize the size of the read buffer
114 */
115 void SetBufferSize(uint32_t bufferSize);
116
117 /**
118 * \brief Set netmap interface representation.
119 * \param nifp the netmap interface representation
120 */
121 void SetNetmapIfp(struct netmap_if* nifp);
122
123 private:
125
126 uint32_t m_bufferSize; //!< size of the read buffer
127 struct netmap_if* m_nifp; //!< Netmap interface representation
128};
129
130/**
131 * \ingroup fd-net-device
132 *
133 * \brief a NetDevice to read/write network traffic from/into a netmap file descriptor.
134 *
135 * A NetmapNetDevice object will read and write packets from/to a netmap file descriptor.
136 *
137 */
139{
140 public:
141 /**
142 * \brief Get the type ID.
143 * \return the object TypeId
144 */
145 static TypeId GetTypeId();
146
148 virtual ~NetmapNetDevice();
149
150 /**
151 * \brief Get the number of bytes currently in the netmap transmission ring.
152 * \return the number of bytes in the netmap transmission ring.
153 */
155
156 /**
157 * \brief Get the number of slots currently available in the netmap transmission ring.
158 * \return the number of slots currently available in the netmap transmission ring.
159 */
160 int GetSpaceInNetmapTxRing() const;
161
162 /**
163 * \brief Set the NetDeviceQueue
164 * \param queue the NetDeviceQueue
165 */
167
168 /**
169 * \brief Set the netmap interface representation
170 * \param nifp the pointer to netmap interface representation
171 */
172 void SetNetmapInterfaceRepresentation(struct netmap_if* nifp);
173
174 /**
175 * \brief Set the netmap transmission rings info
176 * \param nTxRings the number of transmission rings
177 * \param nTxRingsSlots the number of slots for each transmission ring
178 */
179 void SetTxRingsInfo(uint32_t nTxRings, uint32_t nTxRingsSlots);
180
181 /**
182 * \brief Set the netmap receiver rings info
183 * \param nRxRings the number of receiver rings
184 * \param nRxRingsSlots the number of slots for each receiver ring
185 */
186 void SetRxRingsInfo(uint32_t nRxRings, uint32_t nRxRingsSlots);
187
188 /**
189 * \brief The function Writes a packet into the netmap transmission ring.
190 * \param buffer the pointer to packet
191 * \param length the packet length
192 * \return the number of written bytes
193 */
194 virtual ssize_t Write(uint8_t* buffer, size_t length);
195
196 private:
200
201 /**
202 * \brief This function syncs netmap ring and notifies netdevice queue.
203 * This function runs in a separate thread.
204 */
205 virtual void SyncAndNotifyQueue();
206
207 struct netmap_if* m_nifp; //!< Netmap interface representation
208 uint32_t m_nTxRings; //!< Number of transmission rings
209 uint32_t m_nTxRingsSlots; //!< Number of slots in the transmission rings
210 uint32_t m_nRxRings; //!< Number of receiver rings
211 uint32_t m_nRxRingsSlots; //!< Number of slots in the receiver rings
212 Ptr<NetDeviceQueue> m_queue; //!< NetDevice queue
213 uint32_t m_totalQueuedBytes; //!< Total queued bytes
214 std::thread m_syncAndNotifyQueueThread; //!< Thread used to perform the flow control
215 std::atomic<bool> m_syncAndNotifyQueueThreadRun; //!< Running flag of the flow control thread
216 uint8_t m_syncAndNotifyQueuePeriod; //!< The period of time in us after which the device syncs
217 //!< the netmap ring and notifies queue status
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