3570
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
2 |
/*
|
|
3 |
* This program is free software; you can redistribute it and/or modify
|
|
4 |
* it under the terms of the GNU General Public License version 2 as
|
|
5 |
* published by the Free Software Foundation;
|
|
6 |
*
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
* GNU General Public License for more details.
|
|
11 |
*
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
13 |
* along with this program; if not, write to the Free Software
|
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
15 |
*
|
|
16 |
* Authors: Joe Kopena <tjkopena@cs.drexel.edu>
|
|
17 |
*
|
|
18 |
* These applications are used in the WiFi Distance Test experiment,
|
|
19 |
* described and implemented in test02.cc. That file should be in the
|
|
20 |
* same place as this file. The applications have two very simple
|
|
21 |
* jobs, they just generate and receive packets. We could use the
|
|
22 |
* standard Application classes included in the NS-3 distribution.
|
|
23 |
* These have been written just to change the behavior a little, and
|
|
24 |
* provide more examples.
|
|
25 |
*
|
|
26 |
*/
|
|
27 |
|
|
28 |
// #define NS3_LOG_ENABLE // Now defined by Makefile
|
|
29 |
|
|
30 |
#include "ns3/core-module.h"
|
|
31 |
#include "ns3/common-module.h"
|
|
32 |
#include "ns3/application.h"
|
|
33 |
|
|
34 |
#include "ns3/stats-module.h"
|
|
35 |
|
|
36 |
using namespace ns3;
|
|
37 |
|
|
38 |
//----------------------------------------------------------------------
|
|
39 |
//------------------------------------------------------
|
|
40 |
class Sender: public Application {
|
|
41 |
public:
|
|
42 |
static TypeId GetTypeId(void);
|
|
43 |
Sender();
|
|
44 |
virtual ~Sender();
|
|
45 |
|
|
46 |
protected:
|
|
47 |
virtual void DoDispose(void);
|
|
48 |
|
|
49 |
private:
|
|
50 |
virtual void StartApplication(void);
|
|
51 |
virtual void StopApplication(void);
|
|
52 |
|
|
53 |
void SendPacket();
|
|
54 |
|
|
55 |
uint32_t m_pktSize;
|
|
56 |
Ipv4Address m_destAddr;
|
|
57 |
uint32_t m_destPort;
|
|
58 |
RandomVariable m_interval;
|
|
59 |
uint32_t m_numPkts;
|
|
60 |
|
|
61 |
Ptr<Socket> m_socket;
|
|
62 |
EventId m_sendEvent;
|
|
63 |
|
|
64 |
TracedCallback<Ptr<const Packet> > m_txTrace;
|
|
65 |
|
|
66 |
uint32_t m_count;
|
|
67 |
|
|
68 |
// end class Sender
|
|
69 |
};
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
//------------------------------------------------------
|
|
75 |
class Receiver: public Application {
|
|
76 |
public:
|
|
77 |
static TypeId GetTypeId(void);
|
|
78 |
Receiver();
|
|
79 |
virtual ~Receiver();
|
|
80 |
|
|
81 |
void SetCounter(Ptr<CounterCalculator<> > calc);
|
|
82 |
void SetDelayTracker(Ptr<TimeMinMaxAvgTotalCalculator> delay);
|
|
83 |
|
|
84 |
protected:
|
|
85 |
virtual void DoDispose(void);
|
|
86 |
|
|
87 |
private:
|
|
88 |
virtual void StartApplication(void);
|
|
89 |
virtual void StopApplication(void);
|
|
90 |
|
|
91 |
void Receive(Ptr<Socket> socket);
|
|
92 |
|
|
93 |
Ptr<Socket> m_socket;
|
|
94 |
|
|
95 |
uint32_t m_port;
|
|
96 |
|
|
97 |
Ptr<CounterCalculator<> > m_calc;
|
|
98 |
Ptr<TimeMinMaxAvgTotalCalculator> m_delay;
|
|
99 |
|
|
100 |
// end class Receiver
|
|
101 |
};
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
//------------------------------------------------------
|
|
107 |
class TimestampTag : public Tag {
|
|
108 |
public:
|
|
109 |
static TypeId GetTypeId (void);
|
|
110 |
virtual TypeId GetInstanceTypeId (void) const;
|
|
111 |
|
|
112 |
virtual uint32_t GetSerializedSize (void) const;
|
|
113 |
virtual void Serialize (TagBuffer i) const;
|
|
114 |
virtual void Deserialize (TagBuffer i);
|
|
115 |
|
|
116 |
// these are our accessors to our tag structure
|
|
117 |
void SetTimestamp(Time time);
|
|
118 |
Time GetTimestamp(void) const;
|
|
119 |
|
|
120 |
void Print(std::ostream &os) const;
|
|
121 |
|
|
122 |
private:
|
|
123 |
Time m_timestamp;
|
|
124 |
|
|
125 |
// end class TimestampTag
|
|
126 |
};
|