blob: 170f280613882133763b55041853a0d86a2007a8 [file] [log] [blame]
Alexander Afanasyevc4f88282012-01-03 11:27:20 -08001/* -*- 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"
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -080027#include "ns3/node-list.h"
28#include "ns3/node.h"
29#include "ns3/log.h"
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080030
31#include "ns3/tcp-l4-protocol.h"
32#include "ns3/tcp-header.h"
33#include "ns3/ipv4-header.h"
34
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -080035#include <boost/lexical_cast.hpp>
36#include <fstream>
37
38NS_LOG_COMPONENT_DEFINE ("Ipv4SeqsAppTracer");
39
40using namespace boost;
41using namespace std;
42
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080043namespace ns3 {
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -080044
45Ipv4SeqsAppTracer::Ipv4SeqsAppTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
46 : Ipv4AppTracer (node)
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080047 , m_os (os)
48{
49}
50
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -080051boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4SeqsAppTracer> > >
52Ipv4SeqsAppTracer::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
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080081void
82Ipv4SeqsAppTracer::Reset ()
83{
84}
85
86void
87Ipv4SeqsAppTracer::PrintHeader (std::ostream &os) const
88{
89 os << "Time\t"
90 << "Node\t"
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080091 << "Type\t"
92 << "SeqNo";
93}
94
95void
96Ipv4SeqsAppTracer::Print (std::ostream &os) const
97{
98}
99
100#define PRINTER(type,size) \
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -0800101 *m_os \
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800102 << Simulator::Now ().ToDouble (Time::S) << "\t" \
103 << m_node << "\t" \
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800104 << type << "\t" \
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -0800105 << static_cast<uint32_t> (size / 1040.0) << std::endl;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800106
107void
108Ipv4SeqsAppTracer::Tx (std::string context,
109 const Ipv4Header &ip, Ptr<const Packet>, uint32_t)
110{
111 if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER) return;
112}
113
114void
115Ipv4SeqsAppTracer::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 {
Alexander Afanasyevfc8425c2013-01-31 13:33:49 -0800126 if (tcp.GetAckNumber ().GetValue () > 1000) // a little bit more cheating
127 {
128 PRINTER("InAck", tcp.GetAckNumber ().GetValue ());
129 }
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800130 }
131}
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800132
133} // namespace ns3