A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv6-l3-protocol.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #ifndef IPV6_L3_PROTOCOL_H
22 #define IPV6_L3_PROTOCOL_H
23 
24 #include <list>
25 
26 #include "ns3/traced-callback.h"
27 #include "ns3/net-device.h"
28 #include "ns3/ipv6.h"
29 #include "ns3/ipv6-address.h"
30 #include "ns3/ipv6-header.h"
31 #include "ns3/ipv6-pmtu-cache.h"
32 
33 namespace ns3
34 {
35 
36 class Node;
37 class Ipv6Interface;
38 class IpL4Protocol;
39 class Ipv6Route;
40 class Ipv6MulticastRoute;
41 class Ipv6RawSocketImpl;
42 class Icmpv6L4Protocol;
43 class Ipv6AutoconfiguredPrefix;
44 
59 class Ipv6L3Protocol : public Ipv6
60 {
61 public:
66  static TypeId GetTypeId ();
67 
71  static const uint16_t PROT_NUMBER;
72 
77  enum DropReason
78  {
84  };
85 
89  Ipv6L3Protocol ();
90 
94  virtual ~Ipv6L3Protocol ();
95 
100  void SetNode (Ptr<Node> node);
101 
106  void Insert (Ptr<IpL4Protocol> protocol);
107 
112  void Remove (Ptr<IpL4Protocol> protocol);
113 
119  Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
120 
126 
131  void DeleteRawSocket (Ptr<Socket> socket);
132 
137  void SetDefaultTtl (uint8_t ttl);
138 
143  void SetDefaultTclass (uint8_t tclass);
144 
156  void Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType);
157 
168  void Send (Ptr<Packet> packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route);
169 
174  void SetRoutingProtocol (Ptr<Ipv6RoutingProtocol> routingProtocol);
175 
181 
187  uint32_t AddInterface (Ptr<NetDevice> device);
188 
194  Ptr<Ipv6Interface> GetInterface (uint32_t i) const;
195 
200  uint32_t GetNInterfaces () const;
201 
207  int32_t GetInterfaceForAddress (Ipv6Address addr) const;
208 
215  int32_t GetInterfaceForPrefix (Ipv6Address addr, Ipv6Prefix mask) const;
216 
221  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
222 
228  bool AddAddress (uint32_t i, Ipv6InterfaceAddress address);
229 
236  Ipv6InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
237 
243  uint32_t GetNAddresses (uint32_t interface) const;
244 
250  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
251 
258  bool RemoveAddress (uint32_t interface, Ipv6Address address);
259 
265  void SetMetric (uint32_t i, uint16_t metric);
266 
272  uint16_t GetMetric (uint32_t i) const;
273 
279  uint16_t GetMtu (uint32_t i) const;
280 
286  virtual void SetPmtu (Ipv6Address dst, uint32_t pmtu);
287 
292  bool IsUp (uint32_t i) const;
293 
298  void SetUp (uint32_t i);
299 
304  void SetDown (uint32_t i);
305 
310  bool IsForwarding (uint32_t i) const;
311 
317  void SetForwarding (uint32_t i, bool val);
318 
324  Ptr<NetDevice> GetNetDevice (uint32_t i);
325 
331 
342  void AddAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter = Ipv6Address::GetZero ());
343 
353  void RemoveAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter);
354 
358  virtual void RegisterExtensions ();
359 
363  virtual void RegisterOptions ();
364 
365 protected:
369  virtual void DoDispose ();
370 
376  virtual void NotifyNewAggregate ();
377 
378 private:
379  /* for unit-tests */
382 
383  typedef std::list<Ptr<Ipv6Interface> > Ipv6InterfaceList;
384  typedef std::list<Ptr<Ipv6RawSocketImpl> > SocketList;
385  typedef std::list<Ptr<IpL4Protocol> > L4List_t;
386 
387  typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> > Ipv6AutoconfiguredPrefixList;
388  typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> >::iterator Ipv6AutoconfiguredPrefixListI;
389 
394 
399 
404 
409  Ipv6L3Protocol (const Ipv6L3Protocol& o);
410 
416 
426  Ipv6Header BuildHeader (Ipv6Address src, Ipv6Address dst, uint8_t protocol,
427  uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass);
428 
435  void SendRealOut (Ptr<Ipv6Route> route, Ptr<Packet> packet, Ipv6Header const& ipHeader);
436 
444  void IpForward (Ptr<const NetDevice> idev, Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header);
445 
454 
461  void LocalDeliver (Ptr<const Packet> p, Ipv6Header const& ip, uint32_t iif);
462 
469  void RouteInputError (Ptr<const Packet> p, const Ipv6Header& ipHeader, Socket::SocketErrno sockErrno);
470 
476  uint32_t AddIpv6Interface (Ptr<Ipv6Interface> interface);
477 
481  void SetupLoopback ();
482 
487  virtual void SetIpForward (bool forward);
488 
493  virtual bool GetIpForward () const;
494 
499  virtual void SetMtuDiscover (bool mtuDiscover);
500 
505  virtual bool GetMtuDiscover (void) const;
506 
511  virtual void SetSendIcmpv6Redirect (bool sendIcmpv6Redirect);
512 
517  virtual bool GetSendIcmpv6Redirect () const;
518 
523 
528 
533 
538 
543 
548 
552  uint32_t m_nInterfaces;
553 
557  uint8_t m_defaultTtl;
558 
563 
568 
573 
578 
583 };
584 
585 } /* namespace ns3 */
586 
587 #endif /* IPV6_L3_PROTOCOL_H */
588