LEFT | RIGHT |
1 // -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- | 1 // -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- |
2 // | 2 // |
3 // Copyright (c) 2006 Georgia Tech Research Corporation | 3 // Copyright (c) 2006 Georgia Tech Research Corporation |
4 // | 4 // |
5 // This program is free software; you can redistribute it and/or modify | 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 | 6 // it under the terms of the GNU General Public License version 2 as |
7 // published by the Free Software Foundation; | 7 // published by the Free Software Foundation; |
8 // | 8 // |
9 // This program is distributed in the hope that it will be useful, | 9 // This program is distributed in the hope that it will be useful, |
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class Ipv4Route; | 46 class Ipv4Route; |
47 class Node; | 47 class Node; |
48 class Socket; | 48 class Socket; |
49 class Ipv4RawSocketImpl; | 49 class Ipv4RawSocketImpl; |
50 class Ipv4L4Protocol; | 50 class Ipv4L4Protocol; |
51 class Icmpv4L4Protocol; | 51 class Icmpv4L4Protocol; |
52 | 52 |
53 | 53 |
54 /** | 54 /** |
55 * \brief Implement the Ipv4 layer. | 55 * \brief Implement the Ipv4 layer. |
56 * | 56 * |
57 * This is the actual implementation of IP. It contains APIs to send and | 57 * This is the actual implementation of IP. It contains APIs to send and |
58 * receive packets at the IP layer, as well as APIs for IP routing. | 58 * receive packets at the IP layer, as well as APIs for IP routing. |
59 * | 59 * |
60 * This class contains two distinct groups of trace sources. The | 60 * This class contains two distinct groups of trace sources. The |
61 * trace sources 'Rx' and 'Tx' are called, respectively, immediately | 61 * trace sources 'Rx' and 'Tx' are called, respectively, immediately |
62 * after receiving from the NetDevice and immediately before sending | 62 * after receiving from the NetDevice and immediately before sending |
63 * to a NetDevice for transmitting a packet. These are low level | 63 * to a NetDevice for transmitting a packet. These are low level |
64 * trace sources that include the Ipv4Header already serialized into | 64 * trace sources that include the Ipv4Header already serialized into |
65 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward, | 65 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward, |
66 * and LocalDeliver trace sources are slightly higher-level and pass | 66 * and LocalDeliver trace sources are slightly higher-level and pass |
67 * around the Ipv4Header as an explicit parameter and not as part of | 67 * around the Ipv4Header as an explicit parameter and not as part of |
68 * the packet. | 68 * the packet. |
69 * | 69 * |
70 * IP fragmentation and reassembly is handled at this level. | 70 * IP fragmentation and reassembly is handled at this level. |
71 * At the moment the fragmentation does not handle IP option headers, | 71 * At the moment the fragmentation does not handle IP option headers, |
72 * and in particular the ones that shall not be fragmented. | 72 * and in particular the ones that shall not be fragmented. |
73 * Moreover, the actual implementation does not mimic exactly the Linux | 73 * Moreover, the actual implementation does not mimic exactly the Linux |
74 * kernel. Hence it is not possible, for instance, to test a fragmentation | 74 * kernel. Hence it is not possible, for instance, to test a fragmentation |
75 * attack. | 75 * attack. |
76 */ | 76 */ |
77 class Ipv4L3Protocol : public Ipv4 | 77 class Ipv4L3Protocol : public Ipv4 |
78 { | 78 { |
79 public: | 79 public: |
80 static TypeId GetTypeId (void); | 80 static TypeId GetTypeId (void); |
81 static const uint16_t PROT_NUMBER; | 81 static const uint16_t PROT_NUMBER; |
82 | 82 |
83 Ipv4L3Protocol (); | 83 Ipv4L3Protocol(); |
84 virtual ~Ipv4L3Protocol (); | 84 virtual ~Ipv4L3Protocol (); |
85 | 85 |
86 /** | 86 /** |
87 * \enum DropReason | 87 * \enum DropReason |
88 * \brief Reason why a packet has been dropped. | 88 * \brief Reason why a packet has been dropped. |
89 */ | 89 */ |
90 enum DropReason | 90 enum DropReason |
91 { | 91 { |
92 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */ | 92 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */ |
93 DROP_NO_ROUTE, /**< No route to host */ | 93 DROP_NO_ROUTE, /**< No route to host */ |
94 DROP_BAD_CHECKSUM, /**< Bad checksum */ | 94 DROP_BAD_CHECKSUM, /**< Bad checksum */ |
95 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */ | 95 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */ |
96 DROP_ROUTE_ERROR, /**< Route error */ | 96 DROP_ROUTE_ERROR, /**< Route error */ |
97 DROP_FRAGMENT_TIMEOUT /**< Fragment timeout exceeded */ | 97 DROP_FRAGMENT_TIMEOUT /**< Fragment timeout exceeded */ |
98 }; | 98 }; |
99 | 99 |
100 void SetNode (Ptr<Node> node); | 100 void SetNode (Ptr<Node> node); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 /** | 163 /** |
164 * \param packet packet to send | 164 * \param packet packet to send |
165 * \param source source address of packet | 165 * \param source source address of packet |
166 * \param destination address of packet | 166 * \param destination address of packet |
167 * \param protocol number of packet | 167 * \param protocol number of packet |
168 * \param route route entry | 168 * \param route route entry |
169 * | 169 * |
170 * Higher-level layers call this method to send a packet | 170 * Higher-level layers call this method to send a packet |
171 * down the stack to the MAC and PHY layers. | 171 * down the stack to the MAC and PHY layers. |
172 */ | 172 */ |
173 void Send (Ptr<Packet> packet, Ipv4Address source, | 173 void Send (Ptr<Packet> packet, Ipv4Address source, |
174 Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route); | 174 Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route); |
175 /** | 175 /** |
176 * \param packet packet to send | 176 * \param packet packet to send |
177 * \param ipHeader IP Header | 177 * \param ipHeader IP Header |
178 * \param route route entry | 178 * \param route route entry |
179 * | 179 * |
180 * Higher-level layers call this method to send a packet with IPv4 Header | 180 * Higher-level layers call this method to send a packet with IPv4 Header |
181 * (Intend to be used with IpHeaderInclude attribute.) | 181 * (Intend to be used with IpHeaderInclude attribute.) |
182 */ | 182 */ |
183 void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> r
oute); | 183 void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> r
oute); |
(...skipping 20 matching lines...) Expand all Loading... |
204 uint16_t GetMtu (uint32_t i) const; | 204 uint16_t GetMtu (uint32_t i) const; |
205 bool IsUp (uint32_t i) const; | 205 bool IsUp (uint32_t i) const; |
206 void SetUp (uint32_t i); | 206 void SetUp (uint32_t i); |
207 void SetDown (uint32_t i); | 207 void SetDown (uint32_t i); |
208 bool IsForwarding (uint32_t i) const; | 208 bool IsForwarding (uint32_t i) const; |
209 void SetForwarding (uint32_t i, bool val); | 209 void SetForwarding (uint32_t i, bool val); |
210 | 210 |
211 Ptr<NetDevice> GetNetDevice (uint32_t i); | 211 Ptr<NetDevice> GetNetDevice (uint32_t i); |
212 | 212 |
213 protected: | 213 protected: |
| 214 |
214 virtual void DoDispose (void); | 215 virtual void DoDispose (void); |
215 /** | 216 /** |
216 * This function will notify other components connected to the node that a new
stack member is now connected | 217 * This function will notify other components connected to the node that a new
stack member is now connected |
217 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to c
onnect them together. | 218 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to c
onnect them together. |
218 */ | 219 */ |
219 virtual void NotifyNewAggregate (); | 220 virtual void NotifyNewAggregate (); |
220 private: | 221 private: |
221 friend class Ipv4L3ProtocolTestCase; | 222 friend class Ipv4L3ProtocolTestCase; |
222 Ipv4L3Protocol (const Ipv4L3Protocol &); | 223 Ipv4L3Protocol(const Ipv4L3Protocol &); |
223 Ipv4L3Protocol &operator = (const Ipv4L3Protocol &); | 224 Ipv4L3Protocol &operator = (const Ipv4L3Protocol &); |
224 | 225 |
225 // class Ipv4 attributes | 226 // class Ipv4 attributes |
226 virtual void SetIpForward (bool forward); | 227 virtual void SetIpForward (bool forward); |
227 virtual bool GetIpForward (void) const; | 228 virtual bool GetIpForward (void) const; |
228 virtual void SetWeakEsModel (bool model); | 229 virtual void SetWeakEsModel (bool model); |
229 virtual bool GetWeakEsModel (void) const; | 230 virtual bool GetWeakEsModel (void) const; |
230 | 231 |
231 Ipv4Header BuildHeader ( | 232 Ipv4Header BuildHeader ( |
232 Ipv4Address source, | 233 Ipv4Address source, |
233 Ipv4Address destination, | 234 Ipv4Address destination, |
234 uint8_t protocol, | 235 uint8_t protocol, |
235 uint16_t payloadSize, | 236 uint16_t payloadSize, |
236 uint8_t ttl, | 237 uint8_t ttl, |
237 bool mayFragment); | 238 bool mayFragment); |
238 | 239 |
239 void | 240 void |
240 SendRealOut (Ptr<Ipv4Route> route, | 241 SendRealOut (Ptr<Ipv4Route> route, |
241 Ptr<Packet> packet, | 242 Ptr<Packet> packet, |
242 Ipv4Header const &ipHeader); | 243 Ipv4Header const &ipHeader); |
243 | 244 |
| 245 void· |
| 246 IpForward (Ptr<Ipv4Route> rtentry,· |
| 247 Ptr<const Packet> p,· |
| 248 const Ipv4Header &header); |
| 249 |
244 void | 250 void |
245 IpForward (Ptr<Ipv4Route> rtentry, | 251 IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry,· |
246 Ptr<const Packet> p, | 252 Ptr<const Packet> p,· |
247 const Ipv4Header &header); | |
248 | |
249 void | |
250 IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, | |
251 Ptr<const Packet> p, | |
252 const Ipv4Header &header); | 253 const Ipv4Header &header); |
253 | 254 |
254 void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif); | 255 void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif); |
255 void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket
::SocketErrno sockErrno); | 256 void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket
::SocketErrno sockErrno); |
256 | 257 |
257 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface); | 258 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface); |
258 void SetupLoopback (void); | 259 void SetupLoopback (void); |
259 | 260 |
260 /** | 261 /** |
261 * \brief Get ICMPv4 protocol. | 262 * \brief Get ICMPv4 protocol. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 Ptr<Packet> GetPacket () const; | 354 Ptr<Packet> GetPacket () const; |
354 | 355 |
355 /** | 356 /** |
356 * \brief Get the complete part of the packet. | 357 * \brief Get the complete part of the packet. |
357 * \return the part we have comeplete | 358 * \return the part we have comeplete |
358 */ | 359 */ |
359 Ptr<Packet> GetPartialPacket () const; | 360 Ptr<Packet> GetPartialPacket () const; |
360 | 361 |
361 private: | 362 private: |
362 /** | 363 /** |
363 * \brief If other fragments will be sent. | 364 * \brief True if other fragments will be sent. |
364 */ | 365 */ |
365 bool m_moreFragment; | 366 bool m_moreFragment; |
366 | 367 |
367 /** | 368 /** |
368 * \brief The current fragments. | 369 * \brief The current fragments. |
369 */ | 370 */ |
370 std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments; | 371 std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments; |
371 | 372 |
372 /** | 373 /** |
373 * \brief Number of references. | 374 * \brief Number of references. |
374 */ | 375 */ |
375 mutable uint32_t m_refCount; | 376 mutable uint32_t m_refCount; |
376 }; | 377 }; |
377 | 378 |
378 typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments
_t; | 379 typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments
_t; |
379 typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_
t; | 380 typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_
t; |
380 | 381 |
381 /** | 382 /** |
382 * \brief The hash of fragmented packets. | 383 * \brief The hash of fragmented packets. |
383 */ | 384 */ |
384 MapFragments_t m_fragments; | 385 MapFragments_t m_fragments; |
385 Time m_waitFragmentsTimeout; | 386 Time m_fragmentExpirationTimeout; |
386 MapFragmentsTimers_t m_fragmentsTimers; | 387 MapFragmentsTimers_t m_fragmentsTimers; |
387 | 388 |
388 }; | 389 }; |
389 | 390 |
390 } // Namespace ns3 | 391 } // Namespace ns3 |
391 | 392 |
392 #endif /* IPV4_L3_PROTOCOL_H */ | 393 #endif /* IPV4_L3_PROTOCOL_H */ |
LEFT | RIGHT |