NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ipv4-seqs-app-tracer.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2011 UCLA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #include "ipv4-seqs-app-tracer.h"
22 #include "ns3/node.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"
28 #include "ns3/node.h"
29 #include "ns3/log.h"
30 
31 #include "ns3/tcp-l4-protocol.h"
32 #include "ns3/tcp-header.h"
33 #include "ns3/ipv4-header.h"
34 
35 #include <boost/lexical_cast.hpp>
36 #include <fstream>
37 
38 NS_LOG_COMPONENT_DEFINE ("Ipv4SeqsAppTracer");
39 
40 using namespace boost;
41 using namespace std;
42 
43 namespace ns3 {
44 
45 Ipv4SeqsAppTracer::Ipv4SeqsAppTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
46  : Ipv4AppTracer (node)
47  , m_os (os)
48 {
49 }
50 
51 boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4SeqsAppTracer> > >
52 Ipv4SeqsAppTracer::InstallAll (const std::string &file)
53 {
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);
57 
58  if (!outputStream->is_open ())
59  return boost::make_tuple (outputStream, tracers);
60 
61  for (NodeList::Iterator node = NodeList::Begin ();
62  node != NodeList::End ();
63  node++)
64  {
65  NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
66 
67  Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (outputStream, *node);
68  tracers.push_back (trace);
69  }
70 
71  if (tracers.size () > 0)
72  {
73  // *m_l3RateTrace << "# "; // not necessary for R's read.table
74  tracers.front ()->PrintHeader (*outputStream);
75  *outputStream << "\n";
76  }
77 
78  return boost::make_tuple (outputStream, tracers);
79 }
80 
81 void
82 Ipv4SeqsAppTracer::Reset ()
83 {
84 }
85 
86 void
87 Ipv4SeqsAppTracer::PrintHeader (std::ostream &os) const
88 {
89  os << "Time\t"
90  << "Node\t"
91  << "Type\t"
92  << "SeqNo";
93 }
94 
95 void
96 Ipv4SeqsAppTracer::Print (std::ostream &os) const
97 {
98 }
99 
100 #define PRINTER(type,size) \
101  *m_os \
102  << Simulator::Now ().ToDouble (Time::S) << "\t" \
103  << m_node << "\t" \
104  << type << "\t" \
105  << static_cast<uint32_t> (size / 1040.0) << std::endl;
106 
107 void
108 Ipv4SeqsAppTracer::Tx (std::string context,
109  const Ipv4Header &ip, Ptr<const Packet>, uint32_t)
110 {
111  if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER) return;
112 }
113 
114 void
115 Ipv4SeqsAppTracer::Rx (std::string context,
116  const Ipv4Header &ip, Ptr<const Packet> pktOrig, uint32_t)
117 {
118  if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER) return;
119 
120  TcpHeader tcp;
121  Ptr<Packet> packet = pktOrig->Copy ();
122  packet->RemoveHeader (tcp);
123 
124  if (tcp.GetFlags () | TcpHeader::ACK)
125  {
126  if (tcp.GetAckNumber ().GetValue () > 1000) // a little bit more cheating
127  {
128  PRINTER("InAck", tcp.GetAckNumber ().GetValue ());
129  }
130  }
131 }
132 
133 } // namespace ns3
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.