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-newreno.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 << Simulator::Now ().GetSeconds () << " [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 {
100 }
101 
102 void
104 {
105  m_node = node;
106 }
107 
108 void
110 {
111  Ptr<Node> node = this->GetObject<Node> ();
112  Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> ();
114 
115  if (m_node == 0)
116  {
117  if ((node != 0) && (ipv4 != 0 || ipv6 != 0))
118  {
119  this->SetNode (node);
120  Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
121  tcpFactory->SetTcp (this);
122  node->AggregateObject (tcpFactory);
123  }
124  }
125 
126  // We set at least one of our 2 down targets to the IPv4/IPv6 send
127  // functions. Since these functions have different prototypes, we
128  // need to keep track of whether we are connected to an IPv4 or
129  // IPv6 lower layer and call the appropriate one.
130 
131  if (ipv4 != 0 && m_downTarget.IsNull ())
132  {
133  ipv4->Insert (this);
134  this->SetDownTarget (MakeCallback (&Ipv4::Send, ipv4));
135  }
136  if (ipv6 != 0 && m_downTarget6.IsNull ())
137  {
138  ipv6->Insert (this);
140  }
142 }
143 
144 int
146 {
147  return PROT_NUMBER;
148 }
149 
150 void
152 {
154  m_sockets.clear ();
155 
156  if (m_endPoints != 0)
157  {
158  delete m_endPoints;
159  m_endPoints = 0;
160  }
161 
162  if (m_endPoints6 != 0)
163  {
164  delete m_endPoints6;
165  m_endPoints6 = 0;
166  }
167 
168  m_node = 0;
172 }
173 
176 {
178  ObjectFactory rttFactory;
179  ObjectFactory socketFactory;
180  rttFactory.SetTypeId (m_rttTypeId);
181  socketFactory.SetTypeId (socketTypeId);
182  Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator> ();
183  Ptr<TcpSocketBase> socket = socketFactory.Create<TcpSocketBase> ();
184  socket->SetNode (m_node);
185  socket->SetTcp (this);
186  socket->SetRtt (rtt);
187  m_sockets.push_back (socket);
188  return socket;
189 }
190 
193 {
194  return CreateSocket (m_socketTypeId);
195 }
196 
197 Ipv4EndPoint *
199 {
201  return m_endPoints->Allocate ();
202 }
203 
204 Ipv4EndPoint *
206 {
207  NS_LOG_FUNCTION (this << address);
208  return m_endPoints->Allocate (address);
209 }
210 
211 Ipv4EndPoint *
213 {
214  NS_LOG_FUNCTION (this << port);
215  return m_endPoints->Allocate (port);
216 }
217 
218 Ipv4EndPoint *
220 {
221  NS_LOG_FUNCTION (this << address << port);
222  return m_endPoints->Allocate (address, port);
223 }
224 
225 Ipv4EndPoint *
226 TcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
227  Ipv4Address peerAddress, uint16_t peerPort)
228 {
229  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
230  return m_endPoints->Allocate (localAddress, localPort,
231  peerAddress, peerPort);
232 }
233 
234 void
236 {
237  NS_LOG_FUNCTION (this << endPoint);
238  m_endPoints->DeAllocate (endPoint);
239 }
240 
241 Ipv6EndPoint *
243 {
245  return m_endPoints6->Allocate ();
246 }
247 
248 Ipv6EndPoint *
250 {
251  NS_LOG_FUNCTION (this << address);
252  return m_endPoints6->Allocate (address);
253 }
254 
255 Ipv6EndPoint *
257 {
258  NS_LOG_FUNCTION (this << port);
259  return m_endPoints6->Allocate (port);
260 }
261 
262 Ipv6EndPoint *
264 {
265  NS_LOG_FUNCTION (this << address << port);
266  return m_endPoints6->Allocate (address, port);
267 }
268 
269 Ipv6EndPoint *
270 TcpL4Protocol::Allocate6 (Ipv6Address localAddress, uint16_t localPort,
271  Ipv6Address peerAddress, uint16_t peerPort)
272 {
273  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
274  return m_endPoints6->Allocate (localAddress, localPort,
275  peerAddress, peerPort);
276 }
277 
278 void
280 {
281  NS_LOG_FUNCTION (this << endPoint);
282  m_endPoints6->DeAllocate (endPoint);
283 }
284 
285 void
286 TcpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
287  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
288  Ipv4Address payloadSource,Ipv4Address payloadDestination,
289  const uint8_t payload[8])
290 {
291  NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
292  << payloadSource << payloadDestination);
293  uint16_t src, dst;
294  src = payload[0] << 8;
295  src |= payload[1];
296  dst = payload[2] << 8;
297  dst |= payload[3];
298 
299  Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloadDestination, dst);
300  if (endPoint != 0)
301  {
302  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
303  }
304  else
305  {
306  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
307  ", destination=" << payloadDestination <<
308  ", src=" << src << ", dst=" << dst);
309  }
310 }
311 
312 void
313 TcpL4Protocol::ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
314  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
315  Ipv6Address payloadSource,Ipv6Address payloadDestination,
316  const uint8_t payload[8])
317 {
318  NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
319  << payloadSource << payloadDestination);
320  uint16_t src, dst;
321  src = payload[0] << 8;
322  src |= payload[1];
323  dst = payload[2] << 8;
324  dst |= payload[3];
325 
326  Ipv6EndPoint *endPoint = m_endPoints6->SimpleLookup (payloadSource, src, payloadDestination, dst);
327  if (endPoint != 0)
328  {
329  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
330  }
331  else
332  {
333  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
334  ", destination=" << payloadDestination <<
335  ", src=" << src << ", dst=" << dst);
336  }
337 }
338 
341  const Address &source, const Address &destination)
342 {
343 
344  if (Node::ChecksumEnabled ())
345  {
346  incomingTcpHeader.EnableChecksums ();
347  incomingTcpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
348  }
349 
350  packet->PeekHeader (incomingTcpHeader);
351 
352  NS_LOG_LOGIC ("TcpL4Protocol " << this
353  << " receiving seq " << incomingTcpHeader.GetSequenceNumber ()
354  << " ack " << incomingTcpHeader.GetAckNumber ()
355  << " flags "<< TcpHeader::FlagsToString (incomingTcpHeader.GetFlags ())
356  << " data size " << packet->GetSize ());
357 
358  if (!incomingTcpHeader.IsChecksumOk ())
359  {
360  NS_LOG_INFO ("Bad checksum, dropping packet!");
362  }
363 
364  return IpL4Protocol::RX_OK;
365 }
366 
367 void
369  const Address &incomingSAddr,
370  const Address &incomingDAddr)
371 {
372  if (!(incomingHeader.GetFlags () & TcpHeader::RST))
373  {
374  // build a RST packet and send
375  Ptr<Packet> rstPacket = Create<Packet> ();
376  TcpHeader outgoingTcpHeader;
377 
378  if (incomingHeader.GetFlags () & TcpHeader::ACK)
379  {
380  // ACK bit was set
381  outgoingTcpHeader.SetFlags (TcpHeader::RST);
382  outgoingTcpHeader.SetSequenceNumber (incomingHeader.GetAckNumber ());
383  }
384  else
385  {
386  outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK);
387  outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0));
388  outgoingTcpHeader.SetAckNumber (incomingHeader.GetSequenceNumber () +
389  SequenceNumber32 (1));
390  }
391 
392  // Remember that parameters refer to the incoming packet; in reply,
393  // we need to swap src/dst
394 
395  outgoingTcpHeader.SetSourcePort (incomingHeader.GetDestinationPort ());
396  outgoingTcpHeader.SetDestinationPort (incomingHeader.GetSourcePort ());
397 
398  SendPacket (rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
399  }
400 }
401 
404  Ipv4Header const &incomingIpHeader,
405  Ptr<Ipv4Interface> incomingInterface)
406 {
407  NS_LOG_FUNCTION (this << packet << incomingIpHeader << incomingInterface);
408 
409  TcpHeader incomingTcpHeader;
410  IpL4Protocol::RxStatus checksumControl;
411 
412  checksumControl = PacketReceived (packet, incomingTcpHeader,
413  incomingIpHeader.GetSource (),
414  incomingIpHeader.GetDestination ());
415 
416  if (checksumControl != IpL4Protocol::RX_OK)
417  {
418  return checksumControl;
419  }
420 
421  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet");
422 
424  endPoints = m_endPoints->Lookup (incomingIpHeader.GetDestination (),
425  incomingTcpHeader.GetDestinationPort (),
426  incomingIpHeader.GetSource (),
427  incomingTcpHeader.GetSourcePort (),
428  incomingInterface);
429 
430  if (endPoints.empty ())
431  {
432  if (this->GetObject<Ipv6L3Protocol> () != 0)
433  {
434  NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
435  Ptr<Ipv6Interface> fakeInterface;
436  Ipv6Header ipv6Header;
437  Ipv6Address src, dst;
438 
439  src = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetSource ());
440  dst = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetDestination ());
441  ipv6Header.SetSourceAddress (src);
442  ipv6Header.SetDestinationAddress (dst);
443  return (this->Receive (packet, ipv6Header, fakeInterface));
444  }
445 
446  NS_LOG_LOGIC ("No endpoints matched on TcpL4Protocol "<< this <<
447  " destination IP: " << incomingIpHeader.GetDestination () <<
448  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
449  " source IP: " << incomingIpHeader.GetSource () <<
450  " source port: "<< incomingTcpHeader.GetSourcePort ());
451 
452  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSource (),
453  incomingIpHeader.GetDestination ());
454 
456 
457  }
458 
459  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
460  NS_LOG_LOGIC ("TcpL4Protocol " << this << " forwarding up to endpoint/socket");
461 
462  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
463  incomingTcpHeader.GetSourcePort (),
464  incomingInterface);
465 
466  return IpL4Protocol::RX_OK;
467 }
468 
471  Ipv6Header const &incomingIpHeader,
472  Ptr<Ipv6Interface> interface)
473 {
474  NS_LOG_FUNCTION (this << packet << incomingIpHeader.GetSourceAddress () <<
475  incomingIpHeader.GetDestinationAddress ());
476 
477  TcpHeader incomingTcpHeader;
478  IpL4Protocol::RxStatus checksumControl;
479 
480  // If we are receving a v4-mapped packet, we will re-calculate the TCP checksum
481  // Is it worth checking every received "v6" packet to see if it is v4-mapped in
482  // order to avoid re-calculating TCP checksums for v4-mapped packets?
483 
484  checksumControl = PacketReceived (packet, incomingTcpHeader,
485  incomingIpHeader.GetSourceAddress (),
486  incomingIpHeader.GetDestinationAddress ());
487 
488  if (checksumControl != IpL4Protocol::RX_OK)
489  {
490  return checksumControl;
491  }
492 
493  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet");
494  Ipv6EndPointDemux::EndPoints endPoints =
495  m_endPoints6->Lookup (incomingIpHeader.GetDestinationAddress (),
496  incomingTcpHeader.GetDestinationPort (),
497  incomingIpHeader.GetSourceAddress (),
498  incomingTcpHeader.GetSourcePort (), interface);
499  if (endPoints.empty ())
500  {
501  NS_LOG_LOGIC ("No endpoints matched on TcpL4Protocol "<< this <<
502  " destination IP: " << incomingIpHeader.GetDestinationAddress () <<
503  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
504  " source IP: " << incomingIpHeader.GetSourceAddress () <<
505  " source port: "<< incomingTcpHeader.GetSourcePort ());
506 
507  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSourceAddress (),
508  incomingIpHeader.GetDestinationAddress ());
509 
511  }
512 
513  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
514  NS_LOG_LOGIC ("TcpL4Protocol " << this << " forwarding up to endpoint/socket");
515 
516  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
517  incomingTcpHeader.GetSourcePort (), interface);
518 
519  return IpL4Protocol::RX_OK;
520 }
521 
522 void
524  const Ipv4Address &saddr, const Ipv4Address &daddr,
525  Ptr<NetDevice> oif) const
526 {
527  NS_LOG_LOGIC ("TcpL4Protocol " << this
528  << " sending seq " << outgoing.GetSequenceNumber ()
529  << " ack " << outgoing.GetAckNumber ()
530  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
531  << " data size " << packet->GetSize ());
532  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
533  // XXX outgoingHeader cannot be logged
534 
535  TcpHeader outgoingHeader = outgoing;
537  /* outgoingHeader.SetUrgentPointer (0); */
538  if (Node::ChecksumEnabled ())
539  {
540  outgoingHeader.EnableChecksums ();
541  }
542  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
543 
544  packet->AddHeader (outgoingHeader);
545 
546  Ptr<Ipv4> ipv4 =
547  m_node->GetObject<Ipv4> ();
548  if (ipv4 != 0)
549  {
550  Ipv4Header header;
551  header.SetSource (saddr);
552  header.SetDestination (daddr);
553  header.SetProtocol (PROT_NUMBER);
554  Socket::SocketErrno errno_;
555  Ptr<Ipv4Route> route;
556  if (ipv4->GetRoutingProtocol () != 0)
557  {
558  route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
559  }
560  else
561  {
562  NS_LOG_ERROR ("No IPV4 Routing Protocol");
563  route = 0;
564  }
565  m_downTarget (packet, saddr, daddr, PROT_NUMBER, route);
566  }
567  else
568  {
569  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv4 interface");
570  }
571 }
572 
573 void
575  const Ipv6Address &saddr, const Ipv6Address &daddr,
576  Ptr<NetDevice> oif) const
577 {
578  NS_LOG_LOGIC ("TcpL4Protocol " << this
579  << " sending seq " << outgoing.GetSequenceNumber ()
580  << " ack " << outgoing.GetAckNumber ()
581  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
582  << " data size " << packet->GetSize ());
583  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
584  // XXX outgoingHeader cannot be logged
585 
586  if (daddr.IsIpv4MappedAddress ())
587  {
588  return (SendPacket (packet, outgoing, saddr.GetIpv4MappedAddress (), daddr.GetIpv4MappedAddress (), oif));
589  }
590  TcpHeader outgoingHeader = outgoing;
592  /* outgoingHeader.SetUrgentPointer (0); */
593  if (Node::ChecksumEnabled ())
594  {
595  outgoingHeader.EnableChecksums ();
596  }
597  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
598 
599  packet->AddHeader (outgoingHeader);
600 
602  if (ipv6 != 0)
603  {
604  Ipv6Header header;
605  header.SetSourceAddress (saddr);
606  header.SetDestinationAddress (daddr);
607  header.SetNextHeader (PROT_NUMBER);
608  Socket::SocketErrno errno_;
609  Ptr<Ipv6Route> route;
610  if (ipv6->GetRoutingProtocol () != 0)
611  {
612  route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
613  }
614  else
615  {
616  NS_LOG_ERROR ("No IPV6 Routing Protocol");
617  route = 0;
618  }
619  m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, route);
620  }
621  else
622  {
623  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv6 interface");
624  }
625 }
626 
627 void
629  const Address &saddr, const Address &daddr,
630  Ptr<NetDevice> oif) const
631 {
632  if (Ipv4Address::IsMatchingType (saddr))
633  {
635 
636  SendPacketV4 (pkt, outgoing, Ipv4Address::ConvertFrom (saddr),
637  Ipv4Address::ConvertFrom (daddr), oif);
638 
639  return;
640  }
641  else if (Ipv6Address::IsMatchingType (saddr))
642  {
644 
645  SendPacketV6 (pkt, outgoing, Ipv6Address::ConvertFrom (saddr),
646  Ipv6Address::ConvertFrom (daddr), oif);
647 
648  return;
649  }
650  else if (InetSocketAddress::IsMatchingType (saddr))
651  {
654 
655  SendPacketV4 (pkt, outgoing, s.GetIpv4 (), d.GetIpv4 (), oif);
656 
657  return;
658  }
659  else if (Inet6SocketAddress::IsMatchingType (saddr))
660  {
663 
664  SendPacketV6 (pkt, outgoing, s.GetIpv6 (), d.GetIpv6 (), oif);
665 
666  return;
667  }
668 
669  NS_FATAL_ERROR ("Trying to send a packet without IP addresses");
670 }
671 
672 void
674 {
675  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
676 
677  while (it != m_sockets.end ())
678  {
679  if (*it == socket)
680  {
681  return;
682  }
683 
684  ++it;
685  }
686 
687  m_sockets.push_back (socket);
688 }
689 
690 bool
692 {
693  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
694 
695  while (it != m_sockets.end ())
696  {
697  if (*it == socket)
698  {
699  m_sockets.erase (it);
700  return true;
701  }
702 
703  ++it;
704  }
705 
706  return false;
707 }
708 
709 void
711 {
712  m_downTarget = callback;
713 }
714 
717 {
718  return m_downTarget;
719 }
720 
721 void
723 {
724  m_downTarget6 = callback;
725 }
726 
729 {
730  return m_downTarget6;
731 }
732 
733 } // namespace ns3
734 
static bool IsMatchingType(const Address &address)
If the Address matches the type.
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
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.
TypeId m_socketTypeId
The socket TypeId.
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:161
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
virtual void DoDispose(void)
Destructor implementation.
void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers...
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:179
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
static bool ChecksumEnabled(void)
Definition: node.cc:269
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:76
#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
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-newreno.cc:38
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
A base class for implementation of a stream socket using TCP.
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:276
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
virtual void SetNode(Ptr< Node > node)
Set the associated node.
Ipv6EndPoint * SimpleLookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
Simple lookup for a four-tuple match.
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:96
Describes an IPv6 address.
Definition: ipv6-address.h:47
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:101
#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:252
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:106
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:255
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:111
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.