Loading...
Searching...
No Matches
satellite-simple-net-device.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 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
23#include "ns3/log.h"
24#include "ns3/node.h"
25#include "ns3/pointer.h"
26#include "ns3/uinteger.h"
27
28NS_LOG_COMPONENT_DEFINE("SatSimpleNetDevice");
29
30namespace ns3
31{
32
33NS_OBJECT_ENSURE_REGISTERED(SatSimpleNetDevice);
34
35TypeId
37{
38 static TypeId tid =
39 TypeId("ns3::SatSimpleNetDevice")
40 .SetParent<NetDevice>()
41 .AddConstructor<SatSimpleNetDevice>()
42 .AddAttribute(
43 "Mtu",
44 "The MAC-level Maximum Transmission Unit",
45 UintegerValue(0xffff), // 65535 bytes.
47 MakeUintegerChecker<uint16_t>())
48 .AddAttribute("ReceiveErrorModel",
49 "The receiver error model used to simulate packet loss",
50 PointerValue(),
51 MakePointerAccessor(&SatSimpleNetDevice::m_receiveErrorModel),
52 MakePointerChecker<ErrorModel>())
53 .AddTraceSource(
54 "PhyRxDrop",
55 "Trace source indicating a packet has been dropped by the device during reception",
56 MakeTraceSourceAccessor(&SatSimpleNetDevice::m_phyRxDropTrace),
57 "ns3::Packet::TracedCallback");
58 return tid;
59}
60
62 : m_channel(0),
63 m_node(0),
64 m_mtu(0xffff),
65 m_ifIndex(0)
66{
67 NS_LOG_FUNCTION(this);
68}
69
71{
72 NS_LOG_FUNCTION(this);
73}
74
75void
76SatSimpleNetDevice::Receive(Ptr<Packet> packet,
77 uint16_t protocol,
78 Mac48Address to,
79 Mac48Address from)
80{
81 NS_LOG_FUNCTION(this << packet << protocol << to << from);
82 NetDevice::PacketType packetType;
83
84 if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt(packet))
85 {
86 m_phyRxDropTrace(packet);
87 }
88 else
89 {
90 if (to == m_address)
91 {
92 packetType = NetDevice::PACKET_HOST;
93 }
94 else if (to.IsBroadcast())
95 {
96 packetType = NetDevice::PACKET_HOST;
97 }
98 else if (to.IsGroup())
99 {
100 packetType = NetDevice::PACKET_MULTICAST;
101 }
102 else
103 {
104 packetType = NetDevice::PACKET_OTHERHOST;
105 }
106
107 if (packetType != NetDevice::PACKET_OTHERHOST)
108 {
109 m_rxCallback(this, packet, protocol, from);
110
111 if (!m_promiscCallback.IsNull())
112 {
113 m_promiscCallback(this, packet, protocol, from, to, packetType);
114 }
115 }
116 }
117}
118
119void
120SatSimpleNetDevice::SetChannel(Ptr<SatSimpleChannel> channel)
121{
122 NS_LOG_FUNCTION(this << channel);
123 m_channel = channel;
124 m_channel->Add(this);
125}
126
127void
129{
130 NS_LOG_FUNCTION(this << em);
132}
133
134void
136{
137 NS_LOG_FUNCTION(this << index);
138 m_ifIndex = index;
139}
140
141uint32_t
143{
144 NS_LOG_FUNCTION(this);
145 return m_ifIndex;
146}
147
148Ptr<Channel>
150{
151 NS_LOG_FUNCTION(this);
152 return m_channel;
153}
154
155void
157{
158 NS_LOG_FUNCTION(this << address);
159 m_address = Mac48Address::ConvertFrom(address);
160}
161
162Address
164{
165 //
166 // Implicit conversion from Mac48Address to Address
167 //
168 NS_LOG_FUNCTION(this);
169 return m_address;
170}
171
172bool
173SatSimpleNetDevice::SetMtu(const uint16_t mtu)
174{
175 NS_LOG_FUNCTION(this << mtu);
176 m_mtu = mtu;
177 return true;
178}
179
180uint16_t
182{
183 NS_LOG_FUNCTION(this);
184 return m_mtu;
185}
186
187bool
189{
190 NS_LOG_FUNCTION(this);
191 return true;
192}
193
194void
196{
197 NS_LOG_FUNCTION(this << &callback);
198}
199
200bool
202{
203 NS_LOG_FUNCTION(this);
204 return true;
205}
206
207Address
209{
210 NS_LOG_FUNCTION(this);
211 return Mac48Address("ff:ff:ff:ff:ff:ff");
212}
213
214bool
216{
217 NS_LOG_FUNCTION(this);
218 return true;
219}
220
221Address
222SatSimpleNetDevice::GetMulticast(Ipv4Address multicastGroup) const
223{
224 NS_LOG_FUNCTION(this << multicastGroup);
225 return Mac48Address::GetMulticast(multicastGroup);
226}
227
228Address
229SatSimpleNetDevice::GetMulticast(Ipv6Address addr) const
230{
231 NS_LOG_FUNCTION(this << addr);
232 return Mac48Address::GetMulticast(addr);
233}
234
235bool
237{
238 NS_LOG_FUNCTION(this);
239 return false;
240}
241
242bool
244{
245 NS_LOG_FUNCTION(this);
246 return false;
247}
248
249bool
250SatSimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
251{
252 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
253 Mac48Address to = Mac48Address::ConvertFrom(dest);
254 m_channel->Send(packet, protocolNumber, to, m_address, this);
255 return true;
256}
257
258bool
260 const Address& source,
261 const Address& dest,
262 uint16_t protocolNumber)
263{
264 NS_LOG_FUNCTION(this << packet << source << dest << protocolNumber);
265 Mac48Address to = Mac48Address::ConvertFrom(dest);
266 Mac48Address from = Mac48Address::ConvertFrom(source);
267 m_channel->Send(packet, protocolNumber, to, from, this);
268 return true;
269}
270
271Ptr<Node>
273{
274 NS_LOG_FUNCTION(this);
275 return m_node;
276}
277
278void
280{
281 NS_LOG_FUNCTION(this << node);
282 m_node = node;
283}
284
285bool
287{
288 NS_LOG_FUNCTION(this);
289 return true;
290}
291
292void
293SatSimpleNetDevice::SetReceiveCallback(NetDevice::ReceiveCallback cb)
294{
295 NS_LOG_FUNCTION(this << &cb);
296 m_rxCallback = cb;
297}
298
299void
301{
302 NS_LOG_FUNCTION(this);
303 m_channel = 0;
304 m_node = 0;
306 NetDevice::DoDispose();
307}
308
309void
311{
312 NS_LOG_FUNCTION(this << &cb);
314}
315
316bool
318{
319 NS_LOG_FUNCTION(this);
320 return true;
321}
322
323} // namespace ns3
Satellite simple net device for satellite public and backbone network use.
virtual Address GetBroadcast(void) const
virtual uint16_t GetMtu(void) const
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SatSimpleChannel.
virtual void SetNode(Ptr< Node > node)
void SetChannel(Ptr< SatSimpleChannel > channel)
Attach a channel to this net device.
virtual uint32_t GetIfIndex(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
static TypeId GetTypeId(void)
Get the type ID.
virtual bool SupportsSendFrom(void) const
virtual void SetIfIndex(const uint32_t index)
virtual Ptr< Node > GetNode(void) const
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual bool IsBroadcast(void) const
SatSimpleNetDevice()
Default constructor.
NetDevice::ReceiveCallback m_rxCallback
virtual Address GetAddress(void) const
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
NetDevice::PromiscReceiveCallback m_promiscCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
~SatSimpleNetDevice()
Destructor for SatSimpleNetDevice.
virtual void DoDispose(void)
Dispose of this class instance.
virtual bool IsPointToPoint(void) const
virtual void SetAddress(Address address)
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received due to the error model being...
virtual bool SetMtu(const uint16_t mtu)
virtual Ptr< Channel > GetChannel(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice.
virtual bool IsMulticast(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.