author | Tom Henderson <tomh@tomh.org> |
Mon, 28 Sep 2015 20:27:25 -0700 | |
changeset 11676 | 05ea1489e509 |
parent 11547 | 941beab1b849 |
permissions | -rw-r--r-- |
9271 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2012 INRIA, 2012 University of Washington |
|
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: Alina Quereilhac <alina.quereilhac@inria.fr> |
|
19 |
* Claudio Freire <klaussfreire@sourceforge.net> |
|
20 |
*/ |
|
21 |
||
22 |
#include "fd-net-device.h" |
|
23 |
||
24 |
#include "ns3/abort.h" |
|
25 |
#include "ns3/boolean.h" |
|
26 |
#include "ns3/channel.h" |
|
27 |
#include "ns3/enum.h" |
|
28 |
#include "ns3/ethernet-header.h" |
|
29 |
#include "ns3/ethernet-trailer.h" |
|
30 |
#include "ns3/log.h" |
|
31 |
#include "ns3/llc-snap-header.h" |
|
32 |
#include "ns3/mac48-address.h" |
|
33 |
#include "ns3/pointer.h" |
|
34 |
#include "ns3/simulator.h" |
|
35 |
#include "ns3/string.h" |
|
36 |
#include "ns3/trace-source-accessor.h" |
|
37 |
#include "ns3/uinteger.h" |
|
38 |
||
39 |
#include <unistd.h> |
|
40 |
#include <arpa/inet.h> |
|
41 |
#include <net/ethernet.h> |
|
42 |
||
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
43 |
namespace ns3 { |
9271 | 44 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
45 |
NS_LOG_COMPONENT_DEFINE ("FdNetDevice"); |
9271 | 46 |
|
47 |
FdNetDeviceFdReader::FdNetDeviceFdReader () |
|
48 |
: m_bufferSize (65536) // Defaults to maximum TCP window size |
|
49 |
{ |
|
50 |
} |
|
51 |
||
52 |
void |
|
53 |
FdNetDeviceFdReader::SetBufferSize (uint32_t bufferSize) |
|
54 |
{ |
|
11220
018b26ee77e7
add comments and logging around changeset c97ef876d98c
Tom Henderson <tomh@tomh.org>
parents:
11219
diff
changeset
|
55 |
NS_LOG_FUNCTION (this << bufferSize); |
9271 | 56 |
m_bufferSize = bufferSize; |
57 |
} |
|
58 |
||
59 |
FdReader::Data FdNetDeviceFdReader::DoRead (void) |
|
60 |
{ |
|
61 |
NS_LOG_FUNCTION (this); |
|
62 |
||
63 |
uint8_t *buf = (uint8_t *)malloc (m_bufferSize); |
|
64 |
NS_ABORT_MSG_IF (buf == 0, "malloc() failed"); |
|
65 |
||
66 |
NS_LOG_LOGIC ("Calling read on fd " << m_fd); |
|
67 |
ssize_t len = read (m_fd, buf, m_bufferSize); |
|
68 |
if (len <= 0) |
|
69 |
{ |
|
70 |
free (buf); |
|
71 |
buf = 0; |
|
72 |
len = 0; |
|
73 |
} |
|
11220
018b26ee77e7
add comments and logging around changeset c97ef876d98c
Tom Henderson <tomh@tomh.org>
parents:
11219
diff
changeset
|
74 |
NS_LOG_LOGIC ("Read " << len << " bytes on fd " << m_fd); |
9271 | 75 |
return FdReader::Data (buf, len); |
76 |
} |
|
77 |
||
10652
dc18deba4502
[doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10410
diff
changeset
|
78 |
NS_OBJECT_ENSURE_REGISTERED (FdNetDevice); |
9271 | 79 |
|
80 |
TypeId |
|
81 |
FdNetDevice::GetTypeId (void) |
|
82 |
{ |
|
83 |
static TypeId tid = TypeId ("ns3::FdNetDevice") |
|
84 |
.SetParent<NetDevice> () |
|
11371
7b99ca2ee2e7
SetGroupName for fd-net-device module
Tom Henderson <tomh@tomh.org>
parents:
11220
diff
changeset
|
85 |
.SetGroupName ("FdNetDevice") |
9271 | 86 |
.AddConstructor<FdNetDevice> () |
87 |
.AddAttribute ("Address", |
|
88 |
"The MAC address of this device.", |
|
89 |
Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), |
|
90 |
MakeMac48AddressAccessor (&FdNetDevice::m_address), |
|
91 |
MakeMac48AddressChecker ()) |
|
92 |
.AddAttribute ("Start", |
|
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
93 |
"The simulation time at which to spin up " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
94 |
"the device thread.", |
9271 | 95 |
TimeValue (Seconds (0.)), |
96 |
MakeTimeAccessor (&FdNetDevice::m_tStart), |
|
97 |
MakeTimeChecker ()) |
|
98 |
.AddAttribute ("Stop", |
|
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
99 |
"The simulation time at which to tear down " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
100 |
"the device thread.", |
9271 | 101 |
TimeValue (Seconds (0.)), |
102 |
MakeTimeAccessor (&FdNetDevice::m_tStop), |
|
103 |
MakeTimeChecker ()) |
|
104 |
.AddAttribute ("EncapsulationMode", |
|
105 |
"The link-layer encapsulation type to use.", |
|
106 |
EnumValue (DIX), |
|
107 |
MakeEnumAccessor (&FdNetDevice::m_encapMode), |
|
108 |
MakeEnumChecker (DIX, "Dix", |
|
109 |
LLC, "Llc", |
|
110 |
DIXPI, "DixPi")) |
|
111 |
.AddAttribute ("RxQueueSize", "Maximum size of the read queue. " |
|
112 |
"This value limits number of packets that have been read " |
|
113 |
"from the network into a memory buffer but have not yet " |
|
114 |
"been processed by the simulator.", |
|
115 |
UintegerValue (1000), |
|
116 |
MakeUintegerAccessor (&FdNetDevice::m_maxPendingReads), |
|
117 |
MakeUintegerChecker<uint32_t> ()) |
|
118 |
// |
|
119 |
// Trace sources at the "top" of the net device, where packets transition |
|
120 |
// to/from higher layers. These points do not really correspond to the |
|
121 |
// MAC layer of the underlying operating system, but exist to provide |
|
122 |
// a consitent tracing environment. These trace hooks should really be |
|
123 |
// interpreted as the points at which a packet leaves the ns-3 environment |
|
124 |
// destined for the underlying operating system or vice-versa. |
|
125 |
// |
|
126 |
.AddTraceSource ("MacTx", |
|
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
127 |
"Trace source indicating a packet has " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
128 |
"arrived for transmission by this device", |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
129 |
MakeTraceSourceAccessor (&FdNetDevice::m_macTxTrace), |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
130 |
"ns3::Packet::TracedCallback") |
9271 | 131 |
.AddTraceSource ("MacTxDrop", |
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
132 |
"Trace source indicating a packet has " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
133 |
"been dropped by the device before transmission", |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
134 |
MakeTraceSourceAccessor (&FdNetDevice::m_macTxDropTrace), |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
135 |
"ns3::Packet::TracedCallback") |
9271 | 136 |
.AddTraceSource ("MacPromiscRx", |
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
137 |
"A packet has been received by this device, " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
138 |
"has been passed up from the physical layer " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
139 |
"and is being forwarded up the local protocol stack. " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
140 |
"This is a promiscuous trace,", |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
141 |
MakeTraceSourceAccessor (&FdNetDevice::m_macPromiscRxTrace), |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
142 |
"ns3::Packet::TracedCallback") |
9271 | 143 |
.AddTraceSource ("MacRx", |
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
144 |
"A packet has been received by this device, " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
145 |
"has been passed up from the physical layer " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
146 |
"and is being forwarded up the local protocol stack. " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
147 |
"This is a non-promiscuous trace,", |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
148 |
MakeTraceSourceAccessor (&FdNetDevice::m_macRxTrace), |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
149 |
"ns3::Packet::TracedCallback") |
9271 | 150 |
|
151 |
// |
|
152 |
// Trace sources designed to simulate a packet sniffer facility (tcpdump). |
|
153 |
// |
|
154 |
.AddTraceSource ("Sniffer", |
|
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
155 |
"Trace source simulating a non-promiscuous " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
156 |
"packet sniffer attached to the device", |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
157 |
MakeTraceSourceAccessor (&FdNetDevice::m_snifferTrace), |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
158 |
"ns3::Packet::TracedCallback") |
9271 | 159 |
.AddTraceSource ("PromiscSniffer", |
11085
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
160 |
"Trace source simulating a promiscuous " |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
161 |
"packet sniffer attached to the device", |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
162 |
MakeTraceSourceAccessor (&FdNetDevice::m_promiscSnifferTrace), |
6e4d08656d7c
TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
163 |
"ns3::Packet::TracedCallback") |
9271 | 164 |
; |
165 |
return tid; |
|
166 |
} |
|
167 |
||
168 |
FdNetDevice::FdNetDevice () |
|
169 |
: m_node (0), |
|
170 |
m_ifIndex (0), |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
171 |
// Defaults to Ethernet v2 MTU |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
172 |
m_mtu (1500), |
9271 | 173 |
m_fd (-1), |
174 |
m_fdReader (0), |
|
175 |
m_isBroadcast (true), |
|
176 |
m_isMulticast (false), |
|
177 |
m_startEvent (), |
|
178 |
m_stopEvent () |
|
179 |
{ |
|
180 |
NS_LOG_FUNCTION (this); |
|
181 |
Start (m_tStart); |
|
182 |
} |
|
183 |
||
184 |
FdNetDevice::FdNetDevice (FdNetDevice const &) |
|
185 |
{ |
|
186 |
} |
|
187 |
||
188 |
FdNetDevice::~FdNetDevice () |
|
189 |
{ |
|
190 |
NS_LOG_FUNCTION (this); |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
191 |
|
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
192 |
{ |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
193 |
CriticalSection cs (m_pendingReadMutex); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
194 |
|
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
195 |
while (!m_pendingQueue.empty ()) |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
196 |
{ |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
197 |
std::pair<uint8_t *, ssize_t> next = m_pendingQueue.front (); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
198 |
m_pendingQueue.pop (); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
199 |
|
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
200 |
free (next.first); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
201 |
} |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
202 |
} |
9271 | 203 |
} |
204 |
||
205 |
void |
|
206 |
FdNetDevice::DoDispose (void) |
|
207 |
{ |
|
208 |
NS_LOG_FUNCTION (this); |
|
209 |
StopDevice (); |
|
210 |
NetDevice::DoDispose (); |
|
211 |
} |
|
212 |
||
213 |
void |
|
214 |
FdNetDevice::SetEncapsulationMode (enum EncapsulationMode mode) |
|
215 |
{ |
|
216 |
NS_LOG_FUNCTION (mode); |
|
217 |
m_encapMode = mode; |
|
218 |
NS_LOG_LOGIC ("m_encapMode = " << m_encapMode); |
|
219 |
} |
|
220 |
||
221 |
FdNetDevice::EncapsulationMode |
|
222 |
FdNetDevice::GetEncapsulationMode (void) const |
|
223 |
{ |
|
224 |
NS_LOG_FUNCTION (this); |
|
225 |
return m_encapMode; |
|
226 |
} |
|
227 |
||
228 |
void |
|
229 |
FdNetDevice::Start (Time tStart) |
|
230 |
{ |
|
231 |
NS_LOG_FUNCTION (tStart); |
|
232 |
Simulator::Cancel (m_startEvent); |
|
233 |
m_startEvent = Simulator::Schedule (tStart, &FdNetDevice::StartDevice, this); |
|
234 |
} |
|
235 |
||
236 |
void |
|
237 |
FdNetDevice::Stop (Time tStop) |
|
238 |
{ |
|
239 |
NS_LOG_FUNCTION (tStop); |
|
240 |
Simulator::Cancel (m_stopEvent); |
|
241 |
m_startEvent = Simulator::Schedule (tStop, &FdNetDevice::StopDevice, this); |
|
242 |
} |
|
243 |
||
244 |
void |
|
245 |
FdNetDevice::StartDevice (void) |
|
246 |
{ |
|
247 |
NS_LOG_FUNCTION (this); |
|
248 |
||
249 |
if (m_fd == -1) |
|
250 |
{ |
|
251 |
NS_LOG_DEBUG ("FdNetDevice::Start(): Failure, invalid file descriptor."); |
|
252 |
return; |
|
253 |
} |
|
254 |
// |
|
255 |
// A similar story exists for the node ID. We can't just naively do a |
|
256 |
// GetNode ()->GetId () since GetNode is going to give us a Ptr<Node> which |
|
257 |
// is reference counted. We need to stash away the node ID for use in the |
|
258 |
// read thread. |
|
259 |
// |
|
260 |
m_nodeId = GetNode ()->GetId (); |
|
261 |
||
262 |
m_fdReader = Create<FdNetDeviceFdReader> (); |
|
11220
018b26ee77e7
add comments and logging around changeset c97ef876d98c
Tom Henderson <tomh@tomh.org>
parents:
11219
diff
changeset
|
263 |
// 22 bytes covers 14 bytes Ethernet header with possible 8 bytes LLC/SNAP |
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
264 |
m_fdReader->SetBufferSize (m_mtu + 22); |
9271 | 265 |
m_fdReader->Start (m_fd, MakeCallback (&FdNetDevice::ReceiveCallback, this)); |
266 |
||
267 |
NotifyLinkUp (); |
|
268 |
} |
|
269 |
||
270 |
void |
|
271 |
FdNetDevice::StopDevice (void) |
|
272 |
{ |
|
273 |
NS_LOG_FUNCTION (this); |
|
274 |
||
275 |
if (m_fdReader != 0) |
|
276 |
{ |
|
277 |
m_fdReader->Stop (); |
|
278 |
m_fdReader = 0; |
|
279 |
} |
|
280 |
||
281 |
if (m_fd != -1) |
|
282 |
{ |
|
283 |
close (m_fd); |
|
284 |
m_fd = -1; |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
void |
|
289 |
FdNetDevice::ReceiveCallback (uint8_t *buf, ssize_t len) |
|
290 |
{ |
|
291 |
NS_LOG_FUNCTION (this << buf << len); |
|
292 |
bool skip = false; |
|
293 |
||
294 |
{ |
|
295 |
CriticalSection cs (m_pendingReadMutex); |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
296 |
if (m_pendingQueue.size () >= m_maxPendingReads) |
9271 | 297 |
{ |
11220
018b26ee77e7
add comments and logging around changeset c97ef876d98c
Tom Henderson <tomh@tomh.org>
parents:
11219
diff
changeset
|
298 |
NS_LOG_WARN ("Packet dropped"); |
9271 | 299 |
skip = true; |
300 |
} |
|
301 |
else |
|
302 |
{ |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
303 |
m_pendingQueue.push (std::make_pair (buf, len)); |
9271 | 304 |
} |
305 |
} |
|
306 |
||
307 |
if (skip) |
|
308 |
{ |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
309 |
struct timespec time = { |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
310 |
0, 100000000L |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
311 |
}; // 100 ms |
9271 | 312 |
nanosleep (&time, NULL); |
313 |
} |
|
314 |
else |
|
315 |
{ |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
316 |
Simulator::ScheduleWithContext (m_nodeId, Time (0), MakeEvent (&FdNetDevice::ForwardUp, this)); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
317 |
} |
9271 | 318 |
} |
319 |
||
11407
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
320 |
/** |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
321 |
* \ingroup fd-net-device |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
322 |
* \brief Synthesize PI header for the kernel |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
323 |
* \param buf the buffer to add the header to |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
324 |
* \param len the buffer length |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
325 |
* |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
326 |
* \todo Consider having a instance member m_packetBuffer and using memmove |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
327 |
* instead of memcpy to add the PI header. It might be faster in this case |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
328 |
* to use memmove and avoid the extra mallocs. |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
329 |
*/ |
9271 | 330 |
static void |
331 |
AddPIHeader (uint8_t *&buf, ssize_t &len) |
|
332 |
{ |
|
333 |
// Synthesize PI header for our friend the kernel |
|
334 |
uint8_t *buf2 = (uint8_t*)malloc (len + 4); |
|
335 |
memcpy (buf2 + 4, buf, len); |
|
336 |
len += 4; |
|
337 |
||
338 |
// PI = 16 bits flags (0) + 16 bits proto |
|
339 |
// NOTE: be careful to interpret buffer data explicitly as |
|
340 |
// little-endian to be insensible to native byte ordering. |
|
341 |
uint16_t flags = 0; |
|
342 |
uint16_t proto = 0x0008; // default to IPv4 |
|
343 |
if (len > 14) |
|
344 |
{ |
|
345 |
if (buf[12] == 0x81 && buf[13] == 0x00 && len > 18) |
|
346 |
{ |
|
347 |
// tagged ethernet packet |
|
348 |
proto = buf[16] | (buf[17] << 8); |
|
349 |
} |
|
350 |
else |
|
351 |
{ |
|
352 |
// untagged ethernet packet |
|
353 |
proto = buf[12] | (buf[13] << 8); |
|
354 |
} |
|
355 |
} |
|
356 |
buf2[0] = (uint8_t)flags; |
|
357 |
buf2[1] = (uint8_t)(flags >> 8); |
|
358 |
buf2[2] = (uint8_t)proto; |
|
359 |
buf2[3] = (uint8_t)(proto >> 8); |
|
360 |
||
361 |
// swap buffer |
|
362 |
free (buf); |
|
363 |
buf = buf2; |
|
364 |
} |
|
365 |
||
11407
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
366 |
/** |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
367 |
* \ingroup fd-net-device |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
368 |
* \brief Removes PI header |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
369 |
* \param buf the buffer to add the header to |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
370 |
* \param len the buffer length |
c175567f535a
[Doxygen] fd-net-device module fixes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
11371
diff
changeset
|
371 |
*/ |
9271 | 372 |
static void |
373 |
RemovePIHeader (uint8_t *&buf, ssize_t &len) |
|
374 |
{ |
|
375 |
// strip PI header if present, shrink buffer |
|
376 |
if (len >= 4) |
|
377 |
{ |
|
378 |
len -= 4; |
|
379 |
memmove (buf, buf + 4, len); |
|
380 |
buf = (uint8_t*)realloc (buf, len); |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
void |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
385 |
FdNetDevice::ForwardUp (void) |
9271 | 386 |
{ |
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
387 |
|
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
388 |
uint8_t *buf = 0; |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
389 |
ssize_t len = 0; |
9271 | 390 |
|
11547
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
391 |
{ |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
392 |
CriticalSection cs (m_pendingReadMutex); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
393 |
std::pair<uint8_t *, ssize_t> next = m_pendingQueue.front (); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
394 |
m_pendingQueue.pop (); |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
395 |
|
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
396 |
buf = next.first; |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
397 |
len = next.second; |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
398 |
} |
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
399 |
|
941beab1b849
bug 2119: Fixing memory leaks in FdNetDevice test with DefaultSimulatorImpl due to non-executed events when simulation ends
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11407
diff
changeset
|
400 |
NS_LOG_FUNCTION (this << buf << len); |
9271 | 401 |
|
402 |
// We need to remove the PI header and ignore it |
|
403 |
if (m_encapMode == DIXPI) |
|
404 |
{ |
|
405 |
RemovePIHeader (buf, len); |
|
406 |
} |
|
407 |
||
408 |
// |
|
409 |
// Create a packet out of the buffer we received and free that buffer. |
|
410 |
// |
|
411 |
Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len); |
|
412 |
free (buf); |
|
413 |
buf = 0; |
|
414 |
||
415 |
// |
|
416 |
// Trace sinks will expect complete packets, not packets without some of the |
|
417 |
// headers |
|
418 |
// |
|
419 |
Ptr<Packet> originalPacket = packet->Copy (); |
|
420 |
||
421 |
Mac48Address destination; |
|
422 |
Mac48Address source; |
|
423 |
uint16_t protocol; |
|
424 |
bool isBroadcast = false; |
|
425 |
bool isMulticast = false; |
|
426 |
||
427 |
EthernetHeader header (false); |
|
428 |
||
429 |
// |
|
430 |
// This device could be running in an environment where completely unexpected |
|
431 |
// kinds of packets are flying around, so we need to harden things a bit and |
|
432 |
// filter out packets we think are completely bogus, so we always check to see |
|
433 |
// that the packet is long enough to contain the header we want to remove. |
|
434 |
// |
|
435 |
if (packet->GetSize () < header.GetSerializedSize ()) |
|
436 |
{ |
|
437 |
m_phyRxDropTrace (originalPacket); |
|
438 |
return; |
|
439 |
} |
|
440 |
||
441 |
packet->RemoveHeader (header); |
|
442 |
destination = header.GetDestination (); |
|
443 |
source = header.GetSource (); |
|
444 |
isBroadcast = header.GetDestination ().IsBroadcast (); |
|
445 |
isMulticast = header.GetDestination ().IsGroup (); |
|
446 |
protocol = header.GetLengthType (); |
|
447 |
||
448 |
// |
|
449 |
// If the length/type is less than 1500, it corresponds to a length |
|
450 |
// interpretation packet. In this case, it is an 802.3 packet and |
|
451 |
// will also have an 802.2 LLC header. If greater than 1500, we |
|
452 |
// find the protocol number (Ethernet type) directly. |
|
453 |
// |
|
454 |
if (m_encapMode == LLC and header.GetLengthType () <= 1500) |
|
455 |
{ |
|
456 |
LlcSnapHeader llc; |
|
457 |
// |
|
458 |
// Check to see that the packet is long enough to possibly contain the |
|
459 |
// header we want to remove before just naively calling. |
|
460 |
// |
|
461 |
if (packet->GetSize () < llc.GetSerializedSize ()) |
|
462 |
{ |
|
463 |
m_phyRxDropTrace (originalPacket); |
|
464 |
return; |
|
465 |
} |
|
466 |
||
467 |
packet->RemoveHeader (llc); |
|
468 |
protocol = llc.GetType (); |
|
469 |
} |
|
470 |
||
471 |
NS_LOG_LOGIC ("Pkt source is " << source); |
|
472 |
NS_LOG_LOGIC ("Pkt destination is " << destination); |
|
473 |
||
474 |
PacketType packetType; |
|
475 |
||
476 |
if (isBroadcast) |
|
477 |
{ |
|
478 |
packetType = NS3_PACKET_BROADCAST; |
|
479 |
} |
|
480 |
else if (isMulticast) |
|
481 |
{ |
|
482 |
packetType = NS3_PACKET_MULTICAST; |
|
483 |
} |
|
484 |
else if (destination == m_address) |
|
485 |
{ |
|
486 |
packetType = NS3_PACKET_HOST; |
|
487 |
} |
|
488 |
else |
|
489 |
{ |
|
490 |
packetType = NS3_PACKET_OTHERHOST; |
|
491 |
} |
|
492 |
||
493 |
// |
|
494 |
// For all kinds of packetType we receive, we hit the promiscuous sniffer |
|
495 |
// hook and pass a copy up to the promiscuous callback. Pass a copy to |
|
496 |
// make sure that nobody messes with our packet. |
|
497 |
// |
|
498 |
m_promiscSnifferTrace (originalPacket); |
|
499 |
||
500 |
if (!m_promiscRxCallback.IsNull ()) |
|
501 |
{ |
|
502 |
m_macPromiscRxTrace (originalPacket); |
|
503 |
m_promiscRxCallback (this, packet, protocol, source, destination, |
|
504 |
packetType); |
|
505 |
} |
|
506 |
||
507 |
// |
|
508 |
// If this packet is not destined for some other host, it must be for us |
|
509 |
// as either a broadcast, multicast or unicast. We need to hit the mac |
|
510 |
// packet received trace hook and forward the packet up the stack. |
|
511 |
// |
|
512 |
if (packetType != NS3_PACKET_OTHERHOST) |
|
513 |
{ |
|
514 |
m_snifferTrace (originalPacket); |
|
515 |
m_macRxTrace (originalPacket); |
|
516 |
m_rxCallback (this, packet, protocol, source); |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
bool |
|
521 |
FdNetDevice::Send (Ptr<Packet> packet, const Address& destination, uint16_t protocolNumber) |
|
522 |
{ |
|
523 |
NS_LOG_FUNCTION (this << packet << destination << protocolNumber); |
|
524 |
return SendFrom (packet, m_address, destination, protocolNumber); |
|
525 |
} |
|
526 |
||
527 |
bool |
|
528 |
FdNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber) |
|
529 |
{ |
|
530 |
NS_LOG_FUNCTION (this << packet << src << dest << protocolNumber); |
|
11220
018b26ee77e7
add comments and logging around changeset c97ef876d98c
Tom Henderson <tomh@tomh.org>
parents:
11219
diff
changeset
|
531 |
NS_LOG_LOGIC ("packet: " << packet << " UID: " << packet->GetUid ()); |
9271 | 532 |
|
533 |
if (IsLinkUp () == false) |
|
534 |
{ |
|
535 |
m_macTxDropTrace (packet); |
|
536 |
return false; |
|
537 |
} |
|
538 |
||
539 |
Mac48Address destination = Mac48Address::ConvertFrom (dest); |
|
540 |
Mac48Address source = Mac48Address::ConvertFrom (src); |
|
541 |
||
542 |
NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ()); |
|
543 |
NS_LOG_LOGIC ("Transmit packet from " << source); |
|
544 |
NS_LOG_LOGIC ("Transmit packet to " << destination); |
|
545 |
||
546 |
EthernetHeader header (false); |
|
547 |
header.SetSource (source); |
|
548 |
header.SetDestination (destination); |
|
549 |
||
11219
c97ef876d98c
bug 2063: FdNetDevice::SendFrom() Assert does not take into account the size of the headers. (fix due Rubén MartÃnez and Tom Henderson)
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11085
diff
changeset
|
550 |
NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet too big " << packet->GetSize ()); |
c97ef876d98c
bug 2063: FdNetDevice::SendFrom() Assert does not take into account the size of the headers. (fix due Rubén MartÃnez and Tom Henderson)
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
11085
diff
changeset
|
551 |
|
9271 | 552 |
if (m_encapMode == LLC) |
553 |
{ |
|
554 |
LlcSnapHeader llc; |
|
555 |
llc.SetType (protocolNumber); |
|
556 |
packet->AddHeader (llc); |
|
557 |
||
558 |
header.SetLengthType (packet->GetSize ()); |
|
559 |
} |
|
560 |
else |
|
561 |
{ |
|
562 |
header.SetLengthType (protocolNumber); |
|
563 |
} |
|
564 |
||
565 |
packet->AddHeader (header); |
|
566 |
||
567 |
// |
|
568 |
// there's not much meaning associated with the different layers in this |
|
569 |
// device, so don't be surprised when they're all stacked together in |
|
570 |
// essentially one place. We do this for trace consistency across devices. |
|
571 |
// |
|
572 |
m_macTxTrace (packet); |
|
573 |
||
574 |
m_promiscSnifferTrace (packet); |
|
575 |
m_snifferTrace (packet); |
|
576 |
||
577 |
NS_LOG_LOGIC ("calling write"); |
|
578 |
||
579 |
||
580 |
ssize_t len = (ssize_t) packet->GetSize (); |
|
581 |
uint8_t *buffer = (uint8_t*)malloc (len); |
|
582 |
packet->CopyData (buffer, len); |
|
583 |
||
584 |
// We need to add the PI header |
|
585 |
if (m_encapMode == DIXPI) |
|
586 |
{ |
|
587 |
AddPIHeader (buffer, len); |
|
588 |
} |
|
589 |
||
590 |
ssize_t written = write (m_fd, buffer, len); |
|
591 |
free (buffer); |
|
592 |
||
593 |
if (written == -1 || written != len) |
|
594 |
{ |
|
595 |
m_macTxDropTrace (packet); |
|
596 |
return false; |
|
597 |
} |
|
598 |
||
599 |
return true; |
|
600 |
} |
|
601 |
||
602 |
void |
|
603 |
FdNetDevice::SetFileDescriptor (int fd) |
|
604 |
{ |
|
605 |
if (m_fd == -1 and fd > 0) |
|
606 |
{ |
|
607 |
m_fd = fd; |
|
608 |
} |
|
609 |
} |
|
610 |
||
611 |
void |
|
612 |
FdNetDevice::SetAddress (Address address) |
|
613 |
{ |
|
614 |
m_address = Mac48Address::ConvertFrom (address); |
|
615 |
} |
|
616 |
||
617 |
Address |
|
618 |
FdNetDevice::GetAddress (void) const |
|
619 |
{ |
|
620 |
return m_address; |
|
621 |
} |
|
622 |
||
623 |
void |
|
624 |
FdNetDevice::NotifyLinkUp (void) |
|
625 |
{ |
|
626 |
m_linkUp = true; |
|
627 |
m_linkChangeCallbacks (); |
|
628 |
} |
|
629 |
||
630 |
void |
|
631 |
FdNetDevice::SetIfIndex (const uint32_t index) |
|
632 |
{ |
|
633 |
m_ifIndex = index; |
|
634 |
} |
|
635 |
||
636 |
uint32_t |
|
637 |
FdNetDevice::GetIfIndex (void) const |
|
638 |
{ |
|
639 |
return m_ifIndex; |
|
640 |
} |
|
641 |
||
642 |
Ptr<Channel> |
|
643 |
FdNetDevice::GetChannel (void) const |
|
644 |
{ |
|
645 |
return NULL; |
|
646 |
} |
|
647 |
||
648 |
bool |
|
649 |
FdNetDevice::SetMtu (const uint16_t mtu) |
|
650 |
{ |
|
651 |
// The MTU depends on the technology associated to |
|
652 |
// the file descriptor. The user is responsible of |
|
653 |
// setting the correct value of the MTU. |
|
654 |
// If the file descriptor is created using a helper, |
|
655 |
// then is the responsibility of the helper to set |
|
656 |
// the correct MTU value. |
|
657 |
m_mtu = mtu; |
|
658 |
return true; |
|
659 |
} |
|
660 |
||
661 |
uint16_t |
|
662 |
FdNetDevice::GetMtu (void) const |
|
663 |
{ |
|
664 |
return m_mtu; |
|
665 |
} |
|
666 |
||
667 |
bool |
|
668 |
FdNetDevice::IsLinkUp (void) const |
|
669 |
{ |
|
670 |
return m_linkUp; |
|
671 |
} |
|
672 |
||
673 |
void |
|
674 |
FdNetDevice::AddLinkChangeCallback (Callback<void> callback) |
|
675 |
{ |
|
676 |
m_linkChangeCallbacks.ConnectWithoutContext (callback); |
|
677 |
} |
|
678 |
||
679 |
bool |
|
680 |
FdNetDevice::IsBroadcast (void) const |
|
681 |
{ |
|
682 |
return m_isBroadcast; |
|
683 |
} |
|
684 |
||
685 |
void |
|
686 |
FdNetDevice::SetIsBroadcast (bool broadcast) |
|
687 |
{ |
|
688 |
m_isBroadcast = broadcast; |
|
689 |
} |
|
690 |
||
691 |
Address |
|
692 |
FdNetDevice::GetBroadcast (void) const |
|
693 |
{ |
|
694 |
return Mac48Address ("ff:ff:ff:ff:ff:ff"); |
|
695 |
} |
|
696 |
||
697 |
bool |
|
698 |
FdNetDevice::IsMulticast (void) const |
|
699 |
{ |
|
700 |
return m_isMulticast; |
|
701 |
} |
|
702 |
||
703 |
void |
|
704 |
FdNetDevice::SetIsMulticast (bool multicast) |
|
705 |
{ |
|
706 |
m_isMulticast = multicast; |
|
707 |
} |
|
708 |
||
709 |
Address |
|
710 |
FdNetDevice::GetMulticast (Ipv4Address multicastGroup) const |
|
711 |
{ |
|
712 |
return Mac48Address::GetMulticast (multicastGroup); |
|
713 |
} |
|
714 |
||
715 |
Address |
|
716 |
FdNetDevice::GetMulticast (Ipv6Address addr) const |
|
717 |
{ |
|
718 |
return Mac48Address::GetMulticast (addr); |
|
719 |
} |
|
720 |
||
721 |
bool |
|
722 |
FdNetDevice::IsBridge (void) const |
|
723 |
{ |
|
724 |
return false; |
|
725 |
} |
|
726 |
||
727 |
bool |
|
728 |
FdNetDevice::IsPointToPoint (void) const |
|
729 |
{ |
|
730 |
return false; |
|
731 |
} |
|
732 |
||
733 |
Ptr<Node> |
|
734 |
FdNetDevice::GetNode (void) const |
|
735 |
{ |
|
736 |
return m_node; |
|
737 |
} |
|
738 |
||
739 |
void |
|
740 |
FdNetDevice::SetNode (Ptr<Node> node) |
|
741 |
{ |
|
742 |
m_node = node; |
|
743 |
} |
|
744 |
||
745 |
bool |
|
746 |
FdNetDevice::NeedsArp (void) const |
|
747 |
{ |
|
748 |
return true; |
|
749 |
} |
|
750 |
||
751 |
void |
|
752 |
FdNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) |
|
753 |
{ |
|
754 |
m_rxCallback = cb; |
|
755 |
} |
|
756 |
||
757 |
void |
|
758 |
FdNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) |
|
759 |
{ |
|
760 |
m_promiscRxCallback = cb; |
|
761 |
} |
|
762 |
||
763 |
bool |
|
764 |
FdNetDevice::SupportsSendFrom (void) const |
|
765 |
{ |
|
766 |
return true; |
|
767 |
} |
|
768 |
||
769 |
} // namespace ns3 |