A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
35
SimpleChannel::GetTypeId
(
void
)
36
{
37
static
TypeId
tid =
TypeId
(
"ns3::SimpleChannel"
)
38
.
SetParent
<
Channel
> ()
39
.AddConstructor<SimpleChannel> ()
40
;
41
return
tid;
42
}
43
44
SimpleChannel::SimpleChannel
()
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
68
SimpleChannel::Add
(
Ptr<SimpleNetDevice>
device)
69
{
70
NS_LOG_FUNCTION
(
this
<< device);
71
m_devices
.push_back (device);
72
}
73
74
uint32_t
75
SimpleChannel::GetNDevices
(
void
)
const
76
{
77
NS_LOG_FUNCTION
(
this
);
78
return
m_devices
.size ();
79
}
80
Ptr<NetDevice>
81
SimpleChannel::GetDevice
(uint32_t i)
const
82
{
83
NS_LOG_FUNCTION
(
this
<< i);
84
return
m_devices
[i];
85
}
86
87
}
// namespace ns3
simple-net-device.h
ns3::Ptr< Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::SimpleChannel::Add
virtual void Add(Ptr< SimpleNetDevice > device)
Attached a net device to the channel.
Definition:
simple-channel.cc:68
ns3::SimpleNetDevice::Receive
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
Definition:
simple-net-device.cc:64
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::Channel
Abstract Channel Base Class.
Definition:
channel.h:43
ns3::SimpleChannel::Send
virtual void Send(Ptr< Packet > p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr< SimpleNetDevice > sender)
A packet is sent by a net device.
Definition:
simple-channel.cc:50
ns3::SimpleChannel::SimpleChannel
SimpleChannel()
Definition:
simple-channel.cc:44
ns3::SimpleChannel::GetDevice
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
Definition:
simple-channel.cc:81
ns3::Simulator::ScheduleWithContext
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
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
Definition:
packet.cc:122
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:41
ns3::SimpleChannel::m_devices
std::vector< Ptr< SimpleNetDevice > > m_devices
Definition:
simple-channel.h:69
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("SimpleChannel")
simple-channel.h
ns3::SimpleChannel::GetNDevices
virtual uint32_t GetNDevices(void) const
Definition:
simple-channel.cc:75
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
ns3::SimpleChannel::GetTypeId
static TypeId GetTypeId(void)
Definition:
simple-channel.cc:35
src
network
utils
simple-channel.cc
Generated on Sat Apr 19 2014 14:07:06 for ns-3 by
1.8.6