blob: 4d6aa7d6b61ece1af5bcddb24b7eb4d8c296b217 [file] [log] [blame]
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -08001/* -*- 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 Afanasyev6bff0df2012-01-19 17:51:52 -080030#include "ns3/simulator.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080031
32#include <boost/lexical_cast.hpp>
33#include <boost/foreach.hpp>
34
35using namespace std;
36
37namespace ns3 {
38
39CcnxPathWeightTracer::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
55void
56CcnxPathWeightTracer::Connect ()
57{
58 Config::Set ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/MetricTagging",
59 BooleanValue (true));
60
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080061 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/PathWeightsTrace",
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080062 MakeCallback (&CcnxPathWeightTracer::InLocalFace, this));
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080063 // Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/FaceList/*/$ns3::CcnxLocalFace/PathWeightsTrace",
64 // MakeCallback (&CcnxPathWeightTracer::InLocalFace, this));
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080065}
66
67
68void
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080069CcnxPathWeightTracer::PrintHeader (std::ostream &os)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080070{
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080071 os << "Time\t"
72 << "Src\t"
73 << "Dst\t"
74 << "SeqNo\t"
75 << "Weight";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080076}
77
78void
79CcnxPathWeightTracer::InLocalFace (std::string context,
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080080 Ptr<Node> src, Ptr<Node> dst, uint32_t seqno, uint32_t weight)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080081{
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080082 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 Afanasyeve9c9d722012-01-19 16:59:30 -080093}
94
95} // namespace ns3