blob: a2cd3a6890ca6cfbe556e3a7c86c0aef3f55d6bd [file] [log] [blame]
Alexander Afanasyevc7597622013-02-28 10:58:52 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
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 L2_TRACER_H
22#define L2_TRACER_H
23
24#include "ns3/ptr.h"
25#include "ns3/simple-ref-count.h"
26#include "ns3/packet.h"
27
28namespace ns3 {
29
30class Node;
31
Alexander Afanasyev79206512013-07-27 16:49:12 -070032/**
33 * @ingroup ndn-tracers
34 * @brief Link-layer tracer
35 *
36 * @todo Finish implementation
37 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038class L2Tracer : public SimpleRefCount<L2Tracer> {
Alexander Afanasyevc7597622013-02-28 10:58:52 -080039public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 L2Tracer(Ptr<Node> node);
41 virtual ~L2Tracer(){};
Alexander Afanasyevc7597622013-02-28 10:58:52 -080042
43 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 Connect();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080045
46 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080048
49 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 Print(std::ostream& os) const = 0;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080051
52 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 Drop(Ptr<const Packet>) = 0;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080054
55 // Rx/Tx is NetDevice specific
56 // please refer to pyviz.cc in order to extend this tracer
57
58protected:
59 std::string m_node;
60 Ptr<Node> m_nodePtr;
61
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 struct Stats {
63 void
64 Reset()
Alexander Afanasyevc7597622013-02-28 10:58:52 -080065 {
66 m_in = 0;
67 m_out = 0;
68 m_drop = 0;
69 }
70
71 uint64_t m_in;
72 uint64_t m_out;
73 uint64_t m_drop;
74 };
75};
76
77inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078operator<<(std::ostream& os, const L2Tracer& tracer)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080079{
80 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 tracer.PrintHeader(os);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080082 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 tracer.Print(os);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080084 return os;
85}
86
87} // namespace ns3
88
89#endif // L2_TRACER_H