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);
232 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
234 peerAddress, peerPort);
276 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
278 peerAddress, peerPort);
290 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
292 const uint8_t payload[8])
294 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
295 << payloadSource << payloadDestination);
297 src = payload[0] << 8;
299 dst = payload[2] << 8;
305 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
309 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
310 ", destination="<<payloadDestination<<
311 ", src=" << src <<
", dst=" << dst);
317 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
319 const uint8_t payload[8])
321 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
322 << payloadSource << payloadDestination);
324 src = payload[0] << 8;
326 dst = payload[2] << 8;
332 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
336 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
337 ", destination="<<payloadDestination<<
338 ", src=" << src <<
", dst=" << dst);
361 <<
" flags "<< std::hex << (int)tcpHeader.
GetFlags () << std::dec
362 <<
" data size " << packet->
GetSize ());
370 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" received a packet");
374 if (endPoints.empty ())
376 if (this->GetObject<Ipv6L3Protocol> () != 0)
378 NS_LOG_LOGIC (
" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 "<<
this);
385 return (this->
Receive (packet, ipv6Header, fakeInterface));
388 NS_LOG_LOGIC (
" No endpoints matched on TcpL4Protocol "<<
this);
389 std::ostringstream oss;
390 oss<<
" destination IP: ";
406 header.SetSequenceNumber (header.GetAckNumber ());
424 NS_ASSERT_MSG (endPoints.size () == 1,
"Demux returned more than one endpoint");
425 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" forwarding up to endpoint/socket");
426 (*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.
GetSourcePort (),
453 <<
" receiving seq " << tcpHeader.GetSequenceNumber ()
454 <<
" ack " << tcpHeader.GetAckNumber ()
455 <<
" flags "<< std::hex << (int)tcpHeader.GetFlags () << std::dec
456 <<
" data size " << packet->
GetSize ());
458 if(!tcpHeader.IsChecksumOk ())
464 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" received a packet");
468 if (endPoints.empty ())
470 NS_LOG_LOGIC (
" No IPv6 endpoints matched on TcpL4Protocol "<<
this);
471 std::ostringstream oss;
472 oss<<
" destination IP: ";
474 oss<<
" destination port: "<< tcpHeader.GetDestinationPort ()<<
" source IP: ";
476 oss<<
" source port: "<<tcpHeader.GetSourcePort ();
488 header.SetSequenceNumber (header.GetAckNumber ());
496 header.SetSourcePort (tcpHeader.GetDestinationPort ());
497 header.SetDestinationPort (tcpHeader.GetSourcePort ());
506 NS_ASSERT_MSG (endPoints.size () == 1,
"Demux returned more than one endpoint");
507 NS_LOG_LOGIC (
"TcpL4Protocol "<<
this<<
" forwarding up to endpoint/socket");
508 (*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.GetSourcePort ());
517 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << oif);
561 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << oif);
587 if (ipv6->GetRoutingProtocol () != 0)
589 route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
596 ipv6->Send (packet, saddr, daddr,
PROT_NUMBER, route);
607 <<
" flags " << std::hex << (int)outgoing.
GetFlags () << std::dec
608 <<
" data size " << packet->
GetSize ());
644 NS_FATAL_ERROR (
"Trying to use Tcp on a node without an Ipv4 interface");
654 <<
" flags " << std::hex << (int)outgoing.
GetFlags () << std::dec
655 <<
" data size " << packet->
GetSize ());
683 if (ipv6->GetRoutingProtocol () != 0)
685 route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
695 NS_FATAL_ERROR (
"Trying to use Tcp on a node without an Ipv6 interface");