|
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" |
|
24 #include "ns3/composite-trace-resolver.h" |
|
25 #include "ns3/node.h" |
|
26 #include "ns3/net-device.h" |
|
27 |
|
28 #include "arp-ipv4-interface.h" |
|
29 #include "i-arp-private.h" |
|
30 #include "ipv4.h" |
|
31 |
|
32 namespace ns3 { |
|
33 |
|
34 ArpIpv4Interface::ArpIpv4Interface (Node *node, NetDevice *device) |
|
35 : Ipv4Interface (device), |
|
36 m_node (node) |
|
37 { |
|
38 m_node->Ref (); |
|
39 } |
|
40 ArpIpv4Interface::~ArpIpv4Interface () |
|
41 { |
|
42 m_node->Unref (); |
|
43 } |
|
44 |
|
45 TraceResolver * |
|
46 ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) |
|
47 { |
|
48 CompositeTraceResolver *resolver = new CompositeTraceResolver (context); |
|
49 if (PeekDevice () != 0) |
|
50 { |
|
51 resolver->Add ("netdevice", |
|
52 MakeCallback (&NetDevice::CreateTraceResolver, PeekDevice ()), |
|
53 ArpIpv4Interface::NETDEVICE); |
|
54 } |
|
55 |
|
56 return resolver; |
|
57 } |
|
58 |
|
59 void |
|
60 ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) |
|
61 { |
|
62 NS_ASSERT (PeekDevice () != 0); |
|
63 if (PeekDevice ()->NeedsArp ()) |
|
64 { |
|
65 IArpPrivate * arp = m_node->QueryInterface<IArpPrivate> (IArpPrivate::iid); |
|
66 MacAddress hardwareDestination; |
|
67 bool found = arp->Lookup (p, dest, PeekDevice (), &hardwareDestination); |
|
68 if (found) |
|
69 { |
|
70 PeekDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER); |
|
71 } |
|
72 arp->Unref (); |
|
73 } |
|
74 else |
|
75 { |
|
76 PeekDevice ()->Send (p, PeekDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER); |
|
77 } |
|
78 } |
|
79 |
|
80 }//namespace ns3 |