blob: b2685bd9d91baf2f6e9b9f5b97e3791f578fa212 [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
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080039CcnxPathWeightTracer::CcnxPathWeightTracer (std::ostream &os, Ptr<Node> node)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080040 : m_os (os)
41 , m_nodePtr (node)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080042{
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
54void
55CcnxPathWeightTracer::Connect ()
56{
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080057 Config::Set ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/FaceList/*/MetricTagging",
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080058 BooleanValue (true));
59
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080060 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/*/PathWeightsTrace",
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080061 MakeCallback (&CcnxPathWeightTracer::InLocalFace, this));
62}
63
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080064void
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080065CcnxPathWeightTracer::PrintHeader (std::ostream &os)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080066{
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080067 os << "Time\t"
68 << "Src\t"
69 << "Dst\t"
70 << "SeqNo\t"
71 << "Weight";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080072}
73
74void
75CcnxPathWeightTracer::InLocalFace (std::string context,
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080076 Ptr<Node> src, Ptr<Node> dst, uint32_t seqno, uint32_t weight)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080077{
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080078 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 Afanasyeve9c9d722012-01-19 16:59:30 -080089}
90
91} // namespace ns3