View | Details | Raw Unified | Return to bug 2170
Collapse All | Expand All

(-)a/src/netanim/model/animation-interface.cc (-59 / +388 lines)
 Lines 63-84    Link Here 
63
// Public methods
63
// Public methods
64
64
65
AnimationInterface::AnimationInterface (const std::string fn)
65
AnimationInterface::AnimationInterface (const std::string fn)
66
  : m_f (0),
66
  :
67
    m_routingF (0),
67
#ifdef HAVE_LIBXML2
68
    m_mobilityPollInterval (Seconds (0.25)), 
68
  m_xmlWriter(0),
69
    m_outputFileName (fn),
69
  m_routingXmlWriter(0),
70
    gAnimUid (0), 
70
#else
71
    m_writeCallback (0), 
71
  m_f (0),
72
    m_started (false), 
72
  m_routingF (0),
73
    m_enablePacketMetadata (false), 
73
#endif
74
    m_startTime (Seconds (0)), 
74
  m_mobilityPollInterval (Seconds (0.25)),
75
    m_stopTime (Seconds (3600 * 1000)),
75
  m_outputFileName (fn),
76
    m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE), 
76
  gAnimUid (0),
77
    m_originalFileName (fn),
77
  m_writeCallback (0),
78
    m_routingStopTime (Seconds (0)), 
78
  m_started (false),
79
    m_routingFileName (""),
79
  m_enablePacketMetadata (false),
80
    m_routingPollInterval (Seconds (5)), 
80
  m_startTime (Seconds (0)),
81
    m_trackPackets (true)
81
  m_stopTime (Seconds (3600 * 1000)),
82
  m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE),
83
  m_originalFileName (fn),
84
  m_routingStopTime (Seconds (0)),
85
  m_routingFileName (""),
86
  m_routingPollInterval (Seconds (5)),
87
  m_trackPackets (true)
82
{
88
{
83
  initialized = true;
89
  initialized = true;
84
  StartAnimation ();
90
  StartAnimation ();
 Lines 1267-1272    Link Here 
1267
  m_started = false;
1273
  m_started = false;
1268
  NS_LOG_INFO ("Stopping Animation");
1274
  NS_LOG_INFO ("Stopping Animation");
1269
  ResetAnimWriteCallback ();
1275
  ResetAnimWriteCallback ();
1276
#ifdef HAVE_LIBXML2
1277
  if (m_xmlWriter)
1278
    {
1279
      int rc = xmlTextWriterEndDocument (m_xmlWriter);
1280
      if (rc < 0)
1281
        {
1282
          NS_FATAL_ERROR ("Error at xmlTextWriterEndDocument\n");
1283
        }
1284
      xmlFreeTextWriter (m_xmlWriter);
1285
      m_xmlWriter = 0;
1286
  	}
1287
  if (onlyAnimation)
1288
	{
1289
	  return;
1290
	}
1291
  if (m_routingXmlWriter)
1292
    {
1293
      int rc = xmlTextWriterEndDocument (m_routingXmlWriter);
1294
      if (rc < 0)
1295
        {
1296
          NS_FATAL_ERROR ("Error at xmlTextWriterEndDocument when ending routing xml file\n");
1297
        }
1298
      xmlFreeTextWriter (m_routingXmlWriter);
1299
      m_routingXmlWriter = 0;
1300
    }
1301
#else
1270
  if (m_f) 
1302
  if (m_f) 
1271
    {
1303
    {
1272
      // Terminate the anim element
1304
      // Terminate the anim element
 Lines 1284-1289    Link Here 
1284
      std::fclose (m_routingF);
1316
      std::fclose (m_routingF);
1285
      m_routingF = 0;
1317
      m_routingF = 0;
1286
    }
1318
    }
1319
#endif
1287
}
1320
}
1288
1321
1289
void 
1322
void 
 Lines 1670-1675    Link Here 
1670
void 
1703
void 
1671
AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
1704
AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
1672
{
1705
{
1706
#ifdef HAVE_LIBXML2
1707
  if (!routing && m_xmlWriter)
1708
    {
1709
      return;
1710
    }
1711
  if (routing && m_routingXmlWriter)
1712
    {
1713
      NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
1714
      return;
1715
    }
1716
  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
1717
1718
  xmlTextWriterPtr *writer = (routing ? &m_routingXmlWriter : &m_xmlWriter);
1719
1720
  /* Create a new XmlWriter for this filename, with no compression. */
1721
  *writer = xmlNewTextWriterFilename (fn.c_str (), 0);
1722
  if (!*writer)
1723
    {
1724
      NS_FATAL_ERROR ("Error creating the xml writer");
1725
      return;
1726
    }
1727
  /* Make the writer use automatic indentation */
1728
  xmlTextWriterSetIndent (*writer, 1);
1729
1730
  /* Start the document with the xml default for the version,
1731
   * UTF-8 encoding and the default for the standalone
1732
   * declaration. */
1733
  int rc = xmlTextWriterStartDocument (*writer, 0, "utf-8", 0);
1734
  if (rc < 0)
1735
    {
1736
      NS_FATAL_ERROR ("Error at xmlTextWriterStartDocument\n");
1737
      return;
1738
    }
1739
  if (routing)
1740
    {
1741
      m_routingFileName = fn;
1742
    }
1743
  else
1744
    {
1745
      m_outputFileName = fn;
1746
    }
1747
  return;
1748
1749
#else
1673
  if (!routing && m_f)
1750
  if (!routing && m_f)
1674
    {
1751
    {
1675
      return;
1752
      return;
 Lines 1699-1704    Link Here 
1699
      m_outputFileName = fn;
1776
      m_outputFileName = fn;
1700
    }
1777
    }
1701
  return;
1778
  return;
1779
#endif
1702
}
1780
}
1703
1781
1704
void 
1782
void 
 Lines 1987-1993    Link Here 
1987
2065
1988
2066
1989
// XML 
2067
// XML 
2068
#ifdef HAVE_LIBXML2
2069
AnimationInterface::AnimXmlElement::AnimXmlElement(xmlTextWriterPtr writer, std::string tagName):
2070
  m_tagName (tagName),
2071
  m_writer (writer),
2072
	m_closed(false)
2073
{
2074
  if (!m_writer)
2075
    {
2076
      NS_FATAL_ERROR ("Null XML writer");
2077
      return;
2078
    }
2079
  int rc = xmlTextWriterStartElement (m_writer, BAD_CAST m_tagName.c_str ());
2080
  if (rc < 0)
2081
    {
2082
      NS_FATAL_ERROR ("Error at xmlTextWriterStartElement (rp)");
2083
    }
2084
}
1990
2085
2086
template <typename T>
2087
void
2088
AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value)
2089
{
2090
  if (!m_writer)
2091
    {
2092
      NS_FATAL_ERROR ("Null XML writer");
2093
      return;
2094
    }
2095
  if (m_closed)
2096
    {
2097
      NS_FATAL_ERROR ("XML element already closed");
2098
      return;
2099
    }
2100
  std::ostringstream oss;
2101
  oss << std::setprecision (10);
2102
  oss << value;
2103
  int rc = xmlTextWriterWriteAttribute(m_writer,
2104
                                       BAD_CAST attribute.c_str(),
2105
                                   	 	 BAD_CAST oss.str().c_str());
2106
  if (rc < 0)
2107
    {
2108
      NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
2109
      return;
2110
    }
2111
}
2112
2113
template <typename T>
2114
void AnimationInterface::AnimXmlElement::AddAttribute (xmlTextWriterPtr writer, std::string attribute, T value)
2115
{
2116
	if (!writer)
2117
    {
2118
      NS_FATAL_ERROR ("Null XML writer");
2119
      return;
2120
    }
2121
	std::ostringstream oss;
2122
	oss << std::setprecision (10);
2123
	oss << value;
2124
	int rc = xmlTextWriterWriteAttribute(writer,
2125
	                                     BAD_CAST attribute.c_str(),
2126
																			 BAD_CAST oss.str().c_str());
2127
	if (rc < 0)
2128
	  {
2129
      NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
2130
      return;
2131
	  }
2132
}
2133
2134
void
2135
AnimationInterface::AnimXmlElement::CloseElement ()
2136
{
2137
  if (!m_writer)
2138
    {
2139
      NS_FATAL_ERROR ("Null XML writer");
2140
      return;
2141
    }
2142
  if (m_closed)
2143
    {
2144
      NS_FATAL_ERROR ("XML element already closed");
2145
      return;
2146
    }
2147
  m_closed = true;
2148
  int rc = xmlTextWriterEndElement(m_writer);
2149
	if (rc < 0)
2150
	  {
2151
      NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
2152
      return;
2153
	  }
2154
}
2155
#else
1991
AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool emptyElement):
2156
AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool emptyElement):
1992
                                m_tagName (tagName),
2157
                                m_tagName (tagName),
1993
                                m_emptyElement (emptyElement)
2158
                                m_emptyElement (emptyElement)
 Lines 2002-2009    Link Here 
2002
  std::ostringstream oss;
2167
  std::ostringstream oss;
2003
  oss << std::setprecision (10);
2168
  oss << std::setprecision (10);
2004
  oss << value;
2169
  oss << value;
2170
  const char *attribute_char = oss.str ().c_str ();
2005
  m_elementString += attribute.c_str ();
2171
  m_elementString += attribute.c_str ();
2006
  m_elementString += "=\"" + oss.str () + "\" ";
2172
  m_elementString += "=\"";
2173
  while (*attribute_char)
2174
  {
2175
   switch(*attribute_char)
2176
   {
2177
     case '&':
2178
       m_elementString += "&amp;";
2179
       break;
2180
     case '\"':
2181
       m_elementString += "&quot;";
2182
       break;
2183
     case '\'':
2184
       m_elementString += "&apos;";
2185
       break;
2186
     case '<':
2187
       m_elementString += "&lt;";
2188
       break;
2189
     case '>':
2190
       m_elementString += "&gt;";
2191
       break;
2192
     default:
2193
       m_elementString += *attribute_char;
2194
       break;
2195
   }
2196
   attribute_char++;
2197
  }
2198
  m_elementString += "\" ";
2007
}
2199
}
2008
2200
2009
void
2201
void
 Lines 2048-2058    Link Here 
2048
{
2240
{
2049
  return m_elementString;
2241
  return m_elementString;
2050
}
2242
}
2051
2243
#endif
2052
2244
2053
void 
2245
void 
2054
AnimationInterface::WriteXmlAnim (bool routing)
2246
AnimationInterface::WriteXmlAnim (bool routing)
2055
{
2247
{
2248
#ifdef HAVE_LIBXML2
2249
  int rc;
2250
  rc = xmlTextWriterStartElement (m_xmlWriter, BAD_CAST "anim");
2251
  if (rc < 0)
2252
    {
2253
      NS_FATAL_ERROR ("Error at xmlTextWriterStartElement (anim)");
2254
		  return;
2255
    }
2256
  AnimXmlElement::AddAttribute (m_xmlWriter, "ver", GetNetAnimVersion ());
2257
  if (!routing)
2258
    {
2259
      AnimXmlElement::AddAttribute (m_xmlWriter, "filetype", "animation");
2260
    }
2261
	else
2262
    {
2263
      AnimXmlElement::AddAttribute (m_xmlWriter, "filetype", "routing");
2264
    }
2265
#else
2056
  AnimXmlElement element ("anim");
2266
  AnimXmlElement element ("anim");
2057
  element.AddAttribute ("ver", GetNetAnimVersion ());
2267
  element.AddAttribute ("ver", GetNetAnimVersion ());
2058
  FILE * f = m_f;
2268
  FILE * f = m_f;
 Lines 2067-2074    Link Here 
2067
    }
2277
    }
2068
  element.Close ();
2278
  element.Close ();
2069
  WriteN (element.GetElementString (), f);
2279
  WriteN (element.GetElementString (), f);
2280
#endif
2070
}
2281
}
2071
2282
2283
#ifndef HAVE_LIBXML2
2072
void 
2284
void 
2073
AnimationInterface::WriteXmlClose (std::string name, bool routing) 
2285
AnimationInterface::WriteXmlClose (std::string name, bool routing) 
2074
{
2286
{
 Lines 2082-2184    Link Here 
2082
      WriteN (closeString, m_routingF);
2294
      WriteN (closeString, m_routingF);
2083
    }
2295
    }
2084
}
2296
}
2297
#endif
2085
2298
2086
void 
2299
void 
2087
AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2300
AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2088
{
2301
{
2302
#ifdef HAVE_LIBXML2
2303
	AnimXmlElement element (m_xmlWriter, "node");
2304
#else
2089
  AnimXmlElement element ("node");
2305
  AnimXmlElement element ("node");
2306
#endif
2090
  element.AddAttribute ("id", id);
2307
  element.AddAttribute ("id", id);
2091
  element.AddAttribute ("sysId", sysId);
2308
  element.AddAttribute ("sysId", sysId);
2092
  element.AddAttribute ("locX", locX);
2309
  element.AddAttribute ("locX", locX);
2093
  element.AddAttribute ("locY", locY);
2310
  element.AddAttribute ("locY", locY);
2094
  element.CloseElement ();
2311
  element.CloseElement ();
2312
#ifndef HAVE_LIBXML2
2095
  WriteN (element.GetElementString (), m_f);
2313
  WriteN (element.GetElementString (), m_f);
2314
#endif
2096
}
2315
}
2097
2316
2098
void 
2317
void 
2099
AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2318
AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2100
{
2319
{
2320
#ifdef HAVE_LIBXML2
2321
	AnimXmlElement element (m_xmlWriter, "linkupdate");
2322
#else
2101
  AnimXmlElement element ("linkupdate");
2323
  AnimXmlElement element ("linkupdate");
2324
#endif
2102
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2325
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2103
  element.AddAttribute ("fromId", fromId);
2326
  element.AddAttribute ("fromId", fromId);
2104
  element.AddAttribute ("toId", toId);
2327
  element.AddAttribute ("toId", toId);
2105
  element.AddAttribute ("ld", linkDescription);
2328
  element.AddAttribute ("ld", linkDescription);
2106
  element.CloseElement ();
2329
  element.CloseElement ();
2330
#ifndef HAVE_LIBXML2
2107
  WriteN (element.GetElementString (), m_f);
2331
  WriteN (element.GetElementString (), m_f);
2332
#endif
2108
}
2333
}
2109
2334
2110
void 
2335
void 
2111
AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2336
AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2112
{
2337
{
2113
  AnimXmlElement element ("link");
2338
#ifdef HAVE_LIBXML2
2114
  element.AddAttribute ("fromId", fromId);
2339
	AnimXmlElement element (m_xmlWriter, "link");
2115
  element.AddAttribute ("toId", toId);
2340
#else
2341
	AnimXmlElement element ("link");
2342
#endif
2343
	element.AddAttribute ("fromId", fromId);
2344
	element.AddAttribute ("toId", toId);
2116
2345
2117
  LinkProperties lprop ;
2346
	LinkProperties lprop ;
2118
  lprop.fromNodeDescription = "";
2347
	lprop.fromNodeDescription = "";
2119
  lprop.toNodeDescription = "";
2348
	lprop.toNodeDescription = "";
2120
  lprop.linkDescription = "";
2349
	lprop.linkDescription = "";
2121
2350
2122
  P2pLinkNodeIdPair p1 = { fromId, toId };
2351
	P2pLinkNodeIdPair p1 = { fromId, toId };
2123
  P2pLinkNodeIdPair p2 = { toId, fromId };
2352
	P2pLinkNodeIdPair p2 = { toId, fromId };
2124
  if (m_linkProperties.find (p1) != m_linkProperties.end ())
2353
	if (m_linkProperties.find (p1) != m_linkProperties.end ())
2125
    {
2354
		{
2126
      lprop = m_linkProperties[p1];
2355
			lprop = m_linkProperties[p1];
2127
    }
2356
		}
2128
  else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2357
	else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2129
    {
2358
		{
2130
      lprop = m_linkProperties[p2];
2359
			lprop = m_linkProperties[p2];
2131
    }
2360
		}
2132
  
2361
2133
  element.AddAttribute ("fd", lprop.fromNodeDescription); 
2362
	element.AddAttribute ("fd", lprop.fromNodeDescription);
2134
  element.AddAttribute ("td", lprop.toNodeDescription); 
2363
	element.AddAttribute ("td", lprop.toNodeDescription);
2135
  element.AddAttribute ("ld", lprop.linkDescription); 
2364
	element.AddAttribute ("ld", lprop.linkDescription);
2136
  element.CloseElement ();
2365
	element.CloseElement ();
2366
#ifndef HAVE_LIBXML2
2137
  WriteN (element.GetElementString (), m_f);
2367
  WriteN (element.GetElementString (), m_f);
2368
#endif
2138
}
2369
}
2139
2370
2140
void 
2371
void 
2141
AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2372
AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2142
{
2373
{
2374
#ifdef HAVE_LIBXML2
2375
  AnimXmlElement element (m_routingXmlWriter, "rt");
2376
#else
2143
  AnimXmlElement element ("rt");
2377
  AnimXmlElement element ("rt");
2378
#endif
2144
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2379
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2145
  element.AddAttribute ("id", nodeId);
2380
  element.AddAttribute ("id", nodeId);
2146
  element.AddAttribute ("info", routingInfo.c_str ());
2381
  element.AddAttribute ("info", routingInfo.c_str ());
2147
  element.CloseElement ();
2382
  element.CloseElement ();
2383
#ifndef HAVE_LIBXML2
2148
  WriteN (element.GetElementString (), m_routingF);
2384
  WriteN (element.GetElementString (), m_routingF);
2385
#endif
2149
}
2386
}
2150
2387
2151
void 
2388
void 
2152
AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2389
AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2153
{
2390
{
2391
#ifdef HAVE_LIBXML2
2392
  AnimXmlElement element (m_routingXmlWriter, "rp");
2393
#else
2154
  std::string tagName = "rp";
2394
  std::string tagName = "rp";
2155
  AnimXmlElement element (tagName, false);
2395
  AnimXmlElement element (tagName, false);
2396
#endif
2156
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2397
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2157
  element.AddAttribute ("id", nodeId);
2398
	element.AddAttribute ("id", nodeId);
2158
  element.AddAttribute ("d", destination.c_str ());
2399
	element.AddAttribute ("d", destination.c_str ());
2159
  element.AddAttribute ("c", rpElements.size ());
2400
	element.AddAttribute ("c", rpElements.size ());
2160
  element.CloseTag ();
2401
#ifndef HAVE_LIBXML2
2161
  element.AddLineBreak ();
2402
	element.CloseTag ();
2162
  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2403
	element.AddLineBreak ();
2163
       i != rpElements.end ();
2404
#endif
2164
       ++i)
2405
	for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2165
    {
2406
			 i != rpElements.end ();
2166
      Ipv4RoutePathElement rpElement = *i;
2407
			 ++i)
2167
      AnimXmlElement rpeElement ("rpe");
2408
		{
2168
      rpeElement.AddAttribute ("n", rpElement.nodeId);
2409
			Ipv4RoutePathElement rpElement = *i;
2169
      rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2410
#ifdef HAVE_LIBXML2
2170
      rpeElement.CloseElement ();
2411
			AnimXmlElement rpeElement (m_routingXmlWriter, "rpe");
2171
      element.Add (rpeElement);
2412
#else
2172
    }
2413
			AnimXmlElement rpeElement ("rpe");
2173
  element.CloseElement ();
2414
#endif
2174
  WriteN (element.GetElementString (),  m_routingF);
2415
			rpeElement.AddAttribute ("n", rpElement.nodeId);
2416
			rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2417
			rpeElement.CloseElement ();
2418
#ifndef HAVE_LIBXML2
2419
			element.Add (rpeElement);
2420
#endif
2421
		}
2422
	element.CloseElement ();
2423
#ifndef HAVE_LIBXML2
2424
	WriteN (element.GetElementString (),  m_routingF);
2425
#endif
2175
}
2426
}
2176
2427
2177
2428
2178
void 
2429
void 
2179
AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2430
AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2180
{
2431
{
2432
#ifdef HAVE_LIBXML2
2433
	AnimXmlElement element (m_xmlWriter, "pr");
2434
#else
2181
  AnimXmlElement element ("pr");
2435
  AnimXmlElement element ("pr");
2436
#endif
2182
  element.AddAttribute ("uId", animUid);
2437
  element.AddAttribute ("uId", animUid);
2183
  element.AddAttribute ("fId", fId);
2438
  element.AddAttribute ("fId", fId);
2184
  element.AddAttribute ("fbTx", fbTx);
2439
  element.AddAttribute ("fbTx", fbTx);
 Lines 2187-2212    Link Here 
2187
      element.AddAttribute ("meta-info", metaInfo.c_str ());
2442
      element.AddAttribute ("meta-info", metaInfo.c_str ());
2188
    }
2443
    }
2189
  element.CloseElement ();
2444
  element.CloseElement ();
2445
#ifndef HAVE_LIBXML2
2190
  WriteN (element.GetElementString (),  m_f);
2446
  WriteN (element.GetElementString (),  m_f);
2447
#endif
2191
}
2448
}
2192
2449
2193
void 
2450
void 
2194
AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2451
AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2195
{
2452
{
2453
#ifdef HAVE_LIBXML2
2454
	AnimXmlElement element (m_xmlWriter, pktType);
2455
#else
2196
  AnimXmlElement element (pktType);
2456
  AnimXmlElement element (pktType);
2457
#endif
2197
  element.AddAttribute ("uId", animUid);
2458
  element.AddAttribute ("uId", animUid);
2198
  element.AddAttribute ("tId", tId);
2459
  element.AddAttribute ("tId", tId);
2199
  element.AddAttribute ("fbRx", fbRx);
2460
  element.AddAttribute ("fbRx", fbRx);
2200
  element.AddAttribute ("lbRx", lbRx);
2461
  element.AddAttribute ("lbRx", lbRx);
2201
  element.CloseElement ();
2462
  element.CloseElement ();
2463
#ifndef HAVE_LIBXML2
2202
  WriteN (element.GetElementString (),  m_f);
2464
  WriteN (element.GetElementString (),  m_f);
2465
#endif
2203
}
2466
}
2204
2467
2205
void 
2468
void 
2206
AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx, 
2469
AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx, 
2207
                                                   uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2470
                                                   uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2208
{
2471
{
2472
#ifdef HAVE_LIBXML2
2473
	AnimXmlElement element (m_xmlWriter, pktType);
2474
#else
2209
  AnimXmlElement element (pktType);
2475
  AnimXmlElement element (pktType);
2476
#endif
2210
  element.AddAttribute ("fId", fId);
2477
  element.AddAttribute ("fId", fId);
2211
  element.AddAttribute ("fbTx", fbTx);
2478
  element.AddAttribute ("fbTx", fbTx);
2212
  element.AddAttribute ("lbTx", lbTx);
2479
  element.AddAttribute ("lbTx", lbTx);
 Lines 2218-2289    Link Here 
2218
  element.AddAttribute ("fbRx", fbRx);
2485
  element.AddAttribute ("fbRx", fbRx);
2219
  element.AddAttribute ("lbRx", lbRx);
2486
  element.AddAttribute ("lbRx", lbRx);
2220
  element.CloseElement ();
2487
  element.CloseElement ();
2488
#ifndef HAVE_LIBXML2
2221
  WriteN (element.GetElementString (),  m_f);
2489
  WriteN (element.GetElementString (),  m_f);
2490
#endif
2222
}
2491
}
2223
2492
2224
void 
2493
void 
2225
AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2494
AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2226
{
2495
{
2227
  AnimXmlElement element ("ncs");
2496
#ifdef HAVE_LIBXML2
2497
	AnimXmlElement element (m_xmlWriter, "ncs");
2498
#else
2499
	AnimXmlElement element ("ncs");
2500
#endif
2228
  element.AddAttribute ("ncId", nodeCounterId);
2501
  element.AddAttribute ("ncId", nodeCounterId);
2229
  element.AddAttribute ("n", counterName);
2502
  element.AddAttribute ("n", counterName);
2230
  element.AddAttribute ("t", CounterTypeToString (counterType));
2503
  element.AddAttribute ("t", CounterTypeToString (counterType));
2231
  element.CloseElement ();
2504
  element.CloseElement ();
2505
#ifndef HAVE_LIBXML2
2232
  WriteN (element.GetElementString (), m_f);
2506
  WriteN (element.GetElementString (), m_f);
2507
#endif
2233
}
2508
}
2234
2509
2235
void 
2510
void 
2236
AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2511
AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2237
{
2512
{
2513
#ifdef HAVE_LIBXML2
2514
	AnimXmlElement element (m_xmlWriter, "res");
2515
#else
2238
  AnimXmlElement element ("res");
2516
  AnimXmlElement element ("res");
2517
#endif
2239
  element.AddAttribute ("rid", resourceId);
2518
  element.AddAttribute ("rid", resourceId);
2240
  element.AddAttribute ("p", resourcePath);
2519
  element.AddAttribute ("p", resourcePath);
2241
  element.CloseElement ();
2520
  element.CloseElement ();
2521
#ifndef HAVE_LIBXML2
2242
  WriteN (element.GetElementString (), m_f);
2522
  WriteN (element.GetElementString (), m_f);
2523
#endif
2243
}
2524
}
2244
2525
2245
void 
2526
void 
2246
AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2527
AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2247
{
2528
{
2529
#ifdef HAVE_LIBXML2
2530
	AnimXmlElement element (m_xmlWriter, "nu");
2531
#else
2248
  AnimXmlElement element ("nu");
2532
  AnimXmlElement element ("nu");
2533
#endif
2249
  element.AddAttribute ("p", "i");
2534
  element.AddAttribute ("p", "i");
2250
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2535
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2251
  element.AddAttribute ("id", nodeId);
2536
  element.AddAttribute ("id", nodeId);
2252
  element.AddAttribute ("rid", resourceId);
2537
  element.AddAttribute ("rid", resourceId);
2253
  element.CloseElement ();
2538
  element.CloseElement ();
2539
#ifndef HAVE_LIBXML2
2254
  WriteN (element.GetElementString (), m_f);
2540
  WriteN (element.GetElementString (), m_f);
2541
#endif
2255
}
2542
}
2256
2543
2257
void 
2544
void 
2258
AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2545
AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2259
{
2546
{
2547
#ifdef HAVE_LIBXML2
2548
	AnimXmlElement element (m_xmlWriter, "nu");
2549
#else
2260
  AnimXmlElement element ("nu");
2550
  AnimXmlElement element ("nu");
2551
#endif
2261
  element.AddAttribute ("p", "s");
2552
  element.AddAttribute ("p", "s");
2262
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2553
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2263
  element.AddAttribute ("id", nodeId);
2554
  element.AddAttribute ("id", nodeId);
2264
  element.AddAttribute ("w", width);
2555
  element.AddAttribute ("w", width);
2265
  element.AddAttribute ("h", height);
2556
  element.AddAttribute ("h", height);
2266
  element.CloseElement ();
2557
  element.CloseElement ();
2558
#ifndef HAVE_LIBXML2
2267
  WriteN (element.GetElementString (),  m_f);
2559
  WriteN (element.GetElementString (),  m_f);
2560
#endif
2268
}
2561
}
2269
2562
2270
void 
2563
void 
2271
AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2564
AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2272
{
2565
{
2566
#ifdef HAVE_LIBXML2
2567
	AnimXmlElement element (m_xmlWriter, "nu");
2568
#else
2273
  AnimXmlElement element ("nu");
2569
  AnimXmlElement element ("nu");
2570
#endif
2274
  element.AddAttribute ("p", "p");
2571
  element.AddAttribute ("p", "p");
2275
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2572
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2276
  element.AddAttribute ("id", nodeId);
2573
  element.AddAttribute ("id", nodeId);
2277
  element.AddAttribute ("x", x);
2574
  element.AddAttribute ("x", x);
2278
  element.AddAttribute ("y", y);
2575
  element.AddAttribute ("y", y);
2279
  element.CloseElement ();
2576
  element.CloseElement ();
2577
#ifndef HAVE_LIBXML2
2280
  WriteN (element.GetElementString (), m_f);
2578
  WriteN (element.GetElementString (), m_f);
2579
#endif
2281
}
2580
}
2282
2581
2283
void 
2582
void 
2284
AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2583
AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2285
{
2584
{
2585
#ifdef HAVE_LIBXML2
2586
	AnimXmlElement element (m_xmlWriter, "nu");
2587
#else
2286
  AnimXmlElement element ("nu");
2588
  AnimXmlElement element ("nu");
2589
#endif
2287
  element.AddAttribute ("p", "c");
2590
  element.AddAttribute ("p", "c");
2288
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2591
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2289
  element.AddAttribute ("id", nodeId);
2592
  element.AddAttribute ("id", nodeId);
 Lines 2291-2303    Link Here 
2291
  element.AddAttribute ("g", (uint32_t) g);
2594
  element.AddAttribute ("g", (uint32_t) g);
2292
  element.AddAttribute ("b", (uint32_t) b);
2595
  element.AddAttribute ("b", (uint32_t) b);
2293
  element.CloseElement ();
2596
  element.CloseElement ();
2597
#ifndef HAVE_LIBXML2
2294
  WriteN (element.GetElementString (), m_f);
2598
  WriteN (element.GetElementString (), m_f);
2599
#endif
2295
}
2600
}
2296
2601
2297
void 
2602
void 
2298
AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId)
2603
AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId)
2299
{
2604
{
2605
#ifdef HAVE_LIBXML2
2606
	AnimXmlElement element (m_xmlWriter, "nu");
2607
#else
2300
  AnimXmlElement element ("nu");
2608
  AnimXmlElement element ("nu");
2609
#endif
2301
  element.AddAttribute ("p", "d");
2610
  element.AddAttribute ("p", "d");
2302
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2611
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2303
  element.AddAttribute ("id", nodeId);
2612
  element.AddAttribute ("id", nodeId);
 Lines 2306-2331    Link Here 
2306
      element.AddAttribute ("descr", m_nodeDescriptions[nodeId]); 
2615
      element.AddAttribute ("descr", m_nodeDescriptions[nodeId]); 
2307
    }
2616
    }
2308
  element.CloseElement ();
2617
  element.CloseElement ();
2618
#ifndef HAVE_LIBXML2
2309
  WriteN (element.GetElementString (), m_f);
2619
  WriteN (element.GetElementString (), m_f);
2620
#endif
2310
}
2621
}
2311
2622
2312
2623
2313
void 
2624
void 
2314
AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2625
AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2315
{
2626
{
2627
#ifdef HAVE_LIBXML2
2628
	AnimXmlElement element (m_xmlWriter, "nc");
2629
#else
2316
  AnimXmlElement element ("nc");
2630
  AnimXmlElement element ("nc");
2631
#endif
2317
  element.AddAttribute ("c", nodeCounterId);
2632
  element.AddAttribute ("c", nodeCounterId);
2318
  element.AddAttribute ("i", nodeId);
2633
  element.AddAttribute ("i", nodeId);
2319
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2634
  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2320
  element.AddAttribute ("v", counterValue);
2635
  element.AddAttribute ("v", counterValue);
2321
  element.CloseElement ();
2636
  element.CloseElement ();
2637
#ifndef HAVE_LIBXML2
2322
  WriteN (element.GetElementString (), m_f);
2638
  WriteN (element.GetElementString (), m_f);
2639
#endif
2323
}
2640
}
2324
2641
2325
void 
2642
void 
2326
AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2643
AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2327
{
2644
{
2645
#ifdef HAVE_LIBXML2
2646
	AnimXmlElement element (m_xmlWriter, "bg");
2647
#else
2328
  AnimXmlElement element ("bg");
2648
  AnimXmlElement element ("bg");
2649
#endif
2329
  element.AddAttribute ("f", fileName);
2650
  element.AddAttribute ("f", fileName);
2330
  element.AddAttribute ("x", x);
2651
  element.AddAttribute ("x", x);
2331
  element.AddAttribute ("y", y);
2652
  element.AddAttribute ("y", y);
 Lines 2333-2350    Link Here 
2333
  element.AddAttribute ("sy", scaleY);
2654
  element.AddAttribute ("sy", scaleY);
2334
  element.AddAttribute ("o", opacity);
2655
  element.AddAttribute ("o", opacity);
2335
  element.CloseElement ();
2656
  element.CloseElement ();
2657
#ifndef HAVE_LIBXML2
2336
  WriteN (element.GetElementString (), m_f);
2658
  WriteN (element.GetElementString (), m_f);
2659
#endif
2337
}
2660
}
2338
2661
2339
void 
2662
void 
2340
AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2663
AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2341
{
2664
{
2665
#ifdef HAVE_LIBXML2
2666
	AnimXmlElement element (m_xmlWriter, "nonp2plinkproperties");
2667
#else
2342
  AnimXmlElement element ("nonp2plinkproperties");
2668
  AnimXmlElement element ("nonp2plinkproperties");
2669
#endif
2343
  element.AddAttribute ("id", id);
2670
  element.AddAttribute ("id", id);
2344
  element.AddAttribute ("ipv4Address", ipv4Address);
2671
  element.AddAttribute ("ipv4Address", ipv4Address);
2345
  element.AddAttribute ("channelType", channelType);
2672
  element.AddAttribute ("channelType", channelType);
2346
  element.CloseElement ();
2673
  element.CloseElement ();
2674
#ifndef HAVE_LIBXML2
2347
  WriteN (element.GetElementString (), m_f);
2675
  WriteN (element.GetElementString (), m_f);
2676
#endif
2348
}
2677
}
2349
2678
2350
TypeId
2679
TypeId
(-)a/src/netanim/model/animation-interface.h (-3 / +29 lines)
 Lines 43-48    Link Here 
43
#include "ns3/rectangle.h"
43
#include "ns3/rectangle.h"
44
#include "ns3/ipv4.h"
44
#include "ns3/ipv4.h"
45
#include "ns3/ipv4-l3-protocol.h"
45
#include "ns3/ipv4-l3-protocol.h"
46
#ifdef HAVE_LIBXML2
47
#include <libxml/encoding.h>
48
#include <libxml/xmlwriter.h>
49
#include <libxml/xmlstring.h>
50
#endif
46
51
47
namespace ns3 {
52
namespace ns3 {
48
53
 Lines 514-520    Link Here 
514
  // Node Counters
519
  // Node Counters
515
  typedef std::map <uint32_t, uint64_t> NodeCounterMap64;
520
  typedef std::map <uint32_t, uint64_t> NodeCounterMap64;
516
521
522
#ifdef HAVE_LIBXML2
523
  class AnimXmlElement
524
  {
525
    public:
526
    AnimXmlElement (xmlTextWriterPtr writer, std::string tagName);
527
    template <typename T>
528
    void AddAttribute (std::string attribute, T value);
529
    template <typename T>
530
    static void AddAttribute (xmlTextWriterPtr writer, std::string attribute, T value);
531
    void CloseElement ();
532
  private:
533
    std::string m_tagName;
534
    xmlTextWriterPtr m_writer;
535
    bool m_closed;
517
536
537
  };
538
#else
518
  class AnimXmlElement
539
  class AnimXmlElement
519
  {
540
  {
520
    public:
541
    public:
 Lines 533-544    Link Here 
533
    bool m_emptyElement;
554
    bool m_emptyElement;
534
555
535
  };
556
  };
536
557
#endif
537
558
538
  // ##### State #####
559
  // ##### State #####
539
560
#ifdef HAVE_LIBXML2
561
  xmlTextWriterPtr m_xmlWriter;
562
  xmlTextWriterPtr m_routingXmlWriter;
563
#else
540
  FILE * m_f; // File handle for output (0 if none)
564
  FILE * m_f; // File handle for output (0 if none)
541
  FILE * m_routingF; // File handle for routing table output (0 if None);
565
  FILE * m_routingF; // File handle for routing table output (0 if None);
566
#endif
542
  Time m_mobilityPollInterval;
567
  Time m_mobilityPollInterval;
543
  std::string m_outputFileName;
568
  std::string m_outputFileName;
544
  uint64_t gAnimUid ;    // Packet unique identifier used by AnimationInterface
569
  uint64_t gAnimUid ;    // Packet unique identifier used by AnimationInterface
 Lines 774-785    Link Here 
774
                                 std::string metaInfo = ""); 
799
                                 std::string metaInfo = ""); 
775
  void WriteXmlP (uint64_t animUid, std::string pktType, uint32_t fId, double fbTx, double lbTx);
800
  void WriteXmlP (uint64_t animUid, std::string pktType, uint32_t fId, double fbTx, double lbTx);
776
  void WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo = "");
801
  void WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo = "");
802
#ifndef HAVE_LIBXML2
777
  void WriteXmlClose (std::string name, bool routing = false);
803
  void WriteXmlClose (std::string name, bool routing = false);
804
#endif
778
  void WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType);
805
  void WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType);
779
  void WriteXmlRouting (uint32_t id, std::string routingInfo);
806
  void WriteXmlRouting (uint32_t id, std::string routingInfo);
780
  void WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements);
807
  void WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements);
781
  void WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity);
808
  void WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity);
782
783
};
809
};
784
810
785
811

Return to bug 2170