LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2007 Georgia Tech Research Corporation | 3 * Copyright (c) 2007 Georgia Tech Research Corporation |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 471 |
472 void· | 472 void· |
473 TcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) | 473 TcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) |
474 { | 474 { |
475 NS_LOG_FUNCTION (this << endPoint); | 475 NS_LOG_FUNCTION (this << endPoint); |
476 m_endPoints->DeAllocate (endPoint); | 476 m_endPoints->DeAllocate (endPoint); |
477 } | 477 } |
478 | 478 |
479 enum Ipv4L4Protocol::RxStatus | 479 enum Ipv4L4Protocol::RxStatus |
480 TcpL4Protocol::Receive (Ptr<Packet> packet, | 480 TcpL4Protocol::Receive (Ptr<Packet> packet, |
481 Ipv4Address const &source, | 481 Ipv4Header const &ipHeader, |
482 Ipv4Address const &destination, | |
483 Ptr<Ipv4Interface> incomingInterface) | 482 Ptr<Ipv4Interface> incomingInterface) |
484 { | 483 { |
485 NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface)
; | 484 NS_LOG_FUNCTION (this << packet << ipHeader << incomingInterface); |
486 | 485 |
487 TcpHeader tcpHeader; | 486 TcpHeader tcpHeader; |
488 if(Node::ChecksumEnabled ()) | 487 if(Node::ChecksumEnabled ()) |
489 { | 488 { |
490 tcpHeader.EnableChecksums(); | 489 tcpHeader.EnableChecksums(); |
491 tcpHeader.InitializeChecksum (source, destination, PROT_NUMBER); | 490 tcpHeader.InitializeChecksum (ipHeader.GetSource (), ipHeader.GetDestination
(), PROT_NUMBER); |
492 } | 491 } |
493 | 492 |
494 packet->PeekHeader (tcpHeader); | 493 packet->PeekHeader (tcpHeader); |
495 | 494 |
496 NS_LOG_LOGIC("TcpL4Protocol " << this | 495 NS_LOG_LOGIC("TcpL4Protocol " << this |
497 << " receiving seq " << tcpHeader.GetSequenceNumber() | 496 << " receiving seq " << tcpHeader.GetSequenceNumber() |
498 << " ack " << tcpHeader.GetAckNumber() | 497 << " ack " << tcpHeader.GetAckNumber() |
499 << " flags "<< std::hex << (int)tcpHeader.GetFlags() << std::dec | 498 << " flags "<< std::hex << (int)tcpHeader.GetFlags() << std::dec |
500 << " data size " << packet->GetSize()); | 499 << " data size " << packet->GetSize()); |
501 | 500 |
502 if(!tcpHeader.IsChecksumOk ()) | 501 if(!tcpHeader.IsChecksumOk ()) |
503 { | 502 { |
504 NS_LOG_INFO("Bad checksum, dropping packet!"); | 503 NS_LOG_INFO("Bad checksum, dropping packet!"); |
505 return Ipv4L4Protocol::RX_CSUM_FAILED; | 504 return Ipv4L4Protocol::RX_CSUM_FAILED; |
506 } | 505 } |
507 | 506 |
508 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); | 507 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
509 Ipv4EndPointDemux::EndPoints endPoints = | 508 Ipv4EndPointDemux::EndPoints endPoints = |
510 m_endPoints->Lookup (destination, tcpHeader.GetDestinationPort (), | 509 m_endPoints->Lookup (ipHeader.GetDestination (), tcpHeader.GetDestinationPor
t (), |
511 source, tcpHeader.GetSourcePort (),incomingInterface); | 510 ipHeader.GetSource (), tcpHeader.GetSourcePort (),incom
ingInterface); |
512 if (endPoints.empty ()) | 511 if (endPoints.empty ()) |
513 { | 512 { |
514 NS_LOG_LOGIC (" No endpoints matched on TcpL4Protocol "<<this); | 513 NS_LOG_LOGIC (" No endpoints matched on TcpL4Protocol "<<this); |
515 std::ostringstream oss; | 514 std::ostringstream oss; |
516 oss<<" destination IP: "; | 515 oss<<" destination IP: "; |
517 destination.Print (oss); | 516 ipHeader.GetDestination ().Print (oss); |
518 oss<<" destination port: "<< tcpHeader.GetDestinationPort ()<<" source IP: "
; | 517 oss<<" destination port: "<< tcpHeader.GetDestinationPort ()<<" source IP: "
; |
519 source.Print (oss); | 518 ipHeader.GetSource ().Print (oss); |
520 oss<<" source port: "<<tcpHeader.GetSourcePort (); | 519 oss<<" source port: "<<tcpHeader.GetSourcePort (); |
521 NS_LOG_LOGIC (oss.str ()); | 520 NS_LOG_LOGIC (oss.str ()); |
522 | 521 |
523 if (!(tcpHeader.GetFlags () & TcpHeader::RST)) | 522 if (!(tcpHeader.GetFlags () & TcpHeader::RST)) |
524 { | 523 { |
525 // build a RST packet and send | 524 // build a RST packet and send |
526 Ptr<Packet> rstPacket = Create<Packet> (); | 525 Ptr<Packet> rstPacket = Create<Packet> (); |
527 TcpHeader header; | 526 TcpHeader header; |
528 if (tcpHeader.GetFlags () & TcpHeader::ACK) | 527 if (tcpHeader.GetFlags () & TcpHeader::ACK) |
529 { | 528 { |
530 // ACK bit was set | 529 // ACK bit was set |
531 header.SetFlags (TcpHeader::RST); | 530 header.SetFlags (TcpHeader::RST); |
532 header.SetSequenceNumber (header.GetAckNumber ()); | 531 header.SetSequenceNumber (header.GetAckNumber ()); |
533 } | 532 } |
534 else | 533 else |
535 { | 534 { |
536 header.SetFlags (TcpHeader::RST | TcpHeader::ACK); | 535 header.SetFlags (TcpHeader::RST | TcpHeader::ACK); |
537 header.SetSequenceNumber (SequenceNumber (0)); | 536 header.SetSequenceNumber (SequenceNumber (0)); |
538 header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber (1
)); | 537 header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber (1
)); |
539 } | 538 } |
540 header.SetSourcePort (tcpHeader.GetDestinationPort ()); | 539 header.SetSourcePort (tcpHeader.GetDestinationPort ()); |
541 header.SetDestinationPort (tcpHeader.GetSourcePort ()); | 540 header.SetDestinationPort (tcpHeader.GetSourcePort ()); |
542 SendPacket (rstPacket, header, destination, source); | 541 SendPacket (rstPacket, header, ipHeader.GetDestination (), ipHeader.GetS
ource ()); |
543 return Ipv4L4Protocol::RX_ENDPOINT_CLOSED; | 542 return Ipv4L4Protocol::RX_ENDPOINT_CLOSED; |
544 } | 543 } |
545 else | 544 else |
546 { | 545 { |
547 return Ipv4L4Protocol::RX_ENDPOINT_CLOSED; | 546 return Ipv4L4Protocol::RX_ENDPOINT_CLOSED; |
548 } | 547 } |
549 } | 548 } |
550 NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint"
); | 549 NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint"
); |
551 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); | 550 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
552 (*endPoints.begin ())->ForwardUp (packet, source, destination, tcpHeader.GetSo
urcePort (),· | 551 (*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.GetSourcePort ()
,· |
553 incomingInterface->GetDevice ()); | 552 incomingInterface); |
554 return Ipv4L4Protocol::RX_OK; | 553 return Ipv4L4Protocol::RX_OK; |
555 } | 554 } |
556 | 555 |
557 void | 556 void |
558 TcpL4Protocol::Send (Ptr<Packet> packet,· | 557 TcpL4Protocol::Send (Ptr<Packet> packet,· |
559 Ipv4Address saddr, Ipv4Address daddr,· | 558 Ipv4Address saddr, Ipv4Address daddr,· |
560 uint16_t sport, uint16_t dport, Ptr<NetDevice> oif) | 559 uint16_t sport, uint16_t dport, Ptr<NetDevice> oif) |
561 { | 560 { |
562 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport << oif); | 561 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport << oif); |
563 | 562 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 route = 0; | 644 route = 0; |
646 } | 645 } |
647 ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route); | 646 ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route); |
648 } | 647 } |
649 else | 648 else |
650 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv4 interface"); | 649 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv4 interface"); |
651 } | 650 } |
652 | 651 |
653 }; // namespace ns3 | 652 }; // namespace ns3 |
654 | 653 |
LEFT | RIGHT |