21 #include "ns3/assert.h"
23 #include "ns3/nstime.h"
24 #include "ns3/boolean.h"
25 #include "ns3/object-vector.h"
27 #include "ns3/packet.h"
29 #include "ns3/simulator.h"
30 #include "ns3/ipv4-route.h"
31 #include "ns3/ipv6-route.h"
58 #undef NS_LOG_APPEND_CONTEXT
59 #define NS_LOG_APPEND_CONTEXT \
60 if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
70 .AddConstructor<TcpL4Protocol> ()
71 .AddAttribute (
"RttEstimatorType",
72 "Type of RttEstimator objects.",
76 .AddAttribute (
"SocketType",
77 "Socket type of TCP objects.",
81 .AddAttribute (
"SocketList",
"The list of sockets associated to this protocol.",
84 MakeObjectVectorChecker<TcpSocketBase> ())
115 Ptr<Node> node = this->GetObject<Node> ();
116 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> ();
121 if ((node != 0) && (ipv4 != 0 || ipv6 != 0))
125 tcpFactory->SetTcp (
this);
189 socket->SetTcp (
this);
190 socket->SetRtt (rtt);
233 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
235 peerAddress, peerPort);
277 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
279 peerAddress, peerPort);
291 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
293 const uint8_t payload[8])
295 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
296 << payloadSource << payloadDestination);
298 src = payload[0] << 8;
300 dst = payload[2] << 8;
306 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
310 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
311 ", destination="<<payloadDestination<<
312 ", src=" << src <<
", dst=" << dst);
318 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
320 const uint8_t payload[8])
322 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
323 << payloadSource << payloadDestination);
325 src = payload[0] << 8;
327 dst = payload[2] << 8;
333 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
337 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
338 ", destination="<<payloadDestination<<
339 ", src=" << src <<
", dst=" << dst);
362 <<
" flags "<< std::hex << (int)tcpHeader.
GetFlags () << std::dec
363 <<
" data size " << packet->
GetSize ());
371 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" received a packet");
375 if (endPoints.empty ())
377 if (this->GetObject<Ipv6L3Protocol> () != 0)
379 NS_LOG_LOGIC (
" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 "<<
this);
386 return (this->
Receive (packet, ipv6Header, fakeInterface));
389 NS_LOG_LOGIC (
" No endpoints matched on TcpL4Protocol "<<
this);
390 std::ostringstream oss;
391 oss<<
" destination IP: ";
407 header.SetSequenceNumber (header.GetAckNumber ());
425 NS_ASSERT_MSG (endPoints.size () == 1,
"Demux returned more than one endpoint");
426 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" forwarding up to endpoint/socket");
427 (*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.
GetSourcePort (),
454 <<
" receiving seq " << tcpHeader.GetSequenceNumber ()
455 <<
" ack " << tcpHeader.GetAckNumber ()
456 <<
" flags "<< std::hex << (int)tcpHeader.GetFlags () << std::dec
457 <<
" data size " << packet->
GetSize ());
459 if(!tcpHeader.IsChecksumOk ())
465 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" received a packet");
469 if (endPoints.empty ())
471 NS_LOG_LOGIC (
" No IPv6 endpoints matched on TcpL4Protocol "<<
this);
472 std::ostringstream oss;
473 oss<<
" destination IP: ";
475 oss<<
" destination port: "<< tcpHeader.GetDestinationPort ()<<
" source IP: ";
477 oss<<
" source port: "<<tcpHeader.GetSourcePort ();
489 header.SetSequenceNumber (header.GetAckNumber ());
497 header.SetSourcePort (tcpHeader.GetDestinationPort ());
498 header.SetDestinationPort (tcpHeader.GetSourcePort ());
507 NS_ASSERT_MSG (endPoints.size () == 1,
"Demux returned more than one endpoint");
508 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" forwarding up to endpoint/socket");
509 (*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.GetSourcePort ());
518 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << oif);
562 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << oif);
588 if (ipv6->GetRoutingProtocol () != 0)
590 route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
597 ipv6->Send (packet, saddr, daddr,
PROT_NUMBER, route);
608 <<
" flags " << std::hex << (int)outgoing.
GetFlags () << std::dec
609 <<
" data size " << packet->
GetSize ());
646 NS_FATAL_ERROR (
"Trying to use Tcp on a node without an Ipv4 interface");
656 <<
" flags " << std::hex << (int)outgoing.
GetFlags () << std::dec
657 <<
" data size " << packet->
GetSize ());
686 if (ipv6->GetRoutingProtocol () != 0)
688 route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
698 NS_FATAL_ERROR (
"Trying to use Tcp on a node without an Ipv6 interface");