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 "tcp-congestion-ops.h"
45 #include "rtt-estimator.h"
46 
47 #include <vector>
48 #include <sstream>
49 #include <iomanip>
50 
51 namespace ns3 {
52 
53 NS_LOG_COMPONENT_DEFINE ("TcpL4Protocol");
54 
55 NS_OBJECT_ENSURE_REGISTERED (TcpL4Protocol);
56 
57 //TcpL4Protocol stuff----------------------------------------------------------
58 
59 #undef NS_LOG_APPEND_CONTEXT
60 #define NS_LOG_APPEND_CONTEXT \
61  if (m_node) { std::clog << " [node " << m_node->GetId () << "] "; }
62 
63 /* see http://www.iana.org/assignments/protocol-numbers */
64 const uint8_t TcpL4Protocol::PROT_NUMBER = 6;
65 
66 TypeId
68 {
69  static TypeId tid = TypeId ("ns3::TcpL4Protocol")
71  .SetGroupName ("Internet")
72  .AddConstructor<TcpL4Protocol> ()
73  .AddAttribute ("RttEstimatorType",
74  "Type of RttEstimator objects.",
78  .AddAttribute ("SocketType",
79  "Socket type of TCP objects.",
83  .AddAttribute ("SocketList", "The list of sockets associated to this protocol.",
86  MakeObjectVectorChecker<TcpSocketBase> ())
87  ;
88  return tid;
89 }
90 
92  : m_endPoints (new Ipv4EndPointDemux ()), m_endPoints6 (new Ipv6EndPointDemux ())
93 {
95  NS_LOG_LOGIC ("Made a TcpL4Protocol " << this);
96 }
97 
99 {
100  NS_LOG_FUNCTION (this);
101 }
102 
103 void
105 {
106  NS_LOG_FUNCTION (this);
107  m_node = node;
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION (this);
114  Ptr<Node> node = this->GetObject<Node> ();
115  Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> ();
116  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
117 
118  if (m_node == 0)
119  {
120  if ((node != 0) && (ipv4 != 0 || ipv6 != 0))
121  {
122  this->SetNode (node);
123  Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
124  tcpFactory->SetTcp (this);
125  node->AggregateObject (tcpFactory);
126  }
127  }
128 
129  // We set at least one of our 2 down targets to the IPv4/IPv6 send
130  // functions. Since these functions have different prototypes, we
131  // need to keep track of whether we are connected to an IPv4 or
132  // IPv6 lower layer and call the appropriate one.
133 
134  if (ipv4 != 0 && m_downTarget.IsNull ())
135  {
136  ipv4->Insert (this);
137  this->SetDownTarget (MakeCallback (&Ipv4::Send, ipv4));
138  }
139  if (ipv6 != 0 && m_downTarget6.IsNull ())
140  {
141  ipv6->Insert (this);
142  this->SetDownTarget6 (MakeCallback (&Ipv6::Send, ipv6));
143  }
145 }
146 
147 int
149 {
150  return PROT_NUMBER;
151 }
152 
153 void
155 {
156  NS_LOG_FUNCTION (this);
157  m_sockets.clear ();
158 
159  if (m_endPoints != 0)
160  {
161  delete m_endPoints;
162  m_endPoints = 0;
163  }
164 
165  if (m_endPoints6 != 0)
166  {
167  delete m_endPoints6;
168  m_endPoints6 = 0;
169  }
170 
171  m_node = 0;
175 }
176 
179 {
180  NS_LOG_FUNCTION (this << congestionTypeId.GetName ());
181  ObjectFactory rttFactory;
182  ObjectFactory congestionAlgorithmFactory;
183  rttFactory.SetTypeId (m_rttTypeId);
184  congestionAlgorithmFactory.SetTypeId (congestionTypeId);
185 
186  Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator> ();
187  Ptr<TcpSocketBase> socket = CreateObject<TcpSocketBase> ();
188  Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps> ();
189 
190  socket->SetNode (m_node);
191  socket->SetTcp (this);
192  socket->SetRtt (rtt);
193  socket->SetCongestionControlAlgorithm (algo);
194 
195  m_sockets.push_back (socket);
196  return socket;
197 }
198 
201 {
203 }
204 
205 Ipv4EndPoint *
207 {
209  return m_endPoints->Allocate ();
210 }
211 
212 Ipv4EndPoint *
214 {
215  NS_LOG_FUNCTION (this << address);
216  return m_endPoints->Allocate (address);
217 }
218 
219 Ipv4EndPoint *
221 {
222  NS_LOG_FUNCTION (this << port);
223  return m_endPoints->Allocate (port);
224 }
225 
226 Ipv4EndPoint *
228 {
229  NS_LOG_FUNCTION (this << address << port);
230  return m_endPoints->Allocate (address, port);
231 }
232 
233 Ipv4EndPoint *
234 TcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
235  Ipv4Address peerAddress, uint16_t peerPort)
236 {
237  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
238  return m_endPoints->Allocate (localAddress, localPort,
239  peerAddress, peerPort);
240 }
241 
242 void
244 {
245  NS_LOG_FUNCTION (this << endPoint);
246  m_endPoints->DeAllocate (endPoint);
247 }
248 
249 Ipv6EndPoint *
251 {
253  return m_endPoints6->Allocate ();
254 }
255 
256 Ipv6EndPoint *
258 {
259  NS_LOG_FUNCTION (this << address);
260  return m_endPoints6->Allocate (address);
261 }
262 
263 Ipv6EndPoint *
265 {
266  NS_LOG_FUNCTION (this << port);
267  return m_endPoints6->Allocate (port);
268 }
269 
270 Ipv6EndPoint *
272 {
273  NS_LOG_FUNCTION (this << address << port);
274  return m_endPoints6->Allocate (address, port);
275 }
276 
277 Ipv6EndPoint *
278 TcpL4Protocol::Allocate6 (Ipv6Address localAddress, uint16_t localPort,
279  Ipv6Address peerAddress, uint16_t peerPort)
280 {
281  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
282  return m_endPoints6->Allocate (localAddress, localPort,
283  peerAddress, peerPort);
284 }
285 
286 void
288 {
289  NS_LOG_FUNCTION (this << endPoint);
290  m_endPoints6->DeAllocate (endPoint);
291 }
292 
293 void
294 TcpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
295  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
296  Ipv4Address payloadSource,Ipv4Address payloadDestination,
297  const uint8_t payload[8])
298 {
299  NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
300  << payloadSource << payloadDestination);
301  uint16_t src, dst;
302  src = payload[0] << 8;
303  src |= payload[1];
304  dst = payload[2] << 8;
305  dst |= payload[3];
306 
307  Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloadDestination, dst);
308  if (endPoint != 0)
309  {
310  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
311  }
312  else
313  {
314  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
315  ", destination=" << payloadDestination <<
316  ", src=" << src << ", dst=" << dst);
317  }
318 }
319 
320 void
321 TcpL4Protocol::ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
322  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
323  Ipv6Address payloadSource,Ipv6Address payloadDestination,
324  const uint8_t payload[8])
325 {
326  NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
327  << payloadSource << payloadDestination);
328  uint16_t src, dst;
329  src = payload[0] << 8;
330  src |= payload[1];
331  dst = payload[2] << 8;
332  dst |= payload[3];
333 
334  Ipv6EndPoint *endPoint = m_endPoints6->SimpleLookup (payloadSource, src, payloadDestination, dst);
335  if (endPoint != 0)
336  {
337  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
338  }
339  else
340  {
341  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
342  ", destination=" << payloadDestination <<
343  ", src=" << src << ", dst=" << dst);
344  }
345 }
346 
349  const Address &source, const Address &destination)
350 {
351  NS_LOG_FUNCTION (this << packet << incomingTcpHeader << source << destination);
352 
353  if (Node::ChecksumEnabled ())
354  {
355  incomingTcpHeader.EnableChecksums ();
356  incomingTcpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
357  }
358 
359  packet->PeekHeader (incomingTcpHeader);
360 
361  NS_LOG_LOGIC ("TcpL4Protocol " << this
362  << " receiving seq " << incomingTcpHeader.GetSequenceNumber ()
363  << " ack " << incomingTcpHeader.GetAckNumber ()
364  << " flags "<< TcpHeader::FlagsToString (incomingTcpHeader.GetFlags ())
365  << " data size " << packet->GetSize ());
366 
367  if (!incomingTcpHeader.IsChecksumOk ())
368  {
369  NS_LOG_INFO ("Bad checksum, dropping packet!");
371  }
372 
373  return IpL4Protocol::RX_OK;
374 }
375 
376 void
378  const Address &incomingSAddr,
379  const Address &incomingDAddr)
380 {
381  NS_LOG_FUNCTION (this << incomingHeader << incomingSAddr << incomingDAddr);
382 
383  if (!(incomingHeader.GetFlags () & TcpHeader::RST))
384  {
385  // build a RST packet and send
386  Ptr<Packet> rstPacket = Create<Packet> ();
387  TcpHeader outgoingTcpHeader;
388 
389  if (incomingHeader.GetFlags () & TcpHeader::ACK)
390  {
391  // ACK bit was set
392  outgoingTcpHeader.SetFlags (TcpHeader::RST);
393  outgoingTcpHeader.SetSequenceNumber (incomingHeader.GetAckNumber ());
394  }
395  else
396  {
397  outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK);
398  outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0));
399  outgoingTcpHeader.SetAckNumber (incomingHeader.GetSequenceNumber () +
400  SequenceNumber32 (1));
401  }
402 
403  // Remember that parameters refer to the incoming packet; in reply,
404  // we need to swap src/dst
405 
406  outgoingTcpHeader.SetSourcePort (incomingHeader.GetDestinationPort ());
407  outgoingTcpHeader.SetDestinationPort (incomingHeader.GetSourcePort ());
408 
409  SendPacket (rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
410  }
411 }
412 
415  Ipv4Header const &incomingIpHeader,
416  Ptr<Ipv4Interface> incomingInterface)
417 {
418  NS_LOG_FUNCTION (this << packet << incomingIpHeader << incomingInterface);
419 
420  TcpHeader incomingTcpHeader;
421  IpL4Protocol::RxStatus checksumControl;
422 
423  checksumControl = PacketReceived (packet, incomingTcpHeader,
424  incomingIpHeader.GetSource (),
425  incomingIpHeader.GetDestination ());
426 
427  if (checksumControl != IpL4Protocol::RX_OK)
428  {
429  return checksumControl;
430  }
431 
433  endPoints = m_endPoints->Lookup (incomingIpHeader.GetDestination (),
434  incomingTcpHeader.GetDestinationPort (),
435  incomingIpHeader.GetSource (),
436  incomingTcpHeader.GetSourcePort (),
437  incomingInterface);
438 
439  if (endPoints.empty ())
440  {
441  if (this->GetObject<Ipv6L3Protocol> () != 0)
442  {
443  NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
444  Ptr<Ipv6Interface> fakeInterface;
445  Ipv6Header ipv6Header;
446  Ipv6Address src, dst;
447 
448  src = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetSource ());
449  dst = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetDestination ());
450  ipv6Header.SetSourceAddress (src);
451  ipv6Header.SetDestinationAddress (dst);
452  return (this->Receive (packet, ipv6Header, fakeInterface));
453  }
454 
455  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
456  " no endpoints matched." <<
457  " destination IP: " << incomingIpHeader.GetDestination () <<
458  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
459  " source IP: " << incomingIpHeader.GetSource () <<
460  " source port: "<< incomingTcpHeader.GetSourcePort ());
461 
462  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSource (),
463  incomingIpHeader.GetDestination ());
464 
466 
467  }
468 
469  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
470  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
471  " now forwarding it up to endpoint/socket");
472 
473  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
474  incomingTcpHeader.GetSourcePort (),
475  incomingInterface);
476 
477  return IpL4Protocol::RX_OK;
478 }
479 
482  Ipv6Header const &incomingIpHeader,
483  Ptr<Ipv6Interface> interface)
484 {
485  NS_LOG_FUNCTION (this << packet << incomingIpHeader.GetSourceAddress () <<
486  incomingIpHeader.GetDestinationAddress ());
487 
488  TcpHeader incomingTcpHeader;
489  IpL4Protocol::RxStatus checksumControl;
490 
491  // If we are receving a v4-mapped packet, we will re-calculate the TCP checksum
492  // Is it worth checking every received "v6" packet to see if it is v4-mapped in
493  // order to avoid re-calculating TCP checksums for v4-mapped packets?
494 
495  checksumControl = PacketReceived (packet, incomingTcpHeader,
496  incomingIpHeader.GetSourceAddress (),
497  incomingIpHeader.GetDestinationAddress ());
498 
499  if (checksumControl != IpL4Protocol::RX_OK)
500  {
501  return checksumControl;
502  }
503 
504  Ipv6EndPointDemux::EndPoints endPoints =
505  m_endPoints6->Lookup (incomingIpHeader.GetDestinationAddress (),
506  incomingTcpHeader.GetDestinationPort (),
507  incomingIpHeader.GetSourceAddress (),
508  incomingTcpHeader.GetSourcePort (), interface);
509  if (endPoints.empty ())
510  {
511  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
512  " no endpoints matched." <<
513  " destination IP: " << incomingIpHeader.GetDestinationAddress () <<
514  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
515  " source IP: " << incomingIpHeader.GetSourceAddress () <<
516  " source port: "<< incomingTcpHeader.GetSourcePort ());
517 
518  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSourceAddress (),
519  incomingIpHeader.GetDestinationAddress ());
520 
522  }
523 
524  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
525  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
526  " now forwarding it up to endpoint/socket");
527 
528  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
529  incomingTcpHeader.GetSourcePort (), interface);
530 
531  return IpL4Protocol::RX_OK;
532 }
533 
534 void
536  const Ipv4Address &saddr, const Ipv4Address &daddr,
537  Ptr<NetDevice> oif) const
538 {
539  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
540  NS_LOG_LOGIC ("TcpL4Protocol " << this
541  << " sending seq " << outgoing.GetSequenceNumber ()
542  << " ack " << outgoing.GetAckNumber ()
543  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
544  << " data size " << packet->GetSize ());
545  // XXX outgoingHeader cannot be logged
546 
547  TcpHeader outgoingHeader = outgoing;
549  /* outgoingHeader.SetUrgentPointer (0); */
550  if (Node::ChecksumEnabled ())
551  {
552  outgoingHeader.EnableChecksums ();
553  }
554  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
555 
556  packet->AddHeader (outgoingHeader);
557 
558  Ptr<Ipv4> ipv4 =
559  m_node->GetObject<Ipv4> ();
560  if (ipv4 != 0)
561  {
562  Ipv4Header header;
563  header.SetSource (saddr);
564  header.SetDestination (daddr);
565  header.SetProtocol (PROT_NUMBER);
566  Socket::SocketErrno errno_;
567  Ptr<Ipv4Route> route;
568  if (ipv4->GetRoutingProtocol () != 0)
569  {
570  route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
571  }
572  else
573  {
574  NS_LOG_ERROR ("No IPV4 Routing Protocol");
575  route = 0;
576  }
577  m_downTarget (packet, saddr, daddr, PROT_NUMBER, route);
578  }
579  else
580  {
581  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv4 interface");
582  }
583 }
584 
585 void
587  const Ipv6Address &saddr, const Ipv6Address &daddr,
588  Ptr<NetDevice> oif) const
589 {
590  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
591  NS_LOG_LOGIC ("TcpL4Protocol " << this
592  << " sending seq " << outgoing.GetSequenceNumber ()
593  << " ack " << outgoing.GetAckNumber ()
594  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
595  << " data size " << packet->GetSize ());
596  // XXX outgoingHeader cannot be logged
597 
598  if (daddr.IsIpv4MappedAddress ())
599  {
600  return (SendPacket (packet, outgoing, saddr.GetIpv4MappedAddress (), daddr.GetIpv4MappedAddress (), oif));
601  }
602  TcpHeader outgoingHeader = outgoing;
604  /* outgoingHeader.SetUrgentPointer (0); */
605  if (Node::ChecksumEnabled ())
606  {
607  outgoingHeader.EnableChecksums ();
608  }
609  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
610 
611  packet->AddHeader (outgoingHeader);
612 
614  if (ipv6 != 0)
615  {
616  Ipv6Header header;
617  header.SetSourceAddress (saddr);
618  header.SetDestinationAddress (daddr);
619  header.SetNextHeader (PROT_NUMBER);
620  Socket::SocketErrno errno_;
621  Ptr<Ipv6Route> route;
622  if (ipv6->GetRoutingProtocol () != 0)
623  {
624  route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
625  }
626  else
627  {
628  NS_LOG_ERROR ("No IPV6 Routing Protocol");
629  route = 0;
630  }
631  m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, route);
632  }
633  else
634  {
635  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv6 interface");
636  }
637 }
638 
639 void
641  const Address &saddr, const Address &daddr,
642  Ptr<NetDevice> oif) const
643 {
644  NS_LOG_FUNCTION (this << pkt << outgoing << saddr << daddr << oif);
645  if (Ipv4Address::IsMatchingType (saddr))
646  {
648 
649  SendPacketV4 (pkt, outgoing, Ipv4Address::ConvertFrom (saddr),
650  Ipv4Address::ConvertFrom (daddr), oif);
651 
652  return;
653  }
654  else if (Ipv6Address::IsMatchingType (saddr))
655  {
657 
658  SendPacketV6 (pkt, outgoing, Ipv6Address::ConvertFrom (saddr),
659  Ipv6Address::ConvertFrom (daddr), oif);
660 
661  return;
662  }
663  else if (InetSocketAddress::IsMatchingType (saddr))
664  {
667 
668  SendPacketV4 (pkt, outgoing, s.GetIpv4 (), d.GetIpv4 (), oif);
669 
670  return;
671  }
672  else if (Inet6SocketAddress::IsMatchingType (saddr))
673  {
676 
677  SendPacketV6 (pkt, outgoing, s.GetIpv6 (), d.GetIpv6 (), oif);
678 
679  return;
680  }
681 
682  NS_FATAL_ERROR ("Trying to send a packet without IP addresses");
683 }
684 
685 void
687 {
688  NS_LOG_FUNCTION (this << socket);
689  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
690 
691  while (it != m_sockets.end ())
692  {
693  if (*it == socket)
694  {
695  return;
696  }
697 
698  ++it;
699  }
700 
701  m_sockets.push_back (socket);
702 }
703 
704 bool
706 {
707  NS_LOG_FUNCTION (this << socket);
708  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
709 
710  while (it != m_sockets.end ())
711  {
712  if (*it == socket)
713  {
714  m_sockets.erase (it);
715  return true;
716  }
717 
718  ++it;
719  }
720 
721  return false;
722 }
723 
724 void
726 {
727  m_downTarget = callback;
728 }
729 
732 {
733  return m_downTarget;
734 }
735 
736 void
738 {
739  m_downTarget6 = callback;
740 }
741 
744 {
745  return m_downTarget6;
746 }
747 
748 } // namespace ns3
749 
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.
Packet header for IPv6.
Definition: ipv6-header.h:34
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:462
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:252
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:1270
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:792
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:162
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#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.
RxStatus
Rx status codes.
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:33
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:608
An Inet6 address class.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
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
Returns the protocol number of this protocol.
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:958
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:608
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.
Demultiplexer 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 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:1274
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
#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:325
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:1202
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:904
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.