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