blob: d4be0a90c68c8195c5c5aa1c8808ddb4fc431376 [file] [log] [blame]
Alexander Afanasyev7e71c752012-01-25 21:40:39 -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#ifndef IPV4_RATE_L3_TRACER_H
22#define IPV4_RATE_L3_TRACER_H
23
24#include "ipv4-l3-tracer.h"
25
26#include "ns3/nstime.h"
27#include "ns3/event-id.h"
Alexander Afanasyev5352af32013-07-15 09:51:28 -070028#include "ns3/node-container.h"
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080029
30#include <boost/tuple/tuple.hpp>
Alexander Afanasyev49165862013-01-31 00:38:20 -080031#include <boost/shared_ptr.hpp>
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080032#include <map>
33
34namespace ns3 {
35
36/**
37 * @ingroup ccnx
38 * @brief CCNx network-layer rate tracer
39 */
40class Ipv4RateL3Tracer : public Ipv4L3Tracer
41{
42public:
43 /**
44 * @brief Network layer tracer constructor
45 */
Alexander Afanasyev49165862013-01-31 00:38:20 -080046 Ipv4RateL3Tracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080047 virtual ~Ipv4RateL3Tracer ();
48
Alexander Afanasyev49165862013-01-31 00:38:20 -080049 /**
50 * @brief Helper method to install tracers on all simulation nodes
51 *
52 * @param file File to which traces will be written
53 * @param averagingPeriod Defines averaging period for the rate calculation,
54 * as well as how often data will be written into the trace file (default, every half second)
55 *
56 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
57 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
58 *
59 */
60 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > >
61 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
62
Alexander Afanasyev5352af32013-07-15 09:51:28 -070063 /**
64 * @brief Helper method to install tracers on the selected simulation nodes
65 *
66 * @param nodes Nodes on which to install tracer
67 * @param file File to which traces will be written. If filename is -, then std::out is used
68 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
69 *
70 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
71 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
72 *
73 */
74 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > >
75 Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
76
77 /**
78 * @brief Helper method to install tracers on a specific simulation node
79 *
80 * @param nodes Nodes on which to install tracer
81 * @param file File to which traces will be written. If filename is -, then std::out is used
82 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
83 *
84 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
85 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
86 *
87 */
88 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > >
89 Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
90
91 /**
92 * @brief Helper method to install tracers on a specific simulation node
93 *
94 * @param nodes Nodes on which to install tracer
95 * @param outputStream Smart pointer to a stream
96 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
97 *
98 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
99 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
100 */
101 static Ptr<Ipv4RateL3Tracer>
102 Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
103
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800104 void
105 SetAveragingPeriod (const Time &period);
Alexander Afanasyev49165862013-01-31 00:38:20 -0800106
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800107 virtual void
108 PrintHeader (std::ostream &os) const;
109
110 virtual void
111 Print (std::ostream &os) const;
112
113 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700114 Rx (Ptr<const Packet>, Ptr<Ipv4>, uint32_t);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800115
116 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700117 Tx (Ptr<const Packet>, Ptr<Ipv4>, uint32_t);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800118
119 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700120 Drop (const Ipv4Header &, Ptr<const Packet>, Ipv4L3Protocol::DropReason, Ptr<Ipv4>, uint32_t);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800121
122private:
123 void
124 PeriodicPrinter ();
Alexander Afanasyev49165862013-01-31 00:38:20 -0800125
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800126 void
127 Reset ();
128
129private:
Alexander Afanasyev49165862013-01-31 00:38:20 -0800130 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800131 Time m_period;
132 EventId m_printEvent;
133
134 mutable std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
135};
136
137} // namespace ns3
138
139#endif // IPV4_RATE_L3_TRACER_H