author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 14 May 2007 10:06:12 +0200 | |
changeset 607 | 1b7abeccfcda |
parent 604 | 0b6bef4e99bc |
child 609 | 9baaee630644 |
permissions | -rw-r--r-- |
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 |
|
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
519
diff
changeset
|
25 |
#include "ns3/ipv4-address.h" |
604
0b6bef4e99bc
rename node.h to i-node.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
26 |
#include "ns3/i-node.h" |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
#include "ns3/nstime.h" |
382
26528ff50d38
Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents:
372
diff
changeset
|
28 |
#include "ns3/data-rate.h" |
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
519
diff
changeset
|
29 |
#include "ns3/random-variable.h" |
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
519
diff
changeset
|
30 |
#include "ns3/socket.h" |
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
519
diff
changeset
|
31 |
#include "ns3/simulator.h" |
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
519
diff
changeset
|
32 |
#include "ns3/i-udp.h" |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
#include "onoff-application.h" |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
using namespace std; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
namespace ns3 { |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
// Defaults for rate/size |
384 | 40 |
DataRate OnOffApplication::g_defaultRate = DataRate(500000); |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
uint32_t OnOffApplication::g_defaultSize = 512; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
// Constructors |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
44 |
|
607
1b7abeccfcda
rename Node to INode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
604
diff
changeset
|
45 |
OnOffApplication::OnOffApplication(Ptr<INode> n, |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
46 |
const Ipv4Address rip, // Remote IP addr |
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
47 |
uint16_t rport, // Remote port |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
const RandomVariable& ontime, |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
const RandomVariable& offtime, |
382
26528ff50d38
Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents:
372
diff
changeset
|
50 |
DataRate rate, |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
51 |
uint32_t size) |
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
52 |
: Application(n), |
489
97a210720478
remove nil macro
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
478
diff
changeset
|
53 |
m_socket(0), // Socket allocated on Start |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
54 |
m_peerIP(rip), |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
m_peerPort(rport), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
m_connected(false), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
m_onTime(ontime.Copy()), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
m_offTime(offtime.Copy()), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
59 |
m_cbrRate(rate), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
m_pktSize(size), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
m_residualBits(0), |
372
c242f488ef0b
Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents:
367
diff
changeset
|
62 |
m_lastStartTime((HighPrecision)0), |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
m_maxBytes(0xffffffff), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
m_totBytes(0), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
m_startStopScheduled(false), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
m_sendScheduled(false) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
|
607
1b7abeccfcda
rename Node to INode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
604
diff
changeset
|
70 |
OnOffApplication::OnOffApplication(Ptr<INode> n, const OnOffApplication& c) |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
71 |
: Application(n), |
489
97a210720478
remove nil macro
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
478
diff
changeset
|
72 |
m_socket(0), |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
73 |
m_peerIP(c.m_peerIP), |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
74 |
m_peerPort(c.m_peerPort), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
m_connected(c.m_connected), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
m_onTime(c.m_onTime->Copy()), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
m_offTime(c.m_offTime->Copy()), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
m_cbrRate(c.m_cbrRate), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
m_pktSize(c.m_pktSize), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
m_residualBits(c.m_residualBits), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
m_lastStartTime(c.m_lastStartTime), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
m_maxBytes(c.m_maxBytes), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
83 |
m_totBytes(c.m_totBytes), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
m_startStopScheduled(false), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
85 |
m_sendScheduled(false) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
86 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
87 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
88 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
89 |
OnOffApplication::~OnOffApplication() |
517
702e96b8960f
finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
506
diff
changeset
|
90 |
{} |
497
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
91 |
|
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
92 |
void |
517
702e96b8960f
finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
506
diff
changeset
|
93 |
OnOffApplication::DoDispose (void) |
497
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
94 |
{ |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
563
diff
changeset
|
95 |
m_socket = 0; |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
96 |
delete m_onTime; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
97 |
delete m_offTime; |
497
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
98 |
|
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
99 |
m_onTime = 0; |
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
100 |
m_offTime = 0; |
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
101 |
|
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
102 |
// chain up |
517
702e96b8960f
finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
506
diff
changeset
|
103 |
Application::DoDispose (); |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
#ifdef REMOVE_THIS |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
// Handler Methods |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
108 |
void OnOffApplication::Handle(Event* e, Time_t t) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
109 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
AppOOEvent* ev = (AppOOEvent*)e; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
111 |
switch (ev->event) { |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
112 |
case AppOOEvent::SEND_PKT : |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
114 |
SendPkt(false); // Send the packet |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
115 |
return; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
116 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
117 |
case AppOOEvent::START_GEN : |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
118 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
119 |
DEBUG0((cout << "StartGen at " << Simulator::Now() << endl)); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
lastStartTime = Simulator::Now(); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
ScheduleNextTx(); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
Time_t onInterval = onTime->Value(); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |
pendingOO->event = AppOOEvent::STOP_GEN; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
124 |
// Schedule the stop event |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
125 |
Simulator::Schedule(pendingOO, onInterval, this); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
126 |
return; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
127 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
128 |
case AppOOEvent::STOP_GEN : |
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 |
DEBUG0((cout << "StopGen at " << Simulator::Now() << endl)); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
131 |
if (totBytes < maxBytes) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
132 |
{ // Only schedule if not execeeded maxBytes |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
Time_t offInterval = offTime->Value(); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
134 |
pendingOO->event = AppOOEvent::START_GEN; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
135 |
// Schedule the start event |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
136 |
Simulator::Schedule(pendingOO, offInterval, this); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
137 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
138 |
if (pendingEvent) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
139 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
140 |
// 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
|
141 |
residualBits += (uint32_t)(cbrRate*(Simulator::Now()-lastStartTime)); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
142 |
Simulator::Cancel(pendingEvent); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
143 |
delete pendingEvent; |
489
97a210720478
remove nil macro
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
478
diff
changeset
|
144 |
pendingEvent = 0; |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
145 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
146 |
return; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
147 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
148 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
149 |
Application::Handle(e, t); // May be application event |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
150 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
151 |
#endif |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
152 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
153 |
// Application Methods |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
154 |
void OnOffApplication::StartApplication() // Called at time specified by Start |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
// 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
|
157 |
if (!m_socket) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
{ // Create the socket using the specified layer 4 protocol |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
159 |
#ifdef NOTYET |
607
1b7abeccfcda
rename Node to INode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
604
diff
changeset
|
160 |
m_socket = PeekINode()->GetKernel()->CreateGenericSocket(*m_l4Proto); |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
161 |
m_socket->Bind(); // Choose any available port local port |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
162 |
m_socket->Connect(*m_peerIP, m_peerPort, |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
163 |
MakeCallback(&OnOffApplication::ConnectionSucceeded, |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
164 |
this), |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
165 |
MakeCallback(&OnOffApplication::ConnectionFailed, |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
166 |
this)); |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
167 |
#endif |
499
8a469663f7ea
implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
498
diff
changeset
|
168 |
|
607
1b7abeccfcda
rename Node to INode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
604
diff
changeset
|
169 |
Ptr<IUdp> udp = GetINode ()->QueryInterface<IUdp> (IUdp::iid); |
499
8a469663f7ea
implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
498
diff
changeset
|
170 |
m_socket = udp->CreateSocket (); |
453
ddbb935800d8
remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
384
diff
changeset
|
171 |
m_socket->Connect (m_peerIP, m_peerPort); |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
172 |
} |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
173 |
StopApplication(); // Insure no pending event |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
174 |
// 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
|
175 |
// 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
|
176 |
//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
|
177 |
ScheduleStartEvent(); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
178 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
179 |
|
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
180 |
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
|
181 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
182 |
if (m_startStopScheduled) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
183 |
{ // Cancel the startStop event |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
184 |
Simulator::Cancel(m_startStopEvent); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
185 |
m_startStopScheduled = false; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
186 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
187 |
if (m_sendScheduled) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
188 |
{ // 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
|
189 |
Simulator::Cancel(m_sendEvent); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
190 |
m_sendScheduled = false; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
191 |
// 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
|
192 |
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
|
193 |
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
|
194 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
195 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
196 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
197 |
// Event handlers |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
198 |
void OnOffApplication::StartSending() |
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 |
m_startStopScheduled = true; |
478
b067d8ff43df
make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
201 |
ScheduleNextTx(); // Schedule the send packet event |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
202 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
203 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
204 |
void OnOffApplication::StopSending() |
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 |
m_startStopScheduled = true; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
207 |
if (m_sendScheduled) Simulator::Cancel(m_sendEvent); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
208 |
} |
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 |
// Private helpers |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
211 |
void OnOffApplication::ScheduleNextTx() |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
212 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
213 |
if (m_totBytes < m_maxBytes) |
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 |
uint32_t bits = m_pktSize * 8 - m_residualBits; |
382
26528ff50d38
Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents:
372
diff
changeset
|
216 |
Time nextTime(Seconds (bits / |
26528ff50d38
Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents:
372
diff
changeset
|
217 |
static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet |
478
b067d8ff43df
make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
218 |
m_sendScheduled = true; |
b067d8ff43df
make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
219 |
m_sendEvent = Simulator::Schedule(nextTime, &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
|
220 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
221 |
else |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
222 |
{ // All done, cancel any pending events |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
223 |
StopApplication(); |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
224 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
225 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
226 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
227 |
void OnOffApplication::ScheduleStartEvent() |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
228 |
{ // Schedules the event to start sending data (switch to the "On" state) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
229 |
Time offInterval = Seconds(m_offTime->GetValue()); |
478
b067d8ff43df
make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
230 |
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
|
231 |
m_startStopScheduled = true; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
232 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
233 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
234 |
void OnOffApplication::ScheduleStopEvent() |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
235 |
{ // Schedules the event to stop sending data (switch to "Off" state) |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
236 |
Time onInterval = Seconds(m_onTime->GetValue()); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
237 |
Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
238 |
m_startStopScheduled = true; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
239 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
240 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
241 |
|
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
242 |
void OnOffApplication::SendPacket() |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
243 |
{ |
478
b067d8ff43df
make Application::Stop work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
244 |
NS_ASSERT (m_sendScheduled); |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
245 |
m_sendScheduled = false; |
453
ddbb935800d8
remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
384
diff
changeset
|
246 |
m_socket->Send(0, m_pktSize); |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
247 |
#ifdef NOTYET |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
248 |
m_socket->Send(0, m_pktSize); // Send the packet |
359
91b7ad7fa784
OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents:
349
diff
changeset
|
249 |
#endif |
349
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
m_residualBits = 0; |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
253 |
ScheduleNextTx(); |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
254 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
255 |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
563
diff
changeset
|
256 |
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
|
257 |
{ |
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 |
} |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
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 |
{ |
3c91100689d7
Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
264 |
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
|
265 |
} |
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 |
} // Namespace ns3 |