|
|
| 20 |
|
20 |
|
| 21 |
#include <stdio.h> |
21 |
#include <stdio.h> |
| 22 |
#include <sstream> |
22 |
#include <sstream> |
|
|
23 |
#include <string> |
| 24 |
#include <iomanip> |
| 25 |
#include <map> |
| 23 |
|
26 |
|
| 24 |
// Socket related includes |
27 |
// Socket related includes |
| 25 |
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H) |
28 |
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H) |
|
|
| 37 |
#include "ns3/mobility-model.h" |
40 |
#include "ns3/mobility-model.h" |
| 38 |
#include "ns3/packet.h" |
41 |
#include "ns3/packet.h" |
| 39 |
#include "ns3/simulator.h" |
42 |
#include "ns3/simulator.h" |
|
|
43 |
#include "ns3/animation-interface-helper.h" |
| 40 |
|
44 |
|
| 41 |
using namespace std; |
45 |
using namespace std; |
| 42 |
|
46 |
|
|
|
| 45 |
namespace ns3 { |
49 |
namespace ns3 { |
| 46 |
|
50 |
|
| 47 |
AnimationInterface::AnimationInterface () |
51 |
AnimationInterface::AnimationInterface () |
| 48 |
: m_fHandle (STDOUT_FILENO), m_model (0) |
52 |
: m_fHandle (STDOUT_FILENO), m_xml (false), m_model (0), mobilitypollinterval (Seconds(0.25)) |
| 49 |
{ |
53 |
{ |
| 50 |
} |
54 |
} |
| 51 |
|
55 |
|
| 52 |
AnimationInterface::~AnimationInterface () |
56 |
AnimationInterface::~AnimationInterface () |
| 53 |
{ |
57 |
{ |
|
|
58 |
StopAnimation (); |
| 59 |
} |
| 60 |
|
| 61 |
void AnimationInterface::SetXMLOutput () |
| 62 |
{ |
| 63 |
m_xml = true; |
| 54 |
} |
64 |
} |
| 55 |
|
65 |
|
| 56 |
bool AnimationInterface::SetOutputFile (const std::string& fn) |
66 |
bool AnimationInterface::SetOutputFile (const std::string& fn) |
|
|
| 58 |
FILE* f = fopen (fn.c_str (), "w"); |
68 |
FILE* f = fopen (fn.c_str (), "w"); |
| 59 |
if (!f) |
69 |
if (!f) |
| 60 |
{ |
70 |
{ |
|
|
71 |
NS_FATAL_ERROR ("Unable to output Animation output file"); |
| 61 |
return false; // Can't open |
72 |
return false; // Can't open |
| 62 |
} |
73 |
} |
| 63 |
m_fHandle = fileno (f); // Set the file handle |
74 |
m_fHandle = fileno (f); // Set the file handle |
|
|
| 91 |
// which is done to support a platform like MinGW |
102 |
// which is done to support a platform like MinGW |
| 92 |
} |
103 |
} |
| 93 |
|
104 |
|
|
|
105 |
Vector AnimationInterface::GetPosition (Ptr <Node> n) |
| 106 |
{ |
| 107 |
Ptr<MobilityModel> loc = n->GetObject<MobilityModel> (); |
| 108 |
Vector v(0,0,0); |
| 109 |
if (!loc) |
| 110 |
{ |
| 111 |
return v; |
| 112 |
} |
| 113 |
if (loc) |
| 114 |
{ |
| 115 |
v = loc->GetPosition (); |
| 116 |
} |
| 117 |
return v; |
| 118 |
} |
| 94 |
void AnimationInterface::StartAnimation () |
119 |
void AnimationInterface::StartAnimation () |
| 95 |
{ |
120 |
{ |
|
|
121 |
// Find the min/max x/y for the xml topology element |
| 122 |
topo_minX = 0; |
| 123 |
topo_minY = 0; |
| 124 |
topo_maxX = 1000; |
| 125 |
topo_maxY = 1000; |
| 126 |
bool first = true; |
| 127 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) |
| 128 |
{ |
| 129 |
Ptr<Node> n = *i; |
| 130 |
Vector v = GetPosition (n); |
| 131 |
if (first) |
| 132 |
{ |
| 133 |
topo_minX = v.x; |
| 134 |
topo_minY = v.y; |
| 135 |
topo_maxX = v.x; |
| 136 |
topo_maxY = v.y; |
| 137 |
first = false; |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
topo_minX = min (topo_minX, v.x); |
| 142 |
topo_minY = min (topo_minY, v.y); |
| 143 |
topo_maxX = max (topo_maxX, v.x); |
| 144 |
topo_maxY = max (topo_maxY, v.y); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
if (m_xml) |
| 149 |
{ // output the xml headers |
| 150 |
ostringstream oss; |
| 151 |
oss << GetXMLOpen_anim (0); |
| 152 |
oss << GetXMLOpen_topology (topo_minX,topo_minY,topo_maxX,topo_maxY); |
| 153 |
WriteN (m_fHandle, oss.str ()); |
| 154 |
} |
| 96 |
// Dump the topology |
155 |
// Dump the topology |
| 97 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) |
156 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) |
| 98 |
{ |
157 |
{ |
| 99 |
Ptr<Node> n = *i; |
158 |
Ptr<Node> n = *i; |
| 100 |
Ptr<MobilityModel> loc = n->GetObject<MobilityModel> (); |
159 |
ostringstream oss; |
| 101 |
if (loc) |
160 |
if (m_xml) |
|
|
161 |
{ |
| 162 |
Vector v = GetPosition (n); |
| 163 |
oss << GetXMLOpenClose_node (0,n->GetId (),v.x,v.y); |
| 164 |
} |
| 165 |
else |
| 102 |
{ |
166 |
{ |
| 103 |
// Location exists, dump it |
167 |
// Location exists, dump it |
| 104 |
Vector v = loc->GetPosition (); |
168 |
Vector v = GetPosition (n); |
| 105 |
ostringstream oss; |
|
|
| 106 |
oss << "0.0 N " << n->GetId () |
169 |
oss << "0.0 N " << n->GetId () |
| 107 |
<< " " << v.x << " " << v.y << endl; |
170 |
<< " " << v.x << " " << v.y << endl; |
| 108 |
WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ()); |
|
|
| 109 |
} |
171 |
} |
|
|
172 |
|
| 173 |
WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ()); |
| 110 |
} |
174 |
} |
| 111 |
// Now dump the p2p links |
175 |
// Now dump the p2p links |
| 112 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) |
176 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) |
|
|
| 134 |
if (n1Id < n2Id) |
198 |
if (n1Id < n2Id) |
| 135 |
{ // ouptut the p2p link |
199 |
{ // ouptut the p2p link |
| 136 |
ostringstream oss; |
200 |
ostringstream oss; |
| 137 |
oss << "0.0 L " << n1Id << " " << n2Id << endl; |
201 |
if (m_xml) |
| 138 |
WriteN (m_fHandle, oss.str ().c_str (), |
202 |
{ |
| 139 |
oss.str ().length ()); |
203 |
oss << GetXMLOpenClose_link (0,n1Id,0,n2Id); |
|
|
204 |
} |
| 205 |
else |
| 206 |
{ |
| 207 |
oss << "0.0 L " << n1Id << " " << n2Id << endl; |
| 208 |
} |
| 209 |
WriteN (m_fHandle, oss.str ()); |
| 210 |
|
| 140 |
} |
211 |
} |
| 141 |
} |
212 |
} |
| 142 |
} |
213 |
} |
| 143 |
else |
214 |
else |
| 144 |
{ |
215 |
{ |
| 145 |
NS_FATAL_ERROR ("Net animation currently only supports point-to-point links."); |
216 |
//NS_FATAL_ERROR ("Net animation currently only supports point-to-point links."); |
| 146 |
} |
217 |
} |
| 147 |
} |
218 |
} |
| 148 |
} |
219 |
} |
|
|
220 |
if (m_xml) |
| 221 |
{ |
| 222 |
WriteN (m_fHandle, GetXMLClose ("topology")); |
| 223 |
Simulator::Schedule (mobilitypollinterval, &AnimationInterface::MobilityAutoCheck, this); |
| 224 |
} |
| 149 |
|
225 |
|
| 150 |
// Connect the callback for packet tx events |
226 |
// Connect the callbacks |
| 151 |
Config::Connect ("/ChannelList/*/TxRxPointToPoint", |
227 |
Config::Connect ("/ChannelList/*/TxRxPointToPoint", |
| 152 |
MakeCallback (&AnimationInterface::DevTxTrace, this)); |
228 |
MakeCallback (&AnimationInterface::DevTxTrace, this)); |
|
|
229 |
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin", |
| 230 |
MakeCallback (&AnimationInterface::WifiPhyTxBeginTrace, this)); |
| 231 |
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxEnd", |
| 232 |
MakeCallback (&AnimationInterface::WifiPhyTxEndTrace, this)); |
| 233 |
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin", |
| 234 |
MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace, this)); |
| 235 |
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxEnd", |
| 236 |
MakeCallback (&AnimationInterface::WifiPhyRxEndTrace, this)); |
| 237 |
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop", |
| 238 |
MakeCallback (&AnimationInterface::WifiPhyRxDropTrace, this)); |
| 239 |
Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange", |
| 240 |
MakeCallback (&AnimationInterface::MobilityCourseChangeTrace, this)); |
| 241 |
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx", |
| 242 |
MakeCallback (&AnimationInterface::WimaxTxTrace, this)); |
| 243 |
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx", |
| 244 |
MakeCallback (&AnimationInterface::WimaxRxTrace, this)); |
| 245 |
|
| 246 |
|
| 247 |
|
| 153 |
} |
248 |
} |
| 154 |
|
249 |
|
| 155 |
void AnimationInterface::StopAnimation () |
250 |
void AnimationInterface::StopAnimation () |
| 156 |
{ |
251 |
{ |
| 157 |
if (m_fHandle > 0) |
252 |
if (m_fHandle > 0) |
| 158 |
{ |
253 |
{ |
|
|
254 |
if (m_xml) |
| 255 |
{ // Terminate the anim element |
| 256 |
WriteN (m_fHandle, GetXMLClose ("anim")); |
| 257 |
} |
| 159 |
close (m_fHandle); |
258 |
close (m_fHandle); |
|
|
259 |
m_fHandle = 0; |
| 160 |
} |
260 |
} |
| 161 |
} |
261 |
} |
| 162 |
|
262 |
|
|
|
263 |
int AnimationInterface::WriteN (int h, const string& st) |
| 264 |
{ |
| 265 |
return WriteN (h, st.c_str (), st.length ()); |
| 266 |
} |
| 267 |
|
| 163 |
|
268 |
|
| 164 |
// Private methods |
269 |
// Private methods |
|
|
270 |
void AnimationInterface::RecalcTopoBounds (Vector v) |
| 271 |
{ |
| 272 |
topo_minX = min (topo_minX, v.x); |
| 273 |
topo_minY = min (topo_minY, v.y); |
| 274 |
topo_maxX = max (topo_maxX, v.x); |
| 275 |
topo_maxY = max (topo_maxY, v.y); |
| 276 |
|
| 277 |
} |
| 278 |
|
| 165 |
int AnimationInterface::WriteN (int h, const char* data, uint32_t count) |
279 |
int AnimationInterface::WriteN (int h, const char* data, uint32_t count) |
| 166 |
{ // Write count bytes to h from data |
280 |
{ // Write count bytes to h from data |
| 167 |
uint32_t nLeft = count; |
281 |
uint32_t nLeft = count; |
| 168 |
const char* p = data; |
282 |
const char* p = data; |
| 169 |
uint32_t written = 0; |
283 |
uint32_t written = 0; |
| 170 |
|
|
|
| 171 |
while (nLeft) |
284 |
while (nLeft) |
| 172 |
{ |
285 |
{ |
| 173 |
int n = write (h, p, nLeft); |
286 |
int n = write (h, p, nLeft); |
|
|
| 188 |
{ |
301 |
{ |
| 189 |
Time now = Simulator::Now (); |
302 |
Time now = Simulator::Now (); |
| 190 |
ostringstream oss; |
303 |
ostringstream oss; |
| 191 |
oss << now.GetSeconds () << " P " |
304 |
double fbTx = now.GetSeconds (); |
| 192 |
<< tx->GetNode ()->GetId () << " " |
305 |
double lbTx = (now + txTime).GetSeconds (); |
| 193 |
<< rx->GetNode ()->GetId () << " " |
306 |
double fbRx = (now + rxTime - txTime).GetSeconds (); |
| 194 |
<< (now + txTime).GetSeconds () << " " // last bit tx time |
307 |
double lbRx = (now + rxTime).GetSeconds (); |
| 195 |
<< (now + rxTime - txTime).GetSeconds () << " " // first bit rx time |
308 |
if (m_xml) |
| 196 |
<< (now + rxTime).GetSeconds () << endl; // last bit rx time |
309 |
{ |
| 197 |
WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ()); |
310 |
oss << GetXMLOpen_packet (0,tx->GetNode ()->GetId (),fbTx,lbTx); |
|
|
311 |
oss << GetXMLOpenClose_rx (0,rx->GetNode ()->GetId (),fbRx,lbRx); |
| 312 |
oss << GetXMLClose ("packet"); |
| 313 |
} |
| 314 |
else |
| 315 |
{ |
| 316 |
oss << setprecision (10); |
| 317 |
oss << now.GetSeconds () << " P " |
| 318 |
<< tx->GetNode ()->GetId () << " " |
| 319 |
<< rx->GetNode ()->GetId () << " " |
| 320 |
<< (now + txTime).GetSeconds () << " " // last bit tx time |
| 321 |
<< (now + rxTime - txTime).GetSeconds () << " " // first bit rx time |
| 322 |
<< (now + rxTime).GetSeconds () << endl; // last bit rx time |
| 323 |
} |
| 324 |
WriteN (m_fHandle, oss.str ()); |
| 198 |
} |
325 |
} |
| 199 |
|
326 |
|
|
|
327 |
|
| 328 |
Ptr <NetDevice> |
| 329 |
AnimationInterface::GetNetDeviceFromContext (std::string context) |
| 330 |
{ |
| 331 |
// Use "NodeList/*/DeviceList/*/ as reference |
| 332 |
// where element [1] is the Node Id |
| 333 |
// element [2] is the NetDevice Id |
| 334 |
|
| 335 |
vector <std::string> elements = GetElementsFromContext (context); |
| 336 |
Ptr <Node> n = NodeList::GetNode (atoi (elements[1].c_str ())); |
| 337 |
NS_ASSERT (n); |
| 338 |
return n->GetDevice (atoi (elements[3].c_str ())); |
| 339 |
} |
| 340 |
|
| 341 |
void AnimationInterface::WifiPhyTxBeginTrace (std::string context, |
| 342 |
Ptr<const Packet> p) |
| 343 |
{ |
| 344 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 345 |
NS_ASSERT (ndev); |
| 346 |
Ptr <Node> n = ndev->GetNode (); |
| 347 |
NS_ASSERT (n); |
| 348 |
// Add a new pending wireless |
| 349 |
pendingWifiPackets[p->GetUid ()] = |
| 350 |
AnimPacketInfo (ndev, Simulator::Now (), Simulator::Now ()+Seconds(0.5), GetPosition (n)); |
| 351 |
} |
| 352 |
|
| 353 |
void AnimationInterface::WifiPhyTxEndTrace (std::string context, |
| 354 |
Ptr<const Packet> p) |
| 355 |
{ |
| 356 |
} |
| 357 |
|
| 358 |
void AnimationInterface::WifiPhyTxDropTrace (std::string context, |
| 359 |
Ptr<const Packet> p) |
| 360 |
{ |
| 361 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 362 |
NS_ASSERT (ndev); |
| 363 |
// Erase pending wifi |
| 364 |
pendingWifiPackets.erase (pendingWifiPackets.find (p->GetUid ())); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
void AnimationInterface::WifiPhyRxBeginTrace (std::string context, |
| 369 |
Ptr<const Packet> p) |
| 370 |
{ |
| 371 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 372 |
NS_ASSERT (ndev); |
| 373 |
Ptr <Node> n = ndev->GetNode (); |
| 374 |
NS_ASSERT (n); |
| 375 |
pendingWifiPackets[p->GetUid ()].AddRxBegin (ndev, Simulator::Now (), GetPosition (n)); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
void AnimationInterface::WifiPhyRxEndTrace (std::string context, |
| 380 |
Ptr<const Packet> p) |
| 381 |
{ |
| 382 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 383 |
NS_ASSERT (ndev); |
| 384 |
uint32_t uid = p->GetUid (); |
| 385 |
AnimPacketInfo& pkt = pendingWifiPackets[uid]; |
| 386 |
if (pkt.AddRxEnd (ndev, Simulator::Now ())) |
| 387 |
{ |
| 388 |
//cout << "Packet " << uid << " complete" << endl; |
| 389 |
OutputWirelessPacket (uid, pkt); |
| 390 |
pendingWifiPackets.erase (pendingWifiPackets.find (uid));; |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
void AnimationInterface::WifiPhyRxDropTrace (std::string context, |
| 396 |
Ptr<const Packet> p) |
| 397 |
{ |
| 398 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 399 |
NS_ASSERT (ndev); |
| 400 |
pendingWifiPackets[p->GetUid ()].AddRxDrop (ndev); |
| 401 |
} |
| 402 |
|
| 403 |
void AnimationInterface::WimaxTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m) |
| 404 |
{ |
| 405 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 406 |
NS_ASSERT (ndev); |
| 407 |
Ptr <Node> n = ndev->GetNode (); |
| 408 |
NS_ASSERT (n); |
| 409 |
pendingWimaxPackets[p->GetUid ()] = |
| 410 |
AnimPacketInfo (ndev, Simulator::Now (), Simulator::Now ()+Seconds(0.5), GetPosition (n)); |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
void AnimationInterface::WimaxRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m) |
| 415 |
{ |
| 416 |
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context); |
| 417 |
NS_ASSERT (ndev); |
| 418 |
Ptr <Node> n = ndev->GetNode (); |
| 419 |
NS_ASSERT (n); |
| 420 |
uint32_t uid = p->GetUid (); |
| 421 |
AnimPacketInfo& pktinfo = pendingWimaxPackets[uid]; |
| 422 |
pktinfo.AddRxBegin (ndev, Simulator::Now (), GetPosition (n)); |
| 423 |
pktinfo.AddRxEnd (ndev, Simulator::Now ()+ Seconds (0.0001)); |
| 424 |
OutputWirelessPacket (p->GetUid (), pktinfo); |
| 425 |
|
| 426 |
} |
| 427 |
|
| 428 |
void AnimationInterface::MobilityCourseChangeTrace (Ptr <const MobilityModel> mobility) |
| 429 |
|
| 430 |
{ |
| 431 |
Ptr <Node> n = mobility->GetObject <Node> (); |
| 432 |
if (!n) return; |
| 433 |
if (!mobility) return; |
| 434 |
Vector v ; |
| 435 |
v = mobility->GetPosition (); |
| 436 |
RecalcTopoBounds (v); |
| 437 |
ostringstream oss; |
| 438 |
oss << GetXMLOpen_topology (topo_minX,topo_minY,topo_maxX,topo_maxY); |
| 439 |
oss << GetXMLOpenClose_node (0,n->GetId (),v.x,v.y); |
| 440 |
oss << GetXMLClose ("topology"); |
| 441 |
WriteN (m_fHandle, oss.str ()); |
| 442 |
} |
| 443 |
|
| 444 |
void AnimationInterface::MobilityAutoCheck () |
| 445 |
{ |
| 446 |
Simulator::Schedule (mobilitypollinterval, &AnimationInterface::MobilityAutoCheck, this); |
| 447 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) |
| 448 |
{ |
| 449 |
Ptr <Node> n = *i; |
| 450 |
if (!n) continue; |
| 451 |
Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> (); |
| 452 |
if (!mobility) continue; |
| 453 |
Vector v ; |
| 454 |
v = mobility->GetPosition (); |
| 455 |
RecalcTopoBounds (v); |
| 456 |
ostringstream oss; |
| 457 |
oss << GetXMLOpen_topology (topo_minX,topo_minY,topo_maxX,topo_maxY); |
| 458 |
oss << GetXMLOpenClose_node (0,n->GetId (),v.x,v.y); |
| 459 |
oss << GetXMLClose ("topology"); |
| 460 |
WriteN (m_fHandle, oss.str ()); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
// Helper to output a wireless packet. |
| 466 |
// For now, only the XML interface is supported |
| 467 |
|
| 468 |
void AnimationInterface::OutputWirelessPacket (uint32_t uid, AnimPacketInfo& pktInfo) |
| 469 |
|
| 470 |
{ |
| 471 |
if (!m_xml) return; |
| 472 |
ostringstream oss; |
| 473 |
uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId (); |
| 474 |
double lbTx = pktInfo.m_lbTx; |
| 475 |
|
| 476 |
// Oops, need to figure out about range |
| 477 |
oss << GetXMLOpen_wpacket (0,nodeId,pktInfo.m_fbTx,lbTx,pktInfo.reception_range); |
| 478 |
// Now add each rx |
| 479 |
map <uint32_t, AnimRxInfo>::iterator p; |
| 480 |
for (p = pktInfo.m_rx.begin (); p != pktInfo.m_rx.end (); p++) |
| 481 |
{ |
| 482 |
AnimRxInfo& rx = p->second; |
| 483 |
uint32_t rxId = rx.m_rxnd->GetNode ()->GetId (); |
| 484 |
if(rx.m_lbRx) |
| 485 |
oss << GetXMLOpenClose_rx (0,rxId,rx.m_fbRx,rx.m_lbRx); |
| 486 |
} |
| 487 |
oss << GetXMLClose ("wpacket"); |
| 488 |
WriteN (m_fHandle, oss.str ()); |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
// XML Private Helpers |
| 493 |
|
| 494 |
std::string AnimationInterface::GetXMLOpen_anim (uint32_t lp) |
| 495 |
{ |
| 496 |
ostringstream oss; |
| 497 |
oss <<"<anim lp = \"" << lp << "\" >\n"; |
| 498 |
return oss.str (); |
| 499 |
} |
| 500 |
std::string AnimationInterface::GetXMLOpen_topology (double minX,double minY,double maxX,double maxY) |
| 501 |
{ |
| 502 |
ostringstream oss; |
| 503 |
oss <<"<topology minX = \"" << minX << "\" minY = \"" << minY |
| 504 |
<< "\" maxX = \"" << maxX << "\" maxY = \"" << maxY |
| 505 |
<< "\">" << endl; |
| 506 |
return oss.str (); |
| 507 |
|
| 508 |
} |
| 509 |
|
| 510 |
std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp,uint32_t id,double locX,double locY) |
| 511 |
{ |
| 512 |
ostringstream oss; |
| 513 |
oss <<"<node lp = \"" << lp << "\" id = \"" << id << "\"" << " locX = \"" |
| 514 |
<< locX << "\" " << "locY = \"" << locY << "\" />\n"; |
| 515 |
return oss.str (); |
| 516 |
} |
| 517 |
std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId) |
| 518 |
{ |
| 519 |
ostringstream oss; |
| 520 |
oss << "<link fromLP = \"0\" fromId = \"" << fromId |
| 521 |
<< "\" toLp = \"0\" toId = \"" << toId |
| 522 |
<< "\"/>" << endl; |
| 523 |
return oss.str (); |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx) |
| 528 |
{ |
| 529 |
ostringstream oss; |
| 530 |
oss << setprecision (10); |
| 531 |
oss << "<packet fromLp = \"" << fromLp << "\" fromId = \"" << fromId |
| 532 |
<< "\" fbTx = \"" << fbTx |
| 533 |
<< "\" lbTx = \"" << lbTx |
| 534 |
<< "\">" << endl; |
| 535 |
return oss.str (); |
| 536 |
} |
| 537 |
|
| 538 |
std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, double range) |
| 539 |
{ |
| 540 |
ostringstream oss; |
| 541 |
oss << setprecision (10); |
| 542 |
oss << "<wpacket fromLp = \"" << fromLp << "\" fromId = \"" << fromId |
| 543 |
<< "\" fbTx = \"" << fbTx |
| 544 |
<< "\" lbTx = \"" << lbTx |
| 545 |
<< "\" range = \"" << range << "\">" << endl; |
| 546 |
return oss.str (); |
| 547 |
|
| 548 |
} |
| 549 |
|
| 550 |
std::string AnimationInterface::GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, double fbRx, double lbRx) |
| 551 |
{ |
| 552 |
ostringstream oss; |
| 553 |
oss << setprecision (10); |
| 554 |
oss << "<rx toLp = \"" << toLp <<"\" toId = \"" << toId |
| 555 |
<< "\" fbRx = \"" << fbRx |
| 556 |
<< "\" lbRx = \"" << lbRx |
| 557 |
<< "\"/>" << endl; |
| 558 |
return oss.str (); |
| 559 |
} |
| 560 |
|
| 561 |
std::vector<std::string> AnimationInterface::GetElementsFromContext (std::string context) |
| 562 |
{ |
| 563 |
vector <std::string> elements; |
| 564 |
size_t pos1=0, pos2; |
| 565 |
while (pos1 != context.npos) |
| 566 |
{ |
| 567 |
pos1 = context.find ("/",pos1); |
| 568 |
pos2 = context.find ("/",pos1+1); |
| 569 |
elements.push_back (context.substr (pos1+1,pos2-(pos1+1))); |
| 570 |
pos1 = pos2; |
| 571 |
pos2 = context.npos; |
| 572 |
} |
| 573 |
return elements; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 200 |
} // namespace ns3 |
577 |
} // namespace ns3 |