src/applications/model/onoff-application.cc
author Josh Pelkey <jpelkey@gatech.edu>
Fri, 13 May 2011 14:51:11 -0400
changeset 7166 2ea56ac66361
parent 7045 d13fa06886ce
child 7256 b04ba6772f8c
permissions -rw-r--r--
applications coding style changes
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))
7166
2ea56ac66361 applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
    87
  ;
2494
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
6623
616d42c69f05 bug 1005: GetSocket() methods for OnOffApplication and PacketSink
Tom Henderson <tomh@tomh.org>
parents: 6448
diff changeset
   114
Ptr<Socket>
616d42c69f05 bug 1005: GetSocket() methods for OnOffApplication and PacketSink
Tom Henderson <tomh@tomh.org>
parents: 6448
diff changeset
   115
OnOffApplication::GetSocket (void) const
616d42c69f05 bug 1005: GetSocket() methods for OnOffApplication and PacketSink
Tom Henderson <tomh@tomh.org>
parents: 6448
diff changeset
   116
{
616d42c69f05 bug 1005: GetSocket() methods for OnOffApplication and PacketSink
Tom Henderson <tomh@tomh.org>
parents: 6448
diff changeset
   117
  NS_LOG_FUNCTION (this);
616d42c69f05 bug 1005: GetSocket() methods for OnOffApplication and PacketSink
Tom Henderson <tomh@tomh.org>
parents: 6448
diff changeset
   118
  return m_socket;
616d42c69f05 bug 1005: GetSocket() methods for OnOffApplication and PacketSink
Tom Henderson <tomh@tomh.org>
parents: 6448
diff changeset
   119
}
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 611
diff changeset
   120
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   121
void
517
702e96b8960f finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 506
diff changeset
   122
OnOffApplication::DoDispose (void)
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   123
{
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
   124
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   125
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
   126
  m_socket = 0;
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   127
  // chain up
517
702e96b8960f finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 506
diff changeset
   128
  Application::DoDispose ();
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
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   131
// Application Methods
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   132
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
   133
{
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
   134
  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
   135
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
  // 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
   137
  if (!m_socket)
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   138
    {
3116
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   139
      m_socket = Socket::CreateSocket (GetNode(), m_tid);
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   140
      m_socket->Bind ();
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 959
diff changeset
   141
      m_socket->Connect (m_peer);
6448
184a509cc71d Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6447
diff changeset
   142
      m_socket->SetAllowBroadcast (true);
6196
151afb65c7e8 Bug 833 - OnOffApplication with PacketSocket: sniffs all traffic
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4262
diff changeset
   143
      m_socket->ShutdownRecv ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
    }
609
9baaee630644 remove dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   145
  // 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
   146
  CancelEvents ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
  // 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
   148
  // 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
   149
  //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
   150
  ScheduleStartEvent();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   153
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
   154
{
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
   155
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   156
3535
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   157
  CancelEvents ();
3819
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   158
  if(m_socket != 0)
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   159
    {
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   160
      m_socket->Close ();
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   161
    }
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   162
  else
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   163
    {
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   164
      NS_LOG_WARN("OnOffApplication found null socket to close in StopApplication");
37b316422064 Bug 340
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3535
diff changeset
   165
    }
3535
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   166
}
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   167
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   168
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
   169
{
016c70fa60d8 Refactor OnOff so Start doesn't immediate close the socket (bug 259)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3125
diff changeset
   170
  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
   171
611
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   172
  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
   173
    { // 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
   174
      // 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
   175
      Time delta(Simulator::Now() - m_lastStartTime);
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7036
diff changeset
   176
      int64x64_t bits = delta.To(Time::S) * m_cbrRate.GetBitRate ();
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7036
diff changeset
   177
      m_residualBits += bits.GetHigh ();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
    }
611
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   179
  Simulator::Cancel(m_sendEvent);
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   180
  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
   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
// Event handlers
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
void OnOffApplication::StartSending()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
{
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
   186
  NS_LOG_FUNCTION_NOARGS ();
4262
170eff4aba90 set OnOffApplication::m_lastStartTime correctly (bug #490)
Tom Henderson <tomh@tomh.org>
parents: 4007
diff changeset
   187
  m_lastStartTime = Simulator::Now();
478
b067d8ff43df make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
   188
  ScheduleNextTx();  // Schedule the send packet event
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   189
  ScheduleStopEvent();
349
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
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
void OnOffApplication::StopSending()
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 ();
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   195
  CancelEvents();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   196
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   197
  ScheduleStartEvent();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
// Private helpers
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
void OnOffApplication::ScheduleNextTx()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
{
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
   203
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   204
1871
a082b4f3ac92 the intent was to always send data if maxbytes is zero.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1870
diff changeset
   205
  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
   206
    {
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
      uint32_t bits = m_pktSize * 8 - m_residualBits;
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
   208
      NS_LOG_LOGIC ("bits = " << bits);
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 372
diff changeset
   209
      Time nextTime(Seconds (bits / 
7166
2ea56ac66361 applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   210
                             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
   211
      NS_LOG_LOGIC ("nextTime = " << nextTime);
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   212
      m_sendEvent = Simulator::Schedule(nextTime, 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   213
                                        &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
   214
    }
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
  else
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
    { // All done, cancel any pending events
359
91b7ad7fa784 OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents: 349
diff changeset
   217
      StopApplication();
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
    }
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::ScheduleStartEvent()
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 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
   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 offInterval = Seconds(m_offTime.GetValue());
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
   226
  NS_LOG_LOGIC ("start at " << offInterval);
478
b067d8ff43df make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
   227
  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
   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
void OnOffApplication::ScheduleStopEvent()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
{  // 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
   232
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   233
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   234
  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
   235
  NS_LOG_LOGIC ("stop at " << onInterval);
3996
2277ff80158c bug 411 -- apply Raj's patch
raj.b@gatech.edu
parents: 3819
diff changeset
   236
  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
   237
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
7166
2ea56ac66361 applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   239
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
void OnOffApplication::SendPacket()
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
{
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
   242
  NS_LOG_FUNCTION_NOARGS ();
2860
9105a5cf6535 use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2742
diff changeset
   243
  NS_LOG_LOGIC ("sending packet at " << Simulator::Now());
611
edfeeb67e19f simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 609
diff changeset
   244
  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
   245
  Ptr<Packet> packet = Create<Packet> (m_pktSize);
2182
13c8ebd1a19e add application tracing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1871
diff changeset
   246
  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
   247
  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
   248
  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
   249
  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
   250
  m_residualBits = 0;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
  ScheduleNextTx();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
   254
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
   255
{
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
   256
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1267
diff changeset
   257
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
  m_connected = true;
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
  ScheduleStartEvent();
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
}
7166
2ea56ac66361 applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   261
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
   262
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
   263
{
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
   264
  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
   265
  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
   266
}
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
} // Namespace ns3