A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("SimpleChannel");
28 
29 namespace ns3 {
30 
31 NS_OBJECT_ENSURE_REGISTERED (SimpleChannel);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::SimpleChannel")
37  .SetParent<Channel> ()
38  .AddConstructor<SimpleChannel> ()
39  ;
40  return tid;
41 }
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
48 void
49 SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol,
50  Mac48Address to, Mac48Address from,
51  Ptr<SimpleNetDevice> sender)
52 {
53  NS_LOG_FUNCTION (this << p << protocol << to << from << sender);
54  for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i)
55  {
56  Ptr<SimpleNetDevice> tmp = *i;
57  if (tmp == sender)
58  {
59  continue;
60  }
61  Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds (0),
62  &SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
63  }
64 }
65 
66 void
68 {
69  NS_LOG_FUNCTION (this << device);
70  m_devices.push_back (device);
71 }
72 
73 uint32_t
75 {
76  NS_LOG_FUNCTION (this);
77  return m_devices.size ();
78 }
80 SimpleChannel::GetDevice (uint32_t i) const
81 {
82  NS_LOG_FUNCTION (this << i);
83  return m_devices[i];
84 }
85 
86 } // 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 the class in the ns-3 factory.
Definition: object-base.h:38
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:170
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.
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:905
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
an EUI-48 address
Definition: mac48-address.h:41
std::vector< Ptr< SimpleNetDevice > > m_devices
devices connected by the channel
virtual uint32_t GetNDevices(void) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
static TypeId GetTypeId(void)
Get the type ID.