author | Vedran Miletić <rivanvx@gmail.com> |
Tue, 02 Aug 2011 17:42:33 -0400 | |
changeset 7385 | 10beb0e53130 |
parent 7252 | c8200621e252 |
child 7725 | beb12afbe25f |
child 8253 | 6faee3d1d1d0 |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7252
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
6705 | 2 |
/* |
3 |
* Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari |
|
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: Giuseppe Piro <g.piro@poliba.it> |
|
19 |
*/ |
|
20 |
||
21 |
#include "ns3/llc-snap-header.h" |
|
22 |
#include "ns3/simulator.h" |
|
23 |
#include "ns3/callback.h" |
|
24 |
#include "ns3/node.h" |
|
25 |
#include "ns3/packet.h" |
|
26 |
#include "lte-net-device.h" |
|
27 |
#include "ns3/packet-burst.h" |
|
28 |
#include "ns3/uinteger.h" |
|
29 |
#include "ns3/trace-source-accessor.h" |
|
30 |
#include "ns3/pointer.h" |
|
31 |
#include "ns3/enum.h" |
|
32 |
#include "radio-bearer-instance.h" |
|
33 |
#include "amc-module.h" |
|
34 |
#include "rrc-entity.h" |
|
35 |
#include "rlc-entity.h" |
|
36 |
#include "lte-mac-header.h" |
|
37 |
#include "ns3/ipv4-header.h" |
|
38 |
||
39 |
NS_LOG_COMPONENT_DEFINE ("LteNetDevice"); |
|
40 |
||
41 |
namespace ns3 { |
|
42 |
||
43 |
NS_OBJECT_ENSURE_REGISTERED ( LteNetDevice); |
|
44 |
||
45 |
||
46 |
TypeId LteNetDevice::GetTypeId (void) |
|
47 |
{ |
|
48 |
static TypeId |
|
7252
c8200621e252
rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents:
6969
diff
changeset
|
49 |
tid = |
6705 | 50 |
TypeId ("ns3::LteNetDevice") |
51 |
||
52 |
.SetParent<NetDevice> () |
|
53 |
||
54 |
.AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit", |
|
55 |
UintegerValue (1500), |
|
56 |
MakeUintegerAccessor (&LteNetDevice::SetMtu, |
|
57 |
&LteNetDevice::GetMtu), |
|
58 |
MakeUintegerChecker<uint16_t> (0,MAX_MSDU_SIZE)) |
|
59 |
||
60 |
.AddAttribute ("Phy", |
|
61 |
"The PHY layer attached to this device.", |
|
62 |
PointerValue (), |
|
63 |
MakePointerAccessor (&LteNetDevice::GetPhy, &LteNetDevice::SetPhy), |
|
64 |
MakePointerChecker<LtePhy> ()) |
|
65 |
; |
|
66 |
return tid; |
|
67 |
} |
|
68 |
||
69 |
LteNetDevice::LteNetDevice (void) |
|
70 |
{ |
|
71 |
NS_LOG_FUNCTION (this); |
|
72 |
} |
|
73 |
||
74 |
||
75 |
LteNetDevice::~LteNetDevice (void) |
|
76 |
{ |
|
77 |
NS_LOG_FUNCTION (this); |
|
78 |
} |
|
79 |
||
80 |
||
81 |
void |
|
82 |
LteNetDevice::DoDispose (void) |
|
83 |
{ |
|
84 |
NS_LOG_FUNCTION (this); |
|
85 |
||
6710
3cd651349cb6
lte examples now passing valgrind tests
Nicola Baldo <nbaldo@cttc.es>
parents:
6709
diff
changeset
|
86 |
m_phy->Dispose (); |
6705 | 87 |
m_phy = 0; |
88 |
m_node = 0; |
|
6710
3cd651349cb6
lte examples now passing valgrind tests
Nicola Baldo <nbaldo@cttc.es>
parents:
6709
diff
changeset
|
89 |
m_rrcEntity->Dispose (); |
6705 | 90 |
m_rrcEntity = 0; |
91 |
m_phyMacTxStartCallback = MakeNullCallback< bool, Ptr<Packet> > (); |
|
92 |
NetDevice::DoDispose (); |
|
93 |
} |
|
94 |
||
95 |
||
96 |
Ptr<Channel> |
|
97 |
LteNetDevice::GetChannel (void) const |
|
98 |
{ |
|
99 |
NS_LOG_FUNCTION (this); |
|
100 |
return GetPhy ()->GetDownlinkSpectrumPhy ()->GetChannel (); |
|
101 |
} |
|
102 |
||
103 |
||
104 |
void |
|
105 |
LteNetDevice::SetPhy (Ptr<LtePhy> phy) |
|
106 |
{ |
|
107 |
NS_LOG_FUNCTION (this << phy); |
|
108 |
m_phy = phy; |
|
109 |
} |
|
110 |
||
111 |
||
112 |
Ptr<LtePhy> |
|
113 |
LteNetDevice::GetPhy (void) const |
|
114 |
{ |
|
115 |
NS_LOG_FUNCTION (this); |
|
116 |
return m_phy; |
|
117 |
} |
|
118 |
||
119 |
||
120 |
void |
|
121 |
LteNetDevice::SetRrcEntity (Ptr<RrcEntity> rrc) |
|
122 |
{ |
|
123 |
NS_LOG_FUNCTION (this << rrc); |
|
124 |
m_rrcEntity = rrc; |
|
125 |
} |
|
126 |
||
127 |
||
128 |
Ptr<RrcEntity> |
|
129 |
LteNetDevice::GetRrcEntity (void) |
|
130 |
{ |
|
131 |
NS_LOG_FUNCTION (this); |
|
132 |
return m_rrcEntity; |
|
133 |
} |
|
134 |
||
135 |
||
136 |
void |
|
137 |
LteNetDevice::SetAddress (Address address) |
|
138 |
{ |
|
139 |
NS_LOG_FUNCTION (this << address); |
|
140 |
m_address = Mac48Address::ConvertFrom (address); |
|
141 |
} |
|
142 |
||
143 |
||
144 |
Address |
|
145 |
LteNetDevice::GetAddress (void) const |
|
146 |
{ |
|
147 |
NS_LOG_FUNCTION (this); |
|
148 |
return m_address; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
void |
|
153 |
LteNetDevice::SetNode (Ptr<Node> node) |
|
154 |
{ |
|
155 |
NS_LOG_FUNCTION (this << node); |
|
156 |
m_node = node; |
|
157 |
} |
|
158 |
||
159 |
||
160 |
Ptr<Node> |
|
161 |
LteNetDevice::GetNode (void) const |
|
162 |
{ |
|
163 |
NS_LOG_FUNCTION (this); |
|
164 |
return m_node; |
|
165 |
} |
|
166 |
||
167 |
||
168 |
void |
|
169 |
LteNetDevice::SetReceiveCallback (ReceiveCallback cb) |
|
170 |
{ |
|
171 |
NS_LOG_FUNCTION (this); |
|
172 |
m_rxCallback = cb; |
|
173 |
} |
|
174 |
||
175 |
||
176 |
void |
|
177 |
LteNetDevice::ForwardUp (Ptr<Packet> packet, const Mac48Address &source, const Mac48Address &dest) |
|
178 |
{ |
|
179 |
||
180 |
} |
|
181 |
||
182 |
||
183 |
void |
|
184 |
LteNetDevice::ForwardUp (Ptr<Packet> packet) |
|
185 |
{ |
|
186 |
NS_LOG_FUNCTION (this << packet); |
|
187 |
||
188 |
m_macRxTrace (packet); |
|
189 |
||
190 |
LteMacHeader header; |
|
191 |
packet->RemoveHeader (header); |
|
192 |
NS_LOG_LOGIC ("packet " << header.GetSource () << " --> " << header.GetDestination () << " (here: " << m_address << ")"); |
|
193 |
||
194 |
LlcSnapHeader llc; |
|
195 |
packet->RemoveHeader (llc); |
|
196 |
||
197 |
m_rxCallback (this, packet, llc.GetType (), header.GetSource ()); |
|
198 |
} |
|
199 |
||
200 |
||
201 |
||
202 |
bool |
|
203 |
LteNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) |
|
204 |
{ |
|
205 |
NS_LOG_FUNCTION (packet << dest << protocolNumber); |
|
206 |
return SendFrom (packet, m_address, dest, protocolNumber); |
|
207 |
} |
|
208 |
||
209 |
||
210 |
bool |
|
211 |
LteNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) |
|
212 |
{ |
|
213 |
NS_LOG_FUNCTION (packet << source << dest << protocolNumber); |
|
214 |
||
215 |
LlcSnapHeader llcHdr; |
|
216 |
llcHdr.SetType (protocolNumber); |
|
217 |
packet->AddHeader (llcHdr); |
|
218 |
||
219 |
Mac48Address from = Mac48Address::ConvertFrom (source); |
|
220 |
Mac48Address to = Mac48Address::ConvertFrom (dest); |
|
221 |
||
222 |
LteMacHeader header; |
|
223 |
header.SetSource (from); |
|
224 |
header.SetDestination (to); |
|
225 |
packet->AddHeader (header); |
|
226 |
||
227 |
// m_macTxTrace (packet); |
|
228 |
||
229 |
return DoSend (packet, from, to, protocolNumber); |
|
230 |
} |
|
231 |
||
232 |
||
233 |
bool |
|
234 |
LteNetDevice::SupportsSendFrom (void) const |
|
235 |
{ |
|
236 |
NS_LOG_FUNCTION (this); |
|
237 |
return false; |
|
238 |
} |
|
239 |
||
240 |
||
241 |
void |
|
6969 | 242 |
LteNetDevice::SetGenericPhyTxStartCallback (GenericPhyTxStartCallback c) |
6705 | 243 |
{ |
244 |
NS_LOG_FUNCTION (this); |
|
245 |
m_phyMacTxStartCallback = c; |
|
246 |
} |
|
247 |
||
248 |
||
249 |
void |
|
250 |
LteNetDevice::Receive (Ptr<Packet> p) |
|
251 |
{ |
|
252 |
NS_LOG_FUNCTION (this << p); |
|
253 |
Ptr<Packet> packet = p->Copy (); |
|
254 |
DoReceive (packet); |
|
255 |
} |
|
256 |
||
257 |
||
258 |
||
259 |
bool |
|
260 |
LteNetDevice::SetMtu (const uint16_t mtu) |
|
261 |
{ |
|
262 |
NS_LOG_FUNCTION (this << mtu); |
|
263 |
if (mtu > MAX_MSDU_SIZE) |
|
264 |
{ |
|
265 |
return false; |
|
266 |
} |
|
267 |
m_mtu = mtu; |
|
268 |
return true; |
|
269 |
} |
|
270 |
||
271 |
uint16_t |
|
272 |
LteNetDevice::GetMtu (void) const |
|
273 |
{ |
|
274 |
NS_LOG_FUNCTION (this); |
|
275 |
return m_mtu; |
|
276 |
} |
|
277 |
||
278 |
||
279 |
void |
|
280 |
LteNetDevice::SetIfIndex (const uint32_t index) |
|
281 |
{ |
|
282 |
NS_LOG_FUNCTION (this << index); |
|
283 |
m_ifIndex = index; |
|
284 |
} |
|
285 |
||
286 |
uint32_t |
|
287 |
LteNetDevice::GetIfIndex (void) const |
|
288 |
{ |
|
289 |
NS_LOG_FUNCTION (this); |
|
290 |
return m_ifIndex; |
|
291 |
} |
|
292 |
||
293 |
||
294 |
bool |
|
295 |
LteNetDevice::IsLinkUp (void) const |
|
296 |
{ |
|
297 |
NS_LOG_FUNCTION (this); |
|
298 |
return m_phy != 0 && m_linkUp; |
|
299 |
} |
|
300 |
||
301 |
||
302 |
bool |
|
303 |
LteNetDevice::IsBroadcast (void) const |
|
304 |
{ |
|
305 |
NS_LOG_FUNCTION (this); |
|
306 |
return true; |
|
307 |
} |
|
308 |
||
309 |
Address |
|
310 |
LteNetDevice::GetBroadcast (void) const |
|
311 |
{ |
|
312 |
NS_LOG_FUNCTION (this); |
|
313 |
return Mac48Address::GetBroadcast (); |
|
314 |
} |
|
315 |
||
316 |
bool |
|
317 |
LteNetDevice::IsMulticast (void) const |
|
318 |
{ |
|
319 |
NS_LOG_FUNCTION (this); |
|
320 |
return false; |
|
321 |
} |
|
322 |
||
323 |
||
324 |
bool |
|
325 |
LteNetDevice::IsPointToPoint (void) const |
|
326 |
{ |
|
327 |
NS_LOG_FUNCTION (this); |
|
328 |
return false; |
|
329 |
} |
|
330 |
||
331 |
||
332 |
bool |
|
333 |
LteNetDevice::NeedsArp (void) const |
|
334 |
{ |
|
335 |
NS_LOG_FUNCTION (this); |
|
336 |
return true; |
|
337 |
} |
|
338 |
||
339 |
||
340 |
bool |
|
341 |
LteNetDevice::IsBridge (void) const |
|
342 |
{ |
|
343 |
NS_LOG_FUNCTION (this); |
|
344 |
return false; |
|
345 |
} |
|
346 |
||
347 |
Address |
|
348 |
LteNetDevice::GetMulticast (Ipv4Address multicastGroup) const |
|
349 |
{ |
|
350 |
NS_LOG_FUNCTION (this); |
|
351 |
NS_LOG_FUNCTION (multicastGroup); |
|
352 |
||
353 |
Mac48Address ad = Mac48Address::GetMulticast (multicastGroup); |
|
354 |
||
355 |
// |
|
356 |
// Implicit conversion (operator Address ()) is defined for Mac48Address, so |
|
357 |
// use it by just returning the EUI-48 address which is automagically converted |
|
358 |
// to an Address. |
|
359 |
// |
|
360 |
NS_LOG_LOGIC ("multicast address is " << ad); |
|
361 |
||
362 |
return ad; |
|
363 |
} |
|
364 |
||
365 |
Address |
|
366 |
LteNetDevice::GetMulticast (Ipv6Address addr) const |
|
367 |
{ |
|
368 |
NS_LOG_FUNCTION (this << addr); |
|
369 |
Mac48Address ad = Mac48Address::GetMulticast (addr); |
|
370 |
||
371 |
NS_LOG_LOGIC ("MAC IPv6 multicast address is " << ad); |
|
372 |
return ad; |
|
373 |
} |
|
374 |
||
375 |
void |
|
376 |
LteNetDevice::AddLinkChangeCallback (Callback<void> callback) |
|
377 |
{ |
|
378 |
NS_LOG_FUNCTION (this); |
|
379 |
m_linkChangeCallbacks.ConnectWithoutContext (callback); |
|
380 |
} |
|
381 |
||
382 |
||
383 |
void |
|
384 |
LteNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) |
|
385 |
{ |
|
386 |
NS_LOG_FUNCTION (this); |
|
387 |
m_promiscRxCallback = cb; |
|
388 |
} |
|
389 |
||
390 |
||
391 |
void |
|
392 |
LteNetDevice::SetPacketToSend (Ptr<PacketBurst> p) |
|
393 |
{ |
|
394 |
m_packetToSend = p; |
|
395 |
} |
|
396 |
||
397 |
||
398 |
Ptr<PacketBurst> |
|
399 |
LteNetDevice::GetPacketToSend (void) |
|
400 |
{ |
|
401 |
return m_packetToSend; |
|
402 |
} |
|
403 |
||
404 |
||
405 |
||
406 |
} |