|
|
| 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 |
{ |
|
|
| 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 |
|
|
| 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 (); |
|
|
| 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 |
/** |
|
|
| 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 |
{ |