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