examples/tutorial/fifth.cc
author Tom Henderson <tomh@tomh.org>
Mon, 28 Sep 2015 20:27:25 -0700
changeset 11676 05ea1489e509
parent 8986 3391f6a7fb3b
permissions -rw-r--r--
bug 2184: Integer overflow in MacLow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include <fstream>
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/core-module.h"
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6821
diff changeset
    19
#include "ns3/network-module.h"
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6823
diff changeset
    20
#include "ns3/internet-module.h"
6848
1f453ad50ef3 Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6847
diff changeset
    21
#include "ns3/point-to-point-module.h"
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6834
diff changeset
    22
#include "ns3/applications-module.h"
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
using namespace ns3;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
NS_LOG_COMPONENT_DEFINE ("FifthScriptExample");
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
// ===========================================================================
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
//         node 0                 node 1
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
//   |    ns-3 TCP    |    |    ns-3 TCP    |
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
//   |    10.1.1.1    |    |    10.1.1.2    |
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
//   | point-to-point |    | point-to-point |
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
//           |                     |
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
//           +---------------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
//                5 Mbps, 2 ms
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
// We want to look at changes in the ns-3 TCP congestion window.  We need
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
// to crank up a flow and hook the CongestionWindow attribute on the socket
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
// of the sender.  Normally one would use an on-off application to generate a
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
// flow, but this has a couple of problems.  First, the socket of the on-off 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
// application is not created until Application Start time, so we wouldn't be 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
// able to hook the socket (now) at configuration time.  Second, even if we 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
// could arrange a call after start time, the socket is not public so we 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
// couldn't get at it.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
// So, we can cook up a simple version of the on-off application that does what
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
// we want.  On the plus side we don't need all of the complexity of the on-off
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
// application.  On the minus side, we don't have a helper, so we have to get
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
// a little more involved in the details, but this is trivial.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
// So first, we create a socket and do the trace connect on it; then we pass 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
// this socket into the constructor of our simple application which we then 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
// install in the source node.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
// ===========================================================================
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
//
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    62
class MyApp : public Application 
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
public:
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    66
  MyApp ();
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    67
  virtual ~MyApp();
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  void Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
private:
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    72
  virtual void StartApplication (void);
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
  virtual void StopApplication (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  void ScheduleTx (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  void SendPacket (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  Ptr<Socket>     m_socket;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  Address         m_peer;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  uint32_t        m_packetSize;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  uint32_t        m_nPackets;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  DataRate        m_dataRate;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  EventId         m_sendEvent;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  bool            m_running;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  uint32_t        m_packetsSent;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
};
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    88
MyApp::MyApp ()
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
  : m_socket (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
    m_peer (), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
    m_packetSize (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
    m_nPackets (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    m_dataRate (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
    m_sendEvent (), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
    m_running (false), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
    m_packetsSent (0)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   100
MyApp::~MyApp()
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
  m_socket = 0;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
void
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   106
MyApp::Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  m_socket = socket;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
  m_peer = address;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  m_packetSize = packetSize;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  m_nPackets = nPackets;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  m_dataRate = dataRate;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
void
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   116
MyApp::StartApplication (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  m_running = true;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
  m_packetsSent = 0;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  m_socket->Bind ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
  m_socket->Connect (m_peer);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
  SendPacket ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   126
MyApp::StopApplication (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
  m_running = false;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
  if (m_sendEvent.IsRunning ())
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
      Simulator::Cancel (m_sendEvent);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
    }
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
  if (m_socket)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
      m_socket->Close ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
    }
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   142
MyApp::SendPacket (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
  Ptr<Packet> packet = Create<Packet> (m_packetSize);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  m_socket->Send (packet);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
  if (++m_packetsSent < m_nPackets)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
      ScheduleTx ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
    }
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   154
MyApp::ScheduleTx (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  if (m_running)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
      Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   159
      m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this);
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
    }
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
static void
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
  NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
static void
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
RxDrop (Ptr<const Packet> p)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
  NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
int 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
main (int argc, char *argv[])
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
  NodeContainer nodes;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  nodes.Create (2);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
  PointToPointHelper pointToPoint;
5439
7676a44f00eb tracing tutorial changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 5433
diff changeset
   182
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
  NetDeviceContainer devices;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
  devices = pointToPoint.Install (nodes);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
8986
3391f6a7fb3b Replace src/network usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   188
  Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ();
3391f6a7fb3b Replace src/network usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   189
  em->SetAttribute ("ErrorRate", DoubleValue (0.00001));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
  InternetStackHelper stack;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
  stack.Install (nodes);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  Ipv4AddressHelper address;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  address.SetBase ("10.1.1.0", "255.255.255.252");
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
  uint16_t sinkPort = 8080;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
   200
  Address sinkAddress (InetSocketAddress (interfaces.GetAddress (1), sinkPort));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (1));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
  sinkApps.Start (Seconds (0.));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
  sinkApps.Stop (Seconds (20.));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ());
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndChange));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   209
  Ptr<MyApp> app = CreateObject<MyApp> ();
5439
7676a44f00eb tracing tutorial changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 5433
diff changeset
   210
  app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps"));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  nodes.Get (0)->AddApplication (app);
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5439
diff changeset
   212
  app->SetStartTime (Seconds (1.));
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5439
diff changeset
   213
  app->SetStopTime (Seconds (20.));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
   215
  devices.Get (1)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&RxDrop));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
   217
  Simulator::Stop (Seconds (20));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
  Simulator::Run ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  Simulator::Destroy ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  return 0;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223