author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Tue, 06 Nov 2007 15:05:56 +0100 | |
changeset 2081 | 434742b27b1e |
parent 1505 | 286ec92f4113 |
child 1828 | 6ab68edddf45 |
child 1866 | e7dbcc4df546 |
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" |
|
1505 | 24 |
#include "ns3/log.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 |
|
1505 | 34 |
NS_LOG_COMPONENT_DEFINE ("ArpIpv4Interface"); |
1430
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 |
{ |
1505 | 42 |
NS_LOG_FUNCTION; |
1430
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 |
{ |
1505 | 47 |
NS_LOG_FUNCTION; |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
48 |
} |
242 | 49 |
|
1333
c0d66de933e9
convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1325
diff
changeset
|
50 |
Ptr<TraceResolver> |
1383 | 51 |
ArpIpv4Interface::GetTraceResolver (void) const |
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
|
52 |
{ |
1505 | 53 |
NS_LOG_FUNCTION; |
1333
c0d66de933e9
convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1325
diff
changeset
|
54 |
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> (); |
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 |
{ |
1386
f2ee41c3e788
avoid method naming ambiguity in CompositeTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1383
diff
changeset
|
57 |
resolver->AddComposite ("netdevice", 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
|
58 |
} |
1386
f2ee41c3e788
avoid method naming ambiguity in CompositeTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1383
diff
changeset
|
59 |
resolver->SetParentResolver (Ipv4Interface::GetTraceResolver ()); |
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
|
60 |
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
|
61 |
} |
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 |
|
242 | 63 |
void |
64 |
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) |
|
65 |
{ |
|
1505 | 66 |
NS_LOG_FUNCTION; |
67 |
NS_LOG_PARAM ("(" << &p << ", " << dest << ")"); |
|
1430
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 |
{ |
1505 | 72 |
NS_LOG_LOGIC ("Needs ARP"); |
1430
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; |
1318
89b78e2d521e
Fix for bug69: set local address correctly upon UDP connect; apply correct UDP connect() semantics (that sendto cannot override addresses on a connected socket); if destination is IPv4 limited broadcast address, convert to subnet-directed broadcast and send out on each interface; provide example csma-broadcast.cc script
Tom Henderson <tomh@tomh.org>
parents:
1229
diff
changeset
|
77 |
|
89b78e2d521e
Fix for bug69: set local address correctly upon UDP connect; apply correct UDP connect() semantics (that sendto cannot override addresses on a connected socket); if destination is IPv4 limited broadcast address, convert to subnet-directed broadcast and send out on each interface; provide example csma-broadcast.cc script
Tom Henderson <tomh@tomh.org>
parents:
1229
diff
changeset
|
78 |
if (dest.IsBroadcast () || |
89b78e2d521e
Fix for bug69: set local address correctly upon UDP connect; apply correct UDP connect() semantics (that sendto cannot override addresses on a connected socket); if destination is IPv4 limited broadcast address, convert to subnet-directed broadcast and send out on each interface; provide example csma-broadcast.cc script
Tom Henderson <tomh@tomh.org>
parents:
1229
diff
changeset
|
79 |
dest.IsSubnetDirectedBroadcast (GetNetworkMask ()) ) |
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
|
80 |
{ |
1505 | 81 |
NS_LOG_LOGIC ("IsBroadcast"); |
1177
c7bf3cf186ac
remove now-unused ArpPrivate class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
82 |
hardwareDestination = GetDevice ()->GetBroadcast (); |
c7bf3cf186ac
remove now-unused ArpPrivate class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
83 |
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
|
84 |
} |
1432
3aef7d7a71c2
more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
85 |
else if (dest.IsMulticast ()) |
3aef7d7a71c2
more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
86 |
{ |
1505 | 87 |
NS_LOG_LOGIC ("IsMulticast"); |
1441
d6f8a7546e7f
semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
88 |
NS_ASSERT_MSG(GetDevice ()->IsMulticast (), |
d6f8a7546e7f
semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
89 |
"ArpIpv4Interface::SendTo (): Sending multicast packet over " |
d6f8a7546e7f
semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
90 |
"non-multicast device"); |
1442
bb5cf98c0c64
real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents:
1441
diff
changeset
|
91 |
|
1443
580ed7a4dd1e
Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents:
1442
diff
changeset
|
92 |
hardwareDestination = GetDevice ()->MakeMulticastAddress(dest); |
1432
3aef7d7a71c2
more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
93 |
found = true; |
3aef7d7a71c2
more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
94 |
} |
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
|
95 |
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
|
96 |
{ |
1505 | 97 |
NS_LOG_LOGIC ("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
|
98 |
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
|
99 |
} |
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
|
100 |
|
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
101 |
if (found) |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
102 |
{ |
1505 | 103 |
NS_LOG_LOGIC ("Address Resolved. Send."); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
104 |
GetDevice ()->Send (p, hardwareDestination, |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
105 |
Ipv4L3Protocol::PROT_NUMBER); |
446
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
106 |
} |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
107 |
} |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
108 |
else |
ceecc7397053
use NetDevice::NeedsArp where needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
109 |
{ |
1505 | 110 |
NS_LOG_LOGIC ("Doesn't need ARP"); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
111 |
GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1229
diff
changeset
|
112 |
Ipv4L3Protocol::PROT_NUMBER); |
242 | 113 |
} |
114 |
} |
|
115 |
||
116 |
}//namespace ns3 |