author | Craig Dowell <craigdo@ee.washington.edu> |
Fri, 12 Feb 2010 17:31:11 -0800 | |
changeset 6049 | 3dbc035a9ee4 |
parent 6028 | 96fb92f73f3d |
child 6052 | e146b9c9c7e7 |
permissions | -rw-r--r-- |
3828 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2008 University of Washington |
|
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 |
||
19 |
#include <string> |
|
20 |
||
21 |
#include "ns3/log.h" |
|
22 |
#include "ns3/simulator.h" |
|
23 |
#include "ns3/object-factory.h" |
|
4147
5d8530130930
rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents:
4140
diff
changeset
|
24 |
#include "ns3/names.h" |
3828 | 25 |
#include "ns3/queue.h" |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3828
diff
changeset
|
26 |
#include "ns3/emu-net-device.h" |
3828 | 27 |
#include "ns3/config.h" |
28 |
#include "ns3/packet.h" |
|
29 |
||
6028
96fb92f73f3d
merge trace helpers, rescan
Craig Dowell <craigdo@ee.washington.edu>
parents:
6013
diff
changeset
|
30 |
#include "trace-helper.h" |
3828 | 31 |
#include "emu-helper.h" |
32 |
||
33 |
NS_LOG_COMPONENT_DEFINE ("EmuHelper"); |
|
34 |
||
35 |
namespace ns3 { |
|
36 |
||
37 |
EmuHelper::EmuHelper () |
|
38 |
{ |
|
39 |
NS_LOG_FUNCTION_NOARGS (); |
|
40 |
m_queueFactory.SetTypeId ("ns3::DropTailQueue"); |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3828
diff
changeset
|
41 |
m_deviceFactory.SetTypeId ("ns3::EmuNetDevice"); |
3828 | 42 |
} |
43 |
||
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
44 |
void |
3828 | 45 |
EmuHelper::SetQueue ( |
46 |
std::string type, |
|
47 |
std::string n1, const AttributeValue &v1, |
|
48 |
std::string n2, const AttributeValue &v2, |
|
49 |
std::string n3, const AttributeValue &v3, |
|
50 |
std::string n4, const AttributeValue &v4) |
|
51 |
{ |
|
52 |
NS_LOG_FUNCTION_NOARGS (); |
|
53 |
m_queueFactory.SetTypeId (type); |
|
54 |
m_queueFactory.Set (n1, v1); |
|
55 |
m_queueFactory.Set (n2, v2); |
|
56 |
m_queueFactory.Set (n3, v3); |
|
57 |
m_queueFactory.Set (n4, v4); |
|
58 |
} |
|
59 |
||
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
60 |
void |
3828 | 61 |
EmuHelper::SetAttribute (std::string n1, const AttributeValue &v1) |
62 |
{ |
|
63 |
NS_LOG_FUNCTION_NOARGS (); |
|
64 |
m_deviceFactory.Set (n1, v1); |
|
65 |
} |
|
66 |
||
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
67 |
void |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
68 |
EmuHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous) |
3828 | 69 |
{ |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
70 |
// |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
71 |
// All of the Pcap enable functions vector through here including the ones |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
72 |
// that are wandering through all of devices on perhaps all of the nodes in |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
73 |
// the system. We can only deal with devices of type EmuNetDevice. |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
74 |
// |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
75 |
Ptr<EmuNetDevice> device = nd->GetObject<EmuNetDevice> (); |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
76 |
if (device == 0) |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
77 |
{ |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
78 |
NS_LOG_INFO ("EmuHelper::EnablePcapInternal(): Device " << device << " not of type ns3::EmuNetDevice"); |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
79 |
return; |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
80 |
} |
3828 | 81 |
|
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
82 |
PcapHelper pcapHelper; |
6013 | 83 |
std::string filename = pcapHelper.GetFilenameFromDevice (prefix, device); |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
84 |
Ptr<PcapFileObject> file = pcapHelper.CreateFile (filename, "w", PcapHelper::DLT_EN10MB); |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
85 |
if (promiscuous) |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
86 |
{ |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
87 |
pcapHelper.HookDefaultSink<EmuNetDevice> (device, "PromiscSniffer", file); |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
88 |
} |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
89 |
else |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
90 |
{ |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
4712
diff
changeset
|
91 |
pcapHelper.HookDefaultSink<EmuNetDevice> (device, "Sniffer", file); |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
92 |
} |
3828 | 93 |
} |
94 |
||
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
95 |
void |
6049
3dbc035a9ee4
The name OutputStreamObject is no longer appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
6028
diff
changeset
|
96 |
EmuHelper::EnableAsciiInternal (Ptr<OutputStreamKeeper> stream, std::string prefix, Ptr<NetDevice> nd) |
3828 | 97 |
{ |
6013 | 98 |
// |
99 |
// All of the ascii enable functions vector through here including the ones |
|
100 |
// that are wandering through all of devices on perhaps all of the nodes in |
|
101 |
// the system. We can only deal with devices of type EmuNetDevice. |
|
102 |
// |
|
103 |
Ptr<EmuNetDevice> device = nd->GetObject<EmuNetDevice> (); |
|
104 |
if (device == 0) |
|
105 |
{ |
|
106 |
NS_LOG_INFO ("EmuHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::EmuNetDevice"); |
|
107 |
return; |
|
108 |
} |
|
109 |
||
110 |
// |
|
111 |
// Our default trace sinks are going to use packet printing, so we have to |
|
112 |
// make sure that is turned on. |
|
113 |
// |
|
3828 | 114 |
Packet::EnablePrinting (); |
6013 | 115 |
|
116 |
// |
|
6049
3dbc035a9ee4
The name OutputStreamObject is no longer appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
6028
diff
changeset
|
117 |
// If we are not provided an OutputStreamKeeper, we are expected to create |
6013 | 118 |
// one using the usual trace filename conventions and do a Hook*WithoutContext |
119 |
// since there will be one file per context and therefore the context would |
|
120 |
// be redundant. |
|
121 |
// |
|
122 |
if (stream == 0) |
|
123 |
{ |
|
124 |
// |
|
125 |
// Set up an output stream object to deal with private ofstream copy |
|
126 |
// constructor and lifetime issues. Let the helper decide the actual |
|
127 |
// name of the file given the prefix. |
|
128 |
// |
|
129 |
AsciiTraceHelper asciiTraceHelper; |
|
130 |
std::string filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device); |
|
6049
3dbc035a9ee4
The name OutputStreamObject is no longer appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
6028
diff
changeset
|
131 |
Ptr<OutputStreamKeeper> theStream = asciiTraceHelper.CreateFileStream (filename, "w"); |
6013 | 132 |
|
133 |
// |
|
134 |
// The MacRx trace source provides our "r" event. |
|
135 |
// |
|
136 |
asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<EmuNetDevice> (device, "MacRx", theStream); |
|
137 |
||
138 |
// |
|
139 |
// The "+", '-', and 'd' events are driven by trace sources actually in the |
|
140 |
// transmit queue. |
|
141 |
// |
|
142 |
Ptr<Queue> queue = device->GetQueue (); |
|
143 |
asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue> (queue, "Enqueue", theStream); |
|
144 |
asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue> (queue, "Drop", theStream); |
|
145 |
asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue> (queue, "Dequeue", theStream); |
|
146 |
||
147 |
return; |
|
148 |
} |
|
149 |
||
150 |
// |
|
6049
3dbc035a9ee4
The name OutputStreamObject is no longer appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
6028
diff
changeset
|
151 |
// If we are provided an OutputStreamKeeper, we are expected to use it, and |
6013 | 152 |
// to providd a context. We are free to come up with our own context if we |
153 |
// want, and use the AsciiTraceHelper Hook*WithContext functions, but for |
|
154 |
// compatibility and simplicity, we just use Config::Connect and let it deal |
|
155 |
// with the context. |
|
156 |
// |
|
157 |
// Note that we are going to use the default trace sinks provided by the |
|
158 |
// ascii trace helper. There is actually no AsciiTraceHelper in sight here, |
|
159 |
// but the default trace sinks are actually publicly available static |
|
160 |
// functions that are always there waiting for just such a case. |
|
161 |
// |
|
162 |
uint32_t nodeid = nd->GetNode ()->GetId (); |
|
163 |
uint32_t deviceid = nd->GetIfIndex (); |
|
3828 | 164 |
std::ostringstream oss; |
165 |
||
6013 | 166 |
oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/MacRx"; |
167 |
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream)); |
|
3828 | 168 |
|
169 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
170 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Enqueue"; |
6013 | 171 |
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream)); |
3828 | 172 |
|
173 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
174 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Dequeue"; |
6013 | 175 |
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream)); |
3828 | 176 |
|
177 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
178 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Drop"; |
6013 | 179 |
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream)); |
3828 | 180 |
} |
181 |
||
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
182 |
NetDeviceContainer |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
183 |
EmuHelper::Install (Ptr<Node> node) const |
3828 | 184 |
{ |
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
185 |
return NetDeviceContainer (InstallPriv (node)); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
186 |
} |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
187 |
|
4140
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
188 |
NetDeviceContainer |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
189 |
EmuHelper::Install (std::string nodeName) const |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
190 |
{ |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
191 |
Ptr<Node> node = Names::Find<Node> (nodeName); |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
192 |
return NetDeviceContainer (InstallPriv (node)); |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
193 |
} |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
194 |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
195 |
NetDeviceContainer |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
196 |
EmuHelper::Install (const NodeContainer &c) const |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
197 |
{ |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
198 |
NetDeviceContainer devs; |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
199 |
|
3828 | 200 |
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) |
201 |
{ |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
202 |
devs.Add (InstallPriv (*i)); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
203 |
} |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
204 |
|
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
205 |
return devs; |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
206 |
} |
3828 | 207 |
|
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
208 |
Ptr<NetDevice> |
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
209 |
EmuHelper::InstallPriv (Ptr<Node> node) const |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
210 |
{ |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
211 |
Ptr<EmuNetDevice> device = m_deviceFactory.Create<EmuNetDevice> (); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
212 |
device->SetAddress (Mac48Address::Allocate ()); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
213 |
node->AddDevice (device); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
214 |
Ptr<Queue> queue = m_queueFactory.Create<Queue> (); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
215 |
device->SetQueue (queue); |
3828 | 216 |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
217 |
return device; |
3828 | 218 |
} |
219 |
||
220 |
} // namespace ns3 |