A Discrete-Event Network Simulator
API
tcp-l4-protocol.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 Georgia Tech Research Corporation
4  *
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
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Raj Bhattacharjea <raj.b@gatech.edu>
19  */
20 
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/nstime.h"
24 #include "ns3/boolean.h"
25 #include "ns3/object-vector.h"
26 
27 #include "ns3/packet.h"
28 #include "ns3/node.h"
29 #include "ns3/simulator.h"
30 #include "ns3/ipv4-route.h"
31 #include "ns3/ipv6-route.h"
32 
33 #include "tcp-l4-protocol.h"
34 #include "tcp-header.h"
35 #include "ipv4-end-point-demux.h"
36 #include "ipv6-end-point-demux.h"
37 #include "ipv4-end-point.h"
38 #include "ipv6-end-point.h"
39 #include "ipv4-l3-protocol.h"
40 #include "ipv6-l3-protocol.h"
41 #include "ipv6-routing-protocol.h"
43 #include "tcp-socket-base.h"
44 #include "rtt-estimator.h"
45 
46 #include <vector>
47 #include <sstream>
48 #include <iomanip>
49 
50 namespace ns3 {
51 
52 NS_LOG_COMPONENT_DEFINE ("TcpL4Protocol");
53 
54 NS_OBJECT_ENSURE_REGISTERED (TcpL4Protocol);
55 
56 //TcpL4Protocol stuff----------------------------------------------------------
57 
58 #undef NS_LOG_APPEND_CONTEXT
59 #define NS_LOG_APPEND_CONTEXT \
60  if (m_node) { std::clog << " [node " << m_node->GetId () << "] "; }
61 
62 /* see http://www.iana.org/assignments/protocol-numbers */
63 const uint8_t TcpL4Protocol::PROT_NUMBER = 6;
64 
65 TypeId
67 {
68  static TypeId tid = TypeId ("ns3::TcpL4Protocol")
70  .SetGroupName ("Internet")
71  .AddConstructor<TcpL4Protocol> ()
72  .AddAttribute ("RttEstimatorType",
73  "Type of RttEstimator objects.",
77  .AddAttribute ("SocketType",
78  "Socket type of TCP objects.",
82  .AddAttribute ("SocketList", "The list of sockets associated to this protocol.",
85  MakeObjectVectorChecker<TcpSocketBase> ())
86  ;
87  return tid;
88 }
89 
91  : m_endPoints (new Ipv4EndPointDemux ()), m_endPoints6 (new Ipv6EndPointDemux ())
92 {
94  NS_LOG_LOGIC ("Made a TcpL4Protocol " << this);
95 }
96 
98 {
99  NS_LOG_FUNCTION (this);
100 }
101 
102 void
104 {
105  NS_LOG_FUNCTION (this);
106  m_node = node;
107 }
108 
109 void
111 {
112  NS_LOG_FUNCTION (this);
113  Ptr<Node> node = this->GetObject<Node> ();
114  Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> ();
115  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
116 
117  if (m_node == 0)
118  {
119  if ((node != 0) && (ipv4 != 0 || ipv6 != 0))
120  {
121  this->SetNode (node);
122  Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
123  tcpFactory->SetTcp (this);
124  node->AggregateObject (tcpFactory);
125  }
126  }
127 
128  // We set at least one of our 2 down targets to the IPv4/IPv6 send
129  // functions. Since these functions have different prototypes, we
130  // need to keep track of whether we are connected to an IPv4 or
131  // IPv6 lower layer and call the appropriate one.
132 
133  if (ipv4 != 0 && m_downTarget.IsNull ())
134  {
135  ipv4->Insert (this);
136  this->SetDownTarget (MakeCallback (&Ipv4::Send, ipv4));
137  }
138  if (ipv6 != 0 && m_downTarget6.IsNull ())
139  {
140  ipv6->Insert (this);
141  this->SetDownTarget6 (MakeCallback (&Ipv6::Send, ipv6));
142  }
144 }
145 
146 int
148 {
149  return PROT_NUMBER;
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION (this);
156  m_sockets.clear ();
157 
158  if (m_endPoints != 0)
159  {
160  delete m_endPoints;
161  m_endPoints = 0;
162  }
163 
164  if (m_endPoints6 != 0)
165  {
166  delete m_endPoints6;
167  m_endPoints6 = 0;
168  }
169 
170  m_node = 0;
174 }
175 
178 {
179  NS_LOG_FUNCTION (this << congestionTypeId.GetName ());
180  ObjectFactory rttFactory;
181  ObjectFactory congestionAlgorithmFactory;
182  rttFactory.SetTypeId (m_rttTypeId);
183  congestionAlgorithmFactory.SetTypeId (congestionTypeId);
184 
185  Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator> ();
186  Ptr<TcpSocketBase> socket = CreateObject<TcpSocketBase> ();
187  Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps> ();
188 
189  socket->SetNode (m_node);
190  socket->SetTcp (this);
191  socket->SetRtt (rtt);
192  socket->SetCongestionControlAlgorithm (algo);
193 
194  m_sockets.push_back (socket);
195  return socket;
196 }
197 
200 {
202 }
203 
204 Ipv4EndPoint *
206 {
208  return m_endPoints->Allocate ();
209 }
210 
211 Ipv4EndPoint *
213 {
214  NS_LOG_FUNCTION (this << address);
215  return m_endPoints->Allocate (address);
216 }
217 
218 Ipv4EndPoint *
220 {
221  NS_LOG_FUNCTION (this << port);
222  return m_endPoints->Allocate (port);
223 }
224 
225 Ipv4EndPoint *
227 {
228  NS_LOG_FUNCTION (this << address << port);
229  return m_endPoints->Allocate (address, port);
230 }
231 
232 Ipv4EndPoint *
233 TcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
234  Ipv4Address peerAddress, uint16_t peerPort)
235 {
236  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
237  return m_endPoints->Allocate (localAddress, localPort,
238  peerAddress, peerPort);
239 }
240 
241 void
243 {
244  NS_LOG_FUNCTION (this << endPoint);
245  m_endPoints->DeAllocate (endPoint);
246 }
247 
248 Ipv6EndPoint *
250 {
252  return m_endPoints6->Allocate ();
253 }
254 
255 Ipv6EndPoint *
257 {
258  NS_LOG_FUNCTION (this << address);
259  return m_endPoints6->Allocate (address);
260 }
261 
262 Ipv6EndPoint *
264 {
265  NS_LOG_FUNCTION (this << port);
266  return m_endPoints6->Allocate (port);
267 }
268 
269 Ipv6EndPoint *
271 {
272  NS_LOG_FUNCTION (this << address << port);
273  return m_endPoints6->Allocate (address, port);
274 }
275 
276 Ipv6EndPoint *
277 TcpL4Protocol::Allocate6 (Ipv6Address localAddress, uint16_t localPort,
278  Ipv6Address peerAddress, uint16_t peerPort)
279 {
280  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
281  return m_endPoints6->Allocate (localAddress, localPort,
282  peerAddress, peerPort);
283 }
284 
285 void
287 {
288  NS_LOG_FUNCTION (this << endPoint);
289  m_endPoints6->DeAllocate (endPoint);
290 }
291 
292 void
293 TcpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
294  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
295  Ipv4Address payloadSource,Ipv4Address payloadDestination,
296  const uint8_t payload[8])
297 {
298  NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
299  << payloadSource << payloadDestination);
300  uint16_t src, dst;
301  src = payload[0] << 8;
302  src |= payload[1];
303  dst = payload[2] << 8;
304  dst |= payload[3];
305 
306  Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloadDestination, dst);
307  if (endPoint != 0)
308  {
309  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
310  }
311  else
312  {
313  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
314  ", destination=" << payloadDestination <<
315  ", src=" << src << ", dst=" << dst);
316  }
317 }
318 
319 void
320 TcpL4Protocol::ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
321  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
322  Ipv6Address payloadSource,Ipv6Address payloadDestination,
323  const uint8_t payload[8])
324 {
325  NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
326  << payloadSource << payloadDestination);
327  uint16_t src, dst;
328  src = payload[0] << 8;
329  src |= payload[1];
330  dst = payload[2] << 8;
331  dst |= payload[3];
332 
333  Ipv6EndPoint *endPoint = m_endPoints6->SimpleLookup (payloadSource, src, payloadDestination, dst);
334  if (endPoint != 0)
335  {
336  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
337  }
338  else
339  {
340  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
341  ", destination=" << payloadDestination <<
342  ", src=" << src << ", dst=" << dst);
343  }
344 }
345 
348  const Address &source, const Address &destination)
349 {
350  NS_LOG_FUNCTION (this << packet << incomingTcpHeader << source << destination);
351 
352  if (Node::ChecksumEnabled ())
353  {
354  incomingTcpHeader.EnableChecksums ();
355  incomingTcpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
356  }
357 
358  packet->PeekHeader (incomingTcpHeader);
359 
360  NS_LOG_LOGIC ("TcpL4Protocol " << this
361  << " receiving seq " << incomingTcpHeader.GetSequenceNumber ()
362  << " ack " << incomingTcpHeader.GetAckNumber ()
363  << " flags "<< TcpHeader::FlagsToString (incomingTcpHeader.GetFlags ())
364  << " data size " << packet->GetSize ());
365 
366  if (!incomingTcpHeader.IsChecksumOk ())
367  {
368  NS_LOG_INFO ("Bad checksum, dropping packet!");
370  }
371 
372  return IpL4Protocol::RX_OK;
373 }
374 
375 void
377  const Address &incomingSAddr,
378  const Address &incomingDAddr)
379 {
380  NS_LOG_FUNCTION (this << incomingHeader << incomingSAddr << incomingDAddr);
381 
382  if (!(incomingHeader.GetFlags () & TcpHeader::RST))
383  {
384  // build a RST packet and send
385  Ptr<Packet> rstPacket = Create<Packet> ();
386  TcpHeader outgoingTcpHeader;
387 
388  if (incomingHeader.GetFlags () & TcpHeader::ACK)
389  {
390  // ACK bit was set
391  outgoingTcpHeader.SetFlags (TcpHeader::RST);
392  outgoingTcpHeader.SetSequenceNumber (incomingHeader.GetAckNumber ());
393  }
394  else
395  {
396  outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK);
397  outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0));
398  outgoingTcpHeader.SetAckNumber (incomingHeader.GetSequenceNumber () +
399  SequenceNumber32 (1));
400  }
401 
402  // Remember that parameters refer to the incoming packet; in reply,
403  // we need to swap src/dst
404 
405  outgoingTcpHeader.SetSourcePort (incomingHeader.GetDestinationPort ());
406  outgoingTcpHeader.SetDestinationPort (incomingHeader.GetSourcePort ());
407 
408  SendPacket (rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
409  }
410 }
411 
414  Ipv4Header const &incomingIpHeader,
415  Ptr<Ipv4Interface> incomingInterface)
416 {
417  NS_LOG_FUNCTION (this << packet << incomingIpHeader << incomingInterface);
418 
419  TcpHeader incomingTcpHeader;
420  IpL4Protocol::RxStatus checksumControl;
421 
422  checksumControl = PacketReceived (packet, incomingTcpHeader,
423  incomingIpHeader.GetSource (),
424  incomingIpHeader.GetDestination ());
425 
426  if (checksumControl != IpL4Protocol::RX_OK)
427  {
428  return checksumControl;
429  }
430 
432  endPoints = m_endPoints->Lookup (incomingIpHeader.GetDestination (),
433  incomingTcpHeader.GetDestinationPort (),
434  incomingIpHeader.GetSource (),
435  incomingTcpHeader.GetSourcePort (),
436  incomingInterface);
437 
438  if (endPoints.empty ())
439  {
440  if (this->GetObject<Ipv6L3Protocol> () != 0)
441  {
442  NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
443  Ptr<Ipv6Interface> fakeInterface;
444  Ipv6Header ipv6Header;
445  Ipv6Address src, dst;
446 
447  src = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetSource ());
448  dst = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetDestination ());
449  ipv6Header.SetSourceAddress (src);
450  ipv6Header.SetDestinationAddress (dst);
451  return (this->Receive (packet, ipv6Header, fakeInterface));
452  }
453 
454  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
455  " no endpoints matched." <<
456  " destination IP: " << incomingIpHeader.GetDestination () <<
457  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
458  " source IP: " << incomingIpHeader.GetSource () <<
459  " source port: "<< incomingTcpHeader.GetSourcePort ());
460 
461  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSource (),
462  incomingIpHeader.GetDestination ());
463 
465 
466  }
467 
468  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
469  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
470  " now forwarding it up to endpoint/socket");
471 
472  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
473  incomingTcpHeader.GetSourcePort (),
474  incomingInterface);
475 
476  return IpL4Protocol::RX_OK;
477 }
478 
481  Ipv6Header const &incomingIpHeader,
482  Ptr<Ipv6Interface> interface)
483 {
484  NS_LOG_FUNCTION (this << packet << incomingIpHeader.GetSourceAddress () <<
485  incomingIpHeader.GetDestinationAddress ());
486 
487  TcpHeader incomingTcpHeader;
488  IpL4Protocol::RxStatus checksumControl;
489 
490  // If we are receving a v4-mapped packet, we will re-calculate the TCP checksum
491  // Is it worth checking every received "v6" packet to see if it is v4-mapped in
492  // order to avoid re-calculating TCP checksums for v4-mapped packets?
493 
494  checksumControl = PacketReceived (packet, incomingTcpHeader,
495  incomingIpHeader.GetSourceAddress (),
496  incomingIpHeader.GetDestinationAddress ());
497 
498  if (checksumControl != IpL4Protocol::RX_OK)
499  {
500  return checksumControl;
501  }
502 
503  Ipv6EndPointDemux::EndPoints endPoints =
504  m_endPoints6->Lookup (incomingIpHeader.GetDestinationAddress (),
505  incomingTcpHeader.GetDestinationPort (),
506  incomingIpHeader.GetSourceAddress (),
507  incomingTcpHeader.GetSourcePort (), interface);
508  if (endPoints.empty ())
509  {
510  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
511  " no endpoints matched." <<
512  " destination IP: " << incomingIpHeader.GetDestinationAddress () <<
513  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
514  " source IP: " << incomingIpHeader.GetSourceAddress () <<
515  " source port: "<< incomingTcpHeader.GetSourcePort ());
516 
517  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSourceAddress (),
518  incomingIpHeader.GetDestinationAddress ());
519 
521  }
522 
523  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
524  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
525  " now forwarding it up to endpoint/socket");
526 
527  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
528  incomingTcpHeader.GetSourcePort (), interface);
529 
530  return IpL4Protocol::RX_OK;
531 }
532 
533 void
535  const Ipv4Address &saddr, const Ipv4Address &daddr,
536  Ptr<NetDevice> oif) const
537 {
538  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
539  NS_LOG_LOGIC ("TcpL4Protocol " << this
540  << " sending seq " << outgoing.GetSequenceNumber ()
541  << " ack " << outgoing.GetAckNumber ()
542  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
543  << " data size " << packet->GetSize ());
544  // XXX outgoingHeader cannot be logged
545 
546  TcpHeader outgoingHeader = outgoing;
548  /* outgoingHeader.SetUrgentPointer (0); */
549  if (Node::ChecksumEnabled ())
550  {
551  outgoingHeader.EnableChecksums ();
552  }
553  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
554 
555  packet->AddHeader (outgoingHeader);
556 
557  Ptr<Ipv4> ipv4 =
558  m_node->GetObject<Ipv4> ();
559  if (ipv4 != 0)
560  {
561  Ipv4Header header;
562  header.SetSource (saddr);
563  header.SetDestination (daddr);
564  header.SetProtocol (PROT_NUMBER);
565  Socket::SocketErrno errno_;
566  Ptr<Ipv4Route> route;
567  if (ipv4->GetRoutingProtocol () != 0)
568  {
569  route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
570  }
571  else
572  {
573  NS_LOG_ERROR ("No IPV4 Routing Protocol");
574  route = 0;
575  }
576  m_downTarget (packet, saddr, daddr, PROT_NUMBER, route);
577  }
578  else
579  {
580  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv4 interface");
581  }
582 }
583 
584 void
586  const Ipv6Address &saddr, const Ipv6Address &daddr,
587  Ptr<NetDevice> oif) const
588 {
589  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
590  NS_LOG_LOGIC ("TcpL4Protocol " << this
591  << " sending seq " << outgoing.GetSequenceNumber ()
592  << " ack " << outgoing.GetAckNumber ()
593  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
594  << " data size " << packet->GetSize ());
595  // XXX outgoingHeader cannot be logged
596 
597  if (daddr.IsIpv4MappedAddress ())
598  {
599  return (SendPacket (packet, outgoing, saddr.GetIpv4MappedAddress (), daddr.GetIpv4MappedAddress (), oif));
600  }
601  TcpHeader outgoingHeader = outgoing;
603  /* outgoingHeader.SetUrgentPointer (0); */
604  if (Node::ChecksumEnabled ())
605  {
606  outgoingHeader.EnableChecksums ();
607  }
608  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
609 
610  packet->AddHeader (outgoingHeader);
611 
613  if (ipv6 != 0)
614  {
615  Ipv6Header header;
616  header.SetSourceAddress (saddr);
617  header.SetDestinationAddress (daddr);
618  header.SetNextHeader (PROT_NUMBER);
619  Socket::SocketErrno errno_;
620  Ptr<Ipv6Route> route;
621  if (ipv6->GetRoutingProtocol () != 0)
622  {
623  route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
624  }
625  else
626  {
627  NS_LOG_ERROR ("No IPV6 Routing Protocol");
628  route = 0;
629  }
630  m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, route);
631  }
632  else
633  {
634  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv6 interface");
635  }
636 }
637 
638 void
640  const Address &saddr, const Address &daddr,
641  Ptr<NetDevice> oif) const
642 {
643  NS_LOG_FUNCTION (this << pkt << outgoing << saddr << daddr << oif);
644  if (Ipv4Address::IsMatchingType (saddr))
645  {
647 
648  SendPacketV4 (pkt, outgoing, Ipv4Address::ConvertFrom (saddr),
649  Ipv4Address::ConvertFrom (daddr), oif);
650 
651  return;
652  }
653  else if (Ipv6Address::IsMatchingType (saddr))
654  {
656 
657  SendPacketV6 (pkt, outgoing, Ipv6Address::ConvertFrom (saddr),
658  Ipv6Address::ConvertFrom (daddr), oif);
659 
660  return;
661  }
662  else if (InetSocketAddress::IsMatchingType (saddr))
663  {
666 
667  SendPacketV4 (pkt, outgoing, s.GetIpv4 (), d.GetIpv4 (), oif);
668 
669  return;
670  }
671  else if (Inet6SocketAddress::IsMatchingType (saddr))
672  {
675 
676  SendPacketV6 (pkt, outgoing, s.GetIpv6 (), d.GetIpv6 (), oif);
677 
678  return;
679  }
680 
681  NS_FATAL_ERROR ("Trying to send a packet without IP addresses");
682 }
683 
684 void
686 {
687  NS_LOG_FUNCTION (this << socket);
688  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
689 
690  while (it != m_sockets.end ())
691  {
692  if (*it == socket)
693  {
694  return;
695  }
696 
697  ++it;
698  }
699 
700  m_sockets.push_back (socket);
701 }
702 
703 bool
705 {
706  NS_LOG_FUNCTION (this << socket);
707  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
708 
709  while (it != m_sockets.end ())
710  {
711  if (*it == socket)
712  {
713  m_sockets.erase (it);
714  return true;
715  }
716 
717  ++it;
718  }
719 
720  return false;
721 }
722 
723 void
725 {
726  m_downTarget = callback;
727 }
728 
731 {
732  return m_downTarget;
733 }
734 
735 void
737 {
738  m_downTarget6 = callback;
739 }
740 
743 {
744  return m_downTarget6;
745 }
746 
747 } // namespace ns3
748 
static bool IsMatchingType(const Address &address)
If the Address matches the type.
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
TypeId m_congestionTypeId
The socket TypeId.
static std::string FlagsToString(uint8_t flags, const std::string &delimiter="|")
Converts an integer into a human readable list of Tcp flags.
Definition: tcp-header.cc:55
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
Ptr< Socket > CreateSocket(void)
Create a TCP socket using the TypeId set by SocketType attribute.
Introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
an Inet address class
Ipv4Address GetIpv4(void) const
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint16_t GetDestinationPort() const
Get the destination port.
Definition: tcp-header.cc:137
Ptr< Node > m_node
the node this stack is associated with
virtual void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:143
virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
void SendPacketV4(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv4Address &saddr, const Ipv4Address &daddr, Ptr< NetDevice > oif=0) const
Send a packet via TCP (IPv4)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &incomingIpHeader, Ptr< Ipv4Interface > incomingInterface)
Called from lower-level layers to send the packet up in the stack.
std::list< Ipv6EndPoint * > EndPoints
Container of the IPv6 endpoints.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
virtual void DoDispose(void)
Destructor implementation.
IPv6 layer implementation.
EndPoints Lookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport, Ptr< Ipv6Interface > incomingInterface)
lookup for a match with all the parameters.
void InitializeChecksum(const Ipv4Address &source, const Ipv4Address &destination, uint8_t protocol)
Initialize the TCP checksum.
Definition: tcp-header.cc:191
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
static bool ChecksumEnabled(void)
Definition: node.cc:276
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:246
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1258
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
virtual void ReceiveIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource, Ipv4Address payloadDestination, const uint8_t payload[8])
Called from lower-level layers to send the ICMP packet up in the stack.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:75
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
enum IpL4Protocol::RxStatus PacketReceived(Ptr< Packet > packet, TcpHeader &incomingTcpHeader, const Address &source, const Address &destination)
Get the tcp header of the incoming packet and checks its checksum if needed.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:339
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static TypeId GetTypeId(void)
Get the type ID.
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
void AddSocket(Ptr< TcpSocketBase > socket)
Make a socket fully operational.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
Tcp socket creation and multiplexing/demultiplexing.
virtual void NotifyNewAggregate()
Setup socket factory and callbacks when aggregated to a node.
Demultiplexes packets to various transport layer endpoints.
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)=0
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers...
static TypeId GetTypeId(void)
Get the type ID.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Base class for all RTT Estimators.
Definition: rtt-estimator.h:43
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
Ipv6EndPoint * Allocate(void)
Allocate a Ipv6EndPoint.
AttributeValue implementation for TypeId.
Definition: type-id.h:548
An Inet6 address class.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
static bool IsMatchingType(const Address &address)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
std::vector< Ptr< TcpSocketBase > > m_sockets
list of sockets
void DeAllocate(Ipv6EndPoint *endPoint)
Remove a end point.
static const uint8_t PROT_NUMBER
protocol number (0x6)
void SetFlags(uint8_t flags)
Set flags of the header.
Definition: tcp-header.cc:113
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:278
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Forward the ICMP packet to the upper level.
virtual int GetProtocolNumber(void) const
Ipv6EndPoint * SimpleLookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
Simple lookup for a four-tuple match.
Congestion control abstract class.
std::string GetName(void) const
Get the name.
Definition: type-id.cc:880
virtual void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)=0
Ipv4EndPoint * SimpleLookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport)
simple lookup for a match with all the parameters.
void NoEndPointsFound(const TcpHeader &incomingHeader, const Address &incomingSAddr, const Address &incomingDAddr)
Check if RST packet should be sent, and in case, send it.
L4 Protocol abstract base class.
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
void SendPacketV6(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv6Address &saddr, const Ipv6Address &daddr, Ptr< NetDevice > oif=0) const
Send a packet via TCP (IPv6)
EndPoints Lookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
lookup for a match with all the parameters.
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
void SetSourceAddress(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:95
Describes an IPv6 address.
Definition: ipv6-address.h:48
Instantiate subclasses of ns3::Object.
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: type-id.h:548
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
static TypeId GetTypeId(void)
Get the type ID.
Demultiplexor for end points.
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:100
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
A representation of an internet IPv6 endpoint/connection.
bool RemoveSocket(Ptr< TcpSocketBase > socket)
Remove a socket from the internal list.
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
void SendPacket(Ptr< Packet > pkt, const TcpHeader &outgoing, const Address &saddr, const Address &daddr, Ptr< NetDevice > oif=0) const
Send a packet via TCP (IP-agnostic)
static bool IsMatchingType(const Address &addr)
If the address match.
TypeId m_rttTypeId
The RTT Estimator TypeId.
uint16_t GetSourcePort() const
Get the source port.
Definition: tcp-header.cc:131
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1262
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
RxStatus
Rx status codes.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
static Ipv4Address ConvertFrom(const Address &address)
tuple address
Definition: first.py:37
bool IsChecksumOk(void) const
Is the TCP checksum correct ?
Definition: tcp-header.cc:264
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:318
void EnableChecksums(void)
Enable checksum calculation for TCP.
Definition: tcp-header.cc:83
Container for a set of ns3::Object pointers.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove a end point.
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
Definition: type-id.cc:1081
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
a unique identifier for an interface.
Definition: type-id.h:58
void SetDestinationAddress(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:105
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
static bool IsMatchingType(const Address &address)
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:110
A representation of an internet endpoint/connection.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.