author | Craig Dowell <craigdo@ee.washington.edu> |
Sun, 12 Aug 2007 22:41:24 -0700 | |
changeset 1430 | 25fa26a6533e |
parent 1229 | e4cfe4094c10 |
child 1432 | 3aef7d7a71c2 |
permissions | -rw-r--r-- |
242 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2007 INRIA |
|
4 |
* All rights reserved. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License version 2 as |
|
8 |
* published by the Free Software Foundation; |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
* |
|
19 |
* Authors: |
|
20 |
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>, |
|
21 |
*/ |
|
22 |
||
23 |
#include "ns3/packet.h" |
|
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
24 |
#include "ns3/debug.h" |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
25 |
#include "ns3/composite-trace-resolver.h" |
729
b5e744285e92
rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
728
diff
changeset
|
26 |
#include "ns3/node.h" |
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
521
diff
changeset
|
27 |
#include "ns3/net-device.h" |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
745
diff
changeset
|
28 |
#include "ns3/address.h" |
242 | 29 |
|
30 |
#include "arp-ipv4-interface.h" |
|
733
fb1882e7d785
rename ipv4.h to ipv4-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
31 |
#include "ipv4-l3-protocol.h" |
1177
c7bf3cf186ac
remove now-unused ArpPrivate class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
32 |
#include "arp-l3-protocol.h" |
242 | 33 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
34 |
NS_DEBUG_COMPONENT_DEFINE ("ArpIpv4Interface"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
35 |
|
242 | 36 |
namespace ns3 { |
37 |
||
728
95c426b1cb60
rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
607
diff
changeset
|
38 |
ArpIpv4Interface::ArpIpv4Interface (Ptr<Node> node, Ptr<NetDevice> device) |
242 | 39 |
: Ipv4Interface (device), |
40 |
m_node (node) |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
41 |
{ |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
42 |
NS_DEBUG ("ArpIpv4Interface::ArpIpv4Interface ()"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
43 |
} |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
44 |
|
242 | 45 |
ArpIpv4Interface::~ArpIpv4Interface () |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
46 |
{ |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
47 |
NS_DEBUG ("ArpIpv4Interface::~ArpIpv4Interface ()"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
48 |
} |
242 | 49 |
|
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
50 |
TraceResolver * |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
51 |
ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
52 |
{ |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
53 |
NS_DEBUG ("ArpIpv4Interface::DoCreateTraceResolver ()"); |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
54 |
CompositeTraceResolver *resolver = new CompositeTraceResolver (context); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
553
diff
changeset
|
55 |
if (GetDevice () != 0) |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
56 |
{ |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
57 |
resolver->Add ("netdevice", |
1229
e4cfe4094c10
build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
58 |
MakeCallback (&NetDevice::CreateTraceResolver, PeekPointer (GetDevice ()))); |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
59 |
} |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
60 |
|
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
61 |
return resolver; |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
62 |
} |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
63 |
|
242 | 64 |
void |
65 |
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) |
|
66 |
{ |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
67 |
NS_DEBUG ("ArpIpv4Interface::SendTo (" << &p << ", " << dest << ")"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
68 |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
553
diff
changeset
|
69 |
NS_ASSERT (GetDevice () != 0); |
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
553
diff
changeset
|
70 |
if (GetDevice ()->NeedsArp ()) |
242 | 71 |
{ |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
72 |
NS_DEBUG ("ArpIpv4Interface::SendTo (): Needs ARP"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
73 |
Ptr<ArpL3Protocol> arp = |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
74 |
m_node->QueryInterface<ArpL3Protocol> (ArpL3Protocol::iid); |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
745
diff
changeset
|
75 |
Address hardwareDestination; |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
76 |
bool found; |
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
77 |
|
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
78 |
if (dest.IsBroadcast ()) |
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
79 |
{ |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
80 |
NS_DEBUG ("ArpIpv4Interface::SendTo (): IsBroadcast"); |
1177
c7bf3cf186ac
remove now-unused ArpPrivate class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
81 |
hardwareDestination = GetDevice ()->GetBroadcast (); |
c7bf3cf186ac
remove now-unused ArpPrivate class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
82 |
found = true; |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
83 |
} |
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
84 |
else |
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
85 |
{ |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
86 |
NS_DEBUG ("ArpIpv4Interface::SendTo (): ARP Lookup"); |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
87 |
found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); |
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
88 |
} |
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
745
diff
changeset
|
89 |
|
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
90 |
if (found) |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
91 |
{ |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
92 |
NS_DEBUG ("ArpIpv4Interface::SendTo (): Address Resolved. Send."); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
93 |
GetDevice ()->Send (p, hardwareDestination, |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
94 |
Ipv4L3Protocol::PROT_NUMBER); |
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
95 |
} |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
96 |
} |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
97 |
else |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
98 |
{ |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
99 |
NS_DEBUG ("ArpIpv4Interface::SendTo (): Doesn't need ARP"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
100 |
GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
101 |
Ipv4L3Protocol::PROT_NUMBER); |
242 | 102 |
} |
103 |
} |
|
104 |
||
105 |
}//namespace ns3 |