Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 24 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 25 | |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 26 | #include "ns3/ptr.h" |
| 27 | #include "ns3/simple-ref-count.h" |
| 28 | #include "ns3/packet.h" |
| 29 | |
| 30 | namespace ns3 { |
| 31 | |
| 32 | class Node; |
| 33 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 34 | /** |
| 35 | * @ingroup ndn-tracers |
| 36 | * @brief Link-layer tracer |
| 37 | * |
| 38 | * @todo Finish implementation |
| 39 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | class L2Tracer : public SimpleRefCount<L2Tracer> { |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 41 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | L2Tracer(Ptr<Node> node); |
| 43 | virtual ~L2Tracer(){}; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 44 | |
| 45 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | Connect(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 47 | |
| 48 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | PrintHeader(std::ostream& os) const = 0; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 50 | |
| 51 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | Print(std::ostream& os) const = 0; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 53 | |
| 54 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | Drop(Ptr<const Packet>) = 0; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 56 | |
| 57 | // Rx/Tx is NetDevice specific |
| 58 | // please refer to pyviz.cc in order to extend this tracer |
| 59 | |
| 60 | protected: |
| 61 | std::string m_node; |
| 62 | Ptr<Node> m_nodePtr; |
| 63 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | struct Stats { |
| 65 | void |
| 66 | Reset() |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 67 | { |
| 68 | m_in = 0; |
| 69 | m_out = 0; |
| 70 | m_drop = 0; |
| 71 | } |
| 72 | |
| 73 | uint64_t m_in; |
| 74 | uint64_t m_out; |
| 75 | uint64_t m_drop; |
| 76 | }; |
| 77 | }; |
| 78 | |
| 79 | inline std::ostream& |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | operator<<(std::ostream& os, const L2Tracer& tracer) |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 81 | { |
| 82 | os << "# "; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | tracer.PrintHeader(os); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 84 | os << "\n"; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | tracer.Print(os); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 86 | return os; |
| 87 | } |
| 88 | |
| 89 | } // namespace ns3 |
| 90 | |
| 91 | #endif // L2_TRACER_H |