src/node/simple-channel.cc
author Lalith Suresh <suresh.lalith@gmail.com>
Sun, 18 Jul 2010 13:29:13 +0530
changeset 6339 366418369bda
parent 6109 c204cb0f18d8
permissions -rw-r--r--
Click now handles all packets pertaining to Mac High models
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3312
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     2
/*
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     3
 * Copyright (c) 2008 INRIA
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     4
 *
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     7
 * published by the Free Software Foundation;
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     8
 *
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    12
 * GNU General Public License for more details.
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    13
 *
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    14
 * You should have received a copy of the GNU General Public License
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    15
 * along with this program; if not, write to the Free Software
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    17
 *
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
c4f001798693 add missing copyright statement
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2720
diff changeset
    19
 */
2673
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "simple-channel.h"
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "simple-net-device.h"
3534
e170f2c17e03 Use scheduler to call up the stack in SimpleNetDevice (bug 287)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3312
diff changeset
    22
#include "ns3/simulator.h"
2673
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "ns3/packet.h"
5523
86e84169c725 Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents: 3534
diff changeset
    24
#include "ns3/node.h"
6109
c204cb0f18d8 [Bug 414] No error model for SimpleNetDevice
Tom Henderson <tomh@tomh.org>
parents: 5523
diff changeset
    25
#include "ns3/log.h"
c204cb0f18d8 [Bug 414] No error model for SimpleNetDevice
Tom Henderson <tomh@tomh.org>
parents: 5523
diff changeset
    26
c204cb0f18d8 [Bug 414] No error model for SimpleNetDevice
Tom Henderson <tomh@tomh.org>
parents: 5523
diff changeset
    27
NS_LOG_COMPONENT_DEFINE ("SimpleChannel");
2673
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
namespace ns3 {
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
TypeId 
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
SimpleChannel::GetTypeId (void)
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
{
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
  static TypeId tid = TypeId ("ns3::SimpleChannel")
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
    .SetParent<Channel> ()
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
    .AddConstructor<SimpleChannel> ()
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
    ;
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
  return tid;
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
}
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
SimpleChannel::SimpleChannel ()
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
{}
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
void
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol, 
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
		     Mac48Address to, Mac48Address from,
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
		     Ptr<SimpleNetDevice> sender)
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
{
6109
c204cb0f18d8 [Bug 414] No error model for SimpleNetDevice
Tom Henderson <tomh@tomh.org>
parents: 5523
diff changeset
    49
  NS_LOG_FUNCTION (p << protocol << to << from << sender);
2673
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
  for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i)
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
    {
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
      Ptr<SimpleNetDevice> tmp = *i;
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
      if (tmp == sender)
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
	{
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
	  continue;
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
	}
5523
86e84169c725 Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents: 3534
diff changeset
    57
      Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds (0),
86e84169c725 Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents: 3534
diff changeset
    58
                                      &SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
2673
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
    }
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
}
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
void 
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
SimpleChannel::Add (Ptr<SimpleNetDevice> device)
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
{
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
  m_devices.push_back (device);
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
}
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
uint32_t 
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
SimpleChannel::GetNDevices (void) const
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
  return m_devices.size ();
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
}
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
Ptr<NetDevice> 
2720
3c7d9f8c9034 make ns3::Channel wholy pure.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2673
diff changeset
    74
SimpleChannel::GetDevice (uint32_t i) const
2673
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
{
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  return m_devices[i];
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
}
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
a70e0c7aaf56 SimpleChannel/SimpleNetDevice. Use them where needed.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
} // namespace ns3