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/ipv4-address.h"
27 #include "ns3/object.h"
28 #include "ns3/socket.h"
29 
30 #include <stdint.h>
31 
32 namespace ns3
33 {
34 
35 class Node;
36 class NetDevice;
37 class Packet;
38 class Ipv4RoutingProtocol;
39 class IpL4Protocol;
40 class Ipv4Header;
41 
78 class Ipv4 : public Object
79 {
80  public:
85  static TypeId GetTypeId();
86  Ipv4();
87  ~Ipv4() override;
88 
98  virtual void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) = 0;
99 
106 
116  virtual uint32_t AddInterface(Ptr<NetDevice> device) = 0;
117 
121  virtual uint32_t GetNInterfaces() const = 0;
122 
138  virtual int32_t GetInterfaceForAddress(Ipv4Address address) const = 0;
139 
150  virtual void Send(Ptr<Packet> packet,
151  Ipv4Address source,
152  Ipv4Address destination,
153  uint8_t protocol,
154  Ptr<Ipv4Route> route) = 0;
155 
164  virtual void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) = 0;
165 
175  virtual void Insert(Ptr<IpL4Protocol> protocol) = 0;
176 
190  virtual void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) = 0;
191 
198  virtual void Remove(Ptr<IpL4Protocol> protocol) = 0;
199 
205  virtual void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) = 0;
206 
227  virtual bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const = 0;
228 
245  virtual int32_t GetInterfaceForPrefix(Ipv4Address address, Ipv4Mask mask) const = 0;
246 
251  virtual Ptr<NetDevice> GetNetDevice(uint32_t interface) = 0;
252 
257  virtual int32_t GetInterfaceForDevice(Ptr<const NetDevice> device) const = 0;
258 
264  virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address) = 0;
265 
270  virtual uint32_t GetNAddresses(uint32_t interface) const = 0;
271 
280  virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const = 0;
281 
292  virtual bool RemoveAddress(uint32_t interface, uint32_t addressIndex) = 0;
293 
301  virtual bool RemoveAddress(uint32_t interface, Ipv4Address address) = 0;
302 
339  Ptr<const NetDevice> device,
340  Ipv4Address dst,
342 
348  virtual void SetMetric(uint32_t interface, uint16_t metric) = 0;
349 
355  virtual uint16_t GetMetric(uint32_t interface) const = 0;
356 
362  virtual uint16_t GetMtu(uint32_t interface) const = 0;
363 
369  virtual bool IsUp(uint32_t interface) const = 0;
370 
377  virtual void SetUp(uint32_t interface) = 0;
378 
385  virtual void SetDown(uint32_t interface) = 0;
386 
391  virtual bool IsForwarding(uint32_t interface) const = 0;
392 
399  virtual void SetForwarding(uint32_t interface, bool val) = 0;
400 
407  virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) = 0;
408 
417  virtual Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const = 0;
418 
425  virtual Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const = 0;
426 
433 
439  virtual void DeleteRawSocket(Ptr<Socket> socket) = 0;
440 
441  static const uint32_t IF_ANY = 0xffffffff;
442 
443  private:
444  // Indirect the Ipv4 attributes through private pure virtual methods
445 
450  virtual void SetIpForward(bool forward) = 0;
455  virtual bool GetIpForward() const = 0;
456 
463  virtual void SetWeakEsModel(bool model) = 0;
470  virtual bool GetWeakEsModel() const = 0;
471 };
472 
473 } // namespace ns3
474 
475 #endif /* IPV4_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Packet header for IPv4.
Definition: ipv4-header.h:34
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:79
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 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.
Ipv4()
Definition: ipv4.cc:64
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:441
static TypeId GetTypeId()
Get the type ID.
Definition: ipv4.cc:35
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:69
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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:78
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.