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 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::SimpleChannel")
38  .SetParent<Channel> ()
39  .AddConstructor<SimpleChannel> ()
40  ;
41  return tid;
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
49 void
50 SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol,
51  Mac48Address to, Mac48Address from,
52  Ptr<SimpleNetDevice> sender)
53 {
54  NS_LOG_FUNCTION (this << p << protocol << to << from << sender);
55  for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i)
56  {
57  Ptr<SimpleNetDevice> tmp = *i;
58  if (tmp == sender)
59  {
60  continue;
61  }
62  Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds (0),
63  &SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
64  }
65 }
66 
67 void
69 {
70  NS_LOG_FUNCTION (this << device);
71  m_devices.push_back (device);
72 }
73 
74 uint32_t
76 {
77  NS_LOG_FUNCTION (this);
78  return m_devices.size ();
79 }
81 SimpleChannel::GetDevice (uint32_t i) const
82 {
83  NS_LOG_FUNCTION (this << i);
84  return m_devices[i];
85 }
86 
87 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
virtual void Add(Ptr< SimpleNetDevice > device)
Attached a net device to the channel.
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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:904
Ptr< Packet > Copy(void) const
Definition: packet.cc:122
an EUI-48 address
Definition: mac48-address.h:41
std::vector< Ptr< SimpleNetDevice > > m_devices
NS_LOG_COMPONENT_DEFINE("SimpleChannel")
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:611
static TypeId GetTypeId(void)