A Discrete-Event Network Simulator
API
simple-channel.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "simple-channel.h"
21 #include "simple-net-device.h"
22 #include "ns3/simulator.h"
23 #include "ns3/packet.h"
24 #include "ns3/node.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("SimpleChannel");
30 
31 NS_OBJECT_ENSURE_REGISTERED (SimpleChannel);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::SimpleChannel")
37  .SetParent<Channel> ()
38  .SetGroupName("Network")
39  .AddConstructor<SimpleChannel> ()
40  .AddAttribute ("Delay", "Transmission delay through the channel",
41  TimeValue (Seconds (0)),
43  MakeTimeChecker ())
44  ;
45  return tid;
46 }
47 
49 {
50  NS_LOG_FUNCTION (this);
51 }
52 
53 void
54 SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol,
55  Mac48Address to, Mac48Address from,
56  Ptr<SimpleNetDevice> sender)
57 {
58  NS_LOG_FUNCTION (this << p << protocol << to << from << sender);
59  for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i)
60  {
61  Ptr<SimpleNetDevice> tmp = *i;
62  if (tmp == sender)
63  {
64  continue;
65  }
66  Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), m_delay,
67  &SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
68  }
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION (this << device);
75  m_devices.push_back (device);
76 }
77 
78 uint32_t
80 {
81  NS_LOG_FUNCTION (this);
82  return m_devices.size ();
83 }
85 SimpleChannel::GetDevice (uint32_t i) const
86 {
87  NS_LOG_FUNCTION (this << i);
88  return m_devices[i];
89 }
90 
91 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void Add(Ptr< SimpleNetDevice > device)
Attached a net device to the channel.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Abstract Channel Base Class.
Definition: channel.h:43
virtual void Send(Ptr< Packet > p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr< SimpleNetDevice > sender)
A packet is sent by a net device.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
AttributeValue implementation for Time.
Definition: nstime.h:928
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:899
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
Every class exported by the ns3 library is enclosed in the ns3 namespace.
an EUI-48 address
Definition: mac48-address.h:43
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:929
std::vector< Ptr< SimpleNetDevice > > m_devices
devices connected by the channel
Time m_delay
The assigned speed-of-light delay of the channel.
A simple channel, for simple things and testing.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
virtual uint32_t GetNDevices(void) const
a unique identifier for an interface.
Definition: type-id.h:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
static TypeId GetTypeId(void)
Get the type ID.