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 | |
| 39 | CcnxPathWeightTracer::CcnxPathWeightTracer (std::ostream &os, Ptr<Node> node, std::string appId) |
| 40 | : m_os (os) |
| 41 | , m_nodePtr (node) |
| 42 | , m_appId (appId) |
| 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 | void |
| 56 | CcnxPathWeightTracer::Connect () |
| 57 | { |
| 58 | Config::Set ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/MetricTagging", |
| 59 | BooleanValue (true)); |
| 60 | |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame^] | 61 | Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/PathWeightsTrace", |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 62 | MakeCallback (&CcnxPathWeightTracer::InLocalFace, this)); |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame^] | 63 | // Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/FaceList/*/$ns3::CcnxLocalFace/PathWeightsTrace", |
| 64 | // MakeCallback (&CcnxPathWeightTracer::InLocalFace, this)); |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | void |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame^] | 69 | CcnxPathWeightTracer::PrintHeader (std::ostream &os) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 70 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame^] | 71 | os << "Time\t" |
| 72 | << "Src\t" |
| 73 | << "Dst\t" |
| 74 | << "SeqNo\t" |
| 75 | << "Weight"; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void |
| 79 | CcnxPathWeightTracer::InLocalFace (std::string context, |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame^] | 80 | Ptr<Node> src, Ptr<Node> dst, uint32_t seqno, uint32_t weight) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 81 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame^] | 82 | std::string srcName = Names::FindName (src); |
| 83 | std::string dstName = Names::FindName (dst); |
| 84 | if (srcName == "") srcName = boost::lexical_cast<std::string> (src->GetId ()); |
| 85 | if (dstName == "") srcName = boost::lexical_cast<std::string> (dst->GetId ()); |
| 86 | // std::cout << "Path weights from " << Names::FindName (src) << " to "<< Names::FindName (dst) <<" : " << weight << "\n"; |
| 87 | |
| 88 | m_os << Simulator::Now ().ToDouble (Time::S) << "\t" |
| 89 | << srcName << "\t" |
| 90 | << dstName << "\t" |
| 91 | << seqno << "\t" |
| 92 | << weight << "\n"; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | } // namespace ns3 |