# HG changeset patch # User Tom Henderson # Date 1226069661 28800 # Node ID 448c5176bf8a44f16e928578d547aeec43ecaebe # Parent cc6a7f93dc3f66e31f2f4a024f7faed5477678f3 Add an InternetStackHelper method to do ascii tracing on drop events diff -r cc6a7f93dc3f -r 448c5176bf8a src/helper/internet-stack-helper.cc --- a/src/helper/internet-stack-helper.cc Thu Nov 06 15:04:25 2008 -0800 +++ b/src/helper/internet-stack-helper.cc Fri Nov 07 06:54:21 2008 -0800 @@ -92,6 +92,29 @@ InternetStackHelper::Install (Ptr } void +InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n) +{ + Packet::EnablePrinting (); + std::ostringstream oss; + for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) + { + Ptr node = *i; + oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop"; + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os)); + oss.str (""); + oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop"; + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os)); + oss.str (""); + } +} + +void +InternetStackHelper::EnableAsciiAll (std::ostream &os) +{ + EnableAscii (os, NodeContainer::GetGlobal ()); +} + +void InternetStackHelper::EnablePcapAll (std::string filename) { Simulator::ScheduleDestroy (&InternetStackHelper::Cleanup); @@ -157,4 +180,11 @@ InternetStackHelper::GetStream (uint32_t return trace.writer; } +void +InternetStackHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr packet) +{ + *os << "d " << Simulator::Now ().GetSeconds () << " "; + *os << path << " " << *packet << std::endl; +} + } // namespace ns3 diff -r cc6a7f93dc3f -r 448c5176bf8a src/helper/internet-stack-helper.h --- a/src/helper/internet-stack-helper.h Thu Nov 06 15:04:25 2008 -0800 +++ b/src/helper/internet-stack-helper.h Fri Nov 07 06:54:21 2008 -0800 @@ -70,6 +70,25 @@ public: void SetNscStack(std::string soname); /** + * \param os output stream + * \param n node container + * + * Enable ascii output on these drop traces, for each node in the NodeContainer.. + * /NodeList/[i]/$ns3ArpL3Protocol/Drop + * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop + */ + static void EnableAscii (std::ostream &os, NodeContainer n); + + /** + * \param os output stream + * + * Enable ascii output on these drop traces, for all nodes. + * /NodeList/[i]/$ns3ArpL3Protocol/Drop + * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop + */ + static void EnableAsciiAll (std::ostream &os); + + /** * Enable pcap output on each protocol instance which is of the * ns3::Ipv4L3Protocol type. Both Tx and Rx events will be logged. * @@ -95,6 +114,7 @@ private: uint32_t interfaceId; Ptr writer; }; + static void AsciiDropEvent (std::ostream *os, std::string path, Ptr packet); static std::string m_pcapBaseFilename; static uint32_t GetNodeIndex (std::string context); static std::vector m_traces;