326 .AddAttribute ("RttEstimatorFactory", |
327 .AddAttribute ("RttEstimatorFactory", |
327 "How RttEstimator objects are created.", |
328 "How RttEstimator objects are created.", |
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 } |
334 |
340 |
335 TcpL4Protocol::TcpL4Protocol () |
341 TcpL4Protocol::TcpL4Protocol () |
437 Ptr<Ipv4Interface> incomingInterface) |
443 Ptr<Ipv4Interface> incomingInterface) |
438 { |
444 { |
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 (), |
453 source, tcpHeader.GetSourcePort (),incomingInterface); |
476 source, tcpHeader.GetSourcePort (),incomingInterface); |
454 if (endPoints.empty ()) |
477 if (endPoints.empty ()) |
476 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport); |
499 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport); |
477 |
500 |
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); |
484 tcpHeader.SetFlags (TcpHeader::ACK); |
512 tcpHeader.SetFlags (TcpHeader::ACK); |
485 tcpHeader.SetAckNumber (0); |
513 tcpHeader.SetAckNumber (0); |
505 << " data size " << packet->GetSize()); |
533 << " data size " << packet->GetSize()); |
506 NS_LOG_FUNCTION (this << packet << saddr << daddr); |
534 NS_LOG_FUNCTION (this << packet << saddr << daddr); |
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 |
515 Ptr<Ipv4L3Protocol> ipv4 = |
548 Ptr<Ipv4L3Protocol> ipv4 = |
516 m_node->GetObject<Ipv4L3Protocol> (); |
549 m_node->GetObject<Ipv4L3Protocol> (); |