blob: 693a5a168896bc9ea4ac4f0960edf1697fd98f8c [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevc7597622013-02-28 10:58:52 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevc7597622013-02-28 10:58:52 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc7597622013-02-28 10:58:52 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc7597622013-02-28 10:58:52 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevc7597622013-02-28 10:58:52 -080019
20#ifndef L2_TRACER_H
21#define L2_TRACER_H
22
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyevc7597622013-02-28 10:58:52 -080025#include "ns3/ptr.h"
26#include "ns3/simple-ref-count.h"
27#include "ns3/packet.h"
28
29namespace ns3 {
30
31class Node;
32
Alexander Afanasyev79206512013-07-27 16:49:12 -070033/**
34 * @ingroup ndn-tracers
35 * @brief Link-layer tracer
36 *
37 * @todo Finish implementation
38 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039class L2Tracer : public SimpleRefCount<L2Tracer> {
Alexander Afanasyevc7597622013-02-28 10:58:52 -080040public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 L2Tracer(Ptr<Node> node);
42 virtual ~L2Tracer(){};
Alexander Afanasyevc7597622013-02-28 10:58:52 -080043
44 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 Connect();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080046
47 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080049
50 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 Print(std::ostream& os) const = 0;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080052
53 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 Drop(Ptr<const Packet>) = 0;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080055
56 // Rx/Tx is NetDevice specific
57 // please refer to pyviz.cc in order to extend this tracer
58
59protected:
60 std::string m_node;
61 Ptr<Node> m_nodePtr;
62
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 struct Stats {
64 void
65 Reset()
Alexander Afanasyevc7597622013-02-28 10:58:52 -080066 {
67 m_in = 0;
68 m_out = 0;
69 m_drop = 0;
70 }
71
72 uint64_t m_in;
73 uint64_t m_out;
74 uint64_t m_drop;
75 };
76};
77
78inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079operator<<(std::ostream& os, const L2Tracer& tracer)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080080{
81 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 tracer.PrintHeader(os);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080083 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 tracer.Print(os);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080085 return os;
86}
87
88} // namespace ns3
89
90#endif // L2_TRACER_H