author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Wed, 18 Jul 2007 11:43:39 +0100 | |
changeset 933 | df68dad55087 |
parent 745 | 221fda1d30f8 |
child 934 | 1bfcc65213c7 |
child 1167 | 2cb083ff04c6 |
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" |
242 | 28 |
|
29 |
#include "arp-ipv4-interface.h" |
|
740
1d6ce43097d9
i-arp-private.h -> arp-private.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
734
diff
changeset
|
30 |
#include "arp-private.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" |
242 | 32 |
|
33 |
namespace ns3 { |
|
34 |
||
728
95c426b1cb60
rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
607
diff
changeset
|
35 |
ArpIpv4Interface::ArpIpv4Interface (Ptr<Node> node, Ptr<NetDevice> device) |
242 | 36 |
: Ipv4Interface (device), |
37 |
m_node (node) |
|
553
eb9d614accf0
convert more code to use Ptr<Node> instead of Node *
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
38 |
{} |
242 | 39 |
ArpIpv4Interface::~ArpIpv4Interface () |
553
eb9d614accf0
convert more code to use Ptr<Node> instead of Node *
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
40 |
{} |
242 | 41 |
|
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
|
42 |
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
|
43 |
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
|
44 |
{ |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
{ |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
48 |
resolver->Add ("netdevice", |
573
0da9201a048e
rename Ptr::Get and Ptr::Peek to GetPointer and PeekPointer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
568
diff
changeset
|
49 |
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
|
50 |
ArpIpv4Interface::NETDEVICE); |
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 |
} |
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 |
|
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
53 |
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
|
54 |
} |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
303
diff
changeset
|
55 |
|
242 | 56 |
void |
57 |
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) |
|
58 |
{ |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
553
diff
changeset
|
59 |
NS_ASSERT (GetDevice () != 0); |
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
553
diff
changeset
|
60 |
if (GetDevice ()->NeedsArp ()) |
242 | 61 |
{ |
745
221fda1d30f8
IIpv4Impl -> Ipv4Impl
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
740
diff
changeset
|
62 |
Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid); |
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
63 |
MacAddress 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
|
64 |
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
|
65 |
|
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
|
66 |
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
|
67 |
{ |
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
|
68 |
hardwareDestination = GetDevice ()->GetBroadcast (); |
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
|
69 |
found = true; |
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
|
70 |
} |
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
|
71 |
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
|
72 |
{ |
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
|
73 |
Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid); |
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
|
74 |
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
|
75 |
} |
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 |
|
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
77 |
if (found) |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
78 |
{ |
734
039fb338b6e9
Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
733
diff
changeset
|
79 |
GetDevice ()->Send (p, hardwareDestination, Ipv4L3Protocol::PROT_NUMBER); |
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
80 |
} |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
81 |
} |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
82 |
else |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
83 |
{ |
734
039fb338b6e9
Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
733
diff
changeset
|
84 |
GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), Ipv4L3Protocol::PROT_NUMBER); |
242 | 85 |
} |
86 |
} |
|
87 |
||
88 |
}//namespace ns3 |