A Discrete-Event Network Simulator
API
ipv4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef IPV4_H
20 #define IPV4_H
21 
22 #include "ipv4-interface-address.h"
23 #include "ipv4-route.h"
24 
25 #include "ns3/callback.h"
26 #include "ns3/deprecated.h"
27 #include "ns3/ipv4-address.h"
28 #include "ns3/object.h"
29 #include "ns3/socket.h"
30 
31 #include <stdint.h>
32 
33 namespace ns3
34 {
35 
36 class Node;
37 class NetDevice;
38 class Packet;
39 class Ipv4RoutingProtocol;
40 class IpL4Protocol;
41 class Ipv4Header;
42 
79 class Ipv4 : public Object
80 {
81  public:
86  static TypeId GetTypeId();
87  Ipv4();
88  ~Ipv4() override;
89 
99  virtual void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) = 0;
100 
107 
117  virtual uint32_t AddInterface(Ptr<NetDevice> device) = 0;
118 
122  virtual uint32_t GetNInterfaces() const = 0;
123 
139  virtual int32_t GetInterfaceForAddress(Ipv4Address address) const = 0;
140 
151  virtual void Send(Ptr<Packet> packet,
152  Ipv4Address source,
153  Ipv4Address destination,
154  uint8_t protocol,
155  Ptr<Ipv4Route> route) = 0;
156 
165  virtual void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) = 0;
166 
176  virtual void Insert(Ptr<IpL4Protocol> protocol) = 0;
177 
191  virtual void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) = 0;
192 
199  virtual void Remove(Ptr<IpL4Protocol> protocol) = 0;
200 
206  virtual void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) = 0;
207 
228  virtual bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const = 0;
229 
246  virtual int32_t GetInterfaceForPrefix(Ipv4Address address, Ipv4Mask mask) const = 0;
247 
252  virtual Ptr<NetDevice> GetNetDevice(uint32_t interface) = 0;
253 
258  virtual int32_t GetInterfaceForDevice(Ptr<const NetDevice> device) const = 0;
259 
265  virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address) = 0;
266 
271  virtual uint32_t GetNAddresses(uint32_t interface) const = 0;
272 
281  virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const = 0;
282 
293  virtual bool RemoveAddress(uint32_t interface, uint32_t addressIndex) = 0;
294 
302  virtual bool RemoveAddress(uint32_t interface, Ipv4Address address) = 0;
303 
340  Ptr<const NetDevice> device,
341  Ipv4Address dst,
343 
349  virtual void SetMetric(uint32_t interface, uint16_t metric) = 0;
350 
356  virtual uint16_t GetMetric(uint32_t interface) const = 0;
357 
363  virtual uint16_t GetMtu(uint32_t interface) const = 0;
364 
370  virtual bool IsUp(uint32_t interface) const = 0;
371 
378  virtual void SetUp(uint32_t interface) = 0;
379 
386  virtual void SetDown(uint32_t interface) = 0;
387 
392  virtual bool IsForwarding(uint32_t interface) const = 0;
393 
400  virtual void SetForwarding(uint32_t interface, bool val) = 0;
401 
408  virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) = 0;
409 
418  virtual Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const = 0;
419 
426  virtual Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const = 0;
427 
434 
440  virtual void DeleteRawSocket(Ptr<Socket> socket) = 0;
441 
442  static const uint32_t IF_ANY = 0xffffffff;
443 
444  private:
445  // Indirect the Ipv4 attributes through private pure virtual methods
446 
451  virtual void SetIpForward(bool forward) = 0;
456  virtual bool GetIpForward() const = 0;
457 
465  NS_DEPRECATED_3_41("Use GetStrongEndSystemModel instead")
466  virtual bool GetWeakEsModel() const = 0;
467 
476  virtual void SetWeakEsModel(bool model) = 0;
477 
484  virtual void SetStrongEndSystemModel(bool model) = 0;
491  virtual bool GetStrongEndSystemModel() const = 0;
492 };
493 
494 } // namespace ns3
495 
496 #endif /* IPV4_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Packet header for IPv4.
Definition: ipv4-header.h:34
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
virtual int32_t GetInterfaceForAddress(Ipv4Address address) const =0
Return the interface number of the interface that has been assigned the specified IP address.
virtual bool GetIpForward() const =0
Get the IP forwarding state.
virtual bool GetStrongEndSystemModel() const =0
Get the Strong End System Model status.
virtual void SetIpForward(bool forward)=0
Set or unset the IP forwarding state.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber, int32_t interfaceIndex) const =0
Get L4 protocol by protocol number for the specified interface.
virtual void SetStrongEndSystemModel(bool model)=0
Set or unset the Strong End System Model.
Ipv4()
Definition: ipv4.cc:76
virtual void DeleteRawSocket(Ptr< Socket > socket)=0
Deletes a particular raw socket.
virtual bool IsForwarding(uint32_t interface) const =0
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
virtual void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)=0
Register a new routing protocol to be used by this Ipv4 stack.
virtual void SetWeakEsModel(bool model)=0
Set or unset the Weak Es Model.
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
virtual void Insert(Ptr< IpL4Protocol > protocol)=0
virtual uint32_t GetNAddresses(uint32_t interface) const =0
virtual void Remove(Ptr< IpL4Protocol > protocol)=0
virtual bool RemoveAddress(uint32_t interface, Ipv4Address address)=0
Remove the given address on named Ipv4 interface.
virtual uint16_t GetMtu(uint32_t interface) const =0
virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
virtual bool GetWeakEsModel() const =0
Get the Weak Es Model status.
virtual void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route)=0
virtual void SetUp(uint32_t interface)=0
virtual Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)=0
Return the first primary source address with scope less than or equal to the requested scope,...
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const =0
Get the routing protocol to be used by this Ipv4 stack.
virtual void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)=0
virtual bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const =0
Determine whether address and interface corresponding to received packet can be accepted for local de...
virtual void Insert(Ptr< IpL4Protocol > protocol, uint32_t interfaceIndex)=0
Add a L4 protocol to a specific interface.
static const uint32_t IF_ANY
interface wildcard, meaning any interface
Definition: ipv4.h:442
static TypeId GetTypeId()
Get the type ID.
Definition: ipv4.cc:36
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
virtual int32_t GetInterfaceForPrefix(Ipv4Address address, Ipv4Mask mask) const =0
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
virtual void SetDown(uint32_t interface)=0
virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest)=0
Choose the source address to use with destination address.
virtual bool RemoveAddress(uint32_t interface, uint32_t addressIndex)=0
Remove the address at addressIndex on named interface.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const =0
virtual uint16_t GetMetric(uint32_t interface) const =0
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual uint32_t GetNInterfaces() const =0
virtual Ptr< Socket > CreateRawSocket()=0
Creates a raw socket.
virtual void Remove(Ptr< IpL4Protocol > protocol, uint32_t interfaceIndex)=0
Remove a L4 protocol from a specific interface.
virtual void SetForwarding(uint32_t interface, bool val)=0
virtual bool IsUp(uint32_t interface) const =0
~Ipv4() override
Definition: ipv4.cc:81
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
#define NS_DEPRECATED_3_41(msg)
Tag for things deprecated in version ns-3.41.
Definition: deprecated.h:82
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.