src/internet-node/arp-l3-protocol.h
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Thu, 29 May 2008 09:34:31 +0100
changeset 3172 e661e08c3211
parent 3152 4260de124c74
child 3185 c859e129a934
permissions -rw-r--r--
Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
752
a4febfb8416f IIpv4 -> Ipv4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 736
diff changeset
    20
#ifndef ARP_L3_PROTOCOL_H
a4febfb8416f IIpv4 -> Ipv4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 736
diff changeset
    21
#define ARP_L3_PROTOCOL_H
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include <list>
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
    24
#include "ns3/ipv4-address.h"
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 752
diff changeset
    25
#include "ns3/address.h"
552
b5f29caf9d8c convert Arp code to use Ptr<Node> instead of Node *
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 551
diff changeset
    26
#include "ns3/ptr.h"
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    27
#include "ns3/traced-callback.h"
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
3172
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3152
diff changeset
    29
#include "ipv4-interface.h"
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3152
diff changeset
    30
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
class ArpCache;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
class NetDevice;
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    35
class Node;
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
class Packet;
3021
5b1479210da3 Removed TraceContext and TraceResolver references, removed MobilityModelNotifier class, and minor changes on samples/main-random-walk.cc.
tjkopena@cs.drexel.edu
parents: 2834
diff changeset
    37
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    38
/**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    39
 * \brief An implementation of the ARP protocol
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    40
 */
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1161
diff changeset
    41
class ArpL3Protocol : public Object
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
{
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
public:
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    44
  static TypeId GetTypeId (void);
294
aba9a34108d2 remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
    45
  static const uint16_t PROT_NUMBER;
2595
b504951bcca8 fix doxygen errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    46
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    47
  ArpL3Protocol ();
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1161
diff changeset
    48
  virtual ~ArpL3Protocol ();
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    49
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    50
  void SetNode (Ptr<Node> node);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    51
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
    52
  Ptr<ArpCache> CreateCache (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
    53
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    54
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    55
   * \brief Recieve a packet
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    56
   */
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1412
diff changeset
    57
  void Receive(Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from);
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    58
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    59
   * \brief Perform an ARP lookup
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    60
   * \param p
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    61
   * \param destination
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    62
   * \param device
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    63
   * \param hardwareDestination
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    64
   * \return 
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    65
   */
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1412
diff changeset
    66
  bool Lookup (Ptr<Packet> p, Ipv4Address destination, 
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
    67
	       Ptr<NetDevice> device,
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
    68
               Ptr<ArpCache> cache,
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 752
diff changeset
    69
	       Address *hardwareDestination);
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
    70
protected:
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
    71
  virtual void DoDispose (void);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
private:
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3021
diff changeset
    73
  typedef std::list<Ptr<ArpCache> > CacheList;
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3021
diff changeset
    74
  Ptr<ArpCache> FindCache (Ptr<NetDevice> device);
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3021
diff changeset
    75
  void SendArpRequest (Ptr<const ArpCache>cache, Ipv4Address to);
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3021
diff changeset
    76
  void SendArpReply (Ptr<const ArpCache> cache, Ipv4Address toIp, Address toMac);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  CacheList m_cacheList;
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    78
  Ptr<Node> m_node;
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    79
  TracedCallback<Ptr<const Packet> > m_dropTrace;
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
};
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
}//namespace ns3
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
752
a4febfb8416f IIpv4 -> Ipv4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 736
diff changeset
    85
#endif /* ARP_L3_PROTOCOL_H */