|
|
| 21 |
#include "ns3/assert.h" |
21 |
#include "ns3/assert.h" |
| 22 |
#include "ns3/log.h" |
22 |
#include "ns3/log.h" |
| 23 |
#include "ns3/nstime.h" |
23 |
#include "ns3/nstime.h" |
|
|
24 |
#include "ns3/boolean.h" |
| 24 |
|
25 |
|
| 25 |
#include "ns3/packet.h" |
26 |
#include "ns3/packet.h" |
| 26 |
#include "ns3/node.h" |
27 |
#include "ns3/node.h" |
|
Lines 328-333
TcpL4Protocol::GetTypeId (void)
|
Link Here
|
|---|
|
| 328 |
ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), |
329 |
ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), |
| 329 |
MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), |
330 |
MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), |
| 330 |
MakeObjectFactoryChecker ()) |
331 |
MakeObjectFactoryChecker ()) |
|
|
332 |
.AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets" |
| 333 |
" and verify the checksum of incoming packets.", |
| 334 |
BooleanValue (false), |
| 335 |
MakeBooleanAccessor (&TcpL4Protocol::m_calcChecksum), |
| 336 |
MakeBooleanChecker ()) |
| 331 |
; |
337 |
; |
| 332 |
return tid; |
338 |
return tid; |
| 333 |
} |
339 |
} |
|
Lines 439-452
TcpL4Protocol::Receive (Ptr<Packet> pack
|
Link Here
|
|---|
|
| 439 |
NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface); |
445 |
NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface); |
| 440 |
|
446 |
|
| 441 |
TcpHeader tcpHeader; |
447 |
TcpHeader tcpHeader; |
|
|
448 |
if(m_calcChecksum) |
| 449 |
{ |
| 450 |
tcpHeader.EnableChecksums(); |
| 451 |
} |
| 452 |
/* XXX very dirty but needs this to AddHeader again because of checksum */ |
| 453 |
tcpHeader.SetLength(5); /* XXX TCP without options */ |
| 454 |
tcpHeader.SetPayloadSize(packet->GetSize() - tcpHeader.GetSerializedSize()); |
| 455 |
tcpHeader.InitializeChecksum(source, destination, PROT_NUMBER); |
| 456 |
|
| 442 |
//these two do a peek, so that the packet can be forwarded up |
457 |
//these two do a peek, so that the packet can be forwarded up |
| 443 |
packet->RemoveHeader (tcpHeader); |
458 |
packet->RemoveHeader (tcpHeader); |
|
|
459 |
|
| 444 |
NS_LOG_LOGIC("TcpL4Protocol " << this |
460 |
NS_LOG_LOGIC("TcpL4Protocol " << this |
| 445 |
<< " receiving seq " << tcpHeader.GetSequenceNumber() |
461 |
<< " receiving seq " << tcpHeader.GetSequenceNumber() |
| 446 |
<< " ack " << tcpHeader.GetAckNumber() |
462 |
<< " ack " << tcpHeader.GetAckNumber() |
| 447 |
<< " flags "<< std::hex << (int)tcpHeader.GetFlags() << std::dec |
463 |
<< " flags "<< std::hex << (int)tcpHeader.GetFlags() << std::dec |
| 448 |
<< " data size " << packet->GetSize()); |
464 |
<< " data size " << packet->GetSize()); |
| 449 |
packet->AddHeader (tcpHeader); |
465 |
|
|
|
466 |
if(!tcpHeader.IsChecksumOk ()) |
| 467 |
{ |
| 468 |
NS_LOG_INFO("Bad checksum, dropping packet!"); |
| 469 |
return; |
| 470 |
} |
| 471 |
|
| 472 |
packet->AddHeader (tcpHeader); |
| 450 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
473 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
| 451 |
Ipv4EndPointDemux::EndPoints endPoints = |
474 |
Ipv4EndPointDemux::EndPoints endPoints = |
| 452 |
m_endPoints->Lookup (destination, tcpHeader.GetDestinationPort (), |
475 |
m_endPoints->Lookup (destination, tcpHeader.GetDestinationPort (), |
|
Lines 478-483
TcpL4Protocol::Send (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 478 |
TcpHeader tcpHeader; |
501 |
TcpHeader tcpHeader; |
| 479 |
tcpHeader.SetDestinationPort (dport); |
502 |
tcpHeader.SetDestinationPort (dport); |
| 480 |
tcpHeader.SetSourcePort (sport); |
503 |
tcpHeader.SetSourcePort (sport); |
|
|
504 |
tcpHeader.SetPayloadSize(packet->GetSize()); |
| 505 |
if(m_calcChecksum) |
| 506 |
{ |
| 507 |
tcpHeader.EnableChecksums(); |
| 508 |
} |
| 481 |
tcpHeader.InitializeChecksum (saddr, |
509 |
tcpHeader.InitializeChecksum (saddr, |
| 482 |
daddr, |
510 |
daddr, |
| 483 |
PROT_NUMBER); |
511 |
PROT_NUMBER); |
|
Lines 507-514
TcpL4Protocol::SendPacket (Ptr<Packet> p
|
Link Here
|
|---|
|
| 507 |
// XXX outgoingHeader cannot be logged |
535 |
// XXX outgoingHeader cannot be logged |
| 508 |
|
536 |
|
| 509 |
outgoingHeader.SetLength (5); //header length in units of 32bit words |
537 |
outgoingHeader.SetLength (5); //header length in units of 32bit words |
| 510 |
outgoingHeader.SetChecksum (0); //XXX |
538 |
outgoingHeader.SetPayloadSize(packet->GetSize()); |
| 511 |
outgoingHeader.SetUrgentPointer (0); //XXX |
539 |
/* outgoingHeader.SetUrgentPointer (0); //XXX */ |
|
|
540 |
if(m_calcChecksum) |
| 541 |
{ |
| 542 |
outgoingHeader.EnableChecksums(); |
| 543 |
} |
| 544 |
outgoingHeader.InitializeChecksum(saddr, daddr, PROT_NUMBER); |
| 512 |
|
545 |
|
| 513 |
packet->AddHeader (outgoingHeader); |
546 |
packet->AddHeader (outgoingHeader); |
| 514 |
|
547 |
|