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 "tcp-recovery-ops.h"
46 #include "rtt-estimator.h"
47 
48 #include <vector>
49 #include <sstream>
50 #include <iomanip>
51 
52 namespace ns3 {
53 
54 NS_LOG_COMPONENT_DEFINE ("TcpL4Protocol");
55 
56 NS_OBJECT_ENSURE_REGISTERED (TcpL4Protocol);
57 
58 //TcpL4Protocol stuff----------------------------------------------------------
59 
60 #undef NS_LOG_APPEND_CONTEXT
61 #define NS_LOG_APPEND_CONTEXT \
62  if (m_node) { std::clog << " [node " << m_node->GetId () << "] "; }
63 
64 /* see http://www.iana.org/assignments/protocol-numbers */
65 const uint8_t TcpL4Protocol::PROT_NUMBER = 6;
66 
67 TypeId
69 {
70  static TypeId tid = TypeId ("ns3::TcpL4Protocol")
72  .SetGroupName ("Internet")
73  .AddConstructor<TcpL4Protocol> ()
74  .AddAttribute ("RttEstimatorType",
75  "Type of RttEstimator objects.",
79  .AddAttribute ("SocketType",
80  "Socket type of TCP objects.",
84  .AddAttribute ("RecoveryType",
85  "Recovery type of TCP objects.",
89  .AddAttribute ("SocketList", "The list of sockets associated to this protocol.",
92  MakeObjectVectorChecker<TcpSocketBase> ())
93  ;
94  return tid;
95 }
96 
98  : m_endPoints (new Ipv4EndPointDemux ()), m_endPoints6 (new Ipv6EndPointDemux ())
99 {
100  NS_LOG_FUNCTION (this);
101 }
102 
104 {
105  NS_LOG_FUNCTION (this);
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION (this);
112  m_node = node;
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this);
119  Ptr<Node> node = this->GetObject<Node> ();
120  Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> ();
121  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
122 
123  if (m_node == 0)
124  {
125  if ((node != 0) && (ipv4 != 0 || ipv6 != 0))
126  {
127  this->SetNode (node);
128  Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
129  tcpFactory->SetTcp (this);
130  node->AggregateObject (tcpFactory);
131  }
132  }
133 
134  // We set at least one of our 2 down targets to the IPv4/IPv6 send
135  // functions. Since these functions have different prototypes, we
136  // need to keep track of whether we are connected to an IPv4 or
137  // IPv6 lower layer and call the appropriate one.
138 
139  if (ipv4 != 0 && m_downTarget.IsNull ())
140  {
141  ipv4->Insert (this);
142  this->SetDownTarget (MakeCallback (&Ipv4::Send, ipv4));
143  }
144  if (ipv6 != 0 && m_downTarget6.IsNull ())
145  {
146  ipv6->Insert (this);
147  this->SetDownTarget6 (MakeCallback (&Ipv6::Send, ipv6));
148  }
150 }
151 
152 int
154 {
155  return PROT_NUMBER;
156 }
157 
158 void
160 {
161  NS_LOG_FUNCTION (this);
162  m_sockets.clear ();
163 
164  if (m_endPoints != 0)
165  {
166  delete m_endPoints;
167  m_endPoints = 0;
168  }
169 
170  if (m_endPoints6 != 0)
171  {
172  delete m_endPoints6;
173  m_endPoints6 = 0;
174  }
175 
176  m_node = 0;
180 }
181 
184 {
185  return CreateSocket (congestionTypeId, m_recoveryTypeId);
186 }
187 
189 TcpL4Protocol::CreateSocket (TypeId congestionTypeId, TypeId recoveryTypeId)
190 {
191  NS_LOG_FUNCTION (this << congestionTypeId.GetName ());
192  ObjectFactory rttFactory;
193  ObjectFactory congestionAlgorithmFactory;
194  ObjectFactory recoveryAlgorithmFactory;
195  rttFactory.SetTypeId (m_rttTypeId);
196  congestionAlgorithmFactory.SetTypeId (congestionTypeId);
197  recoveryAlgorithmFactory.SetTypeId (recoveryTypeId);
198 
199  Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator> ();
200  Ptr<TcpSocketBase> socket = CreateObject<TcpSocketBase> ();
201  Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps> ();
202  Ptr<TcpRecoveryOps> recovery = recoveryAlgorithmFactory.Create<TcpRecoveryOps> ();
203 
204  socket->SetNode (m_node);
205  socket->SetTcp (this);
206  socket->SetRtt (rtt);
207  socket->SetCongestionControlAlgorithm (algo);
208  socket->SetRecoveryAlgorithm (recovery);
209 
210  m_sockets.push_back (socket);
211  return socket;
212 }
213 
216 {
218 }
219 
220 Ipv4EndPoint *
222 {
223  NS_LOG_FUNCTION (this);
224  return m_endPoints->Allocate ();
225 }
226 
227 Ipv4EndPoint *
229 {
230  NS_LOG_FUNCTION (this << address);
231  return m_endPoints->Allocate (address);
232 }
233 
234 Ipv4EndPoint *
235 TcpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port)
236 {
237  NS_LOG_FUNCTION (this << boundNetDevice << port);
238  return m_endPoints->Allocate (boundNetDevice, port);
239 }
240 
241 Ipv4EndPoint *
243 {
244  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
245  return m_endPoints->Allocate (boundNetDevice, address, port);
246 }
247 
248 Ipv4EndPoint *
250  Ipv4Address localAddress, uint16_t localPort,
251  Ipv4Address peerAddress, uint16_t peerPort)
252 {
253  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
254  return m_endPoints->Allocate (boundNetDevice,
255  localAddress, localPort,
256  peerAddress, peerPort);
257 }
258 
259 void
261 {
262  NS_LOG_FUNCTION (this << endPoint);
263  m_endPoints->DeAllocate (endPoint);
264 }
265 
266 Ipv6EndPoint *
268 {
269  NS_LOG_FUNCTION (this);
270  return m_endPoints6->Allocate ();
271 }
272 
273 Ipv6EndPoint *
275 {
276  NS_LOG_FUNCTION (this << address);
277  return m_endPoints6->Allocate (address);
278 }
279 
280 Ipv6EndPoint *
281 TcpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port)
282 {
283  NS_LOG_FUNCTION (this << boundNetDevice << port);
284  return m_endPoints6->Allocate (boundNetDevice, port);
285 }
286 
287 Ipv6EndPoint *
289 {
290  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
291  return m_endPoints6->Allocate (boundNetDevice, address, port);
292 }
293 
294 Ipv6EndPoint *
296  Ipv6Address localAddress, uint16_t localPort,
297  Ipv6Address peerAddress, uint16_t peerPort)
298 {
299  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
300  return m_endPoints6->Allocate (boundNetDevice,
301  localAddress, localPort,
302  peerAddress, peerPort);
303 }
304 
305 void
307 {
308  NS_LOG_FUNCTION (this << endPoint);
309  m_endPoints6->DeAllocate (endPoint);
310 }
311 
312 void
313 TcpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
314  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
315  Ipv4Address payloadSource,Ipv4Address payloadDestination,
316  const uint8_t payload[8])
317 {
318  NS_LOG_FUNCTION (this << icmpSource << (uint16_t) icmpTtl << (uint16_t) icmpType << (uint16_t) 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  Ipv4EndPoint *endPoint = m_endPoints->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 
339 void
340 TcpL4Protocol::ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
341  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
342  Ipv6Address payloadSource,Ipv6Address payloadDestination,
343  const uint8_t payload[8])
344 {
345  NS_LOG_FUNCTION (this << icmpSource << (uint16_t) icmpTtl << (uint16_t) icmpType << (uint16_t) icmpCode << icmpInfo
346  << payloadSource << payloadDestination);
347  uint16_t src, dst;
348  src = payload[0] << 8;
349  src |= payload[1];
350  dst = payload[2] << 8;
351  dst |= payload[3];
352 
353  Ipv6EndPoint *endPoint = m_endPoints6->SimpleLookup (payloadSource, src, payloadDestination, dst);
354  if (endPoint != 0)
355  {
356  endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
357  }
358  else
359  {
360  NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
361  ", destination=" << payloadDestination <<
362  ", src=" << src << ", dst=" << dst);
363  }
364 }
365 
368  const Address &source, const Address &destination)
369 {
370  NS_LOG_FUNCTION (this << packet << incomingTcpHeader << source << destination);
371 
372  if (Node::ChecksumEnabled ())
373  {
374  incomingTcpHeader.EnableChecksums ();
375  incomingTcpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
376  }
377 
378  packet->PeekHeader (incomingTcpHeader);
379 
380  NS_LOG_LOGIC ("TcpL4Protocol " << this
381  << " receiving seq " << incomingTcpHeader.GetSequenceNumber ()
382  << " ack " << incomingTcpHeader.GetAckNumber ()
383  << " flags "<< TcpHeader::FlagsToString (incomingTcpHeader.GetFlags ())
384  << " data size " << packet->GetSize ());
385 
386  if (!incomingTcpHeader.IsChecksumOk ())
387  {
388  NS_LOG_INFO ("Bad checksum, dropping packet!");
390  }
391 
392  return IpL4Protocol::RX_OK;
393 }
394 
395 void
397  const Address &incomingSAddr,
398  const Address &incomingDAddr)
399 {
400  NS_LOG_FUNCTION (this << incomingHeader << incomingSAddr << incomingDAddr);
401 
402  if (!(incomingHeader.GetFlags () & TcpHeader::RST))
403  {
404  // build a RST packet and send
405  Ptr<Packet> rstPacket = Create<Packet> ();
406  TcpHeader outgoingTcpHeader;
407 
408  if (incomingHeader.GetFlags () & TcpHeader::ACK)
409  {
410  // ACK bit was set
411  outgoingTcpHeader.SetFlags (TcpHeader::RST);
412  outgoingTcpHeader.SetSequenceNumber (incomingHeader.GetAckNumber ());
413  }
414  else
415  {
416  outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK);
417  outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0));
418  outgoingTcpHeader.SetAckNumber (incomingHeader.GetSequenceNumber () +
419  SequenceNumber32 (1));
420  }
421 
422  // Remember that parameters refer to the incoming packet; in reply,
423  // we need to swap src/dst
424 
425  outgoingTcpHeader.SetSourcePort (incomingHeader.GetDestinationPort ());
426  outgoingTcpHeader.SetDestinationPort (incomingHeader.GetSourcePort ());
427 
428  SendPacket (rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
429  }
430 }
431 
434  Ipv4Header const &incomingIpHeader,
435  Ptr<Ipv4Interface> incomingInterface)
436 {
437  NS_LOG_FUNCTION (this << packet << incomingIpHeader << incomingInterface);
438 
439  TcpHeader incomingTcpHeader;
440  IpL4Protocol::RxStatus checksumControl;
441 
442  checksumControl = PacketReceived (packet, incomingTcpHeader,
443  incomingIpHeader.GetSource (),
444  incomingIpHeader.GetDestination ());
445 
446  if (checksumControl != IpL4Protocol::RX_OK)
447  {
448  return checksumControl;
449  }
450 
452  endPoints = m_endPoints->Lookup (incomingIpHeader.GetDestination (),
453  incomingTcpHeader.GetDestinationPort (),
454  incomingIpHeader.GetSource (),
455  incomingTcpHeader.GetSourcePort (),
456  incomingInterface);
457 
458  if (endPoints.empty ())
459  {
460  if (this->GetObject<Ipv6L3Protocol> () != 0)
461  {
462  NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
463  Ptr<Ipv6Interface> fakeInterface;
464  Ipv6Header ipv6Header;
465  Ipv6Address src, dst;
466 
467  src = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetSource ());
468  dst = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetDestination ());
469  ipv6Header.SetSourceAddress (src);
470  ipv6Header.SetDestinationAddress (dst);
471  return (this->Receive (packet, ipv6Header, fakeInterface));
472  }
473 
474  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
475  " no endpoints matched." <<
476  " destination IP: " << incomingIpHeader.GetDestination () <<
477  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
478  " source IP: " << incomingIpHeader.GetSource () <<
479  " source port: "<< incomingTcpHeader.GetSourcePort ());
480 
481  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSource (),
482  incomingIpHeader.GetDestination ());
483 
485 
486  }
487 
488  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
489  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
490  " now forwarding it up to endpoint/socket");
491 
492  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
493  incomingTcpHeader.GetSourcePort (),
494  incomingInterface);
495 
496  return IpL4Protocol::RX_OK;
497 }
498 
501  Ipv6Header const &incomingIpHeader,
502  Ptr<Ipv6Interface> interface)
503 {
504  NS_LOG_FUNCTION (this << packet << incomingIpHeader.GetSourceAddress () <<
505  incomingIpHeader.GetDestinationAddress ());
506 
507  TcpHeader incomingTcpHeader;
508  IpL4Protocol::RxStatus checksumControl;
509 
510  // If we are receiving a v4-mapped packet, we will re-calculate the TCP checksum
511  // Is it worth checking every received "v6" packet to see if it is v4-mapped in
512  // order to avoid re-calculating TCP checksums for v4-mapped packets?
513 
514  checksumControl = PacketReceived (packet, incomingTcpHeader,
515  incomingIpHeader.GetSourceAddress (),
516  incomingIpHeader.GetDestinationAddress ());
517 
518  if (checksumControl != IpL4Protocol::RX_OK)
519  {
520  return checksumControl;
521  }
522 
523  Ipv6EndPointDemux::EndPoints endPoints =
524  m_endPoints6->Lookup (incomingIpHeader.GetDestinationAddress (),
525  incomingTcpHeader.GetDestinationPort (),
526  incomingIpHeader.GetSourceAddress (),
527  incomingTcpHeader.GetSourcePort (), interface);
528  if (endPoints.empty ())
529  {
530  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet but"
531  " no endpoints matched." <<
532  " destination IP: " << incomingIpHeader.GetDestinationAddress () <<
533  " destination port: "<< incomingTcpHeader.GetDestinationPort () <<
534  " source IP: " << incomingIpHeader.GetSourceAddress () <<
535  " source port: "<< incomingTcpHeader.GetSourcePort ());
536 
537  NoEndPointsFound (incomingTcpHeader, incomingIpHeader.GetSourceAddress (),
538  incomingIpHeader.GetDestinationAddress ());
539 
541  }
542 
543  NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint");
544  NS_LOG_LOGIC ("TcpL4Protocol " << this << " received a packet and"
545  " now forwarding it up to endpoint/socket");
546 
547  (*endPoints.begin ())->ForwardUp (packet, incomingIpHeader,
548  incomingTcpHeader.GetSourcePort (), interface);
549 
550  return IpL4Protocol::RX_OK;
551 }
552 
553 void
555  const Ipv4Address &saddr, const Ipv4Address &daddr,
556  Ptr<NetDevice> oif) const
557 {
558  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
559  NS_LOG_LOGIC ("TcpL4Protocol " << this
560  << " sending seq " << outgoing.GetSequenceNumber ()
561  << " ack " << outgoing.GetAckNumber ()
562  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
563  << " data size " << packet->GetSize ());
564  // XXX outgoingHeader cannot be logged
565 
566  TcpHeader outgoingHeader = outgoing;
568  /* outgoingHeader.SetUrgentPointer (0); */
569  if (Node::ChecksumEnabled ())
570  {
571  outgoingHeader.EnableChecksums ();
572  }
573  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
574 
575  packet->AddHeader (outgoingHeader);
576 
577  Ptr<Ipv4> ipv4 =
578  m_node->GetObject<Ipv4> ();
579  if (ipv4 != 0)
580  {
581  Ipv4Header header;
582  header.SetSource (saddr);
583  header.SetDestination (daddr);
584  header.SetProtocol (PROT_NUMBER);
585  Socket::SocketErrno errno_;
586  Ptr<Ipv4Route> route;
587  if (ipv4->GetRoutingProtocol () != 0)
588  {
589  route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
590  }
591  else
592  {
593  NS_LOG_ERROR ("No IPV4 Routing Protocol");
594  route = 0;
595  }
596  m_downTarget (packet, saddr, daddr, PROT_NUMBER, route);
597  }
598  else
599  {
600  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv4 interface");
601  }
602 }
603 
604 void
606  const Ipv6Address &saddr, const Ipv6Address &daddr,
607  Ptr<NetDevice> oif) const
608 {
609  NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
610  NS_LOG_LOGIC ("TcpL4Protocol " << this
611  << " sending seq " << outgoing.GetSequenceNumber ()
612  << " ack " << outgoing.GetAckNumber ()
613  << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
614  << " data size " << packet->GetSize ());
615  // XXX outgoingHeader cannot be logged
616 
617  if (daddr.IsIpv4MappedAddress ())
618  {
619  return (SendPacket (packet, outgoing, saddr.GetIpv4MappedAddress (), daddr.GetIpv4MappedAddress (), oif));
620  }
621  TcpHeader outgoingHeader = outgoing;
623  /* outgoingHeader.SetUrgentPointer (0); */
624  if (Node::ChecksumEnabled ())
625  {
626  outgoingHeader.EnableChecksums ();
627  }
628  outgoingHeader.InitializeChecksum (saddr, daddr, PROT_NUMBER);
629 
630  packet->AddHeader (outgoingHeader);
631 
633  if (ipv6 != 0)
634  {
635  Ipv6Header header;
636  header.SetSourceAddress (saddr);
637  header.SetDestinationAddress (daddr);
638  header.SetNextHeader (PROT_NUMBER);
639  Socket::SocketErrno errno_;
640  Ptr<Ipv6Route> route;
641  if (ipv6->GetRoutingProtocol () != 0)
642  {
643  route = ipv6->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
644  }
645  else
646  {
647  NS_LOG_ERROR ("No IPV6 Routing Protocol");
648  route = 0;
649  }
650  m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, route);
651  }
652  else
653  {
654  NS_FATAL_ERROR ("Trying to use Tcp on a node without an Ipv6 interface");
655  }
656 }
657 
658 void
660  const Address &saddr, const Address &daddr,
661  Ptr<NetDevice> oif) const
662 {
663  NS_LOG_FUNCTION (this << pkt << outgoing << saddr << daddr << oif);
664  if (Ipv4Address::IsMatchingType (saddr))
665  {
667 
668  SendPacketV4 (pkt, outgoing, Ipv4Address::ConvertFrom (saddr),
669  Ipv4Address::ConvertFrom (daddr), oif);
670 
671  return;
672  }
673  else if (Ipv6Address::IsMatchingType (saddr))
674  {
676 
677  SendPacketV6 (pkt, outgoing, Ipv6Address::ConvertFrom (saddr),
678  Ipv6Address::ConvertFrom (daddr), oif);
679 
680  return;
681  }
682  else if (InetSocketAddress::IsMatchingType (saddr))
683  {
686 
687  SendPacketV4 (pkt, outgoing, s.GetIpv4 (), d.GetIpv4 (), oif);
688 
689  return;
690  }
691  else if (Inet6SocketAddress::IsMatchingType (saddr))
692  {
695 
696  SendPacketV6 (pkt, outgoing, s.GetIpv6 (), d.GetIpv6 (), oif);
697 
698  return;
699  }
700 
701  NS_FATAL_ERROR ("Trying to send a packet without IP addresses");
702 }
703 
704 void
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  return;
715  }
716 
717  ++it;
718  }
719 
720  m_sockets.push_back (socket);
721 }
722 
723 bool
725 {
726  NS_LOG_FUNCTION (this << socket);
727  std::vector<Ptr<TcpSocketBase> >::iterator it = m_sockets.begin ();
728 
729  while (it != m_sockets.end ())
730  {
731  if (*it == socket)
732  {
733  m_sockets.erase (it);
734  return true;
735  }
736 
737  ++it;
738  }
739 
740  return false;
741 }
742 
743 void
745 {
746  m_downTarget = callback;
747 }
748 
751 {
752  return m_downTarget;
753 }
754 
755 void
757 {
758  m_downTarget6 = callback;
759 }
760 
763 {
764  return m_downTarget6;
765 }
766 
767 } // namespace ns3
768 
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
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)
std::string GetName(void) const
Get the name.
Definition: type-id.cc:977
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
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 "...
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
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...
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
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.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
uint16_t GetSourcePort() const
Get the source port.
Definition: tcp-header.cc:131
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
static bool ChecksumEnabled(void)
Definition: node.cc:278
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
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:205
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.
uint16_t GetDestinationPort() const
Get the destination port.
Definition: tcp-header.cc:137
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
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)
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:281
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
recovery abstract class
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
TypeId m_recoveryTypeId
The recovery TypeId.
static TypeId GetTypeId(void)
Get the type ID.
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
static TypeId GetTypeId(void)
Get the type ID.
void AddSocket(Ptr< TcpSocketBase > socket)
Make a socket fully operational.
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
uint16_t port
Definition: dsdv-manet.cc:45
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.
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Base class for all RTT Estimators.
Definition: rtt-estimator.h:43
Ipv6EndPoint * Allocate(void)
Allocate a Ipv6EndPoint.
AttributeValue implementation for TypeId.
Definition: type-id.h:595
An Inet6 address class.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
static bool IsMatchingType(const Address &address)
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:100
std::vector< Ptr< TcpSocketBase > > m_sockets
list of sockets
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...
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
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
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.
address
Definition: first.py:44
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.
bool IsChecksumOk(void) const
Is the TCP checksum correct ?
Definition: tcp-header.cc:264
Ipv6EndPoint * SimpleLookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
Simple lookup for a four-tuple match.
Congestion control abstract class.
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
Definition: type-id.cc:1227
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")
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.
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
void SetSourceAddress(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:95
Describes an IPv6 address.
Definition: ipv6-address.h:49
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:595
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
static TypeId GetTypeId(void)
Get the type ID.
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)
Demultiplexer for end points.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
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...
static bool IsMatchingType(const Address &addr)
If the address match.
TypeId m_rttTypeId
The RTT Estimator TypeId.
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1391
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:257
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:143
static Ipv4Address ConvertFrom(const Address &address)
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.
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:110
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
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...
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:923
static bool IsMatchingType(const Address &address)
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
A representation of an internet endpoint/connection.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
Ipv4Address GetIpv4(void) const
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.