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 {
208  NS_LOG_FUNCTION (this);
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 *
220 TcpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port)
221 {
222  NS_LOG_FUNCTION (this << boundNetDevice << port);
223  return m_endPoints->Allocate (boundNetDevice, port);
224 }
225 
226 Ipv4EndPoint *
228 {
229  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
230  return m_endPoints->Allocate (boundNetDevice, address, port);
231 }
232 
233 Ipv4EndPoint *
235  Ipv4Address localAddress, uint16_t localPort,
236  Ipv4Address peerAddress, uint16_t peerPort)
237 {
238  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
239  return m_endPoints->Allocate (boundNetDevice,
240  localAddress, localPort,
241  peerAddress, peerPort);
242 }
243 
244 void
246 {
247  NS_LOG_FUNCTION (this << endPoint);
248  m_endPoints->DeAllocate (endPoint);
249 }
250 
251 Ipv6EndPoint *
253 {
254  NS_LOG_FUNCTION (this);
255  return m_endPoints6->Allocate ();
256 }
257 
258 Ipv6EndPoint *
260 {
261  NS_LOG_FUNCTION (this << address);
262  return m_endPoints6->Allocate (address);
263 }
264 
265 Ipv6EndPoint *
266 TcpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port)
267 {
268  NS_LOG_FUNCTION (this << boundNetDevice << port);
269  return m_endPoints6->Allocate (boundNetDevice, port);
270 }
271 
272 Ipv6EndPoint *
274 {
275  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
276  return m_endPoints6->Allocate (boundNetDevice, address, port);
277 }
278 
279 Ipv6EndPoint *
281  Ipv6Address localAddress, uint16_t localPort,
282  Ipv6Address peerAddress, uint16_t peerPort)
283 {
284  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
285  return m_endPoints6->Allocate (boundNetDevice,
286  localAddress, localPort,
287  peerAddress, peerPort);
288 }
289 
290 void
292 {
293  NS_LOG_FUNCTION (this << endPoint);
294  m_endPoints6->DeAllocate (endPoint);
295 }
296 
297 void
298 TcpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
299  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
300  Ipv4Address payloadSource,Ipv4Address payloadDestination,
301  const uint8_t payload[8])
302 {
303  NS_LOG_FUNCTION (this << icmpSource << (uint16_t) icmpTtl << (uint16_t) icmpType << (uint16_t) icmpCode << icmpInfo
304  << payloadSource << payloadDestination);
305  uint16_t src, dst;
306  src = payload[0] << 8;
307  src |= payload[1];
308  dst = payload[2] << 8;
309  dst |= payload[3];
310 
311  Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloadDestination, dst);
312  if (endPoint != 0)
313  {
314  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
315  }
316  else
317  {
318  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
319  ", destination=" << payloadDestination <<
320  ", src=" << src << ", dst=" << dst);
321  }
322 }
323 
324 void
325 TcpL4Protocol::ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
326  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
327  Ipv6Address payloadSource,Ipv6Address payloadDestination,
328  const uint8_t payload[8])
329 {
330  NS_LOG_FUNCTION (this << icmpSource << (uint16_t) icmpTtl << (uint16_t) icmpType << (uint16_t) icmpCode << icmpInfo
331  << payloadSource << payloadDestination);
332  uint16_t src, dst;
333  src = payload[0] << 8;
334  src |= payload[1];
335  dst = payload[2] << 8;
336  dst |= payload[3];
337 
338  Ipv6EndPoint *endPoint = m_endPoints6->SimpleLookup (payloadSource, src, payloadDestination, dst);
339  if (endPoint != 0)
340  {
341  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
342  }
343  else
344  {
345  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
346  ", destination=" << payloadDestination <<
347  ", src=" << src << ", dst=" << dst);
348  }
349 }
350 
353  const Address &source, const Address &destination)
354 {
355  NS_LOG_FUNCTION (this << packet << incomingTcpHeader << source << destination);
356 
357  if (Node::ChecksumEnabled ())
358  {
359  incomingTcpHeader.EnableChecksums ();
360  incomingTcpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
361  }
362 
363  packet->PeekHeader (incomingTcpHeader);
364 
365  NS_LOG_LOGIC ("TcpL4Protocol " << this
366  << " receiving seq " << incomingTcpHeader.GetSequenceNumber ()
367  << " ack " << incomingTcpHeader.GetAckNumber ()
368  << " flags "<< TcpHeader::FlagsToString (incomingTcpHeader.GetFlags ())
369  << " data size " << packet->GetSize ());
370 
371  if (!incomingTcpHeader.IsChecksumOk ())
372  {
373  NS_LOG_INFO ("Bad checksum, dropping packet!");
375  }
376 
377  return IpL4Protocol::RX_OK;
378 }
379 
380 void
382  const Address &incomingSAddr,
383  const Address &incomingDAddr)
384 {
385  NS_LOG_FUNCTION (this << incomingHeader << incomingSAddr << incomingDAddr);
386 
387  if (!(incomingHeader.GetFlags () & TcpHeader::RST))
388  {
389  // build a RST packet and send
390  Ptr<Packet> rstPacket = Create<Packet> ();
391  TcpHeader outgoingTcpHeader;
392 
393  if (incomingHeader.GetFlags () & TcpHeader::ACK)
394  {
395  // ACK bit was set
396  outgoingTcpHeader.SetFlags (TcpHeader::RST);
397  outgoingTcpHeader.SetSequenceNumber (incomingHeader.GetAckNumber ());
398  }
399  else
400  {
401  outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK);
402  outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0));
403  outgoingTcpHeader.SetAckNumber (incomingHeader.GetSequenceNumber () +
404  SequenceNumber32 (1));
405  }
406 
407  // Remember that parameters refer to the incoming packet; in reply,
408  // we need to swap src/dst
409 
410  outgoingTcpHeader.SetSourcePort (incomingHeader.GetDestinationPort ());
411  outgoingTcpHeader.SetDestinationPort (incomingHeader.GetSourcePort ());
412 
413  SendPacket (rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
414  }
415 }
416 
419  Ipv4Header const &incomingIpHeader,
420  Ptr<Ipv4Interface> incomingInterface)
421 {
422  NS_LOG_FUNCTION (this << packet << incomingIpHeader << incomingInterface);
423 
424  TcpHeader incomingTcpHeader;
425  IpL4Protocol::RxStatus checksumControl;
426 
427  checksumControl = PacketReceived (packet, incomingTcpHeader,
428  incomingIpHeader.GetSource (),
429  incomingIpHeader.GetDestination ());
430 
431  if (checksumControl != IpL4Protocol::RX_OK)
432  {
433  return checksumControl;
434  }
435 
437  endPoints = m_endPoints->Lookup (incomingIpHeader.GetDestination (),
438  incomingTcpHeader.GetDestinationPort (),
439  incomingIpHeader.GetSource (),
440  incomingTcpHeader.GetSourcePort (),
441  incomingInterface);
442 
443  if (endPoints.empty ())
444  {
445  if (this->GetObject<Ipv6L3Protocol> () != 0)
446  {
447  NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
448  Ptr<Ipv6Interface> fakeInterface;
449  Ipv6Header ipv6Header;
450  Ipv6Address src, dst;
451 
452  src = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetSource ());
453  dst = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetDestination ());
454  ipv6Header.SetSourceAddress (src);
455  ipv6Header.SetDestinationAddress (dst);
456  return (this->Receive (packet, ipv6Header, fakeInterface));
457  }
458 
459  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
460  " no endpoints matched." <<
461  " destination IP: " << incomingIpHeader.GetDestination () <<
462  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
463  " source IP: " << incomingIpHeader.GetSource () <<
464  " source port: "<< incomingTcpHeader.GetSourcePort ());
465 
466  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSource (),
467  incomingIpHeader.GetDestination ());
468 
470 
471  }
472 
473  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
474  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
475  " now forwarding it up to endpoint/socket");
476 
477  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
478  incomingTcpHeader.GetSourcePort (),
479  incomingInterface);
480 
481  return IpL4Protocol::RX_OK;
482 }
483 
486  Ipv6Header const &incomingIpHeader,
487  Ptr<Ipv6Interface> interface)
488 {
489  NS_LOG_FUNCTION (this << packet << incomingIpHeader.GetSourceAddress () <<
490  incomingIpHeader.GetDestinationAddress ());
491 
492  TcpHeader incomingTcpHeader;
493  IpL4Protocol::RxStatus checksumControl;
494 
495  // If we are receiving a v4-mapped packet, we will re-calculate the TCP checksum
496  // Is it worth checking every received "v6" packet to see if it is v4-mapped in
497  // order to avoid re-calculating TCP checksums for v4-mapped packets?
498 
499  checksumControl = PacketReceived (packet, incomingTcpHeader,
500  incomingIpHeader.GetSourceAddress (),
501  incomingIpHeader.GetDestinationAddress ());
502 
503  if (checksumControl != IpL4Protocol::RX_OK)
504  {
505  return checksumControl;
506  }
507 
508  Ipv6EndPointDemux::EndPoints endPoints =
509  m_endPoints6->Lookup (incomingIpHeader.GetDestinationAddress (),
510  incomingTcpHeader.GetDestinationPort (),
511  incomingIpHeader.GetSourceAddress (),
512  incomingTcpHeader.GetSourcePort (), interface);
513  if (endPoints.empty ())
514  {
515  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
516  " no endpoints matched." <<
517  " destination IP: " << incomingIpHeader.GetDestinationAddress () <<
518  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
519  " source IP: " << incomingIpHeader.GetSourceAddress () <<
520  " source port: "<< incomingTcpHeader.GetSourcePort ());
521 
522  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSourceAddress (),
523  incomingIpHeader.GetDestinationAddress ());
524 
526  }
527 
528  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
529  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
530  " now forwarding it up to endpoint/socket");
531 
532  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
533  incomingTcpHeader.GetSourcePort (), interface);
534 
535  return IpL4Protocol::RX_OK;
536 }
537 
538 void
540  const Ipv4Address &saddr, const Ipv4Address &daddr,
541  Ptr<NetDevice> oif) const
542 {
543  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
544  NS_LOG_LOGIC ("TcpL4Protocol " << this
545  << " sending seq " << outgoing.GetSequenceNumber ()
546  << " ack " << outgoing.GetAckNumber ()
547  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
548  << " data size " << packet->GetSize ());
549  // XXX outgoingHeader cannot be logged
550 
551  TcpHeader outgoingHeader = outgoing;
553  /* outgoingHeader.SetUrgentPointer (0); */
554  if (Node::ChecksumEnabled ())
555  {
556  outgoingHeader.EnableChecksums ();
557  }
558  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
559 
560  packet->AddHeader (outgoingHeader);
561 
562  Ptr<Ipv4> ipv4 =
563  m_node->GetObject<Ipv4> ();
564  if (ipv4 != 0)
565  {
566  Ipv4Header header;
567  header.SetSource (saddr);
568  header.SetDestination (daddr);
569  header.SetProtocol (PROT_NUMBER);
570  Socket::SocketErrno errno_;
571  Ptr<Ipv4Route> route;
572  if (ipv4->GetRoutingProtocol () != 0)
573  {
574  route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
575  }
576  else
577  {
578  NS_LOG_ERROR ("No IPV4 Routing Protocol");
579  route = 0;
580  }
581  m_downTarget (packet, saddr, daddr, PROT_NUMBER, route);
582  }
583  else
584  {
585  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv4 interface");
586  }
587 }
588 
589 void
591  const Ipv6Address &saddr, const Ipv6Address &daddr,
592  Ptr<NetDevice> oif) const
593 {
594  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
595  NS_LOG_LOGIC ("TcpL4Protocol " << this
596  << " sending seq " << outgoing.GetSequenceNumber ()
597  << " ack " << outgoing.GetAckNumber ()
598  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
599  << " data size " << packet->GetSize ());
600  // XXX outgoingHeader cannot be logged
601 
602  if (daddr.IsIpv4MappedAddress ())
603  {
604  return (SendPacket (packet, outgoing, saddr.GetIpv4MappedAddress (), daddr.GetIpv4MappedAddress (), oif));
605  }
606  TcpHeader outgoingHeader = outgoing;
608  /* outgoingHeader.SetUrgentPointer (0); */
609  if (Node::ChecksumEnabled ())
610  {
611  outgoingHeader.EnableChecksums ();
612  }
613  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
614 
615  packet->AddHeader (outgoingHeader);
616 
618  if (ipv6 != 0)
619  {
620  Ipv6Header header;
621  header.SetSourceAddress (saddr);
622  header.SetDestinationAddress (daddr);
623  header.SetNextHeader (PROT_NUMBER);
624  Socket::SocketErrno errno_;
625  Ptr<Ipv6Route> route;
626  if (ipv6->GetRoutingProtocol () != 0)
627  {
628  route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
629  }
630  else
631  {
632  NS_LOG_ERROR ("No IPV6 Routing Protocol");
633  route = 0;
634  }
635  m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, route);
636  }
637  else
638  {
639  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv6 interface");
640  }
641 }
642 
643 void
645  const Address &saddr, const Address &daddr,
646  Ptr<NetDevice> oif) const
647 {
648  NS_LOG_FUNCTION (this << pkt << outgoing << saddr << daddr << oif);
649  if (Ipv4Address::IsMatchingType (saddr))
650  {
652 
653  SendPacketV4 (pkt, outgoing, Ipv4Address::ConvertFrom (saddr),
654  Ipv4Address::ConvertFrom (daddr), oif);
655 
656  return;
657  }
658  else if (Ipv6Address::IsMatchingType (saddr))
659  {
661 
662  SendPacketV6 (pkt, outgoing, Ipv6Address::ConvertFrom (saddr),
663  Ipv6Address::ConvertFrom (daddr), oif);
664 
665  return;
666  }
667  else if (InetSocketAddress::IsMatchingType (saddr))
668  {
671 
672  SendPacketV4 (pkt, outgoing, s.GetIpv4 (), d.GetIpv4 (), oif);
673 
674  return;
675  }
676  else if (Inet6SocketAddress::IsMatchingType (saddr))
677  {
680 
681  SendPacketV6 (pkt, outgoing, s.GetIpv6 (), d.GetIpv6 (), oif);
682 
683  return;
684  }
685 
686  NS_FATAL_ERROR ("Trying to send a packet without IP addresses");
687 }
688 
689 void
691 {
692  NS_LOG_FUNCTION (this << socket);
693  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
694 
695  while (it != m_sockets.end ())
696  {
697  if (*it == socket)
698  {
699  return;
700  }
701 
702  ++it;
703  }
704 
705  m_sockets.push_back (socket);
706 }
707 
708 bool
710 {
711  NS_LOG_FUNCTION (this << socket);
712  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
713 
714  while (it != m_sockets.end ())
715  {
716  if (*it == socket)
717  {
718  m_sockets.erase (it);
719  return true;
720  }
721 
722  ++it;
723  }
724 
725  return false;
726 }
727 
728 void
730 {
731  m_downTarget = callback;
732 }
733 
736 {
737  return m_downTarget;
738 }
739 
740 void
742 {
743  m_downTarget6 = callback;
744 }
745 
748 {
749  return m_downTarget6;
750 }
751 
752 } // namespace ns3
753 
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:45
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:459
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:796
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:277
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)
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:277
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:968
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.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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:269
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:253
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:1224
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:914
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:256
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.