blob: beef83f9779b45239979b56c4d42cdfad83c8c07 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevc7597622013-02-28 10:58:52 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevc7597622013-02-28 10:58:52 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc7597622013-02-28 10:58:52 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc7597622013-02-28 10:58:52 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevc7597622013-02-28 10:58:52 -080019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "l2-tracer.hpp"
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080021
Alexander Afanasyevc7597622013-02-28 10:58:52 -080022#include "ns3/node.h"
23#include "ns3/config.h"
24#include "ns3/names.h"
25#include "ns3/callback.h"
26
Alexander Afanasyev260e4092013-08-11 17:12:46 -070027#include "ns3/point-to-point-net-device.h"
28#include "ns3/queue.h"
Alexander Afanasyevc7597622013-02-28 10:58:52 -080029#include <boost/lexical_cast.hpp>
30
Alexander Afanasyevc7597622013-02-28 10:58:52 -080031namespace ns3 {
32
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033L2Tracer::L2Tracer(Ptr<Node> node)
34 : m_nodePtr(node)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080035{
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080036 m_node = boost::lexical_cast<std::string>(m_nodePtr->GetId());
Alexander Afanasyevc7597622013-02-28 10:58:52 -080037
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038 Connect();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080039
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080040 std::string name = Names::FindName(node);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 if (!name.empty()) {
42 m_node = name;
43 }
Alexander Afanasyevc7597622013-02-28 10:58:52 -080044}
45
46void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047L2Tracer::Connect()
Alexander Afanasyevc7597622013-02-28 10:58:52 -080048{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 for (uint32_t devId = 0; devId < m_nodePtr->GetNDevices(); devId++) {
50 Ptr<PointToPointNetDevice> p2pnd =
51 DynamicCast<PointToPointNetDevice>(m_nodePtr->GetDevice(devId));
52 if (p2pnd) {
53 p2pnd->GetQueue()->TraceConnectWithoutContext("Drop", MakeCallback(&L2Tracer::Drop, this));
Alexander Afanasyev260e4092013-08-11 17:12:46 -070054 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 }
Alexander Afanasyevc7597622013-02-28 10:58:52 -080056}
57
58} // namespace ns3