examples/tutorial/fifth.cc
author Lalith Suresh <suresh.lalith@gmail.com>
Thu, 03 Mar 2011 19:54:57 +0000
changeset 6848 1f453ad50ef3
parent 6847 138f00c56381
child 6865 220373544a6c
permissions -rw-r--r--
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
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"
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/helper-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
    22
#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
    23
#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
    24
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
using namespace ns3;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
NS_LOG_COMPONENT_DEFINE ("FifthScriptExample");
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
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
//         node 0                 node 1
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//   |    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
    34
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//   |    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
    36
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
//   | 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
    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
//           +---------------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
//                5 Mbps, 2 ms
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
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
// 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
    45
// 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
    46
// 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
    47
// 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
    48
// 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
    49
// 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
    50
// 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
    51
// couldn't get at it.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
// 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
    54
// 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
    55
// 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
    56
// 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
    57
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
// 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
    59
// 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
    60
// install in the source node.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
// ===========================================================================
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
//
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    63
class MyApp : public Application 
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
public:
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    67
  MyApp ();
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    68
  virtual ~MyApp();
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  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
    71
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
private:
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
  virtual void StartApplication (void);  
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  virtual void StopApplication (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  void ScheduleTx (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  void SendPacket (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  Ptr<Socket>     m_socket;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  Address         m_peer;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  uint32_t        m_packetSize;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  uint32_t        m_nPackets;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  DataRate        m_dataRate;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  EventId         m_sendEvent;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  bool            m_running;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  uint32_t        m_packetsSent;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
};
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    89
MyApp::MyApp ()
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
  : m_socket (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
    m_peer (), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
    m_packetSize (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    m_nPackets (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
    m_dataRate (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
    m_sendEvent (), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
    m_running (false), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
    m_packetsSent (0)
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
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   101
MyApp::~MyApp()
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  m_socket = 0;
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
void
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   107
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
   108
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
  m_socket = socket;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  m_peer = address;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  m_packetSize = packetSize;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  m_nPackets = nPackets;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
  m_dataRate = dataRate;
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
void
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   117
MyApp::StartApplication (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
  m_running = true;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  m_packetsSent = 0;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
  m_socket->Bind ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
  m_socket->Connect (m_peer);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
  SendPacket ();
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   127
MyApp::StopApplication (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
  m_running = false;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
  if (m_sendEvent.IsRunning ())
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
      Simulator::Cancel (m_sendEvent);
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
  if (m_socket)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
      m_socket->Close ();
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   143
MyApp::SendPacket (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  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
   146
  m_socket->Send (packet);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
  if (++m_packetsSent < m_nPackets)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
      ScheduleTx ();
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   155
MyApp::ScheduleTx (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  if (m_running)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
    {
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
      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
   160
      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
   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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
static void
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
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
   166
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
  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
   168
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
static void
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
RxDrop (Ptr<const Packet> p)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
  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
   174
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
int 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
main (int argc, char *argv[])
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  NodeContainer nodes;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
  nodes.Create (2);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  PointToPointHelper pointToPoint;
5439
7676a44f00eb tracing tutorial changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 5433
diff changeset
   183
  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
   184
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
  NetDeviceContainer devices;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  devices = pointToPoint.Install (nodes);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
  Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> (
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
    "RanVar", RandomVariableValue (UniformVariable (0., 1.)),
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
    "ErrorRate", DoubleValue (0.00001));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
  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
   193
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
  InternetStackHelper stack;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  stack.Install (nodes);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  Ipv4AddressHelper address;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
  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
   199
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  uint16_t sinkPort = 8080;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  Address sinkAddress (InetSocketAddress(interfaces.GetAddress (1), sinkPort));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
  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
   204
  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
   205
  sinkApps.Start (Seconds (0.));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  sinkApps.Stop (Seconds (20.));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  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
   209
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndChange));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   211
  Ptr<MyApp> app = CreateObject<MyApp> ();
5439
7676a44f00eb tracing tutorial changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 5433
diff changeset
   212
  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
   213
  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
   214
  app->SetStartTime (Seconds (1.));
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5439
diff changeset
   215
  app->SetStopTime (Seconds (20.));
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
  devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeCallback (&RxDrop));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  Simulator::Stop (Seconds(20));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
  Simulator::Run ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  Simulator::Destroy ();
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
  return 0;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
}
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225