A Discrete-Event Network Simulator
API
arp-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) 2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef ARP_L3_PROTOCOL_H
21 #define ARP_L3_PROTOCOL_H
22 
23 #include <list>
24 #include "ns3/ipv4-header.h"
25 #include "ns3/net-device.h"
26 #include "ns3/address.h"
27 #include "ns3/ptr.h"
28 #include "ns3/traced-callback.h"
29 #include "ns3/random-variable-stream.h"
30 
31 namespace ns3 {
32 
33 class ArpCache;
34 class NetDevice;
35 class Node;
36 class Packet;
37 class Ipv4Interface;
38 
52 class ArpL3Protocol : public Object
53 {
54 public:
59  static TypeId GetTypeId (void);
60  static const uint16_t PROT_NUMBER;
61 
62  ArpL3Protocol ();
63  virtual ~ArpL3Protocol ();
64 
69  void SetNode (Ptr<Node> node);
70 
78 
88  void Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to,
89  NetDevice::PacketType packetType);
100  bool Lookup (Ptr<Packet> p, const Ipv4Header & ipHeader, Ipv4Address destination,
101  Ptr<NetDevice> device,
102  Ptr<ArpCache> cache,
103  Address *hardwareDestination);
104 
113  int64_t AssignStreams (int64_t stream);
114 
115 protected:
116  virtual void DoDispose (void);
117  /*
118  * This function will notify other components connected to the node that a new stack member is now connected
119  * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
120  */
121  virtual void NotifyNewAggregate ();
122 private:
123  typedef std::list<Ptr<ArpCache> > CacheList;
124 
130  ArpL3Protocol (const ArpL3Protocol &o);
139 
146 
160  void SendArpReply (Ptr<const ArpCache> cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac);
161 
162  CacheList m_cacheList;
166 
167 };
168 
169 } // namespace ns3
170 
171 
172 #endif /* ARP_L3_PROTOCOL_H */
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
void SendArpReply(Ptr< const ArpCache > cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac)
Send an ARP reply to an host.
Forward calls to a chain of Callback.
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
std::list< Ptr< ArpCache > > CacheList
container of the ARP caches
ArpL3Protocol & operator=(const ArpL3Protocol &o)
Copy constructor.
Ptr< ArpCache > CreateCache(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Create an ARP cache for the device/interface.
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by ARP
void SendArpRequest(Ptr< const ArpCache >cache, Ipv4Address to)
Send an ARP request to an host.
a polymophic address class
Definition: address.h:90
Packet header for IPv4.
Definition: ipv4-header.h:33
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
virtual void DoDispose(void)
Destructor implementation.
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Node > m_node
node the ARP L3 protocol is associated with
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void SetNode(Ptr< Node > node)
Set the node the ARP L3 protocol is associated with.
Ptr< RandomVariableStream > m_requestJitter
jitter to de-sync ARP requests
An implementation of the ARP protocol.
A base class which provides memory management and object aggregation.
Definition: object.h:87
CacheList m_cacheList
ARP cache container.
a unique identifier for an interface.
Definition: type-id.h:58
bool Lookup(Ptr< Packet > p, const Ipv4Header &ipHeader, Ipv4Address destination, Ptr< NetDevice > device, Ptr< ArpCache > cache, Address *hardwareDestination)
Perform an ARP lookup.
Ptr< ArpCache > FindCache(Ptr< NetDevice > device)
Finds the cache associated with a NetDevice.
static TypeId GetTypeId(void)
Get the type ID.