satellite-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) 2014 Magister Solutions Ltd.
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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
22 
24 
25 #include <ns3/log.h>
26 #include <ns3/node.h>
27 #include <ns3/packet.h>
28 #include <ns3/simulator.h>
29 
30 NS_LOG_COMPONENT_DEFINE("SatSimpleChannel");
31 
32 namespace ns3
33 {
34 
35 NS_OBJECT_ENSURE_REGISTERED(SatSimpleChannel);
36 
37 TypeId
39 {
40  static TypeId tid =
41  TypeId("ns3::SatSimpleChannel").SetParent<Channel>().AddConstructor<SatSimpleChannel>();
42  return tid;
43 }
44 
46 {
47  NS_LOG_FUNCTION(this);
48 }
49 
50 void
51 SatSimpleChannel::Send(Ptr<Packet> p,
52  uint16_t protocol,
53  Mac48Address to,
54  Mac48Address from,
55  Ptr<SatSimpleNetDevice> sender)
56 {
57  NS_LOG_FUNCTION(this << p << protocol << to << from << sender);
58  for (std::vector<Ptr<SatSimpleNetDevice>>::const_iterator i = m_devices.begin();
59  i != m_devices.end();
60  ++i)
61  {
62  Ptr<SatSimpleNetDevice> device = *i;
63 
64  if (device != sender)
65  {
66  Simulator::ScheduleWithContext(device->GetNode()->GetId(),
67  Seconds(0),
69  device,
70  p->Copy(),
71  protocol,
72  to,
73  from);
74  }
75  }
76 }
77 
78 void
79 SatSimpleChannel::Add(Ptr<SatSimpleNetDevice> device)
80 {
81  NS_LOG_FUNCTION(this << device);
82  m_devices.push_back(device);
83 }
84 
85 std::size_t
87 {
88  NS_LOG_FUNCTION(this);
89  return m_devices.size();
90 }
91 
92 Ptr<NetDevice>
93 SatSimpleChannel::GetDevice(std::size_t i) const
94 {
95  NS_LOG_FUNCTION(this << i);
96  return m_devices[i];
97 }
98 
99 } // namespace ns3
SatSimpleChannel()
Default constructor.
virtual void Send(Ptr< Packet > p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr< SatSimpleNetDevice > sender)
A packet is sent by a net device.
virtual std::size_t GetNDevices(void) const
std::vector< Ptr< SatSimpleNetDevice > > m_devices
static TypeId GetTypeId(void)
Get the type ID.
virtual void Add(Ptr< SatSimpleNetDevice > device)
Attached a net device to the channel.
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SatSimpleChannel.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.