OLD | NEW |
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 |
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 // GNU General Public License for more details. | 12 // GNU General Public License for more details. |
13 // | 13 // |
14 // You should have received a copy of the GNU General Public License | 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 | 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 | 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 // | 17 // |
18 // Author: George F. Riley<riley@ece.gatech.edu> | 18 // Author: George F. Riley<riley@ece.gatech.edu> |
19 // | 19 // |
20 | 20 |
21 #ifndef IPV4_L3_PROTOCOL_H | 21 #ifndef IPV4_L3_PROTOCOL_H |
22 #define IPV4_L3_PROTOCOL_H | 22 #define IPV4_L3_PROTOCOL_H |
23 | 23 |
24 #include <list> | 24 #include <list> |
| 25 #include <map> |
25 #include <vector> | 26 #include <vector> |
26 #include <stdint.h> | 27 #include <stdint.h> |
27 #include "ns3/ipv4-address.h" | 28 #include "ns3/ipv4-address.h" |
28 #include "ns3/ptr.h" | 29 #include "ns3/ptr.h" |
29 #include "ns3/net-device.h" | 30 #include "ns3/net-device.h" |
30 #include "ns3/ipv4.h" | 31 #include "ns3/ipv4.h" |
31 #include "ns3/traced-callback.h" | 32 #include "ns3/traced-callback.h" |
32 #include "ns3/ipv4-header.h" | 33 #include "ns3/ipv4-header.h" |
33 #include "ns3/ipv4-routing-protocol.h" | 34 #include "ns3/ipv4-routing-protocol.h" |
| 35 #include "ns3/nstime.h" |
| 36 #include "ns3/simulator.h" |
34 | 37 |
35 namespace ns3 { | 38 namespace ns3 { |
36 | 39 |
37 class Packet; | 40 class Packet; |
38 class NetDevice; | 41 class NetDevice; |
39 class Ipv4Interface; | 42 class Ipv4Interface; |
40 class Ipv4Address; | 43 class Ipv4Address; |
41 class Ipv4Header; | 44 class Ipv4Header; |
42 class Ipv4RoutingTableEntry; | 45 class Ipv4RoutingTableEntry; |
43 class Ipv4Route; | 46 class Ipv4Route; |
(...skipping 12 matching lines...) Expand all Loading... |
56 * | 59 * |
57 * This class contains two distinct groups of trace sources. The | 60 * This class contains two distinct groups of trace sources. The |
58 * trace sources 'Rx' and 'Tx' are called, respectively, immediately | 61 * trace sources 'Rx' and 'Tx' are called, respectively, immediately |
59 * after receiving from the NetDevice and immediately before sending | 62 * after receiving from the NetDevice and immediately before sending |
60 * to a NetDevice for transmitting a packet. These are low level | 63 * to a NetDevice for transmitting a packet. These are low level |
61 * trace sources that include the Ipv4Header already serialized into | 64 * trace sources that include the Ipv4Header already serialized into |
62 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward, | 65 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward, |
63 * and LocalDeliver trace sources are slightly higher-level and pass | 66 * and LocalDeliver trace sources are slightly higher-level and pass |
64 * 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 |
65 * the packet. | 68 * the packet. |
| 69 * |
| 70 * IP fragmentation and reassembly is handled at this level. |
| 71 * At the moment the fragmentation does not handle IP option headers, |
| 72 * and in particular the ones that shall not be fragmented. |
| 73 * Moreover, the actual implementation does not mimic exactly the Linux |
| 74 * kernel. Hence it is not possible, for instance, to test a fragmentation |
| 75 * attack. |
66 */ | 76 */ |
67 class Ipv4L3Protocol : public Ipv4 | 77 class Ipv4L3Protocol : public Ipv4 |
68 { | 78 { |
69 public: | 79 public: |
70 static TypeId GetTypeId (void); | 80 static TypeId GetTypeId (void); |
71 static const uint16_t PROT_NUMBER; | 81 static const uint16_t PROT_NUMBER; |
72 | 82 |
73 Ipv4L3Protocol(); | 83 Ipv4L3Protocol(); |
74 virtual ~Ipv4L3Protocol (); | 84 virtual ~Ipv4L3Protocol (); |
75 | 85 |
76 /** | 86 /** |
77 * \enum DropReason | 87 * \enum DropReason |
78 * \brief Reason why a packet has been dropped. | 88 * \brief Reason why a packet has been dropped. |
79 */ | 89 */ |
80 enum DropReason· | 90 enum DropReason· |
81 { | 91 { |
82 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */ | 92 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */ |
83 DROP_NO_ROUTE, /**< No route to host */ | 93 DROP_NO_ROUTE, /**< No route to host */ |
84 DROP_BAD_CHECKSUM, /**< Bad checksum */ | 94 DROP_BAD_CHECKSUM, /**< Bad checksum */ |
85 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */ | 95 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */ |
86 DROP_ROUTE_ERROR, /**< Route error */ | 96 DROP_ROUTE_ERROR, /**< Route error */ |
| 97 DROP_FRAGMENT_TIMEOUT /**< Fragment timeout exceeded */ |
87 }; | 98 }; |
88 | 99 |
89 void SetNode (Ptr<Node> node); | 100 void SetNode (Ptr<Node> node); |
90 | 101 |
91 // functions defined in base class Ipv4 | 102 // functions defined in base class Ipv4 |
92 | 103 |
93 void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol); | 104 void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol); |
94 Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const; | 105 Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const; |
95 | 106 |
96 Ptr<Socket> CreateRawSocket (void); | 107 Ptr<Socket> CreateRawSocket (void); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 void | 250 void |
240 IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry,· | 251 IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry,· |
241 Ptr<const Packet> p,· | 252 Ptr<const Packet> p,· |
242 const Ipv4Header &header); | 253 const Ipv4Header &header); |
243 | 254 |
244 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); |
245 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); |
246 | 257 |
247 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface); | 258 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface); |
248 void SetupLoopback (void); | 259 void SetupLoopback (void); |
| 260 |
| 261 /** |
| 262 * \brief Get ICMPv4 protocol. |
| 263 * \return Icmpv4L4Protocol pointer |
| 264 */ |
249 Ptr<Icmpv4L4Protocol> GetIcmp (void) const; | 265 Ptr<Icmpv4L4Protocol> GetIcmp (void) const; |
250 bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const; | 266 bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const; |
251 | 267 |
| 268 /** |
| 269 * \brief Fragment a packet |
| 270 * \param packet the packet |
| 271 * \param outIfaceMtu the MTU of the interface |
| 272 * \param listFragments the list of fragments |
| 273 */ |
| 274 void DoFragmentation (Ptr<Packet> packet, uint32_t outIfaceMtu, std::list<Ptr<
Packet> >& listFragments); |
| 275 |
| 276 /** |
| 277 * \brief Process a packet fragment |
| 278 * \param packet the packet |
| 279 * \param fragmentSize the size of the fragment |
| 280 * \param iif Input Interface |
| 281 * \return true is the fragment completed the packet |
| 282 */ |
| 283 bool ProcessFragment (Ptr<Packet>& packet, Ipv4Header & ipHeader, uint32_t iif
); |
| 284 |
| 285 /** |
| 286 * \brief Process the timeout for packet fragments |
| 287 * \param key representing the packet fragments |
| 288 * \param ipHeader the IP header of the original packet |
| 289 * \param iif Input Interface |
| 290 */ |
| 291 void HandleFragmentsTimeout ( std::pair<uint64_t, uint32_t> key, Ipv4Header &
ipHeader, uint32_t iif); |
| 292 |
252 typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList; | 293 typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList; |
253 typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList; | 294 typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList; |
254 typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t; | 295 typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t; |
255 | 296 |
256 bool m_ipForward; | 297 bool m_ipForward; |
257 bool m_weakEsModel; | 298 bool m_weakEsModel; |
258 L4List_t m_protocols; | 299 L4List_t m_protocols; |
259 Ipv4InterfaceList m_interfaces; | 300 Ipv4InterfaceList m_interfaces; |
260 uint8_t m_defaultTtl; | 301 uint8_t m_defaultTtl; |
261 uint16_t m_identification; | 302 uint16_t m_identification; |
262 Ptr<Node> m_node; | 303 Ptr<Node> m_node; |
263 | 304 |
264 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoing
Trace; | 305 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoing
Trace; |
265 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwa
rdTrace; | 306 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwa
rdTrace; |
266 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliver
Trace; | 307 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliver
Trace; |
267 | 308 |
268 // The following two traces pass a packet with an IP header | 309 // The following two traces pass a packet with an IP header |
269 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_txTrace; | 310 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_txTrace; |
270 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_rxTrace; | 311 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_rxTrace; |
271 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_
NO_ROUTE) | 312 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_
NO_ROUTE) |
272 TracedCallback<const Ipv4Header &, Ptr<const Packet>, DropReason, Ptr<Ipv4>, u
int32_t> m_dropTrace; | 313 TracedCallback<const Ipv4Header &, Ptr<const Packet>, DropReason, Ptr<Ipv4>, u
int32_t> m_dropTrace; |
273 | 314 |
274 Ptr<Ipv4RoutingProtocol> m_routingProtocol; | 315 Ptr<Ipv4RoutingProtocol> m_routingProtocol; |
275 | 316 |
276 SocketList m_sockets; | 317 SocketList m_sockets; |
| 318 |
| 319 /** |
| 320 * \class Fragments |
| 321 * \brief A Set of Fragment belonging to the same packet (src, dst, identifica
tion and proto) |
| 322 */ |
| 323 class Fragments : public SimpleRefCount<Fragments> |
| 324 { |
| 325 public: |
| 326 /** |
| 327 * \brief Constructor. |
| 328 */ |
| 329 Fragments (); |
| 330 |
| 331 /** |
| 332 * \brief Destructor. |
| 333 */ |
| 334 ~Fragments (); |
| 335 |
| 336 /** |
| 337 * \brief Add a fragment. |
| 338 * \param fragment the fragment |
| 339 * \param fragmentOffset the offset of the fragment |
| 340 * \param moreFragment the bit "More Fragment" |
| 341 */ |
| 342 void AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFr
agment); |
| 343 |
| 344 /** |
| 345 * \brief If all fragments have been added. |
| 346 * \returns true if the packet is entire |
| 347 */ |
| 348 bool IsEntire () const; |
| 349 |
| 350 /** |
| 351 * \brief Get the entire packet. |
| 352 * \return the entire packet |
| 353 */ |
| 354 Ptr<Packet> GetPacket () const; |
| 355 |
| 356 /** |
| 357 * \brief Get the complete part of the packet. |
| 358 * \return the part we have comeplete |
| 359 */ |
| 360 Ptr<Packet> GetPartialPacket () const; |
| 361 |
| 362 private: |
| 363 /** |
| 364 * \brief True if other fragments will be sent. |
| 365 */ |
| 366 bool m_moreFragment; |
| 367 |
| 368 /** |
| 369 * \brief The current fragments. |
| 370 */ |
| 371 std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments; |
| 372 |
| 373 /** |
| 374 * \brief Number of references. |
| 375 */ |
| 376 mutable uint32_t m_refCount; |
| 377 }; |
| 378 |
| 379 typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments
_t; |
| 380 typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_
t; |
| 381 |
| 382 /** |
| 383 * \brief The hash of fragmented packets. |
| 384 */ |
| 385 MapFragments_t m_fragments; |
| 386 Time m_fragmentExpirationTimeout; |
| 387 MapFragmentsTimers_t m_fragmentsTimers; |
| 388 |
277 }; | 389 }; |
278 | 390 |
279 } // Namespace ns3 | 391 } // Namespace ns3 |
280 | 392 |
281 #endif /* IPV4_L3_PROTOCOL_H */ | 393 #endif /* IPV4_L3_PROTOCOL_H */ |
OLD | NEW |