examples/tutorial/fifth.cc
author Tom Henderson <tomh@tomh.org>
Mon, 21 Feb 2011 09:11:37 -0800
changeset 6823 a27f86fb4e55
parent 6821 203367ae7433
child 6834 036f9a0b9899
permissions -rw-r--r--
Merge node and common modules into new network module
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"
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6821
diff changeset
    20
#include "ns3/internet-stack-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"
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
using namespace ns3;
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
NS_LOG_COMPONENT_DEFINE ("FifthScriptExample");
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
// ===========================================================================
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
//         node 0                 node 1
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
//   |    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
    32
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//   |    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
    34
//   +----------------+    +----------------+
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//   | 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
    36
//   +----------------+    +----------------+
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
//                5 Mbps, 2 ms
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
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
// 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
    43
// 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
    44
// 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
    45
// 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
    46
// 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
    47
// 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
    48
// 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
    49
// couldn't get at it.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
// 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
    52
// 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
    53
// 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
    54
// 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
    55
//
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
// 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
    57
// 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
    58
// install in the source node.
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
// ===========================================================================
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
//
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    61
class MyApp : public Application 
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
public:
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    65
  MyApp ();
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    66
  virtual ~MyApp();
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  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
    69
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
private:
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  virtual void StartApplication (void);  
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  virtual void StopApplication (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  void ScheduleTx (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  void SendPacket (void);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  Ptr<Socket>     m_socket;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  Address         m_peer;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  uint32_t        m_packetSize;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  uint32_t        m_nPackets;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  DataRate        m_dataRate;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  EventId         m_sendEvent;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  bool            m_running;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  uint32_t        m_packetsSent;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
};
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    87
MyApp::MyApp ()
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
  : m_socket (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
    m_peer (), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
    m_packetSize (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
    m_nPackets (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
    m_dataRate (0), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    m_sendEvent (), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
    m_running (false), 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
    m_packetsSent (0)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
{
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
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
    99
MyApp::~MyApp()
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  m_socket = 0;
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
void
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   105
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
   106
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  m_socket = socket;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  m_peer = address;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
  m_packetSize = packetSize;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  m_nPackets = nPackets;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  m_dataRate = dataRate;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
}
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
void
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   115
MyApp::StartApplication (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
  m_running = true;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  m_packetsSent = 0;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
  m_socket->Bind ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  m_socket->Connect (m_peer);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
  SendPacket ();
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
}
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
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   125
MyApp::StopApplication (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
  m_running = false;
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
  if (m_sendEvent.IsRunning ())
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
      Simulator::Cancel (m_sendEvent);
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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
  if (m_socket)
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
      m_socket->Close ();
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
}
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
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   141
MyApp::SendPacket (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
  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
   144
  m_socket->Send (packet);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
  if (++m_packetsSent < m_nPackets)
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
      ScheduleTx ();
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
}
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
void 
5433
be5517a35ea0 Rename SimpleSource to MyApp
Craig Dowell <craigdo@ee.washington.edu>
parents: 5432
diff changeset
   153
MyApp::ScheduleTx (void)
5432
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  if (m_running)
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
      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
   158
      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
   159
    }
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
static void
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
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
   164
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
  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
   166
}
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
static void
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
RxDrop (Ptr<const Packet> p)
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
  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
   172
}
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
int 
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
main (int argc, char *argv[])
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
{
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
  NodeContainer nodes;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
  nodes.Create (2);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
  PointToPointHelper pointToPoint;
5439
7676a44f00eb tracing tutorial changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 5433
diff changeset
   181
  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
   182
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
  NetDeviceContainer devices;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
  devices = pointToPoint.Install (nodes);
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> (
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
    "RanVar", RandomVariableValue (UniformVariable (0., 1.)),
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
    "ErrorRate", DoubleValue (0.00001));
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;
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
  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
   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
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
  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
   216
2cb21147d154 fill out tutorial tracing section with semi-real plot
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
  Simulator::Stop (Seconds(20));
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