examples/tutorial/sixth.cc
author Craig Dowell <craigdo@ee.washington.edu>
Mon, 25 Jan 2010 16:12:16 -0800
changeset 6021 fddc1ed290f8
parent 6020 f8212529e82a
child 6023 c7fbbfc5a7e8
permissions -rw-r--r--
DLT_PPP for sixth dropped packets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6020
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include <fstream>
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/core-module.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/common-module.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/simulator-module.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/node-module.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/helper-module.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "ns3/ascii-trace-helper.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "ns3/pcap-helper.h"
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
using namespace ns3;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
NS_LOG_COMPONENT_DEFINE ("SixthScriptExample");
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
// ===========================================================================
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
//
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
//         node 0                 node 1
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//   +----------------+    +----------------+
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
//   |    ns-3 TCP    |    |    ns-3 TCP    |
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//   +----------------+    +----------------+
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
//   |    10.1.1.1    |    |    10.1.1.2    |
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
//   +----------------+    +----------------+
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
//   | point-to-point |    | point-to-point |
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
//   +----------------+    +----------------+
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
//           |                     |
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
//           +---------------------+
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
//                5 Mbps, 2 ms
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
//
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
//
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
// We want to look at changes in the ns-3 TCP congestion window.  We need
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
// to crank up a flow and hook the CongestionWindow attribute on the socket
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
// of the sender.  Normally one would use an on-off application to generate a
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
// flow, but this has a couple of problems.  First, the socket of the on-off 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
// application is not created until Application Start time, so we wouldn't be 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
// able to hook the socket (now) at configuration time.  Second, even if we 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
// could arrange a call after start time, the socket is not public so we 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
// couldn't get at it.
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
//
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
// So, we can cook up a simple version of the on-off application that does what
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
// we want.  On the plus side we don't need all of the complexity of the on-off
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
// application.  On the minus side, we don't have a helper, so we have to get
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
// a little more involved in the details, but this is trivial.
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
//
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
// So first, we create a socket and do the trace connect on it; then we pass 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
// this socket into the constructor of our simple application which we then 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
// install in the source node.
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
// ===========================================================================
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
//
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
class MyApp : public Application 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
public:
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  MyApp ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  virtual ~MyApp();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  void Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
private:
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  virtual void StartApplication (void);  
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  virtual void StopApplication (void);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  void ScheduleTx (void);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  void SendPacket (void);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  Ptr<Socket>     m_socket;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  Address         m_peer;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  uint32_t        m_packetSize;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  uint32_t        m_nPackets;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  DataRate        m_dataRate;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  EventId         m_sendEvent;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  bool            m_running;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
  uint32_t        m_packetsSent;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
};
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
MyApp::MyApp ()
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
  : m_socket (0), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
    m_peer (), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    m_packetSize (0), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
    m_nPackets (0), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
    m_dataRate (0), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
    m_sendEvent (), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
    m_running (false), 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
    m_packetsSent (0)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
MyApp::~MyApp()
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  m_socket = 0;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
void
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
MyApp::Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  m_socket = socket;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  m_peer = address;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  m_packetSize = packetSize;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
  m_nPackets = nPackets;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
  m_dataRate = dataRate;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
void
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
MyApp::StartApplication (void)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  m_running = true;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
  m_packetsSent = 0;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
  m_socket->Bind ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
  m_socket->Connect (m_peer);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
  SendPacket ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
void 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
MyApp::StopApplication (void)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
  m_running = false;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
  if (m_sendEvent.IsRunning ())
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
    {
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
      Simulator::Cancel (m_sendEvent);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
    }
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
  if (m_socket)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
    {
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
      m_socket->Close ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
    }
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
void 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
MyApp::SendPacket (void)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
  Ptr<Packet> packet = Create<Packet> (m_packetSize);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
  m_socket->Send (packet);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  if (++m_packetsSent < m_nPackets)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
    {
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
      ScheduleTx ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
    }
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
void 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
MyApp::ScheduleTx (void)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
  if (m_running)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
    {
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
      Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
      m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
    }
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
static void
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
CwndChange (Ptr<OutputStreamObject> stream, uint32_t oldCwnd, uint32_t newCwnd)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
{
6021
fddc1ed290f8 DLT_PPP for sixth dropped packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 6020
diff changeset
   168
  NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
6020
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
  *stream->GetStream () << Simulator::Now ().GetSeconds () << "\t" << oldCwnd << "\t" << newCwnd << std::endl;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
static void
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
RxDrop (Ptr<PcapFileObject> file, Ptr<const Packet> p)
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
{
6021
fddc1ed290f8 DLT_PPP for sixth dropped packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 6020
diff changeset
   175
  NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
6020
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  file->Write(Simulator::Now(), p);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
int 
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
main (int argc, char *argv[])
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
{
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  NodeContainer nodes;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
  nodes.Create (2);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
  PointToPointHelper pointToPoint;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
  NetDeviceContainer devices;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  devices = pointToPoint.Install (nodes);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
  Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> (
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
    "RanVar", RandomVariableValue (UniformVariable (0., 1.)),
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
    "ErrorRate", DoubleValue (0.00001));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  InternetStackHelper stack;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
  stack.Install (nodes);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
  Ipv4AddressHelper address;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  address.SetBase ("10.1.1.0", "255.255.255.252");
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
  uint16_t sinkPort = 8080;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
  Address sinkAddress (InetSocketAddress(interfaces.GetAddress (1), sinkPort));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (1));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  sinkApps.Start (Seconds (0.));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  sinkApps.Stop (Seconds (20.));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ());
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  AsciiTraceHelper asciiTraceHelper;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
  Ptr<OutputStreamObject> stream = asciiTraceHelper.CreateFileStream ("sixth.cwnd");
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeBoundCallback (&CwndChange, stream));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
  Ptr<MyApp> app = CreateObject<MyApp> ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
  app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps"));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  nodes.Get (0)->AddApplication (app);
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
  app->SetStartTime (Seconds (1.));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  app->SetStopTime (Seconds (20.));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
  PcapHelper pcapHelper;
6021
fddc1ed290f8 DLT_PPP for sixth dropped packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 6020
diff changeset
   224
  Ptr<PcapFileObject> file = pcapHelper.CreateFile ("sixth.pcap", "w", PcapHelper::DLT_PPP);
6020
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
  devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeBoundCallback (&RxDrop, file));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
  Simulator::Stop (Seconds(20));
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
  Simulator::Run ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
  Simulator::Destroy ();
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
  return 0;
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
}
f8212529e82a add sixth tutorial example for mid-level tracing helpers
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233