doc/manual/source/tcp.rst
author Mitch Watrous <watrous@u.washington.edu>
Mon, 09 May 2011 18:04:52 -0700
changeset 7145 a925e518220b
parent 7024 4392d52b3536
child 7147 71adbc0422a5
permissions -rw-r--r--
Rescan wifi's bindings and fix some paths in the documentation
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
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
TCP models in ns-3
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
------------------
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
This chapter describes the TCP models available in |ns3|.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
Generic support for TCP
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
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
|ns3| was written to support multiple TCP implementations. The implementations
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
inherit from a few common header classes in the ``src/node`` directory, so that
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
user code can swap out implementations with minimal changes to the scripts.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
There are two important abstract base classes:
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
* class :cpp:class:`TcpSocket`:  This is defined in
6766
4caf532b12c3 formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 6751
diff changeset
    18
  ``src/node/tcp-socket.{cc,h}``. This class exists for hosting TcpSocket
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
  attributes that can be reused across different implementations. For instance,
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    20
  the attribute ``InitialCwnd`` can be used for any of the implementations
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
  that derive from class :cpp:class:`TcpSocket`.
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    22
* class :cpp:class:`TcpSocketFactory`:  This is used by the layer-4 protocol
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    23
  instance to create TCP sockets of the right type.
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    24
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    25
There are presently two implementations of TCP available for |ns3|.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    27
* a natively implemented TCP for ns-3
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    28
* support for the `Network Simulation Cradle (NSC) <http://www.wand.net.nz/~stj2/nsc/>`_
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    30
It should also be mentioned that various ways of combining virtual machines
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    31
with |ns3| makes available also some additional TCP implementations, but
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    32
those are out of scope for this chapter.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
ns-3 TCP
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
********
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    37
Until ns-3.10 release, |ns3| contained a port of the TCP model from `GTNetS
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    38
<http://www.ece.gatech.edu/research/labs/MANIACS/GTNetS/index.html>`_. 
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    39
This implementation was substantially rewritten by Adriam Tam for ns-3.10.
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    40
The model is a full TCP, in that it is bidirectional and attempts to model the
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    41
connection setup and close logic. 
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
The implementation of TCP is contained in the following files:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
    src/internet-stack/tcp-header.{cc,h}
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
    src/internet-stack/tcp-l4-protocol.{cc,h}
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
    src/internet-stack/tcp-socket-factory-impl.{cc,h}
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    48
    src/internet-stack/tcp-socket-base.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    49
    src/internet-stack/tcp-tx-buffer.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    50
    src/internet-stack/tcp-rx-buffer.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    51
    src/internet-stack/tcp-rfc793.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    52
    src/internet-stack/tcp-tahoe.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    53
    src/internet-stack/tcp-reno.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    54
    src/internet-stack/tcp-newreno.{cc,h}
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
    src/internet-stack/rtt-estimator.{cc,h}
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    56
    src/common/sequence-number.{cc,h}
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    57
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    58
Different variants of TCP congestion control are supported by subclassing
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    59
the common base class :cpp:class:`TcpSocketBase`.  Several variants
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    60
are supported, including RFC 793 (no congestion control), Tahoe, Reno,
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    61
and NewReno.  NewReno is used by default.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
Usage
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
+++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    66
In many cases, usage of TCP is set at the application layer by telling
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    67
the |ns3| application which kind of socket factory to use.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
Using the helper functions defined in ``src/helper``, here is how
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
one would create a TCP receiver:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
  // Create a packet sink on the star "hub" to receive these packets
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  uint16_t port = 50000;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
  Address sinkLocalAddress(InetSocketAddress (Ipv4Address::GetAny (), port));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  ApplicationContainer sinkApp = sinkHelper.Install (serverNode);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  sinkApp.Start (Seconds (1.0));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
  sinkApp.Stop (Seconds (10.0));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
Similarly, the below snippet configures OnOffApplication traffic source to use
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
TCP:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
  // Create the OnOff applications to send TCP to the server
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
  OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
The careful reader will note above that we have specified the TypeId of an
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
abstract base class :cpp:class:`TcpSocketFactory`. How does the script tell
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
|ns3| that it wants the native |ns3| TCP vs. some other one?  Well, when
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
internet stacks are added to the node, the default TCP implementation that is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
aggregated to the node is the |ns3| TCP.  This can be overridden as we show
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
below when using Network Simulation Cradle. So, by default, when using the |ns3|
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
helper API, the TCP that is aggregated to nodes with an Internet stack is the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
native |ns3| TCP.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    95
To configure behavior of TCP, a number of parameters are exported through the
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    96
:ref:`Attributes <ns-3 attribute system>`. These are documented in the `Doxygen
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    97
<http://www.nsnam.org/doxygen/classns3_1_1_tcp_socket.html>` for class
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    98
:cpp:class:`TcpSocket`.  For example, the maximum segment size is a
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
    99
settable attribute.
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   100
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   101
For users who wish to have a pointer to the actual socket (so that
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   102
socket operations like Bind(), setting socket options, etc. can be
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   103
done on a per-socket basis), Tcp sockets can be created by using the 
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   104
``Socket::CreateSocket()`` method and passing in the TypeId 
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   105
corresponding to the type of socket desired; e.g.::: 
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   106
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   107
      // Create the socket if not already created
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   108
      TypeId tid = TypeId::LookupByName ("ns3::TcpTahoe");
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   109
      Ptr<Socket> localSocket = Socket::CreateSocket (node, tid);
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   110
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   111
The parameter ``tid`` controls the TypeId of the actual TCP Socket
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   112
implementation that is instantiated. This way, the application can be written
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   113
generically and different socket implementations can be swapped out by
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   114
specifying the TypeId.
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   115
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   116
Once a TCP socket is created, one will want to follow conventional socket logic
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
and either connect() and send() (for a TCP client) or bind(), listen(), and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
accept() (for a TCP server). :ref:`Sockets API <Sockets APIs>` for a review of
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
how sockets are used in |ns3|.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   121
Validation
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   122
++++++++++
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   123
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   124
Several TCP validation test results can be found in the
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   125
`wiki page <http://www.nsnam.org/wiki/index.php/New_TCP_Socket_Architecture>`_ 
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   126
describing this implementation.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
Current limitations
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
+++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
6751
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   131
* Only IPv4 is supported
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   132
* Neither the Nagle algorithm nor SACK are supported
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
Network Simulation Cradle
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
*************************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
The `Network Simulation Cradle (NSC) <http://www.wand.net.nz/~stj2/nsc/>`_ is a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
framework for wrapping real-world network code into simulators, allowing
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
simulation of real-world behavior at little extra cost. This work has been
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
validated by comparing situations using a test network with the same situations
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
in the simulator. To date, it has been shown that the NSC is able to produce
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
extremely accurate results.  NSC supports four real world stacks: FreeBSD,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
OpenBSD, lwIP and Linux. Emphasis has been placed on not changing any of the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
network stacks by hand. Not a single line of code has been changed in the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
network protocol implementations of any of the above four stacks. However, a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
custom C parser was built to programmatically change source code.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
NSC has previously been ported to |ns2| and OMNeT++, and recently 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
was added to |ns3|.  This section describes the |ns3| port of NSC and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
how to use it.
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
Prerequisites
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
+++++++++++++
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
Presently, NSC has been tested and shown to work on these platforms:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
Linux i386 and Linux x86-64. NSC does not support powerpc.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
Building NSC requires the packages flex and bison.  
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
Configuring and Downloading
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
+++++++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
Using the ``build.py`` script in ns-3-allinone directory, NSC will be enabled by
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
default unless the platform does not support it. To disable it when building
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
|ns3|, type:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
7024
4392d52b3536 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 6998
diff changeset
   167
./waf configure --enable-examples --enable-tests --disable-nsc
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
Building and validating
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
+++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
Building |ns3| with nsc support is the same as building it without; no
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
additional arguments are needed for waf. Building nsc may take some time
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
compared to |ns3|; it is interleaved in the |ns3| building process.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
6751
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   176
Try running the following ns-3 test suite:::  
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   177
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   178
    ./test.py -s ns3-tcp-interoperability
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
6751
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   180
If NSC has been successfully built, the following test should show up 
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   181
in the results:::
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   182
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   183
    PASS TestSuite ns3-tcp-interoperability
6742
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
This confirms that NSC is ready to use.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
Usage
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
+++++
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
There are a few example files.  Try::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
    ./waf --run tcp-nsc-zoo
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
    ./waf --run tcp-nsc-lfn
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
These examples will deposit some ``.pcap`` files in your directory,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
which can be examined by tcpdump or wireshark.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
7145
a925e518220b Rescan wifi's bindings and fix some paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7024
diff changeset
   198
Let's look at the ``examples/tcp/tcp-nsc-zoo.cc`` file for some typical
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
usage. How does it differ from using native |ns3| TCP? There is one main
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
configuration line, when using NSC and the |ns3| helper API, that needs to be
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
set:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
  InternetStackHelper internetStack;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
  internetStack.SetNscStack ("liblinux2.6.26.so");
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
  // this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
  internetStack.Install (n.Get(0));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
  internetStack.Install (n.Get(1));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
The key line is the ``SetNscStack``.  This tells the InternetStack
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
helper to aggregate instances of NSC TCP instead of native |ns3| TCP
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
to the remaining nodes.  It is important that this function be called
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
**before** calling the ``Install()`` function, as shown above.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
Which stacks are available to use? Presently, the focus has been on
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
Linux 2.6.18 and Linux 2.6.26 stacks for |ns3|. To see which stacks
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
were built, one can execute the following find command at the |ns3| top level
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
directory:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
6751
700a92acb8ec add back manual changes made since ns-3.9
Tom Henderson <tomh@tomh.org>
parents: 6742
diff changeset
   221
    ~/ns-3.10> find nsc -name "*.so" -type f 
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
    nsc/linux-2.6.18/liblinux2.6.18.so
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
    nsc/linux-2.6.26/liblinux2.6.26.so
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
This tells us that we may either pass the library name liblinux2.6.18.so or
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
liblinux2.6.26.so to the above configuration step.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
Stack configuration
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
+++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
NSC TCP shares the same configuration attributes that are common across TCP
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
sockets, as described above and documented in `Doxygen
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
<http://www.nsnam.org/doxygen/classns3_1_1_tcp_socket.html>`_
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   234
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
Additionally, NSC TCP exports a lot of configuration variables into the 
7145
a925e518220b Rescan wifi's bindings and fix some paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7024
diff changeset
   236
|ns3| :ref:`Attributes` system, via a `sysctl <http://en.wikipedia.org/wiki/Sysctl>`_-like interface. In the ``examples/tcp/tcp-nsc-zoo`` example, you
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
can see the following configuration:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
  // this disables TCP SACK, wscale and timestamps on node 1 (the attributes 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
    represent sysctl-values).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
  Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
    StringValue ("0"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
  Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   245
  StringValue ("0"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
  Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
  StringValue ("0"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
These additional configuration variables are not available to native |ns3| TCP.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
NSC API
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
+++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
This subsection describes the API that NSC presents to |ns3| or any other
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
simulator. NSC provides its API in the form of a number of classes that are
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
defined in ``sim/sim_interface.h`` in the nsc directory.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
* **INetStack** INetStack contains the 'low level' operations for the operating
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
  system network stack, e.g. in and output functions from and to the network
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
  stack (think of this as the 'network driver interface'. There are also
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
  functions to create new TCP or UDP sockets.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
* **ISendCallback** This is called by NSC when a packet should be sent out to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
  the network. This simulator should use this callback to re-inject the packet
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
  into the simulator so the actual data can be delivered/routed to its
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
  destination, where it will eventually be handed into Receive() (and eventually
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
  back to the receivers NSC instance via INetStack->if_receive() ).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
* **INetStreamSocket** This is the structure defining a particular connection
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
  endpoint (file descriptor). It contains methods to operate on this endpoint,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
  e.g. connect, disconnect, accept, listen, send_data/read_data, ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
* **IInterruptCallback** This contains the wakeup callback, which is called by
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
  NSC whenever something of interest happens. Think of wakeup() as a replacement
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
  of the operating systems wakeup function: Whenever the operating system would
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
  wake up a process that has been waiting for an operation to complete (for
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
  example the TCP handshake during connect()), NSC invokes the wakeup() callback
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
  to allow the simulator to check for state changes in its connection endpoints. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
ns-3 implementation
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
+++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
The |ns3| implementation makes use of the above NSC API, and is implemented as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
follows.
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
The three main parts are:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   284
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
* :cpp:class:`ns3::NscTcpL4Protocol`:  a subclass of Ipv4L4Protocol (and two nsc
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
  classes: ISendCallback and IInterruptCallback)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
* :cpp:class:`ns3::NscTcpSocketImpl`: a subclass of TcpSocket 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
* :cpp:class:`ns3::NscTcpSocketFactoryImpl`:  a factory to create new NSC
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
  sockets
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   291
``src/internet-stack/nsc-tcp-l4-protocol`` is the main class. Upon
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
Initialization, it loads an nsc network stack to use (via dlopen()). Each
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   293
instance of this class may use a different stack. The stack (=shared library) to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
use is set using the SetNscLibrary() method (at this time its called indirectly
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
via the internet stack helper). The nsc stack is then set up accordingly (timers
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
etc). The NscTcpL4Protocol::Receive() function hands the packet it receives
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
(must be a complete tcp/ip packet) to the nsc stack for further processing.  To
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
be able to send packets, this class implements the nsc send_callback method.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
This method is called by nsc whenever the nsc stack wishes to send a packet out
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
to the network. Its arguments are a raw buffer, containing a complete TCP/IP
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
packet, and a length value. This method therefore has to convert the raw data to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
a Ptr<Packet> usable by |ns3|. In order to avoid various ipv4 header issues,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
the nsc ip header is not included. Instead, the tcp header and the actual
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
payload are put into the Ptr<Packet>, after this the Packet is passed down to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
layer 3 for sending the packet out (no further special treatment is needed in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
the send code path).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
This class calls ``ns3::NscTcpSocketImpl`` both from the nsc wakeup() callback
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
and from the Receive path (to ensure that possibly queued data is scheduled for
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
sending).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
``src/internet-stack/nsc-tcp-socket-impl`` implements the nsc socket interface.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
Each instance has its own nscTcpSocket. Data that is Send() will be handed to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
the nsc stack via m_nscTcpSocket->send_data(). (and not to nsc-tcp-l4, this is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
the major difference compared to |ns3| TCP). The class also queues up data that
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
is Send() before the underlying descriptor has entered an ESTABLISHED state.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
This class is called from the nsc-tcp-l4 class, when the nsc-tcp-l4 wakeup()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
callback is invoked by nsc. nsc-tcp-socket-impl then checks the current
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
connection state (SYN_SENT, ESTABLISHED, LISTEN...) and schedules appropriate
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   320
callbacks as needed, e.g. a LISTEN socket will schedule Accept to see if a new
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
connection must be accepted, an ESTABLISHED socket schedules any pending data
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   322
for writing, schedule a read callback, etc.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   323
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
Note that ``ns3::NscTcpSocketImpl`` does not interact with nsc-tcp directly:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
instead, data is redirected to nsc. nsc-tcp calls the nsc-tcp-sockets of a node
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
when its wakeup callback is invoked by nsc. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
Limitations
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
+++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
* NSC only works on single-interface nodes; attempting to run it on a
6767
415711451cc6 Update TCP manual chapter
Tom Henderson <tomh@tomh.org>
parents: 6766
diff changeset
   332
  multi-interface node will cause a program error.  
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
* Cygwin and OS X PPC are not supported
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
* The non-Linux stacks of NSC are not supported in |ns3|
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
* Not all socket API callbacks are supported
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
For more information, see `this wiki page <http://www.nsnam.org/wiki/index.php/Network_Simulation_Cradle_Integration>`_.