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" |
| 30 | |
| 31 | #include <boost/lexical_cast.hpp> |
| 32 | #include <boost/foreach.hpp> |
| 33 | |
| 34 | using namespace std; |
| 35 | |
| 36 | namespace ns3 { |
| 37 | |
| 38 | CcnxPathWeightTracer::CcnxPathWeightTracer (std::ostream &os, Ptr<Node> node, std::string appId) |
| 39 | : m_os (os) |
| 40 | , m_nodePtr (node) |
| 41 | , m_appId (appId) |
| 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 | { |
| 57 | Config::Set ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/MetricTagging", |
| 58 | BooleanValue (true)); |
| 59 | |
| 60 | Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/FaceList/*/$ns3::CcnxLocalFace/PathWeightsTrace", |
| 61 | MakeCallback (&CcnxPathWeightTracer::InLocalFace, this)); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | void |
| 66 | CcnxPathWeightTracer::PrintHeader (std::ostream &os) const |
| 67 | { |
| 68 | os << "Node\t" |
| 69 | << "AppId\t" |
| 70 | << "PathWeight\t" |
| 71 | << "PathWeights\n"; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | CcnxPathWeightTracer::InLocalFace (std::string context, |
| 76 | uint32_t weight, Ptr<Node> src, Ptr<Node> dst) |
| 77 | { |
| 78 | std::cout << "Path weights from " << Names::FindName (src) << " to "<< Names::FindName (dst) <<" : " << weight << "\n"; |
| 79 | } |
| 80 | |
| 81 | } // namespace ns3 |