|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
3 |
* Copyright (c) 2007 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: Craig Dowell <craigdo@ee.washington.edu> |
19 |
*/ |
20 |
|
21 |
#ifndef POINT_TO_POINT_NET_DEVICE_H |
22 |
#define POINT_TO_POINT_NET_DEVICE_H |
23 |
|
24 |
#include <string.h> |
25 |
#include "ns3/mac-address.h" |
26 |
#include "ns3/node.h" |
27 |
#include "ns3/net-device.h" |
28 |
#include "ns3/callback.h" |
29 |
#include "ns3/packet.h" |
30 |
#include "ns3/callback-trace-source.h" |
31 |
#include "ns3/nstime.h" |
32 |
#include "ns3/data-rate.h" |
33 |
#include "ns3/default-value.h" |
34 |
#include "ns3/ptr.h" |
35 |
|
36 |
namespace ns3 { |
37 |
|
38 |
class Queue; |
39 |
class PointToPointChannel; |
40 |
|
41 |
/** |
42 |
* \class PointToPointNetDevice |
43 |
* \brief A Device for a Point to Point Network Link. |
44 |
* |
45 |
* Ns-3 takes a four-layer view of a protocol stack. This is the same model |
46 |
* that TCP uses. In this view, layers 5-7 of the OSI reference model are |
47 |
* grouped together into an application layer; layer four (transport / TCP) is |
48 |
* broken out; layer three (network / IP) is broken out; and layers 1-2 are |
49 |
* grouped together. We call this grouping of layers one and two a NetDevice |
50 |
* and represent it as a class in the system. |
51 |
* |
52 |
* The NetDevice class is specialized according to the needs of the specific |
53 |
* kind of network link. In this case, the link is a PointToPoint link. The |
54 |
* PointToPoint link is a family of classes that includes this class, the |
55 |
* PointToPointNetDevice, a PointToPointChannel class that represents the |
56 |
* actual medium across which bits are sent, a PointToPointIpv4Interface class |
57 |
* that provides the hook to tie a general purpose node to this specific |
58 |
* link, and finally, a PointToPointTopology object that is responsible for |
59 |
* putting all of the pieces together. |
60 |
* |
61 |
* This is the PointToPointNetDevice class that represents, essentially, the |
62 |
* PC card that is used to connect to the PointToPoint network. |
63 |
*/ |
64 |
class PointToPointNetDevice : public NetDevice { |
65 |
public: |
66 |
/** |
67 |
* Enumeration of the types of traces supported in the class. |
68 |
* |
69 |
*/ |
70 |
enum TraceType { |
71 |
QUEUE, /**< Trace queue events on the attached queue */ |
72 |
RX, /**< Trace packet reception events (from the channel) */ |
73 |
}; |
74 |
/** |
75 |
* Construct a PointToPointNetDevice |
76 |
* |
77 |
* This is the constructor for the PointToPointNetDevice. It takes as a |
78 |
* parameter the Node to which this device is connected. Ownership of the |
79 |
* Node pointer is not implied and the node must not be deleded. |
80 |
* |
81 |
* @see PointToPointTopology::AddPointToPointLink () |
82 |
* @param node the Node to which this device is connected. |
83 |
*/ |
84 |
PointToPointNetDevice (Ptr<Node> node, |
85 |
const DataRate& = g_defaultRate.GetValue()); |
86 |
/** |
87 |
* Copy Construct a PointToPointNetDevice |
88 |
* |
89 |
* This is the copy constructor for the PointToPointNetDevice. This is |
90 |
* primarily used in topology creation. |
91 |
* |
92 |
* @see PointToPointTopology::AddPointToPointLink () |
93 |
* @param nd the object to be copied |
94 |
*/ |
95 |
PointToPointNetDevice (const PointToPointNetDevice& nd); |
96 |
/** |
97 |
* Destroy a PointToPointNetDevice |
98 |
* |
99 |
* This is the destructor for the PointToPointNetDevice. |
100 |
*/ |
101 |
virtual ~PointToPointNetDevice(); |
102 |
/** |
103 |
* Assignment Operator for a PointToPointNetDevice |
104 |
* |
105 |
* This is the assignment operator for the PointToPointNetDevice. This is |
106 |
* to allow |
107 |
* |
108 |
* @param nd the object to be copied |
109 |
*/ |
110 |
PointToPointNetDevice& operator= (const PointToPointNetDevice& nd); |
111 |
/** |
112 |
* Set the Data Rate used for transmission of packets. The data rate is |
113 |
* set in the Attach () method from the corresponding field in the channel |
114 |
* to which the device is attached. It can be overridden using this method. |
115 |
* |
116 |
* @see Attach () |
117 |
* @param bps the data rate at which this object operates |
118 |
*/ |
119 |
void SetDataRate(const DataRate& bps); |
120 |
/** |
121 |
* Set the inteframe gap used to separate packets. The interframe gap |
122 |
* defines the minimum space required between packets sent by this device. |
123 |
* It is usually set in the Attach () method based on the speed of light |
124 |
* delay of the channel to which the device is attached. It can be |
125 |
* overridden using this method if desired. |
126 |
* |
127 |
* @see Attach () |
128 |
* @param t the interframe gap time |
129 |
*/ |
130 |
void SetInterframeGap(const Time& t); |
131 |
/** |
132 |
* Attach the device to a channel. |
133 |
* |
134 |
* The PointToPointTopology object creates a PointToPointChannel and two |
135 |
* PointtoPointNetDevices. In order to introduce these components to each |
136 |
* other, the topology object calls Attach () on each PointToPointNetDevice. |
137 |
* Inside this method, the Net Device calls out to the PointToPointChannel |
138 |
* to introduce itself. |
139 |
* |
140 |
* @see PointToPointTopology::AddPointToPointLink () |
141 |
* @see SetDataRate () |
142 |
* @see SetInterframeGap () |
143 |
* @param ch a pointer to the channel to which this object is being attached. |
144 |
*/ |
145 |
bool Attach(Ptr<PointToPointChannel> ch); |
146 |
/** |
147 |
* Attach a queue to the PointToPointNetDevice. |
148 |
* |
149 |
* The PointToPointNetDevice "owns" a queue. This queue is created by the |
150 |
* PointToPointTopology object and implements a queueing method such as |
151 |
* DropTail or RED. The PointToPointNetDevice assumes ownership of this |
152 |
* queue and must delete it when the device is destroyed. |
153 |
* |
154 |
* @see PointToPointTopology::AddPointToPointLink () |
155 |
* @see Queue |
156 |
* @see DropTailQueue |
157 |
* @param queue a pointer to the queue for which object is assuming |
158 |
* ownership. |
159 |
*/ |
160 |
void AddQueue(Ptr<Queue> queue); |
161 |
/** |
162 |
* Receive a packet from a connected PointToPointChannel. |
163 |
* |
164 |
* The PointToPointNetDevice receives packets from its connected channel |
165 |
* and forwards them up the protocol stack. This is the public method |
166 |
* used by the channel to indicate that the last bit of a packet has |
167 |
* arrived at the device. |
168 |
* |
169 |
* @see PointToPointChannel |
170 |
* @param p a reference to the received packet |
171 |
*/ |
172 |
void Receive (Packet& p); |
173 |
protected: |
174 |
virtual void DoDispose (void); |
175 |
/** |
176 |
* Get a copy of the attached Queue. |
177 |
* |
178 |
* This method is provided for any derived class that may need to get |
179 |
* direct access to the underlying queue. |
180 |
* |
181 |
* @see PointToPointTopology |
182 |
* @returns a pointer to the queue. |
183 |
*/ |
184 |
Ptr<Queue> GetQueue(void) const; |
185 |
/** |
186 |
* Get a copy of the attached Channel |
187 |
* |
188 |
* This method is provided for any derived class that may need to get |
189 |
* direct access to the connected channel |
190 |
* |
191 |
* @see PointToPointChannel |
192 |
* @returns a pointer to the channel |
193 |
*/ |
194 |
virtual Ptr<Channel> DoGetChannel(void) const; |
195 |
/** |
196 |
* Set a new default data rate |
197 |
* @param Data rate to set for new default |
198 |
*/ |
199 |
static void SetDefaultRate(const DataRate&); |
200 |
|
201 |
/** |
202 |
* Get the current default rate. |
203 |
* @returns a const reference to current default |
204 |
*/ |
205 |
|
206 |
static const DataRate& GetDefaultRate(); |
207 |
|
208 |
private: |
209 |
/** |
210 |
* Send a Packet Down the Wire. |
211 |
* |
212 |
* The SendTo method is defined as the standard way that the level three |
213 |
* protocol uses to tell a NetDevice to send a packet. SendTo is declared |
214 |
* as abstract in the NetDevice class and we declare it here. |
215 |
* |
216 |
* @see NetDevice |
217 |
* @param p a reference to the packet to send |
218 |
* @param dest a reference to the MacAddress of the destination device |
219 |
* @returns true if success, false on failure |
220 |
*/ |
221 |
virtual bool SendTo (Packet& p, const MacAddress& dest); |
222 |
/** |
223 |
* Start Sending a Packet Down the Wire. |
224 |
* |
225 |
* The TransmitStart method is the method that is used internally in the |
226 |
* PointToPointNetDevice to begin the process of sending a packet out on |
227 |
* the channel. The corresponding method is called on the channel to let |
228 |
* it know that the physical device this class represents has virually |
229 |
* started sending signals. An event is scheduled for the time at which |
230 |
* the bits have been completely transmitted. |
231 |
* |
232 |
* @see PointToPointChannel::TransmitStart () |
233 |
* @see TransmitCompleteEvent () |
234 |
* @param p a reference to the packet to send |
235 |
* @returns true if success, false on failure |
236 |
*/ |
237 |
bool TransmitStart (Packet &p); |
238 |
/** |
239 |
* Stop Sending a Packet Down the Wire and Begin the Interframe Gap. |
240 |
* |
241 |
* The TransmitComplete method is used internally to finish the process |
242 |
* of sending a packet out on the channel. |
243 |
* |
244 |
*/ |
245 |
void TransmitComplete(void); |
246 |
/** |
247 |
* Create a Trace Resolver for events in the net device. |
248 |
* |
249 |
* @see class TraceResolver |
250 |
*/ |
251 |
virtual TraceResolver* DoCreateTraceResolver (TraceContext const &context); |
252 |
virtual bool DoNeedsArp (void) const; |
253 |
/** |
254 |
* Enumeration of the states of the transmit machine of the net device. |
255 |
*/ |
256 |
enum TxMachineState |
257 |
{ |
258 |
READY, /**< The transmitter is ready to begin transmission of a packet */ |
259 |
BUSY /**< The transmitter is busy transmitting a packet */ |
260 |
}; |
261 |
/** |
262 |
* The state of the Net Device transmit state machine. |
263 |
* @see TxMachineState |
264 |
*/ |
265 |
TxMachineState m_txMachineState; |
266 |
/** |
267 |
* The data rate that the Net Device uses to simulate packet transmission |
268 |
* timing. |
269 |
* @see class DataRate |
270 |
*/ |
271 |
DataRate m_bps; |
272 |
/** |
273 |
* The interframe gap that the Net Device uses to throttle packet |
274 |
* transmission |
275 |
* @see class Time |
276 |
*/ |
277 |
Time m_tInterframeGap; |
278 |
/** |
279 |
* The PointToPointChannel to which this PointToPointNetDevice has been |
280 |
* attached. |
281 |
* @see class PointToPointChannel |
282 |
*/ |
283 |
Ptr<PointToPointChannel> m_channel; |
284 |
/** |
285 |
* The Queue which this PointToPointNetDevice uses as a packet source. |
286 |
* Management of this Queue has been delegated to the PointToPointNetDevice |
287 |
* and it has the responsibility for deletion. |
288 |
* @see class Queue |
289 |
* @see class DropTailQueue |
290 |
*/ |
291 |
Ptr<Queue> m_queue; |
292 |
/** |
293 |
* The trace source for the packet reception events that the device can |
294 |
* fire. |
295 |
* |
296 |
* @see class CallBackTraceSource |
297 |
* @see class TraceResolver |
298 |
*/ |
299 |
CallbackTraceSource<Packet &> m_rxTrace; |
300 |
/** |
301 |
* Default data rate. Used for all newly created p2p net devices |
302 |
*/ |
303 |
static DataRateDefaultValue g_defaultRate; |
304 |
|
305 |
}; |
306 |
|
307 |
}; // namespace ns3 |
308 |
|
309 |
#endif // POINT_TO_POINT_NET_DEVICE_H |
310 |
|