180 * (Intend to be used with IpHeaderInclude attribute.) |
188 * (Intend to be used with IpHeaderInclude attribute.) |
181 */ |
189 */ |
182 void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route); |
190 void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route); |
183 |
191 |
184 uint32_t AddInterface (Ptr<NetDevice> device); |
192 uint32_t AddInterface (Ptr<NetDevice> device); |
|
193 /** |
|
194 * \brief Get an interface. |
|
195 * \param i interface index |
|
196 * \return IPv4 interface pointer |
|
197 */ |
185 Ptr<Ipv4Interface> GetInterface (uint32_t i) const; |
198 Ptr<Ipv4Interface> GetInterface (uint32_t i) const; |
186 uint32_t GetNInterfaces (void) const; |
199 uint32_t GetNInterfaces (void) const; |
187 |
200 |
188 int32_t GetInterfaceForAddress (Ipv4Address addr) const; |
201 int32_t GetInterfaceForAddress (Ipv4Address addr) const; |
189 int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const; |
202 int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const; |
218 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together. |
231 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together. |
219 */ |
232 */ |
220 virtual void NotifyNewAggregate (); |
233 virtual void NotifyNewAggregate (); |
221 private: |
234 private: |
222 friend class Ipv4L3ProtocolTestCase; |
235 friend class Ipv4L3ProtocolTestCase; |
|
236 |
|
237 /** |
|
238 * \brief Copy constructor. |
|
239 * |
|
240 * Defined but not implemented to avoid misuse |
|
241 */ |
223 Ipv4L3Protocol(const Ipv4L3Protocol &); |
242 Ipv4L3Protocol(const Ipv4L3Protocol &); |
|
243 |
|
244 /** |
|
245 * \brief Copy constructor. |
|
246 * |
|
247 * Defined but not implemented to avoid misuse |
|
248 * \returns the copied object |
|
249 */ |
224 Ipv4L3Protocol &operator = (const Ipv4L3Protocol &); |
250 Ipv4L3Protocol &operator = (const Ipv4L3Protocol &); |
225 |
251 |
226 // class Ipv4 attributes |
252 // class Ipv4 attributes |
227 virtual void SetIpForward (bool forward); |
253 virtual void SetIpForward (bool forward); |
228 virtual bool GetIpForward (void) const; |
254 virtual bool GetIpForward (void) const; |
229 virtual void SetWeakEsModel (bool model); |
255 virtual void SetWeakEsModel (bool model); |
230 virtual bool GetWeakEsModel (void) const; |
256 virtual bool GetWeakEsModel (void) const; |
231 |
257 |
|
258 /** |
|
259 * \brief Construct an IPv4 header. |
|
260 * \param source source IPv4 address |
|
261 * \param destination destination IPv4 address |
|
262 * \param protocol L4 protocol |
|
263 * \param payloadSize payload size |
|
264 * \param ttl Time to Live |
|
265 * \param tos Type of Service |
|
266 * \param mayFragment true if the packet can be fragmented |
|
267 * \return newly created IPv4 header |
|
268 */ |
232 Ipv4Header BuildHeader ( |
269 Ipv4Header BuildHeader ( |
233 Ipv4Address source, |
270 Ipv4Address source, |
234 Ipv4Address destination, |
271 Ipv4Address destination, |
235 uint8_t protocol, |
272 uint8_t protocol, |
236 uint16_t payloadSize, |
273 uint16_t payloadSize, |
237 uint8_t ttl, |
274 uint8_t ttl, |
238 uint8_t tos, |
275 uint8_t tos, |
239 bool mayFragment); |
276 bool mayFragment); |
240 |
277 |
|
278 /** |
|
279 * \brief Send packet with route. |
|
280 * \param route route |
|
281 * \param packet packet to send |
|
282 * \param ipHeader IPv4 header to add to the packet |
|
283 */ |
241 void |
284 void |
242 SendRealOut (Ptr<Ipv4Route> route, |
285 SendRealOut (Ptr<Ipv4Route> route, |
243 Ptr<Packet> packet, |
286 Ptr<Packet> packet, |
244 Ipv4Header const &ipHeader); |
287 Ipv4Header const &ipHeader); |
245 |
288 |
|
289 /** |
|
290 * \brief Forward a packet. |
|
291 * \param rtentry route |
|
292 * \param p packet to forward |
|
293 * \param header IPv4 header to add to the packet |
|
294 */ |
246 void |
295 void |
247 IpForward (Ptr<Ipv4Route> rtentry, |
296 IpForward (Ptr<Ipv4Route> rtentry, |
248 Ptr<const Packet> p, |
297 Ptr<const Packet> p, |
249 const Ipv4Header &header); |
298 const Ipv4Header &header); |
250 |
299 |
|
300 /** |
|
301 * \brief Forward a multicast packet. |
|
302 * \param mrtentry route |
|
303 * \param p packet to forward |
|
304 * \param header IPv6 header to add to the packet |
|
305 */ |
251 void |
306 void |
252 IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, |
307 IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, |
253 Ptr<const Packet> p, |
308 Ptr<const Packet> p, |
254 const Ipv4Header &header); |
309 const Ipv4Header &header); |
255 |
310 |
|
311 /** |
|
312 * \brief Deliver a packet. |
|
313 * \param p packet delivered |
|
314 * \param ip IPv4 header |
|
315 * \param iif input interface packet was received |
|
316 */ |
256 void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif); |
317 void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif); |
|
318 |
|
319 /** |
|
320 * \brief Fallback when no route is found. |
|
321 * \param p packet |
|
322 * \param ipHeader IPv4 header |
|
323 * \param sockErrno error number |
|
324 */ |
257 void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno); |
325 void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno); |
258 |
326 |
|
327 /** |
|
328 * \brief Add an IPv4 interface to the stack. |
|
329 * \param interface interface to add |
|
330 * \return index of newly added interface |
|
331 */ |
259 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface); |
332 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface); |
|
333 |
|
334 /** |
|
335 * \brief Setup loopback interface. |
|
336 */ |
260 void SetupLoopback (void); |
337 void SetupLoopback (void); |
261 |
338 |
262 /** |
339 /** |
263 * \brief Get ICMPv4 protocol. |
340 * \brief Get ICMPv4 protocol. |
264 * \return Icmpv4L4Protocol pointer |
341 * \return Icmpv4L4Protocol pointer |
265 */ |
342 */ |
266 Ptr<Icmpv4L4Protocol> GetIcmp (void) const; |
343 Ptr<Icmpv4L4Protocol> GetIcmp (void) const; |
|
344 |
|
345 /** |
|
346 * \brief Check if an IPv4 address is unicast. |
|
347 * \param ad address |
|
348 * \param interfaceMask the network mask |
|
349 * \return true if the address is unicast |
|
350 */ |
267 bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const; |
351 bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const; |
268 |
352 |
269 /** |
353 /** |
270 * \brief Fragment a packet |
354 * \brief Fragment a packet |
271 * \param packet the packet |
355 * \param packet the packet |
289 * \param ipHeader the IP header of the original packet |
373 * \param ipHeader the IP header of the original packet |
290 * \param iif Input Interface |
374 * \param iif Input Interface |
291 */ |
375 */ |
292 void HandleFragmentsTimeout ( std::pair<uint64_t, uint32_t> key, Ipv4Header & ipHeader, uint32_t iif); |
376 void HandleFragmentsTimeout ( std::pair<uint64_t, uint32_t> key, Ipv4Header & ipHeader, uint32_t iif); |
293 |
377 |
|
378 /** |
|
379 * \brief Container of the IPv4 Interfaces. |
|
380 */ |
294 typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList; |
381 typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList; |
|
382 /** |
|
383 * \brief Container of the IPv4 Raw Sockets. |
|
384 */ |
295 typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList; |
385 typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList; |
296 typedef std::list<Ptr<IpL4Protocol> > L4List_t; |
386 /** |
297 |
387 * \brief Container of the IPv4 L4 instances. |
298 bool m_ipForward; |
388 */ |
299 bool m_weakEsModel; |
389 typedef std::list<Ptr<IpL4Protocol> > L4List_t; |
300 L4List_t m_protocols; |
390 |
301 Ipv4InterfaceList m_interfaces; |
391 bool m_ipForward; //!< Forwarding packets (i.e. router mode) state. |
302 uint8_t m_defaultTos; |
392 bool m_weakEsModel; //!< Weak ES model state |
303 uint8_t m_defaultTtl; |
393 L4List_t m_protocols; //!< List of transport protocol. |
304 uint16_t m_identification; |
394 Ipv4InterfaceList m_interfaces; //!< List of IPv4 interfaces. |
305 Ptr<Node> m_node; |
395 uint8_t m_defaultTos; //!< Default TOS |
306 |
396 uint8_t m_defaultTtl; //!< Default TTL |
|
397 uint16_t m_identification; //!< Identification |
|
398 Ptr<Node> m_node; //!< Node attached to stack. |
|
399 |
|
400 /// Trace of sent packets |
307 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace; |
401 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace; |
|
402 /// Trace of unicast forwarded packets |
308 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace; |
403 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace; |
|
404 /// Trace of locally delivered packets |
309 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace; |
405 TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace; |
310 |
406 |
311 // The following two traces pass a packet with an IP header |
407 // The following two traces pass a packet with an IP header |
|
408 /// Trace of transmitted packets |
312 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_txTrace; |
409 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_txTrace; |
|
410 /// Trace of received packets |
313 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_rxTrace; |
411 TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_rxTrace; |
314 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE) |
412 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE) |
|
413 /// Trace of dropped packets |
315 TracedCallback<const Ipv4Header &, Ptr<const Packet>, DropReason, Ptr<Ipv4>, uint32_t> m_dropTrace; |
414 TracedCallback<const Ipv4Header &, Ptr<const Packet>, DropReason, Ptr<Ipv4>, uint32_t> m_dropTrace; |
316 |
415 |
317 Ptr<Ipv4RoutingProtocol> m_routingProtocol; |
416 Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< Routing protocol associated with the stack |
318 |
417 |
319 SocketList m_sockets; |
418 SocketList m_sockets; //!< List of IPv4 raw sockets. |
320 |
419 |
321 /** |
420 /** |
322 * \class Fragments |
421 * \class Fragments |
323 * \brief A Set of Fragment belonging to the same packet (src, dst, identification and proto) |
422 * \brief A Set of Fragment belonging to the same packet (src, dst, identification and proto) |
324 */ |
423 */ |
372 */ |
471 */ |
373 std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments; |
472 std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments; |
374 |
473 |
375 }; |
474 }; |
376 |
475 |
|
476 /// Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment |
377 typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments_t; |
477 typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments_t; |
|
478 /// Container of fragment timeout event, stored as pairs(src+dst addr, src+dst port) / EventId |
378 typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_t; |
479 typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_t; |
379 |
480 |
380 /** |
481 MapFragments_t m_fragments; //!< Fragmented packets. |
381 * \brief The hash of fragmented packets. |
482 Time m_fragmentExpirationTimeout; //!< Expiration timeout |
382 */ |
483 MapFragmentsTimers_t m_fragmentsTimers; //!< Expiration events. |
383 MapFragments_t m_fragments; |
|
384 Time m_fragmentExpirationTimeout; |
|
385 MapFragmentsTimers_t m_fragmentsTimers; |
|
386 |
484 |
387 }; |
485 }; |
388 |
486 |
389 } // Namespace ns3 |
487 } // Namespace ns3 |
390 |
488 |