author | Craig Dowell <craigdo@ee.washington.edu> |
Sat, 28 Feb 2009 16:25:24 -0800 | |
changeset 4263 | fec2f830d015 |
parent 4147 | 5d8530130930 |
child 4264 | 9d2e96c4e6e4 |
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/pcap-writer.h" |
28 |
#include "ns3/config.h" |
|
29 |
#include "ns3/packet.h" |
|
30 |
||
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 |
||
44 |
void |
|
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 |
||
60 |
void |
|
61 |
EmuHelper::SetAttribute (std::string n1, const AttributeValue &v1) |
|
62 |
{ |
|
63 |
NS_LOG_FUNCTION_NOARGS (); |
|
64 |
m_deviceFactory.Set (n1, v1); |
|
65 |
} |
|
66 |
||
67 |
void |
|
68 |
EmuHelper::EnablePcap ( |
|
69 |
std::string filename, |
|
70 |
uint32_t nodeid, |
|
71 |
uint32_t deviceid) |
|
72 |
{ |
|
73 |
NS_LOG_FUNCTION (filename << nodeid << deviceid); |
|
74 |
std::ostringstream oss; |
|
75 |
oss << filename << "-" << nodeid << "-" << deviceid << ".pcap"; |
|
76 |
Ptr<PcapWriter> pcap = Create<PcapWriter> (); |
|
77 |
pcap->Open (oss.str ()); |
|
78 |
pcap->WriteEthernetHeader (); |
|
79 |
||
80 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
81 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/Sniffer"; |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
82 |
Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&EmuHelper::SniffEvent, pcap)); |
3828 | 83 |
} |
84 |
||
85 |
void |
|
86 |
EmuHelper::EnablePcap (std::string filename, NetDeviceContainer d) |
|
87 |
{ |
|
88 |
NS_LOG_FUNCTION (filename << &d); |
|
89 |
for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i) |
|
90 |
{ |
|
91 |
Ptr<NetDevice> dev = *i; |
|
92 |
EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ()); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
void |
|
97 |
EmuHelper::EnablePcap (std::string filename, NodeContainer n) |
|
98 |
{ |
|
99 |
NS_LOG_FUNCTION (filename << &n); |
|
100 |
NetDeviceContainer devs; |
|
101 |
for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
|
102 |
{ |
|
103 |
Ptr<Node> node = *i; |
|
104 |
for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
|
105 |
{ |
|
106 |
devs.Add (node->GetDevice (j)); |
|
107 |
} |
|
108 |
} |
|
109 |
EnablePcap (filename, devs); |
|
110 |
} |
|
111 |
||
112 |
void |
|
113 |
EmuHelper::EnablePcapAll (std::string filename) |
|
114 |
{ |
|
115 |
NS_LOG_FUNCTION (filename); |
|
116 |
EnablePcap (filename, NodeContainer::GetGlobal ()); |
|
117 |
} |
|
118 |
||
119 |
void |
|
120 |
EmuHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) |
|
121 |
{ |
|
122 |
NS_LOG_FUNCTION (&os << nodeid << deviceid); |
|
123 |
Packet::EnablePrinting (); |
|
124 |
std::ostringstream oss; |
|
125 |
||
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
126 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/MacRx"; |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
127 |
Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiRxEvent, &os)); |
3828 | 128 |
|
129 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
130 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Enqueue"; |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
131 |
Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, &os)); |
3828 | 132 |
|
133 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
134 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Dequeue"; |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
135 |
Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, &os)); |
3828 | 136 |
|
137 |
oss.str (""); |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
138 |
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Drop"; |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
139 |
Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDropEvent, &os)); |
3828 | 140 |
} |
141 |
||
142 |
void |
|
143 |
EmuHelper::EnableAscii (std::ostream &os, NetDeviceContainer d) |
|
144 |
{ |
|
145 |
NS_LOG_FUNCTION (&os << &d); |
|
146 |
for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i) |
|
147 |
{ |
|
148 |
Ptr<NetDevice> dev = *i; |
|
149 |
EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ()); |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
void |
|
154 |
EmuHelper::EnableAscii (std::ostream &os, NodeContainer n) |
|
155 |
{ |
|
156 |
NS_LOG_FUNCTION (&os << &n); |
|
157 |
NetDeviceContainer devs; |
|
158 |
for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
|
159 |
{ |
|
160 |
Ptr<Node> node = *i; |
|
161 |
for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
|
162 |
{ |
|
163 |
devs.Add (node->GetDevice (j)); |
|
164 |
} |
|
165 |
} |
|
166 |
EnableAscii (os, devs); |
|
167 |
} |
|
168 |
||
169 |
void |
|
170 |
EmuHelper::EnableAsciiAll (std::ostream &os) |
|
171 |
{ |
|
172 |
NS_LOG_FUNCTION (&os); |
|
173 |
EnableAscii (os, NodeContainer::GetGlobal ()); |
|
174 |
} |
|
175 |
||
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
176 |
NetDeviceContainer |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
177 |
EmuHelper::Install (Ptr<Node> node) const |
3828 | 178 |
{ |
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
179 |
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
|
180 |
} |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
181 |
|
4140
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
182 |
NetDeviceContainer |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
183 |
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
|
184 |
{ |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
185 |
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
|
186 |
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
|
187 |
} |
6bbf05bf4826
Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
3848
diff
changeset
|
188 |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
189 |
NetDeviceContainer |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
190 |
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
|
191 |
{ |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
192 |
NetDeviceContainer devs; |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
193 |
|
3828 | 194 |
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) |
195 |
{ |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
196 |
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
|
197 |
} |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
198 |
|
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
199 |
return devs; |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
200 |
} |
3828 | 201 |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
202 |
Ptr<NetDevice> |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
203 |
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
|
204 |
{ |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
node->AddDevice (device); |
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
208 |
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
|
209 |
device->SetQueue (queue); |
3828 | 210 |
|
3848
affd0834debc
address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents:
3837
diff
changeset
|
211 |
return device; |
3828 | 212 |
} |
213 |
||
214 |
void |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
215 |
EmuHelper::SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet) |
3828 | 216 |
{ |
217 |
NS_LOG_FUNCTION (writer << packet); |
|
218 |
writer->WritePacket (packet); |
|
219 |
} |
|
220 |
||
221 |
void |
|
222 |
EmuHelper::AsciiEnqueueEvent ( |
|
223 |
std::ostream *os, |
|
224 |
std::string path, |
|
225 |
Ptr<const Packet> packet) |
|
226 |
{ |
|
227 |
NS_LOG_FUNCTION (&os << path << packet); |
|
228 |
*os << "+ " << Simulator::Now ().GetSeconds () << " "; |
|
229 |
*os << path << " " << *packet << std::endl; |
|
230 |
} |
|
231 |
||
232 |
void |
|
233 |
EmuHelper::AsciiDequeueEvent ( |
|
234 |
std::ostream *os, |
|
235 |
std::string path, |
|
236 |
Ptr<const Packet> packet) |
|
237 |
{ |
|
238 |
NS_LOG_FUNCTION (&os << path << packet); |
|
239 |
*os << "- " << Simulator::Now ().GetSeconds () << " "; |
|
240 |
*os << path << " " << *packet << std::endl; |
|
241 |
} |
|
242 |
||
243 |
void |
|
244 |
EmuHelper::AsciiDropEvent ( |
|
245 |
std::ostream *os, |
|
246 |
std::string path, |
|
247 |
Ptr<const Packet> packet) |
|
248 |
{ |
|
249 |
NS_LOG_FUNCTION (&os << path << packet); |
|
250 |
*os << "d " << Simulator::Now ().GetSeconds () << " "; |
|
251 |
*os << path << " " << *packet << std::endl; |
|
252 |
} |
|
253 |
||
254 |
void |
|
255 |
EmuHelper::AsciiRxEvent ( |
|
256 |
std::ostream *os, |
|
257 |
std::string path, |
|
258 |
Ptr<const Packet> packet) |
|
259 |
{ |
|
260 |
NS_LOG_FUNCTION (&os << path << packet); |
|
261 |
*os << "r " << Simulator::Now ().GetSeconds () << " "; |
|
262 |
*os << path << " " << *packet << std::endl; |
|
263 |
} |
|
264 |
||
265 |
} // namespace ns3 |