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