--- a/src/netanim/model/animation-interface.cc Thu May 24 04:16:20 2012 -0400
+++ b/src/netanim/model/animation-interface.cc Thu May 24 00:17:05 2012 -0400
@@ -62,22 +62,10 @@
static bool initialized = false;
std::map <uint32_t, std::string> AnimationInterface::nodeDescriptions;
-AnimationInterface::AnimationInterface ()
- : m_fHandle (STDOUT_FILENO), m_xml (false), m_mobilityPollInterval (Seconds(0.25)),
- m_usingSockets (false), m_port (0), m_outputFileName (""),
- m_outputFileSet (false), m_serverPortSet (false), gAnimUid (0),m_randomPosition (true),
- m_writeCallback (0), m_started (false),
- m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)),
- m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE)
-{
- initialized = true;
- StartAnimation ();
-}
-
AnimationInterface::AnimationInterface (const std::string fn, uint64_t maxPktsPerFile, bool usingXML)
- : m_fHandle (STDOUT_FILENO), m_xml (usingXML), m_mobilityPollInterval (Seconds(0.25)),
- m_usingSockets (false), m_port (0), m_outputFileName (fn),
- m_outputFileSet (false), m_serverPortSet (false), gAnimUid (0), m_randomPosition (true),
+ : m_xml (usingXML), m_mobilityPollInterval (Seconds(0.25)),
+ m_outputFileName (fn),
+ m_outputFileSet (false), gAnimUid (0), m_randomPosition (true),
m_writeCallback (0), m_started (false),
m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)),
m_maxPktsPerFile (maxPktsPerFile), m_originalFileName (fn)
@@ -86,18 +74,6 @@
StartAnimation ();
}
-AnimationInterface::AnimationInterface (const uint16_t port, bool usingXML)
- : m_fHandle (STDOUT_FILENO), m_xml (usingXML), m_mobilityPollInterval (Seconds(0.25)),
- m_usingSockets (true), m_port (port), m_outputFileName (""),
- m_outputFileSet (false), m_serverPortSet (false), gAnimUid (0), m_randomPosition (true),
- m_writeCallback (0), m_started (false),
- m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)),
- m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE)
-{
- initialized = true;
- StartAnimation ();
-}
-
AnimationInterface::~AnimationInterface ()
{
StopAnimation ();
@@ -142,21 +118,13 @@
{
return true;
}
- if (fn == "")
- {
- m_fHandle = STDOUT_FILENO;
- m_outputFileSet = true;
- return true;
- }
NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
- FILE* f = fopen (fn.c_str (), "w");
- if (!f)
+ m_f = fopen (fn.c_str (), "w");
+ if (!m_f)
{
NS_FATAL_ERROR ("Unable to open Animation output file");
return false; // Can't open
}
- m_fHandle = fileno (f); // Set the file handle
- m_usingSockets = false;
m_outputFileName = fn;
m_outputFileSet = true;
return true;
@@ -199,39 +167,6 @@
return false;
}
-bool AnimationInterface::SetServerPort (uint16_t port)
-{
-#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
- if (m_serverPortSet)
- {
- return true;
- }
- int s = socket (AF_INET, SOCK_STREAM, 0);
- struct sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons (port);
- addr.sin_addr.s_addr = htonl (INADDR_ANY);
- if (bind (s, (struct sockaddr*)&addr, sizeof (addr)) < 0)
- {
- NS_LOG_WARN ("Can't bind to port " << port << ", exiting.");
- return false;
- }
- listen (s, 1);
- NS_LOG_INFO ("Waiting for animator connection");
- // Now wait for the animator to connect in
- m_fHandle = accept (s, 0, 0);
- NS_LOG_INFO ("Got animator connection from remote");
- // set the linger socket option
- int t = 1;
- setsockopt (s, SOL_SOCKET, SO_LINGER, &t, sizeof(t));
- m_usingSockets = true;
- m_serverPortSet = true;
- return true;
-#endif
- return false; // never reached unless the above is disabled
- // which is done to support a platform like MinGW
-}
-
bool AnimationInterface::WifiPacketIsPending (uint64_t AnimUid)
{
return (m_pendingWifiPackets.find (AnimUid) != m_pendingWifiPackets.end ());
@@ -416,14 +351,7 @@
{
m_currentPktCount = 0;
m_started = true;
- if (m_usingSockets)
- {
- SetServerPort (m_port);
- }
- else
- {
- SetOutputFile (m_outputFileName);
- }
+ SetOutputFile (m_outputFileName);
// Find the min/max x/y for the xml topology element
m_topoMinX = -2;
@@ -448,7 +376,7 @@
oss << GetXMLOpen_anim (0);
oss << GetPreamble ();
oss << GetXMLOpen_topology (m_topoMinX, m_topoMinY, m_topoMaxX, m_topoMaxY);
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
NS_LOG_INFO ("Setting topology for "<<NodeList::GetNNodes ()<<" Nodes");
// Dump the topology
@@ -460,7 +388,7 @@
{
Vector v = GetPosition (n);
oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y);
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
else
{
@@ -468,7 +396,7 @@
Vector v = GetPosition (n);
oss << "0.0 N " << n->GetId ()
<< " " << v.x << " " << v.y << std::endl;
- WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
+ WriteN (oss.str ().c_str (), oss.str ().length ());
}
}
NS_LOG_INFO ("Setting p2p links");
@@ -508,7 +436,7 @@
{
oss << "0.0 L " << n1Id << " " << n2Id << std::endl;
}
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
}
}
@@ -520,7 +448,7 @@
}
if (m_xml && !restart)
{
- WriteN (m_fHandle, GetXMLClose ("topology"));
+ WriteN (GetXMLClose ("topology"));
Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this);
}
if (!restart)
@@ -564,32 +492,24 @@
m_started = false;
NS_LOG_INFO ("Stopping Animation");
ResetAnimWriteCallback ();
- if (m_fHandle > 0)
+ if (m_f)
{
if (m_xml)
{ // Terminate the anim element
- WriteN (m_fHandle, GetXMLClose ("anim"));
+ WriteN (GetXMLClose ("anim"));
}
- if (m_fHandle != STDOUT_FILENO)
- {
- close (m_fHandle);
- }
- m_outputFileSet = false;
- m_fHandle = -1;
+ fclose (m_f);
}
+ m_outputFileSet = false;
}
-int AnimationInterface::WriteN (int h, const std::string& st)
+int AnimationInterface::WriteN (const std::string& st)
{
- if (h < 0)
- {
- return 0;
- }
if (m_writeCallback)
{
m_writeCallback (st.c_str ());
}
- return WriteN (h, st.c_str (), st.length ());
+ return WriteN (st.c_str (), st.length ());
}
// Private methods
@@ -655,19 +575,15 @@
}
}
-int AnimationInterface::WriteN (HANDLETYPE h, const char* data, uint32_t count)
+int AnimationInterface::WriteN (const char* data, uint32_t count)
{
- if (h < 0)
- {
- return 0;
- }
// Write count bytes to h from data
uint32_t nLeft = count;
const char* p = data;
uint32_t written = 0;
while (nLeft)
{
- int n = write (h, p, nLeft);
+ int n = fwrite (p, nLeft, 1, m_f);
if (n <= 0)
{
return written;
@@ -693,7 +609,7 @@
oss << GetXMLOpenClose_rx (0, 0, fbRx, lbRx);
oss << GetXMLClose ("packet");
}
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
@@ -731,7 +647,7 @@
<< (now + rxTime - txTime).GetSeconds () << " " // first bit rx time
<< (now + rxTime).GetSeconds () << std::endl; // last bit rx time
}
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
@@ -1129,7 +1045,7 @@
oss << GetXMLOpen_topology (m_topoMinX, m_topoMinY, m_topoMaxX, m_topoMaxY);
oss << GetXMLOpenClose_node (0,n->GetId (),v.x,v.y);
oss << GetXMLClose ("topology");
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
WriteDummyPacket ();
}
@@ -1163,7 +1079,7 @@
oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y);
}
oss << GetXMLClose ("topology");
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
WriteDummyPacket ();
if (!Simulator::IsFinished ())
{
@@ -1251,7 +1167,7 @@
oss << GetXMLOpenClose_meta (GetPacketMetadata (p));
oss << GetXMLClose ("wpacket");
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
void AnimationInterface::OutputCsmaPacket (Ptr<const Packet> p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo)
@@ -1268,7 +1184,7 @@
if (m_enablePacketMetadata)
oss << GetXMLOpenClose_meta (GetPacketMetadata (p));
oss << GetXMLClose ("packet");
- WriteN (m_fHandle, oss.str ());
+ WriteN (oss.str ());
}
void AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y, double z)
--- a/src/netanim/model/animation-interface.h Thu May 24 04:16:20 2012 -0400
+++ b/src/netanim/model/animation-interface.h Thu May 24 00:17:05 2012 -0400
@@ -35,21 +35,6 @@
#include "ns3/animation-interface-helper.h"
#include "ns3/mac48-address.h"
-#ifdef WIN32
-#include <winsock2.h>
-#include <io.h>
-#define STDOUT_FILENO (SOCKET)GetStdHandle(STD_OUTPUT_HANDLE)
-#define close _close
-#define write _write
-#undef GetObject
-#undef min
-#undef max
-#define HANDLETYPE SOCKET
-#else
-#include "ns3/netanim-config.h"
-#define HANDLETYPE int
-#endif
-
namespace ns3 {
#define MAX_PKTS_PER_TRACE_FILE 100000
@@ -73,18 +58,6 @@
public:
/**
- * \brief Construct the animator interface. No arguments needed.
- *
- */
- AnimationInterface ();
-
- /**
- * \brief Destructor for the animator interface.
- *
- */
- ~AnimationInterface ();
-
- /**
* \brief Constructor
* \param filename The Filename for the trace file used by the Animator
* \param maxPktsPerFile The maximum number of packets per trace file.
@@ -99,13 +72,10 @@
bool usingXML = true);
/**
- * \brief Constructor
- * \param port Port on which ns-3 should listen to for connection from the
- * external netanim application
- * \param usingXML Set to true if XML output traces are required
+ * \brief Destructor for the animator interface.
*
*/
- AnimationInterface (uint16_t port, bool usingXML = true);
+ ~AnimationInterface ();
/**
* \brief Check if AnimationInterface is initialized
@@ -155,21 +125,6 @@
void SetStopTime (Time t);
/**
- * \brief (Deprecated) Specify that animation commands are to be written to
- * a socket.
- *
- * This call is used to set the ns3 process in server mode, waiting
- * for a TCP connection from the animator. This call will not
- * return until the animator connects in, or if the bind to the
- * specified port fails.
- *
- * \param port Port number to bind to.
- * \returns true if connection created, false if bind failed.
- *
- */
- bool SetServerPort (uint16_t port);
-
- /**
* \brief Writes the topology information and sets up the appropriate
* animation packet tx callback
*
@@ -289,21 +244,13 @@
private:
-#ifndef WIN32
- int m_fHandle; // File handle for output (-1 if none)
+ FILE * m_f; // File handle for output (-1 if none)
// Write specified amount of data to the specified handle
- int WriteN (int, const char*, uint32_t);
-#else
- SOCKET m_fHandle; // File handle for output (-1 if none)
- int WriteN (SOCKET, const char*, uint32_t);
-#endif
+ int WriteN (const char*, uint32_t);
bool m_xml; // True if xml format desired
Time m_mobilityPollInterval;
- bool m_usingSockets;
- uint16_t m_port;
std::string m_outputFileName;
bool m_outputFileSet;
- bool m_serverPortSet;
uint64_t gAnimUid ; // Packet unique identifier used by Animtion
bool m_randomPosition;
AnimWriteCallback m_writeCallback;
@@ -360,7 +307,7 @@
void MobilityCourseChangeTrace (Ptr <const MobilityModel> mob);
// Write a string to the specified handle;
- int WriteN (int, const std::string&);
+ int WriteN (const std::string&);
void OutputWirelessPacket (Ptr<const Packet> p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
void OutputCsmaPacket (Ptr<const Packet> p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);