21 #include "ipv4-seqs-app-tracer.h"
23 #include "ns3/packet.h"
24 #include "ns3/config.h"
25 #include "ns3/callback.h"
26 #include "ns3/simulator.h"
27 #include "ns3/node-list.h"
31 #include "ns3/tcp-l4-protocol.h"
32 #include "ns3/tcp-header.h"
33 #include "ns3/ipv4-header.h"
35 #include <boost/lexical_cast.hpp>
38 NS_LOG_COMPONENT_DEFINE (
"Ipv4SeqsAppTracer");
40 using namespace boost;
45 Ipv4SeqsAppTracer::Ipv4SeqsAppTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
46 : Ipv4AppTracer (node)
51 boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4SeqsAppTracer> > >
54 std::list<Ptr<Ipv4SeqsAppTracer> > tracers;
55 boost::shared_ptr<std::ofstream> outputStream (
new std::ofstream ());
56 outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
58 if (!outputStream->is_open ())
59 return boost::make_tuple (outputStream, tracers);
61 for (NodeList::Iterator node = NodeList::Begin ();
62 node != NodeList::End ();
65 NS_LOG_DEBUG (
"Node: " << lexical_cast<string> ((*node)->GetId ()));
67 Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (outputStream, *node);
68 tracers.push_back (trace);
71 if (tracers.size () > 0)
74 tracers.front ()->PrintHeader (*outputStream);
75 *outputStream <<
"\n";
78 return boost::make_tuple (outputStream, tracers);
82 Ipv4SeqsAppTracer::Reset ()
87 Ipv4SeqsAppTracer::PrintHeader (std::ostream &os)
const
96 Ipv4SeqsAppTracer::Print (std::ostream &os)
const
100 #define PRINTER(type,size) \
102 << Simulator::Now ().ToDouble (Time::S) << "\t" \
105 << static_cast<uint32_t> (size / 1040.0) << std::endl;
108 Ipv4SeqsAppTracer::Tx (std::string context,
109 const Ipv4Header &ip, Ptr<const Packet>, uint32_t)
111 if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER)
return;
115 Ipv4SeqsAppTracer::Rx (std::string context,
116 const Ipv4Header &ip, Ptr<const Packet> pktOrig, uint32_t)
118 if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER)
return;
121 Ptr<Packet> packet = pktOrig->Copy ();
122 packet->RemoveHeader (tcp);
124 if (tcp.GetFlags () | TcpHeader::ACK)
126 if (tcp.GetAckNumber ().GetValue () > 1000)
128 PRINTER(
"InAck", tcp.GetAckNumber ().GetValue ());
static boost::tuple< boost::shared_ptr< std::ostream >, std::list< Ptr< Ipv4SeqsAppTracer > > > InstallAll(const std::string &file)
Helper method to install tracers on all simulation nodes.