src/applications/onoff/onoff-application.cc
author raj.b@gatech.edu
Tue, 09 Dec 2008 12:24:24 -0800
changeset 3996 2277ff80158c
parent 3819 37b316422064
child 4007 d6f0c6f47cc4
permissions -rw-r--r--
bug 411 -- apply Raj's patch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
//
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
//
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
// published by the Free Software Foundation;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
//
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
// GNU General Public License for more details.
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
//
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
//
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
// Author: George F. Riley<riley@ece.gatech.edu>
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
//
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
// ns3 - On/Off Data Source Application class
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
// George F. Riley, Georgia Tech, Spring 2007
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
// Adapted from ApplicationOnOff in GTNetS.
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
    25
#include "ns3/log.h"
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 959
diff changeset
    26
#include "ns3/address.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    27
#include "ns3/node.h"
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/nstime.h"
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 372
diff changeset
    29
#include "ns3/data-rate.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 519
diff changeset
    30
#include "ns3/random-variable.h"
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 519
diff changeset
    31
#include "ns3/socket.h"
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 519
diff changeset
    32
#include "ns3/simulator.h"
747
65afca7824d7 i-socket-factory.h -> socket-factory.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    33
#include "ns3/socket-factory.h"
1267
0ea5ae44f96b remove uint8_t * from the send path of the socket API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1162
diff changeset
    34
#include "ns3/packet.h"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    35
#include "ns3/uinteger.h"
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    36
#include "ns3/trace-source-accessor.h"
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
#include "onoff-application.h"
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
    38
#include "ns3/udp-socket-factory.h"
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
    40
NS_LOG_COMPONENT_DEFINE ("OnOffApplication");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
    41
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
using namespace std;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
namespace ns3 {
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    46
NS_OBJECT_ENSURE_REGISTERED (OnOffApplication);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    48
TypeId
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    49
OnOffApplication::GetTypeId (void)
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    50
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    51
  static TypeId tid = TypeId ("ns3::OnOffApplication")
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    52
    .SetParent<Application> ()
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    53
    .AddConstructor<OnOffApplication> ()
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    54
    .AddAttribute ("DataRate", "The data rate in on state.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    55
                   DataRateValue (DataRate ("500kb/s")),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    56
                   MakeDataRateAccessor (&OnOffApplication::m_cbrRate),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    57
                   MakeDataRateChecker ())
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    58
    .AddAttribute ("PacketSize", "The size of packets sent in on state",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    59
                   UintegerValue (512),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    60
                   MakeUintegerAccessor (&OnOffApplication::m_pktSize),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    61
                   MakeUintegerChecker<uint32_t> (1))
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    62
    .AddAttribute ("Remote", "The address of the destination",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    63
                   AddressValue (),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    64
                   MakeAddressAccessor (&OnOffApplication::m_peer),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    65
                   MakeAddressChecker ())
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    66
    .AddAttribute ("OnTime", "A RandomVariable used to pick the duration of the 'On' state.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    67
                   RandomVariableValue (ConstantVariable (1.0)),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    68
                   MakeRandomVariableAccessor (&OnOffApplication::m_onTime),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    69
                   MakeRandomVariableChecker ())
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    70
    .AddAttribute ("OffTime", "A RandomVariable used to pick the duration of the 'Off' state.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    71
                   RandomVariableValue (ConstantVariable (1.0)),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    72
                   MakeRandomVariableAccessor (&OnOffApplication::m_offTime),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    73
                   MakeRandomVariableChecker ())
2742
19209c8d963f make MaxBytes an attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    74
    .AddAttribute ("MaxBytes", 
19209c8d963f make MaxBytes an attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    75
                   "The total number of bytes to send. Once these bytes are sent, "
19209c8d963f make MaxBytes an attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    76
                   "no packet is sent again, even in on state. The value zero means "
19209c8d963f make MaxBytes an attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    77
                   "that there is no limit.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    78
                   UintegerValue (0),
2742
19209c8d963f make MaxBytes an attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    79
                   MakeUintegerAccessor (&OnOffApplication::m_maxBytes),
19209c8d963f make MaxBytes an attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    80
                   MakeUintegerChecker<uint32_t> ())
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    81
    .AddAttribute ("Protocol", "The type of protocol to use.",
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
    82
                   TypeIdValue (UdpSocketFactory::GetTypeId ()),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    83
                   MakeTypeIdAccessor (&OnOffApplication::m_tid),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    84
                   MakeTypeIdChecker ())
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    85
    .AddTraceSource ("Tx", "A new packet is created and is sent",
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    86
                     MakeTraceSourceAccessor (&OnOffApplication::m_txTrace))
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    87
    ;
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    88
  return tid;
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    89
}
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    90
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    91
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    92
OnOffApplication::OnOffApplication ()
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    93
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    94
  NS_LOG_FUNCTION_NOARGS ();
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    95
  m_socket = 0;
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    96
  m_connected = false;
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    97
  m_residualBits = 0;
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    98
  m_lastStartTime = Seconds (0);
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
    99
  m_totBytes = 0;
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
   100
}
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
   101
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
OnOffApplication::~OnOffApplication()
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   103
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   104
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   105
}
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   106
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   107
void 
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   108
OnOffApplication::SetMaxBytes(uint32_t maxBytes)
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   109
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   110
  NS_LOG_FUNCTION (this << maxBytes);
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   111
  m_maxBytes = maxBytes;
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   112
}
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   113
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
   114
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   115
void
517
702e96b8960f finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 506
diff changeset
   116
OnOffApplication::DoDispose (void)
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   117
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   118
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   119
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
   120
  m_socket = 0;
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   121
  // chain up
517
702e96b8960f finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 506
diff changeset
   122
  Application::DoDispose ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   125
// Application Methods
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   126
void OnOffApplication::StartApplication() // Called at time specified by Start
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   127
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   128
  NS_LOG_FUNCTION_NOARGS ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
  // Create the socket if not already
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
  if (!m_socket)
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   132
    {
3116
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   133
      m_socket = Socket::CreateSocket (GetNode(), m_tid);
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   134
      m_socket->Bind ();
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 959
diff changeset
   135
      m_socket->Connect (m_peer);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
    }
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   137
  // Insure no pending event
3535
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   138
  CancelEvents ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
  // If we are not yet connected, there is nothing to do here
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
  // The ConnectionComplete upcall will start timers at that time
359
91b7ad7fa784 OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents: 349
diff changeset
   141
  //if (!m_connected) return;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
  ScheduleStartEvent();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   145
void OnOffApplication::StopApplication() // Called at time specified by Stop
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   147
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   148
3535
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   149
  CancelEvents ();
3819
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   150
  if(m_socket != 0)
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   151
    {
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   152
      m_socket->Close ();
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   153
    }
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   154
  else
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   155
    {
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   156
      NS_LOG_WARN("OnOffApplication found null socket to close in StopApplication");
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   157
    }
3535
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   158
}
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   159
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   160
void OnOffApplication::CancelEvents ()
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   161
{
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   162
  NS_LOG_FUNCTION_NOARGS ();
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   163
611
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   164
  if (m_sendEvent.IsRunning ())
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
    { // Cancel the pending send packet event
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
      // Calculate residual bits since last packet sent
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
      Time delta(Simulator::Now() - m_lastStartTime);
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 372
diff changeset
   168
      m_residualBits += (uint32_t)(m_cbrRate.GetBitRate() * delta.GetSeconds());
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
    }
611
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   170
  Simulator::Cancel(m_sendEvent);
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   171
  Simulator::Cancel(m_startStopEvent);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
// Event handlers
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
void OnOffApplication::StartSending()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   177
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   178
478
b067d8ff43df make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
   179
  ScheduleNextTx();  // Schedule the send packet event
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   180
  ScheduleStopEvent();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
void OnOffApplication::StopSending()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   185
  NS_LOG_FUNCTION_NOARGS ();
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   186
  CancelEvents();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   187
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   188
  ScheduleStartEvent();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
// Private helpers
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
void OnOffApplication::ScheduleNextTx()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   194
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   195
1871
a082b4f3ac92 the intent was to always send data if maxbytes is zero.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1870
diff changeset
   196
  if (m_maxBytes == 0 || m_totBytes < m_maxBytes)
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
    {
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
      uint32_t bits = m_pktSize * 8 - m_residualBits;
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
   199
      NS_LOG_LOGIC ("bits = " << bits);
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 372
diff changeset
   200
      Time nextTime(Seconds (bits / 
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 372
diff changeset
   201
        static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
   202
      NS_LOG_LOGIC ("nextTime = " << nextTime);
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   203
      m_sendEvent = Simulator::Schedule(nextTime, 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   204
                                        &OnOffApplication::SendPacket, this);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
    }
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
  else
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
    { // All done, cancel any pending events
359
91b7ad7fa784 OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents: 349
diff changeset
   208
      StopApplication();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
    }
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
void OnOffApplication::ScheduleStartEvent()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
{  // Schedules the event to start sending data (switch to the "On" state)
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   214
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   215
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   216
  Time offInterval = Seconds(m_offTime.GetValue());
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
   217
  NS_LOG_LOGIC ("start at " << offInterval);
478
b067d8ff43df make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
   218
  m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
void OnOffApplication::ScheduleStopEvent()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
{  // Schedules the event to stop sending data (switch to "Off" state)
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   223
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   224
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   225
  Time onInterval = Seconds(m_onTime.GetValue());
2860
9105a5cf6535 use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2742
diff changeset
   226
  NS_LOG_LOGIC ("stop at " << onInterval);
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   227
  m_startStopEvent = Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
  
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
void OnOffApplication::SendPacket()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   233
  NS_LOG_FUNCTION_NOARGS ();
2860
9105a5cf6535 use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2742
diff changeset
   234
  NS_LOG_LOGIC ("sending packet at " << Simulator::Now());
611
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   235
  NS_ASSERT (m_sendEvent.IsExpired ());
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   236
  Ptr<Packet> packet = Create<Packet> (m_pktSize);
2182
13c8ebd1a19e add application tracing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1871
diff changeset
   237
  m_txTrace (packet);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   238
  m_socket->Send (packet);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
  m_totBytes += m_pktSize;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
  m_lastStartTime = Simulator::Now();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
  m_residualBits = 0;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
  ScheduleNextTx();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
   245
void OnOffApplication::ConnectionSucceeded(Ptr<Socket>)
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   247
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   248
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
  m_connected = true;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
  ScheduleStartEvent();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
  
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
   253
void OnOffApplication::ConnectionFailed(Ptr<Socket>)
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   255
  NS_LOG_FUNCTION_NOARGS ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
  cout << "OnOffApplication, Connection Failed" << endl;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
} // Namespace ns3