src/applications/bulk-send/bulk-send-application.h
author Josh Pelkey <jpelkey@gatech.edu>
Thu, 16 Dec 2010 20:24:14 -0500
changeset 6690 3fab9a03dacd
permissions -rw-r--r--
Add BulkSendApplication
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6690
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     2
/*
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     3
 * Copyright (c) 2010 Georgia Institute of Technology
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     4
 *
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     8
 *
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    13
 *
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    17
 *
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    18
 * Author: George F. Riley <riley@ece.gatech.edu>
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    19
 */
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    20
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    21
#ifndef __bulksend_application_h__
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    22
#define __bulksend_application_h__
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    23
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    24
#include "ns3/address.h"
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    25
#include "ns3/application.h"
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    26
#include "ns3/event-id.h"
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    27
#include "ns3/ptr.h"
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    28
#include "ns3/traced-callback.h"
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    29
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    30
namespace ns3 {
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    31
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    32
class Address;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    33
class RandomVariable;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    34
class Socket;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    35
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    36
/**
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    37
 * \ingroup applications
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    38
 * \defgroup bulksend BulkSendApplication
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    39
 *
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    40
 * This traffic generator simply sends data
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    41
 * as fast as possible up to MaxBytes or until
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    42
 * the appplication is stopped if MaxBytes is
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    43
 * zero. Once the lower layer send buffer is
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    44
 * filled, it waits until space is free to
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    45
 * send more data, essentially keeping a
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    46
 * constant flow of data. Only SOCK_STREAM 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    47
 * and SOCK_SEQPACKET sockets are supported. 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    48
 * For example, TCP sockets can be used, but 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    49
 * UDP sockets can not be used.
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    50
 */
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    51
class BulkSendApplication : public Application
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    52
{
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    53
public:
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    54
  static TypeId GetTypeId (void);
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    55
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    56
  BulkSendApplication ();
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    57
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    58
  virtual ~BulkSendApplication ();
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    59
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    60
  /**
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    61
   * \param maxBytes the upper bound of bytes to send
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    62
   *
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    63
   * Set the upper bound for the total number of bytes to send. Once 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    64
   * this bound is reached, no more application bytes are sent. If the 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    65
   * application is stopped during the simulation and restarted, the 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    66
   * total number of bytes sent is not reset; however, the maxBytes 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    67
   * bound is still effective and the application will continue sending 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    68
   * up to maxBytes. The value zero for maxBytes means that 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    69
   * there is no upper bound; i.e. data is sent until the application 
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    70
   * or simulation is stopped.
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    71
   */
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    72
  void SetMaxBytes (uint32_t maxBytes);
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    73
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    74
  /**
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    75
   * \return pointer to associated socket
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    76
   */
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    77
  Ptr<Socket> GetSocket (void) const;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    78
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    79
protected:
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    80
  virtual void DoDispose (void);
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    81
private:
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    82
  // inherited from Application base class.
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    83
  virtual void StartApplication (void);    // Called at time specified by Start
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    84
  virtual void StopApplication (void);     // Called at time specified by Stop
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    85
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    86
  void SendData ();
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    87
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    88
  Ptr<Socket>     m_socket;       // Associated socket
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    89
  Address         m_peer;         // Peer address
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    90
  bool            m_connected;    // True if connected
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    91
  uint32_t        m_sendSize;     // Size of data to send each time
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    92
  uint32_t        m_maxBytes;     // Limit total number of bytes sent
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    93
  uint32_t        m_totBytes;     // Total bytes sent so far
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    94
  TypeId          m_tid;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    95
  TracedCallback<Ptr<const Packet> > m_txTrace;
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    96
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    97
private:
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    98
  void ConnectionSucceeded (Ptr<Socket> socket);
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    99
  void ConnectionFailed (Ptr<Socket> socket);
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   100
  void DataSend (Ptr<Socket>, uint32_t); // for socket's SetSendCallback
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   101
  void Ignore (Ptr<Socket> socket);
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   102
};
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   103
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   104
} // namespace ns3
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   105
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   106
#endif
3fab9a03dacd Add BulkSendApplication
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   107