src/internet/doc/internet-stack.rst
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Fri, 12 Sep 2014 20:47:17 +0200
changeset 10933 7442f5603ef4
parent 10409 4533305686ad
permissions -rw-r--r--
Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
.. include:: replace.txt
10408
5c604e8ec2e1 Models source highlighting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9910
diff changeset
     2
.. highlight:: cpp
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
Internet Stack
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
--------------
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
Internet stack aggregation
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
**************************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
A bare class :cpp:class:`Node` is not very useful as-is; other objects must be
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
aggregated to it to provide useful node functionality.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
7147
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
    13
The |ns3| source code directory ``src/internet`` provides implementation
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
of TCP/IPv4- and IPv6-related components. These include IPv4, ARP, UDP, TCP,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
IPv6, Neighbor Discovery, and other related protocols.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
Internet Nodes are not subclasses of class Node; they are simply Nodes that have
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    18
had a bunch of IP-related objects aggregated to them. They can be put together
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
by hand, or via a helper function :cpp:func:`InternetStackHelper::Install ()`
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
    20
which does the following to all nodes passed in as arguments::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
    void
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
    InternetStackHelper::Install (Ptr<Node> node) const
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
    {
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    25
      if (m_ipv4Enabled)
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
        {
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    27
          /* IPv4 stack */
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    28
          if (node->GetObject<Ipv4> () != 0)
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    29
            {
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    30
              NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating " 
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    31
                              "an InternetStack to a node with an existing Ipv4 object");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    32
              return;
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    33
            }
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    34
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    35
          CreateAndAggregateObjectFromTypeId (node, "ns3::ArpL3Protocol");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    36
          CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv4L3Protocol");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    37
          CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv4L4Protocol");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    38
          // Set routing
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    39
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    40
          Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create (node);
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    41
          ipv4->SetRoutingProtocol (ipv4Routing);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
        }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    44
      if (m_ipv6Enabled)
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    45
        {
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    46
          /* IPv6 stack */
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    47
          if (node->GetObject<Ipv6> () != 0)
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    48
            {
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    49
              NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating " 
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    50
                              "an InternetStack to a node with an existing Ipv6 object");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    51
              return;
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    52
            }
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    53
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    54
          CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv6L3Protocol");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    55
          CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv6L4Protocol");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    56
          // Set routing
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    57
          Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    58
          Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create (node);
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    59
          ipv6->SetRoutingProtocol (ipv6Routing);
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    60
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    61
          /* register IPv6 extensions and options */
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    62
          ipv6->RegisterExtensions ();
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    63
          ipv6->RegisterOptions ();
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    64
        }
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    65
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    66
      if (m_ipv4Enabled || m_ipv6Enabled)
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    67
        {
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    68
          /* UDP and TCP stacks */
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    69
          CreateAndAggregateObjectFromTypeId (node, "ns3::UdpL4Protocol");
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    70
          node->AggregateObject (m_tcpFactory.Create<Object> ());
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    71
          Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    72
          node->AggregateObject (factory);
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    73
        }
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
Where multiple implementations exist in |ns3| (TCP, IP routing), these objects
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
are added by a factory object (TCP) or by a routing helper (m_routing).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
Note that the routing protocol is configured and set outside this
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
    80
function. By default, the following protocols are added::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    82
    void InternetStackHelper::Initialize ()
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
      SetTcp ("ns3::TcpL4Protocol");
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    85
      Ipv4StaticRoutingHelper staticRouting;
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    86
      Ipv4GlobalRoutingHelper globalRouting;
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    87
      Ipv4ListRoutingHelper listRouting;
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    88
      Ipv6ListRoutingHelper listRoutingv6;
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    89
      Ipv6StaticRoutingHelper staticRoutingv6;
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
      listRouting.Add (staticRouting, 0);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
      listRouting.Add (globalRouting, -10);
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    92
      listRoutingv6.Add (staticRoutingv6, 0);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
      SetRoutingHelper (listRouting);
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
    94
      SetRoutingHelper (listRoutingv6);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
By default, IPv4 and IPv6 are enabled.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
Internet Node structure
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
+++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   102
An IP-capable Node (an |ns3| Node augmented by aggregation to have one or more
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
IP stacks) has the following internal structure.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
Layer-3 protocols
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
~~~~~~~~~~~~~~~~~
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
At the lowest layer, sitting above the NetDevices, are the "layer 3" protocols,
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   109
including IPv4, IPv6, ARP and so on. The class
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
:cpp:class:`Ipv4L3Protocol` is an implementation class whose public interface is
7147
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
   111
typically class :cpp:class:`Ipv4`, but the
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
   112
Ipv4L3Protocol public API is also used internally at present.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   114
In class Ipv4L3Protocol, one method described below is ``Receive ()``::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
     /**
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
       * Lower layer calls this method after calling L3Demux::Lookup
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
       * The ARP subclass needs to know from which NetDevice this
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
       * packet is coming to:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
       *    - implement a per-NetDevice ARP cache
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
       *    - send back arp replies on the right device
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
       */
10408
5c604e8ec2e1 Models source highlighting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9910
diff changeset
   123
     void Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, 
5c604e8ec2e1 Models source highlighting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9910
diff changeset
   124
     const Address &from, const Address &to, NetDevice::PacketType packetType);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
First, note that the ``Receive ()`` function has a matching signature to the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
ReceiveCallback in the class :cpp:class:`Node`. This function pointer is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
inserted into the Node's protocol handler when ``AddInterface ()`` is called.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
The actual registration is done
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   130
with a statement such as follows::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
     RegisterProtocolHandler ( MakeCallback (&Ipv4Protocol::Receive, ipv4),
10408
5c604e8ec2e1 Models source highlighting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9910
diff changeset
   133
                               Ipv4L3Protocol::PROT_NUMBER, 0);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
The Ipv4L3Protocol object is aggregated to the Node; there is only one such
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
Ipv4L3Protocol object. Higher-layer protocols that have a packet to send down to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
the Ipv4L3Protocol object can call ``GetObject<Ipv4L3Protocol> ()`` to obtain a
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   138
pointer, as follows::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
  if (ipv4 != 0)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
      ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
This class nicely demonstrates two techniques we exploit in |ns3| to bind
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
objects together:  callbacks, and object aggregation.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
Once IPv4 routing has determined that a packet is for the local node, it
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   150
forwards it up the stack.  This is done with the following function::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
    void
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
    Ipv4L3Protocol::LocalDeliver (Ptr<const Packet> packet, Ipv4Header const&ip, uint32_t iif)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
The first step is to find the right Ipv4L4Protocol object, based on IP protocol
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
number. For instance, TCP is registered in the demux as protocol number 6.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
Finally, the ``Receive()`` function on the Ipv4L4Protocol (such as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
``TcpL4Protocol::Receive`` is called.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
We have not yet introduced the class Ipv4Interface. Basically, each NetDevice is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
paired with an IPv4 representation of such device. In Linux, this class
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
:cpp:class:`Ipv4Interface` roughly corresponds to the ``struct in_device``; the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
main purpose is to provide address-family specific information (addresses) about
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
an interface.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
7699
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   166
All the classes have appropriate traces in order to track sent, received and lost packets.
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   167
The users is encouraged to use them so to find out if (and where) a packet is dropped. A
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   168
common mistake is to forget the effects of local queues when sending packets, e.g., the ARP
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   169
queue. This can be particularly puzzling when sending jumbo packets or packet bursts using UDP.
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   170
The ARP cache pending queue is limited (3 datagrams) and IP packets might be fragmented, easily
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   171
overfilling the ARP cache queue size. In those cases it is useful to increase the ARP cache
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   172
pending size to a proper value, e.g.::
7699
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   173
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   174
    Config::SetDefault ("ns3::ArpCache::PendingQueueSize", UintegerValue (MAX_BURST_SIZE/L2MTU*3));
90904c14135f Bug 1109 - Point out the effects of ArpCache::PendingQueueSize attribute
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7204
diff changeset
   175
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   176
The IPv6 implementation follows a similar architecture.  Dual-stacked nodes (one with
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   177
support for both IPv4 and IPv6) will allow an IPv6 socket to receive IPv4 connections
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   178
as a standard dual-stacked system does.  A socket bound and listening to an IPv6 endpoint
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   179
can receive an IPv4 connection and will return the remote address as an IPv4-mapped address.
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   180
Support for the IPV6_V6ONLY socket option does not currently exist.
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   181
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
Layer-4 protocols and sockets
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
We next describe how the transport protocols, sockets, and applications tie
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
together. In summary, each transport protocol implementation is a socket
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
factory. An application that needs a new socket 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
For instance, to create a UDP socket, an application would use a code snippet
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   191
such as the following::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
      Ptr<Udp> udpSocketFactory = GetNode ()->GetObject<Udp> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
      Ptr<Socket> m_socket = socketFactory->CreateSocket ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
      m_socket->Bind (m_local_address);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
The above will query the node to get a pointer to its UDP socket factory, will
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
create one such socket, and will use the socket with an API similar to the
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   200
C-based sockets API, such as ``Connect ()`` and ``Send ()``.  The address passed
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   201
to the ``Bind ()``, ``Connect ()``, or ``Send ()`` functions may be a
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   202
:cpp:class:`Ipv4Address`, :cpp:class:`Ipv6Address`, or :cpp:class:`Address`.
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   203
If a :cpp:class:`Address` is passed in and contains anything other than
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   204
a :cpp:class:`Ipv4Address` or :cpp:class:`Ipv6Address`, these functions will
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   205
return an error.  The ``Bind (void)`` and ``Bind6 (void)`` functions bind to
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   206
"0.0.0.0" and "::" respectively.
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   207
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   208
The socket can also be bound to a specific NetDevice though the 
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   209
``BindToNetDevice (Ptr<NetDevice> netdevice)`` function.
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   210
``BindToNetDevice (Ptr<NetDevice> netdevice)`` will bind the socket
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   211
to "0.0.0.0" and "::" (equivalent to calling ``Bind ()`` and ``Bind6 ()``,
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   212
unless the socket has been already bound to a specific address.
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   213
Summarizing, the correct sequence is::
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   214
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   215
      Ptr<Udp> udpSocketFactory = GetNode ()->GetObject<Udp> ();
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   216
      Ptr<Socket> m_socket = socketFactory->CreateSocket ();
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   217
      m_socket->BindToNetDevice (n_netDevice);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   218
     ...
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   219
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   220
or::
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   221
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   222
      Ptr<Udp> udpSocketFactory = GetNode ()->GetObject<Udp> ();
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   223
      Ptr<Socket> m_socket = socketFactory->CreateSocket ();
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   224
      m_socket->Bind (m_local_address);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   225
      m_socket->BindToNetDevice (n_netDevice);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   226
      ...
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   227
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   228
The following raises an error::
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   229
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   230
      Ptr<Udp> udpSocketFactory = GetNode ()->GetObject<Udp> ();
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   231
      Ptr<Socket> m_socket = socketFactory->CreateSocket ();
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   232
      m_socket->BindToNetDevice (n_netDevice);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   233
      m_socket->Bind (m_local_address);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   234
      ...
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10409
diff changeset
   235
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7699
diff changeset
   236
See the chapter on |ns3| sockets for more information.  
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
We have described so far a socket factory (e.g. ``class Udp``) and a socket,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
which may be specialized (e.g., class :cpp:class:`UdpSocket`).  There are a few
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
more key objects that relate to the specialized task of demultiplexing a packet
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
to one or more receiving sockets.  The key object in this task is class
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
:cpp:class:`Ipv4EndPointDemux`.  This demultiplexer stores objects of class
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
:cpp:class:`Ipv4EndPoint`.  This class holds the addressing/port tuple (local
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
port, local address, destination port, destination address) associated with the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   245
socket, and a receive callback. This receive callback has a receive function
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
registered by the socket. The ``Lookup ()`` function to Ipv4EndPointDemux
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
returns a list of Ipv4EndPoint objects (there may be a list since more than one
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
socket may match the packet). The layer-4 protocol copies the packet to each
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
Ipv4EndPoint and calls its ``ForwardUp ()`` method, which then calls the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
``Receive ()`` function registered by the socket.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
An issue that arises when working with the sockets API on real
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
systems is the need to manage the reading from a socket, using 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
some type of I/O (e.g., blocking, non-blocking, asynchronous, ...).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
|ns3| implements an asynchronous model for socket I/O; the application
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
sets a callback to be notified of received data ready to be read, and the 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
callback is invoked by the transport protocol when data is available.
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   258
This callback is specified as follows::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
  void Socket::SetRecvCallback (Callback<void, Ptr<Socket>, 
10408
5c604e8ec2e1 Models source highlighting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9910
diff changeset
   261
                                Ptr<Packet>,
5c604e8ec2e1 Models source highlighting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9910
diff changeset
   262
                                const Address&> receivedData);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
The data being received is conveyed in the Packet data buffer.  An example
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10408
diff changeset
   265
usage is in class :cpp:class:`PacketSink`::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
  m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
To summarize, internally, the UDP implementation is organized as follows:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
* a ``UdpImpl`` class that implements the UDP socket factory functionality
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
* a ``UdpL4Protocol`` class that implements the protocol logic that is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
  socket-independent 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
* a ``UdpSocketImpl`` class that implements socket-specific aspects of UDP
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
* a class called ``Ipv4EndPoint`` that stores the addressing tuple (local port,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
  local address, destination port, destination address) associated with the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
  socket, and a receive callback for the socket.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   280
IP-capable node interfaces
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   281
++++++++++++++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
Many of the implementation details, or internal objects themselves, of
9910
e9807cf4a7a5 IPv6 manual
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   284
IP-capable Node objects are not exposed at the simulator public API. This
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
allows for different implementations; for instance, replacing the native |ns3|
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
models with ported TCP/IP stack code. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
 
7147
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
   288
The C++ public APIs of all of these objects is found in the ``src/network``
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
directory, including principally:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
7147
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
   291
* ``address.h``
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
* ``socket.h``
7147
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
   293
* ``node.h``
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6742
diff changeset
   294
* ``packet.h``
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
These are typically base class objects that implement the default values used in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
the implementation, implement access methods to get/set state variables, host
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
attributes, and implement publicly-available methods exposed to clients such as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
``CreateSocket``.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
Example path of a packet
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
++++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
These two figures show an example stack trace of how packets flow through the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
Internet Node objects.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
.. _internet-node-send:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
.. figure:: figures/internet-node-send.*
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
   
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
   Send path of a packet.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
.. _internet-node-recv:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
.. figure:: figures/internet-node-recv.*
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
   
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
   Receive path of a packet.