View | Details | Raw Unified | Return to bug 187
Collapse All | Expand All

(-)a/examples/csma-one-subnet.cc (+1 lines)
 Lines 80-85   main (int argc, char *argv[]) Link Here 
80
  NetDeviceContainer nd0 = csma.Install (c);
80
  NetDeviceContainer nd0 = csma.Install (c);
81
81
82
  InternetStackHelper internet;
82
  InternetStackHelper internet;
83
  internet.UseGodArp ();
83
  internet.Install (c);
84
  internet.Install (c);
84
85
85
// We've got the "hardware" in place.  Now we need to add IP addresses.
86
// We've got the "hardware" in place.  Now we need to add IP addresses.
(-)a/src/helper/internet-stack-helper.cc (-2 / +29 lines)
 Lines 47-52   InternetStackHelper::Cleanup (void) Link Here 
47
  m_traces.clear ();
47
  m_traces.clear ();
48
}
48
}
49
49
50
InternetStackHelper::InternetStackHelper ()
51
  : m_godArp (false)
52
{}
53
54
void 
55
InternetStackHelper::UseGodArp (void)
56
{
57
  m_godArp = true;
58
}
59
void 
60
InternetStackHelper::UseRealArp (void)
61
{
62
  m_godArp = false;
63
}
64
65
50
void 
66
void 
51
InternetStackHelper::Install (NodeContainer c)
67
InternetStackHelper::Install (NodeContainer c)
52
{
68
{
 Lines 58-65   InternetStackHelper::Install (NodeContai Link Here 
58
          NS_FATAL_ERROR ("InternetStackHelper::Install(): Aggregating " 
74
          NS_FATAL_ERROR ("InternetStackHelper::Install(): Aggregating " 
59
             "an InternetStack to a node with an existing Ipv4 object");
75
             "an InternetStack to a node with an existing Ipv4 object");
60
          return;
76
          return;
61
        } 
77
        }
62
      AddInternetStack (node);
78
      if (m_godArp)
79
        {
80
          InternetStack::AddGodArp (node);
81
        }
82
      else
83
        {
84
          InternetStack::AddRealArp (node);
85
        }
86
      InternetStack::AddIpv4 (node);
87
      InternetStack::AddUdp (node);
88
      InternetStack::AddTcp (node);
89
63
      Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
90
      Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
64
      node->AggregateObject (factory);
91
      node->AggregateObject (factory);
65
    }
92
    }
(-)a/src/helper/internet-stack-helper.h (+17 lines)
 Lines 33-38   class InternetStackHelper Link Here 
33
class InternetStackHelper
33
class InternetStackHelper
34
{
34
{
35
public:
35
public:
36
  InternetStackHelper ();
37
  /**
38
   * Every internet stack created with Install after calling this 
39
   * method will contain a 'God' ARP implementation.
40
   *
41
   * \sa ns3::GodArp
42
   */
43
  void UseGodArp (void);
44
  /*
45
   * Every internet stack created with Install after calling this 
46
   * method will contain a 'Real' ARP implementation.
47
   *
48
   * \sa ns3::Ipv4L3Protocol
49
   */
50
  void UseRealArp (void);
51
36
  /**
52
  /**
37
   * \param c the set of nodes
53
   * \param c the set of nodes
38
   *
54
   *
 Lines 72-77   private: Link Here 
72
  static std::string m_pcapBaseFilename;
88
  static std::string m_pcapBaseFilename;
73
  static uint32_t GetNodeIndex (std::string context);
89
  static uint32_t GetNodeIndex (std::string context);
74
  static std::vector<Trace> m_traces;
90
  static std::vector<Trace> m_traces;
91
  bool m_godArp;
75
};
92
};
76
93
77
} // namespace ns3
94
} // namespace ns3
(-)a/src/internet-node/arp-ipv4-interface.cc (-2 / +2 lines)
 Lines 76-83   ArpIpv4Interface::SendTo (Ptr<Packet> p, Link Here 
76
  if (GetDevice ()->NeedsArp ())
76
  if (GetDevice ()->NeedsArp ())
77
    {
77
    {
78
      NS_LOG_LOGIC ("Needs ARP");
78
      NS_LOG_LOGIC ("Needs ARP");
79
      Ptr<ArpL3Protocol> arp = 
79
      Ptr<Arp> arp = 
80
        m_node->GetObject<ArpL3Protocol> ();
80
        m_node->GetObject<Arp> ();
81
      Address hardwareDestination;
81
      Address hardwareDestination;
82
      bool found;
82
      bool found;
83
      
83
      
(-)a/src/internet-node/arp-l3-protocol.cc (-1 / +1 lines)
 Lines 40-46   ArpL3Protocol::GetTypeId (void) Link Here 
40
ArpL3Protocol::GetTypeId (void)
40
ArpL3Protocol::GetTypeId (void)
41
{
41
{
42
  static TypeId tid = TypeId ("ns3::ArpL3Protocol")
42
  static TypeId tid = TypeId ("ns3::ArpL3Protocol")
43
    .SetParent<Object> ()
43
    .SetParent<Arp> ()
44
    ;
44
    ;
45
  return tid;
45
  return tid;
46
}
46
}
(-)a/src/internet-node/arp-l3-protocol.h (-12 / +6 lines)
 Lines 21-26    Link Here 
21
#define ARP_L3_PROTOCOL_H
21
#define ARP_L3_PROTOCOL_H
22
22
23
#include <list>
23
#include <list>
24
#include "arp.h"
24
#include "ns3/ipv4-address.h"
25
#include "ns3/ipv4-address.h"
25
#include "ns3/address.h"
26
#include "ns3/address.h"
26
#include "ns3/ptr.h"
27
#include "ns3/ptr.h"
 Lines 35-41   class Packet; Link Here 
35
/**
36
/**
36
 * \brief An implementation of the ARP protocol
37
 * \brief An implementation of the ARP protocol
37
 */
38
 */
38
class ArpL3Protocol : public Object
39
class ArpL3Protocol : public Arp
39
{
40
{
40
public:
41
public:
41
  static TypeId GetTypeId (void);
42
  static TypeId GetTypeId (void);
 Lines 50-66   public: Link Here 
50
   * \brief Recieve a packet
51
   * \brief Recieve a packet
51
   */
52
   */
52
  void Receive(Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from);
53
  void Receive(Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from);
53
  /**
54
54
   * \brief Perform an ARP lookup
55
  virtual bool Lookup (Ptr<Packet> p, Ipv4Address destination, 
55
   * \param p
56
                       Ptr<NetDevice> device,
56
   * \param destination
57
                       Address *hardwareDestination);
57
   * \param device
58
   * \param hardwareDestination
59
   * \return 
60
   */
61
  bool Lookup (Ptr<Packet> p, Ipv4Address destination, 
62
	       Ptr<NetDevice> device,
63
	       Address *hardwareDestination);
64
protected:
58
protected:
65
  virtual void DoDispose (void);
59
  virtual void DoDispose (void);
66
private:
60
private:
(-)509c35cf49ae (+36 lines)
Added Link Here 
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
#include "arp.h"
21
22
namespace ns3 {
23
24
TypeId 
25
Arp::GetTypeId (void)
26
{
27
  static TypeId tid = TypeId ("ns3::Arp")
28
    .SetParent<Object> ()
29
    ;
30
  return tid;
31
}
32
33
Arp::~Arp ()
34
{}
35
36
} // namespace ns3
(-)509c35cf49ae (+62 lines)
Added Link Here 
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_H
21
#define ARP_H
22
23
#include <list>
24
#include "ns3/object.h"
25
#include "ns3/ipv4-address.h"
26
#include "ns3/ptr.h"
27
28
namespace ns3 {
29
30
class NetDevice;
31
class Node;
32
class Packet;
33
class Address;
34
35
/**
36
 * \brief An interface to access the functionality provided
37
 *        by the ARP layer.
38
 */
39
class Arp : public Object
40
{
41
public:
42
  static TypeId GetTypeId (void);
43
44
  virtual ~Arp ();
45
46
  /**
47
   * \brief Perform an ARP lookup
48
   * \param p
49
   * \param destination
50
   * \param device
51
   * \param hardwareDestination
52
   * \return 
53
   */
54
  virtual bool Lookup (Ptr<Packet> p, Ipv4Address destination, 
55
                       Ptr<NetDevice> device,
56
                       Address *hardwareDestination) = 0;
57
};
58
59
}//namespace ns3
60
61
62
#endif /* ARP_H */
(-)509c35cf49ae (+66 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2008 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
#include "god-arp.h"
21
#include "ns3/ipv4.h"
22
#include "ns3/channel.h"
23
#include "ns3/net-device.h"
24
#include "ns3/node.h"
25
26
namespace ns3 {
27
28
TypeId 
29
GodArp::GetTypeId (void)
30
{
31
  static TypeId tid = TypeId ("ns3::GodArp")
32
    .SetParent<Arp> ()
33
    ;
34
  return tid;
35
}
36
37
GodArp::GodArp ()
38
{}
39
  
40
bool 
41
GodArp::Lookup (Ptr<Packet> p, Ipv4Address destination, 
42
		Ptr<NetDevice> device,
43
		Address *hardwareDestination)
44
{
45
  Ptr<Channel> channel = device->GetChannel ();
46
  for (uint32_t i = 0; i < channel->GetNDevices (); ++i)
47
    {
48
      Ptr<NetDevice> remote = channel->GetDevice (i);
49
      Ptr<Node> remoteNode = remote->GetNode ();
50
      Ptr<Ipv4> remoteIpv4 = remoteNode->GetObject<Ipv4> ();
51
      if (remoteIpv4 == 0)
52
	{
53
	  continue;
54
	}
55
      int32_t index = remoteIpv4->FindInterfaceForDevice (remote);
56
      if (index == -1)
57
	{
58
	  continue;
59
	}
60
      *hardwareDestination = remote->GetAddress ();
61
      return true;
62
    }
63
  return false;
64
}
65
66
} // namespace ns3 
(-)509c35cf49ae (+41 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2008 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 GOD_ARP_H
21
#define GOD_ARP_H
22
23
#include "arp.h"
24
25
namespace ns3 {
26
27
class GodArp : public Arp
28
{
29
public:
30
  static TypeId GetTypeId (void);
31
  GodArp ();
32
  
33
  virtual bool Lookup (Ptr<Packet> p, Ipv4Address destination, 
34
                       Ptr<NetDevice> device,
35
                       Address *hardwareDestination);
36
};
37
38
39
} // namespace ns3
40
41
#endif /* GOD_ARP_H */
(-)a/src/internet-node/internet-stack.cc (-26 / +73 lines)
 Lines 27-77    Link Here 
27
#include "tcp-l4-protocol.h"
27
#include "tcp-l4-protocol.h"
28
#include "ipv4-l3-protocol.h"
28
#include "ipv4-l3-protocol.h"
29
#include "arp-l3-protocol.h"
29
#include "arp-l3-protocol.h"
30
#include "god-arp.h"
30
#include "udp-impl.h"
31
#include "udp-impl.h"
31
#include "tcp-impl.h"
32
#include "tcp-impl.h"
32
#include "ipv4-impl.h"
33
#include "ipv4-impl.h"
33
34
34
namespace ns3 {
35
namespace ns3 {
35
36
37
namespace InternetStack {
38
39
static Ptr<Ipv4L4Demux>
40
AddIpv4L4Demux (Ptr<Node> node)
41
{
42
43
  Ptr<Ipv4L4Demux> ipv4L4Demux = node->GetObject<Ipv4L4Demux> ();
44
  if (ipv4L4Demux != 0)
45
    {
46
      return ipv4L4Demux;
47
    }
48
  ipv4L4Demux = CreateObject<Ipv4L4Demux> ();
49
  ipv4L4Demux->SetNode (node);
50
  node->AggregateObject (ipv4L4Demux);
51
  return ipv4L4Demux;
52
}
53
54
void
55
AddTcp (Ptr<Node> node)
56
{
57
  Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
58
  tcp->SetNode (node);
59
  Ptr<Ipv4L4Demux> ipv4L4Demux = AddIpv4L4Demux (node);
60
  ipv4L4Demux->Insert (tcp);
61
  Ptr<TcpImpl> tcpImpl = CreateObject<TcpImpl> ();
62
  tcpImpl->SetTcp (tcp);
63
  node->AggregateObject (tcpImpl);
64
}
65
66
void
67
AddUdp (Ptr<Node> node)
68
{
69
  Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
70
  udp->SetNode (node);
71
  Ptr<Ipv4L4Demux> ipv4L4Demux = AddIpv4L4Demux (node);
72
  ipv4L4Demux->Insert (udp);
73
  Ptr<UdpImpl> udpImpl = CreateObject<UdpImpl> ();
74
  udpImpl->SetUdp (udp);
75
  node->AggregateObject (udpImpl);
76
}
77
36
void 
78
void 
37
AddInternetStack (Ptr<Node> node)
79
AddIpv4 (Ptr<Node> node)
38
{
80
{
39
  Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
81
  Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
40
  Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
41
  ipv4->SetNode (node);
82
  ipv4->SetNode (node);
42
  arp->SetNode (node);
43
  // XXX remove the PeekPointer below.
83
  // XXX remove the PeekPointer below.
44
  node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, PeekPointer (ipv4)), 
84
  node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, PeekPointer (ipv4)), 
45
                                 Ipv4L3Protocol::PROT_NUMBER, 0);
85
                                 Ipv4L3Protocol::PROT_NUMBER, 0);
46
  node->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (arp)),
47
                                 ArpL3Protocol::PROT_NUMBER, 0);
48
86
49
50
  Ptr<Ipv4L4Demux> ipv4L4Demux = CreateObject<Ipv4L4Demux> ();
51
  Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
52
  Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
53
54
  ipv4L4Demux->SetNode (node);
55
  udp->SetNode (node);
56
  tcp->SetNode (node);
57
58
  ipv4L4Demux->Insert (udp);
59
  ipv4L4Demux->Insert (tcp);
60
61
  Ptr<UdpImpl> udpImpl = CreateObject<UdpImpl> ();
62
  Ptr<TcpImpl> tcpImpl = CreateObject<TcpImpl> ();
63
  Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
87
  Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
64
65
  udpImpl->SetUdp (udp);
66
  tcpImpl->SetTcp (tcp);
67
  ipv4Impl->SetIpv4 (ipv4);
88
  ipv4Impl->SetIpv4 (ipv4);
68
89
69
  node->AggregateObject (ipv4);
90
  node->AggregateObject (ipv4);
70
  node->AggregateObject (arp);
71
  node->AggregateObject (ipv4Impl);
91
  node->AggregateObject (ipv4Impl);
72
  node->AggregateObject (udpImpl);
73
  node->AggregateObject (tcpImpl);
74
  node->AggregateObject (ipv4L4Demux);
75
}
92
}
76
93
94
void 
95
AddGodArp (Ptr<Node> node)
96
{
97
  Ptr<Arp> arp = CreateObject<GodArp> ();
98
  node->AggregateObject (arp);
99
}
100
101
void 
102
AddRealArp (Ptr<Node> node)
103
{
104
  // XXX remove the PeekPointer below.
105
  Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
106
  arp->SetNode (node);
107
  node->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (arp)),
108
                                 ArpL3Protocol::PROT_NUMBER, 0);
109
  node->AggregateObject (arp);
110
}
111
112
void 
113
AddAll (Ptr<Node> node)
114
{
115
  AddRealArp (node);
116
  AddIpv4 (node);
117
  AddUdp (node);
118
  AddTcp (node);
119
}
120
121
122
} // namespace InternetStack
123
77
}//namespace ns3
124
}//namespace ns3
(-)a/src/internet-node/internet-stack.h (-1 / +10 lines)
 Lines 26-32   namespace ns3 { Link Here 
26
26
27
class Node;
27
class Node;
28
28
29
void AddInternetStack (Ptr<Node> node);
29
namespace InternetStack {
30
31
void AddAll (Ptr<Node> node);
32
void AddGodArp (Ptr<Node> node);
33
void AddRealArp (Ptr<Node> node);
34
void AddIpv4 (Ptr<Node> node);
35
void AddUdp (Ptr<Node> node);
36
void AddTcp (Ptr<Node> node);
37
38
} // namespace InternetStack
30
39
31
}//namespace ns3
40
}//namespace ns3
32
41
(-)a/src/internet-node/udp-socket.cc (-2 / +2 lines)
 Lines 393-399   UdpSocketTest::RunTests (void) Link Here 
393
  
393
  
394
  // Receiver Node
394
  // Receiver Node
395
  Ptr<Node> rxNode = CreateObject<Node> ();
395
  Ptr<Node> rxNode = CreateObject<Node> ();
396
  AddInternetStack (rxNode);
396
  InternetStack::AddAll (rxNode);
397
  Ptr<SimpleNetDevice> rxDev1, rxDev2;
397
  Ptr<SimpleNetDevice> rxDev1, rxDev2;
398
  { // first interface
398
  { // first interface
399
    rxDev1 = CreateObject<SimpleNetDevice> ();
399
    rxDev1 = CreateObject<SimpleNetDevice> ();
 Lines 419-425   UdpSocketTest::RunTests (void) Link Here 
419
  
419
  
420
  // Sender Node
420
  // Sender Node
421
  Ptr<Node> txNode = CreateObject<Node> ();
421
  Ptr<Node> txNode = CreateObject<Node> ();
422
  AddInternetStack (txNode);
422
  InternetStack::AddAll (txNode);
423
  Ptr<SimpleNetDevice> txDev1;
423
  Ptr<SimpleNetDevice> txDev1;
424
  {
424
  {
425
    txDev1 = CreateObject<SimpleNetDevice> ();
425
    txDev1 = CreateObject<SimpleNetDevice> ();
(-)a/src/internet-node/wscript (+2 lines)
 Lines 17-22   def build(bld): Link Here 
17
        'ipv4-end-point.cc',
17
        'ipv4-end-point.cc',
18
        'udp-l4-protocol.cc',
18
        'udp-l4-protocol.cc',
19
        'tcp-l4-protocol.cc',
19
        'tcp-l4-protocol.cc',
20
        'arp.cc',
21
        'god-arp.cc',
20
        'arp-header.cc',
22
        'arp-header.cc',
21
        'arp-cache.cc',
23
        'arp-cache.cc',
22
        'arp-ipv4-interface.cc',
24
        'arp-ipv4-interface.cc',

Return to bug 187