View | Details | Raw Unified | Return to bug 2119
Collapse All | Expand All

(-)a/src/fd-net-device/model/fd-net-device.cc (-17 / +36 lines)
 Lines 168-179    Link Here 
168
FdNetDevice::FdNetDevice ()
168
FdNetDevice::FdNetDevice ()
169
  : m_node (0),
169
  : m_node (0),
170
    m_ifIndex (0),
170
    m_ifIndex (0),
171
    m_mtu (1500), // Defaults to Ethernet v2 MTU 
171
    // Defaults to Ethernet v2 MTU
172
    m_mtu (1500),
172
    m_fd (-1),
173
    m_fd (-1),
173
    m_fdReader (0),
174
    m_fdReader (0),
174
    m_isBroadcast (true),
175
    m_isBroadcast (true),
175
    m_isMulticast (false),
176
    m_isMulticast (false),
176
    m_pendingReadCount (0),
177
    m_startEvent (),
177
    m_startEvent (),
178
    m_stopEvent ()
178
    m_stopEvent ()
179
{
179
{
 Lines 188-193    Link Here 
188
FdNetDevice::~FdNetDevice ()
188
FdNetDevice::~FdNetDevice ()
189
{
189
{
190
  NS_LOG_FUNCTION (this);
190
  NS_LOG_FUNCTION (this);
191
192
  {
193
    CriticalSection cs (m_pendingReadMutex);
194
195
    while (!m_pendingQueue.empty ())
196
      {
197
        std::pair<uint8_t *, ssize_t> next = m_pendingQueue.front ();
198
        m_pendingQueue.pop ();
199
200
        free (next.first);
201
      }
202
  }
191
}
203
}
192
204
193
void
205
void
 Lines 249-255    Link Here 
249
261
250
  m_fdReader = Create<FdNetDeviceFdReader> ();
262
  m_fdReader = Create<FdNetDeviceFdReader> ();
251
  // 22 bytes covers 14 bytes Ethernet header with possible 8 bytes LLC/SNAP
263
  // 22 bytes covers 14 bytes Ethernet header with possible 8 bytes LLC/SNAP
252
  m_fdReader->SetBufferSize(m_mtu + 22);  
264
  m_fdReader->SetBufferSize (m_mtu + 22);
253
  m_fdReader->Start (m_fd, MakeCallback (&FdNetDevice::ReceiveCallback, this));
265
  m_fdReader->Start (m_fd, MakeCallback (&FdNetDevice::ReceiveCallback, this));
254
266
255
  NotifyLinkUp ();
267
  NotifyLinkUp ();
 Lines 281-306    Link Here 
281
293
282
  {
294
  {
283
    CriticalSection cs (m_pendingReadMutex);
295
    CriticalSection cs (m_pendingReadMutex);
284
    if (m_pendingReadCount >= m_maxPendingReads)
296
    if (m_pendingQueue.size () >= m_maxPendingReads)
285
      {
297
      {
286
        NS_LOG_WARN ("Packet dropped");
298
        NS_LOG_WARN ("Packet dropped");
287
        skip = true;
299
        skip = true;
288
      }
300
      }
289
    else
301
    else
290
      {
302
      {
291
        ++m_pendingReadCount;
303
        m_pendingQueue.push (std::make_pair (buf, len));
292
      }
304
      }
293
  }
305
  }
294
306
295
  if (skip)
307
  if (skip)
296
    {
308
    {
297
      struct timespec time = { 0, 100000000L }; // 100 ms
309
      struct timespec time = {
310
        0, 100000000L
311
      };                                        // 100 ms
298
      nanosleep (&time, NULL);
312
      nanosleep (&time, NULL);
299
    }
313
    }
300
  else
314
  else
301
    {
315
    {
302
      Simulator::ScheduleWithContext (m_nodeId, Time (0), MakeEvent (&FdNetDevice::ForwardUp, this, buf, len));
316
      Simulator::ScheduleWithContext (m_nodeId, Time (0), MakeEvent (&FdNetDevice::ForwardUp, this));
303
   }
317
    }
304
}
318
}
305
319
306
/**
320
/**
 Lines 368-385    Link Here 
368
}
382
}
369
383
370
void
384
void
371
FdNetDevice::ForwardUp (uint8_t *buf, ssize_t len)
385
FdNetDevice::ForwardUp (void)
372
{
386
{
387
388
  uint8_t *buf = 0; 
389
  ssize_t len = 0;
390
391
  {
392
    CriticalSection cs (m_pendingReadMutex);
393
    std::pair<uint8_t *, ssize_t> next = m_pendingQueue.front ();
394
    m_pendingQueue.pop ();
395
396
    buf = next.first;
397
    len = next.second;
398
  }
399
373
  NS_LOG_FUNCTION (this << buf << len);
400
  NS_LOG_FUNCTION (this << buf << len);
374
401
375
  if (m_pendingReadCount > 0)
376
    {
377
      {
378
        CriticalSection cs (m_pendingReadMutex);
379
        --m_pendingReadCount;
380
      }
381
    }
382
383
  // We need to remove the PI header and ignore it
402
  // We need to remove the PI header and ignore it
384
  if (m_encapMode == DIXPI)
403
  if (m_encapMode == DIXPI)
385
    {
404
    {
(-)a/src/fd-net-device/model/fd-net-device.h (-7 / +7 lines)
 Lines 36-42    Link Here 
36
#include "ns3/unix-fd-reader.h"
36
#include "ns3/unix-fd-reader.h"
37
#include "ns3/system-mutex.h"
37
#include "ns3/system-mutex.h"
38
38
39
#include <string.h>
39
#include <utility>
40
#include <queue>
40
41
41
namespace ns3 {
42
namespace ns3 {
42
43
 Lines 63-69    Link Here 
63
64
64
private:
65
private:
65
  FdReader::Data DoRead (void);
66
  FdReader::Data DoRead (void);
66
  
67
67
  uint32_t m_bufferSize; //!< size of the read buffer
68
  uint32_t m_bufferSize; //!< size of the read buffer
68
};
69
};
69
70
 Lines 216-222    Link Here 
216
  /**
217
  /**
217
   * Forward the frame to the appropriate callback for processing
218
   * Forward the frame to the appropriate callback for processing
218
   */
219
   */
219
  void ForwardUp (uint8_t *buf, ssize_t len);
220
  void ForwardUp (void);
220
221
221
  /**
222
  /**
222
   * Start Sending a Packet Down the Wire.
223
   * Start Sending a Packet Down the Wire.
 Lines 298-311    Link Here 
298
  /**
299
  /**
299
   * Number of packets that were received and scheduled for read but not yeat read.
300
   * Number of packets that were received and scheduled for read but not yeat read.
300
   */
301
   */
301
  uint32_t m_pendingReadCount;
302
  std::queue< std::pair<uint8_t *, ssize_t> > m_pendingQueue;
302
  
303
303
  /**
304
  /**
304
   * Maximum number of packets that can be received and scheduled for read but not yeat read.
305
   * Maximum number of packets that can be received and scheduled for read but not yeat read.
305
   */
306
   */
306
  uint32_t m_maxPendingReads;
307
  uint32_t m_maxPendingReads;
307
  
308
308
   
309
  /**
309
  /**
310
   * Mutex to increase pending read counter.
310
   * Mutex to increase pending read counter.
311
   */
311
   */

Return to bug 2119