|
mathieu@2833
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
mathieu@2833
|
2 |
/*
|
|
mathieu@2833
|
3 |
* Copyright (c) 2008 INRIA
|
|
mathieu@2833
|
4 |
*
|
|
mathieu@2833
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
mathieu@2833
|
6 |
* it under the terms of the GNU General Public License version 2 as
|
|
mathieu@2833
|
7 |
* published by the Free Software Foundation;
|
|
mathieu@2833
|
8 |
*
|
|
mathieu@2833
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
mathieu@2833
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
mathieu@2833
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
mathieu@2833
|
12 |
* GNU General Public License for more details.
|
|
mathieu@2833
|
13 |
*
|
|
mathieu@2833
|
14 |
* You should have received a copy of the GNU General Public License
|
|
mathieu@2833
|
15 |
* along with this program; if not, write to the Free Software
|
|
mathieu@2833
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
mathieu@2833
|
17 |
*
|
|
mathieu@2833
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
mathieu@2833
|
19 |
*/
|
|
mathieu@2673
|
20 |
#include "simple-net-device.h"
|
|
mathieu@2673
|
21 |
#include "simple-channel.h"
|
|
mathieu@2673
|
22 |
#include "node.h"
|
|
mathieu@2673
|
23 |
#include "ns3/packet.h"
|
|
mathieu@2673
|
24 |
|
|
mathieu@2673
|
25 |
namespace ns3 {
|
|
mathieu@2673
|
26 |
|
|
mathieu@2673
|
27 |
TypeId
|
|
mathieu@2673
|
28 |
SimpleNetDevice::GetTypeId (void)
|
|
mathieu@2673
|
29 |
{
|
|
mathieu@2673
|
30 |
static TypeId tid = TypeId ("ns3::SimpleNetDevice")
|
|
mathieu@2673
|
31 |
.SetParent<NetDevice> ()
|
|
mathieu@2673
|
32 |
.AddConstructor<SimpleNetDevice> ()
|
|
mathieu@2673
|
33 |
;
|
|
mathieu@2673
|
34 |
return tid;
|
|
mathieu@2673
|
35 |
}
|
|
mathieu@2673
|
36 |
|
|
mathieu@2673
|
37 |
SimpleNetDevice::SimpleNetDevice ()
|
|
mathieu@2673
|
38 |
: m_channel (0),
|
|
mathieu@2673
|
39 |
m_node (0),
|
|
mathieu@2673
|
40 |
m_mtu (0xffff),
|
|
mathieu@2673
|
41 |
m_name (""),
|
|
mathieu@2673
|
42 |
m_ifIndex (0)
|
|
mathieu@2673
|
43 |
{}
|
|
mathieu@2673
|
44 |
|
|
mathieu@2673
|
45 |
void
|
|
mathieu@2673
|
46 |
SimpleNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
|
|
mathieu@2673
|
47 |
Mac48Address to, Mac48Address from)
|
|
mathieu@2673
|
48 |
{
|
|
gjc@3448
|
49 |
NetDevice::PacketType packetType;
|
|
gjc@3448
|
50 |
if (to == m_address)
|
|
mathieu@2673
|
51 |
{
|
|
gjc@3448
|
52 |
packetType = NetDevice::PACKET_HOST;
|
|
mathieu@2673
|
53 |
}
|
|
mathieu@3584
|
54 |
else if (to.IsBroadcast ())
|
|
gjc@3448
|
55 |
{
|
|
gjc@3448
|
56 |
packetType = NetDevice::PACKET_HOST;
|
|
gjc@3448
|
57 |
}
|
|
mathieu@3584
|
58 |
else if (to.IsMulticast ())
|
|
gjc@3448
|
59 |
{
|
|
mathieu@3584
|
60 |
packetType = NetDevice::PACKET_MULTICAST;
|
|
mathieu@3584
|
61 |
}
|
|
mathieu@3584
|
62 |
else
|
|
mathieu@3584
|
63 |
{
|
|
mathieu@3584
|
64 |
packetType = NetDevice::PACKET_OTHERHOST;
|
|
gjc@3448
|
65 |
}
|
|
gjc@3460
|
66 |
m_rxCallback (this, packet, protocol, from);
|
|
mathieu@3584
|
67 |
if (!m_promiscCallback.IsNull ())
|
|
mathieu@3584
|
68 |
{
|
|
mathieu@3584
|
69 |
m_promiscCallback (this, packet, protocol, from, to, packetType);
|
|
mathieu@3584
|
70 |
}
|
|
mathieu@2673
|
71 |
}
|
|
mathieu@2673
|
72 |
|
|
mathieu@2673
|
73 |
void
|
|
mathieu@2673
|
74 |
SimpleNetDevice::SetChannel (Ptr<SimpleChannel> channel)
|
|
mathieu@2673
|
75 |
{
|
|
mathieu@2673
|
76 |
m_channel = channel;
|
|
mathieu@2673
|
77 |
m_channel->Add (this);
|
|
mathieu@2673
|
78 |
}
|
|
mathieu@2673
|
79 |
|
|
mathieu@2673
|
80 |
void
|
|
mathieu@2673
|
81 |
SimpleNetDevice::SetAddress (Mac48Address address)
|
|
mathieu@2673
|
82 |
{
|
|
mathieu@2673
|
83 |
m_address = address;
|
|
mathieu@2673
|
84 |
}
|
|
mathieu@2673
|
85 |
|
|
mathieu@2673
|
86 |
void
|
|
mathieu@2673
|
87 |
SimpleNetDevice::SetName(const std::string name)
|
|
mathieu@2673
|
88 |
{
|
|
mathieu@2673
|
89 |
m_name = name;
|
|
mathieu@2673
|
90 |
}
|
|
mathieu@2673
|
91 |
std::string
|
|
mathieu@2673
|
92 |
SimpleNetDevice::GetName(void) const
|
|
mathieu@2673
|
93 |
{
|
|
mathieu@2673
|
94 |
return m_name;
|
|
mathieu@2673
|
95 |
}
|
|
mathieu@2673
|
96 |
void
|
|
mathieu@2673
|
97 |
SimpleNetDevice::SetIfIndex(const uint32_t index)
|
|
mathieu@2673
|
98 |
{
|
|
mathieu@2673
|
99 |
m_ifIndex = index;
|
|
mathieu@2673
|
100 |
}
|
|
mathieu@2673
|
101 |
uint32_t
|
|
mathieu@2673
|
102 |
SimpleNetDevice::GetIfIndex(void) const
|
|
mathieu@2673
|
103 |
{
|
|
mathieu@2673
|
104 |
return m_ifIndex;
|
|
mathieu@2673
|
105 |
}
|
|
mathieu@2673
|
106 |
Ptr<Channel>
|
|
mathieu@2673
|
107 |
SimpleNetDevice::GetChannel (void) const
|
|
mathieu@2673
|
108 |
{
|
|
mathieu@2673
|
109 |
return m_channel;
|
|
mathieu@2673
|
110 |
}
|
|
mathieu@2673
|
111 |
Address
|
|
mathieu@2673
|
112 |
SimpleNetDevice::GetAddress (void) const
|
|
mathieu@2673
|
113 |
{
|
|
mathieu@2673
|
114 |
return m_address;
|
|
mathieu@2673
|
115 |
}
|
|
mathieu@2673
|
116 |
bool
|
|
mathieu@2673
|
117 |
SimpleNetDevice::SetMtu (const uint16_t mtu)
|
|
mathieu@2673
|
118 |
{
|
|
mathieu@2673
|
119 |
m_mtu = mtu;
|
|
mathieu@2673
|
120 |
return true;
|
|
mathieu@2673
|
121 |
}
|
|
mathieu@2673
|
122 |
uint16_t
|
|
mathieu@2673
|
123 |
SimpleNetDevice::GetMtu (void) const
|
|
mathieu@2673
|
124 |
{
|
|
mathieu@2673
|
125 |
return m_mtu;
|
|
mathieu@2673
|
126 |
}
|
|
mathieu@2673
|
127 |
bool
|
|
mathieu@2673
|
128 |
SimpleNetDevice::IsLinkUp (void) const
|
|
mathieu@2673
|
129 |
{
|
|
mathieu@2673
|
130 |
return true;
|
|
mathieu@2673
|
131 |
}
|
|
mathieu@2673
|
132 |
void
|
|
mathieu@2673
|
133 |
SimpleNetDevice::SetLinkChangeCallback (Callback<void> callback)
|
|
mathieu@2673
|
134 |
{}
|
|
mathieu@2673
|
135 |
bool
|
|
mathieu@2673
|
136 |
SimpleNetDevice::IsBroadcast (void) const
|
|
mathieu@2673
|
137 |
{
|
|
mathieu@2673
|
138 |
return true;
|
|
mathieu@2673
|
139 |
}
|
|
mathieu@2673
|
140 |
Address
|
|
mathieu@2673
|
141 |
SimpleNetDevice::GetBroadcast (void) const
|
|
mathieu@2673
|
142 |
{
|
|
mathieu@2673
|
143 |
return Mac48Address ("ff:ff:ff:ff:ff:ff");
|
|
mathieu@2673
|
144 |
}
|
|
mathieu@2673
|
145 |
bool
|
|
mathieu@2673
|
146 |
SimpleNetDevice::IsMulticast (void) const
|
|
mathieu@2673
|
147 |
{
|
|
mathieu@2673
|
148 |
return false;
|
|
mathieu@2673
|
149 |
}
|
|
mathieu@2673
|
150 |
Address
|
|
craigdo@3841
|
151 |
SimpleNetDevice::GetMulticast (Ipv4Address multicastGroup) const
|
|
mathieu@2673
|
152 |
{
|
|
mathieu@3549
|
153 |
return Mac48Address::GetMulticast (multicastGroup);
|
|
mathieu@2673
|
154 |
}
|
|
vincent@3852
|
155 |
|
|
vincent@3852
|
156 |
Address SimpleNetDevice::GetMulticast (Ipv6Address addr) const
|
|
vincent@3852
|
157 |
{
|
|
vincent@3852
|
158 |
return Mac48Address::GetMulticast (addr);
|
|
vincent@3852
|
159 |
}
|
|
vincent@3852
|
160 |
|
|
mathieu@2673
|
161 |
bool
|
|
mathieu@2673
|
162 |
SimpleNetDevice::IsPointToPoint (void) const
|
|
mathieu@2673
|
163 |
{
|
|
mathieu@2673
|
164 |
return false;
|
|
mathieu@2673
|
165 |
}
|
|
mathieu@2673
|
166 |
bool
|
|
mathieu@2673
|
167 |
SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
|
|
mathieu@2673
|
168 |
{
|
|
mathieu@2673
|
169 |
Mac48Address to = Mac48Address::ConvertFrom (dest);
|
|
mathieu@2673
|
170 |
m_channel->Send (packet, protocolNumber, to, m_address, this);
|
|
mathieu@2673
|
171 |
return true;
|
|
mathieu@2673
|
172 |
}
|
|
gjc@3442
|
173 |
bool
|
|
gjc@3442
|
174 |
SimpleNetDevice::SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
|
|
gjc@3442
|
175 |
{
|
|
gjc@3442
|
176 |
Mac48Address to = Mac48Address::ConvertFrom (dest);
|
|
gjc@3442
|
177 |
Mac48Address from = Mac48Address::ConvertFrom (source);
|
|
gjc@3442
|
178 |
m_channel->Send (packet, protocolNumber, to, from, this);
|
|
gjc@3442
|
179 |
return true;
|
|
gjc@3442
|
180 |
}
|
|
gjc@3442
|
181 |
|
|
mathieu@2673
|
182 |
Ptr<Node>
|
|
mathieu@2673
|
183 |
SimpleNetDevice::GetNode (void) const
|
|
mathieu@2673
|
184 |
{
|
|
mathieu@2673
|
185 |
return m_node;
|
|
mathieu@2673
|
186 |
}
|
|
mathieu@2673
|
187 |
void
|
|
mathieu@2673
|
188 |
SimpleNetDevice::SetNode (Ptr<Node> node)
|
|
mathieu@2673
|
189 |
{
|
|
mathieu@2673
|
190 |
m_node = node;
|
|
mathieu@2673
|
191 |
}
|
|
mathieu@2673
|
192 |
bool
|
|
mathieu@2673
|
193 |
SimpleNetDevice::NeedsArp (void) const
|
|
mathieu@2673
|
194 |
{
|
|
mathieu@2673
|
195 |
return false;
|
|
mathieu@2673
|
196 |
}
|
|
mathieu@2673
|
197 |
void
|
|
mathieu@2673
|
198 |
SimpleNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
|
|
mathieu@2673
|
199 |
{
|
|
mathieu@2673
|
200 |
m_rxCallback = cb;
|
|
mathieu@2673
|
201 |
}
|
|
mathieu@2673
|
202 |
|
|
mathieu@2831
|
203 |
void
|
|
mathieu@2831
|
204 |
SimpleNetDevice::DoDispose (void)
|
|
mathieu@2831
|
205 |
{
|
|
mathieu@2831
|
206 |
m_channel = 0;
|
|
mathieu@2831
|
207 |
m_node = 0;
|
|
mathieu@2831
|
208 |
NetDevice::DoDispose ();
|
|
mathieu@2831
|
209 |
}
|
|
mathieu@2831
|
210 |
|
|
mathieu@2673
|
211 |
|
|
gjc@3480
|
212 |
void
|
|
gjc@3480
|
213 |
SimpleNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
|
|
gjc@3480
|
214 |
{
|
|
mathieu@3584
|
215 |
m_promiscCallback = cb;
|
|
gjc@3480
|
216 |
}
|
|
gjc@3480
|
217 |
|
|
gjc@3480
|
218 |
bool
|
|
mathieu@3584
|
219 |
SimpleNetDevice::SupportsSendFrom (void) const
|
|
gjc@3480
|
220 |
{
|
|
mathieu@3584
|
221 |
return true;
|
|
gjc@3480
|
222 |
}
|
|
mathieu@2673
|
223 |
|
|
mathieu@2673
|
224 |
} // namespace ns3
|