blob: bf1fcf110a33d4075d0ed734bb2de50e395ec993 [file] [log] [blame]
Alexander Afanasyevc7597622013-02-28 10:58:52 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080021#include "l2-tracer.hpp"
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
31using namespace std;
32
33namespace ns3 {
34
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035L2Tracer::L2Tracer(Ptr<Node> node)
36 : m_nodePtr(node)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080037{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038 m_node = boost::lexical_cast<string>(m_nodePtr->GetId());
Alexander Afanasyevc7597622013-02-28 10:58:52 -080039
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 Connect();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080041
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042 string name = Names::FindName(node);
43 if (!name.empty()) {
44 m_node = name;
45 }
Alexander Afanasyevc7597622013-02-28 10:58:52 -080046}
47
48void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049L2Tracer::Connect()
Alexander Afanasyevc7597622013-02-28 10:58:52 -080050{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 for (uint32_t devId = 0; devId < m_nodePtr->GetNDevices(); devId++) {
52 Ptr<PointToPointNetDevice> p2pnd =
53 DynamicCast<PointToPointNetDevice>(m_nodePtr->GetDevice(devId));
54 if (p2pnd) {
55 p2pnd->GetQueue()->TraceConnectWithoutContext("Drop", MakeCallback(&L2Tracer::Drop, this));
Alexander Afanasyev260e4092013-08-11 17:12:46 -070056 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 }
Alexander Afanasyevc7597622013-02-28 10:58:52 -080058}
59
60} // namespace ns3