Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 1 | /* -*- 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 "ndn-l3-tracer.h" |
| 22 | #include "ns3/node.h" |
| 23 | #include "ns3/packet.h" |
| 24 | #include "ns3/config.h" |
| 25 | #include "ns3/names.h" |
| 26 | #include "ns3/callback.h" |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 27 | #include "ns3/ndn-forwarding-strategy.h" |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 28 | |
| 29 | #include <boost/lexical_cast.hpp> |
| 30 | |
| 31 | #include "ns3/ndn-face.h" |
| 32 | #include "ns3/ndn-interest.h" |
Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 33 | #include "ns3/ndn-data.h" |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 34 | #include "ns3/ndn-pit-entry.h" |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 35 | |
| 36 | using namespace std; |
| 37 | |
| 38 | namespace ns3 { |
| 39 | namespace ndn { |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 41 | L3Tracer::L3Tracer (Ptr<Node> node) |
| 42 | : m_nodePtr (node) |
| 43 | { |
| 44 | m_node = boost::lexical_cast<string> (m_nodePtr->GetId ()); |
| 45 | |
| 46 | Connect (); |
| 47 | |
| 48 | string name = Names::FindName (node); |
| 49 | if (!name.empty ()) |
| 50 | { |
| 51 | m_node = name; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | L3Tracer::L3Tracer (const std::string &node) |
| 56 | : m_node (node) |
| 57 | { |
| 58 | Connect (); |
| 59 | } |
| 60 | |
| 61 | L3Tracer::~L3Tracer () |
| 62 | { |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | void |
| 67 | L3Tracer::Connect () |
| 68 | { |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 69 | Ptr<ForwardingStrategy> fw = m_nodePtr->GetObject<ForwardingStrategy> (); |
| 70 | |
| 71 | fw->TraceConnectWithoutContext ("OutInterests", MakeCallback (&L3Tracer::OutInterests, this)); |
| 72 | fw->TraceConnectWithoutContext ("InInterests", MakeCallback (&L3Tracer::InInterests, this)); |
| 73 | fw->TraceConnectWithoutContext ("DropInterests", MakeCallback (&L3Tracer::DropInterests, this)); |
| 74 | |
| 75 | fw->TraceConnectWithoutContext ("OutData", MakeCallback (&L3Tracer::OutData, this)); |
| 76 | fw->TraceConnectWithoutContext ("InData", MakeCallback (&L3Tracer::InData, this)); |
| 77 | fw->TraceConnectWithoutContext ("DropData", MakeCallback (&L3Tracer::DropData, this)); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 78 | |
| 79 | // only for some strategies |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 80 | fw->TraceConnectWithoutContext ("OutNacks", MakeCallback (&L3Tracer::OutNacks, this)); |
| 81 | fw->TraceConnectWithoutContext ("InNacks", MakeCallback (&L3Tracer::InNacks, this)); |
| 82 | fw->TraceConnectWithoutContext ("DropNacks", MakeCallback (&L3Tracer::DropNacks, this)); |
| 83 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 84 | // satisfied/timed out PIs |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 85 | fw->TraceConnectWithoutContext ("SatisfiedInterests", MakeCallback (&L3Tracer::SatisfiedInterests, this)); |
| 86 | fw->TraceConnectWithoutContext ("TimedOutInterests", MakeCallback (&L3Tracer::TimedOutInterests, this)); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | } // namespace ndn |
| 90 | } // namespace ns3 |