Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -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 "ccnx-path-weight-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" |
| 27 | #include "ns3/ccnx-app.h" |
| 28 | #include "ns3/ccnx-face.h" |
| 29 | #include "ns3/boolean.h" |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 30 | #include "ns3/simulator.h" |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 31 | |
| 32 | #include <boost/lexical_cast.hpp> |
| 33 | #include <boost/foreach.hpp> |
| 34 | |
| 35 | using namespace std; |
| 36 | |
| 37 | namespace ns3 { |
| 38 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 39 | CcnxPathWeightTracer::CcnxPathWeightTracer (std::ostream &os, Ptr<Node> node) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 40 | : m_os (os) |
| 41 | , m_nodePtr (node) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 42 | { |
| 43 | m_node = boost::lexical_cast<string> (m_nodePtr->GetId ()); |
| 44 | |
| 45 | Connect (); |
| 46 | |
| 47 | string name = Names::FindName (node); |
| 48 | if (!name.empty ()) |
| 49 | { |
| 50 | m_node = name; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | CcnxPathWeightTracer::Connect () |
| 56 | { |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 57 | Config::Set ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/FaceList/*/MetricTagging", |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 58 | BooleanValue (true)); |
| 59 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 60 | Config::Connect ("/NodeList/"+m_node+"/ApplicationList/*/PathWeightsTrace", |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 61 | MakeCallback (&CcnxPathWeightTracer::InLocalFace, this)); |
| 62 | } |
| 63 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 64 | void |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 65 | CcnxPathWeightTracer::PrintHeader (std::ostream &os) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 66 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 67 | os << "Time\t" |
| 68 | << "Src\t" |
| 69 | << "Dst\t" |
| 70 | << "SeqNo\t" |
| 71 | << "Weight"; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void |
| 75 | CcnxPathWeightTracer::InLocalFace (std::string context, |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 76 | Ptr<Node> src, Ptr<Node> dst, uint32_t seqno, uint32_t weight) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 77 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 78 | std::string srcName = Names::FindName (src); |
| 79 | std::string dstName = Names::FindName (dst); |
| 80 | if (srcName == "") srcName = boost::lexical_cast<std::string> (src->GetId ()); |
| 81 | if (dstName == "") srcName = boost::lexical_cast<std::string> (dst->GetId ()); |
| 82 | // std::cout << "Path weights from " << Names::FindName (src) << " to "<< Names::FindName (dst) <<" : " << weight << "\n"; |
| 83 | |
| 84 | m_os << Simulator::Now ().ToDouble (Time::S) << "\t" |
| 85 | << srcName << "\t" |
| 86 | << dstName << "\t" |
| 87 | << seqno << "\t" |
| 88 | << weight << "\n"; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | } // namespace ns3 |