1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2008 INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 #include "simple-net-device.h"
21 #include "simple-channel.h"
23 #include "ns3/packet.h"
28 SimpleNetDevice::GetTypeId (void)
30 static TypeId tid = TypeId ("ns3::SimpleNetDevice")
31 .SetParent<NetDevice> ()
32 .AddConstructor<SimpleNetDevice> ()
37 SimpleNetDevice::SimpleNetDevice ()
46 SimpleNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
47 Mac48Address to, Mac48Address from)
49 NetDevice::PacketType packetType;
52 packetType = NetDevice::PACKET_HOST;
54 else if (to.IsBroadcast ())
56 packetType = NetDevice::PACKET_HOST;
58 else if (to.IsMulticast ())
60 packetType = NetDevice::PACKET_MULTICAST;
64 packetType = NetDevice::PACKET_OTHERHOST;
66 m_rxCallback (this, packet, protocol, from);
67 if (!m_promiscCallback.IsNull ())
69 m_promiscCallback (this, packet, protocol, from, to, packetType);
74 SimpleNetDevice::SetChannel (Ptr<SimpleChannel> channel)
77 m_channel->Add (this);
81 SimpleNetDevice::SetAddress (Mac48Address address)
87 SimpleNetDevice::SetName(const std::string name)
92 SimpleNetDevice::GetName(void) const
97 SimpleNetDevice::SetIfIndex(const uint32_t index)
102 SimpleNetDevice::GetIfIndex(void) const
107 SimpleNetDevice::GetChannel (void) const
112 SimpleNetDevice::GetAddress (void) const
117 SimpleNetDevice::SetMtu (const uint16_t mtu)
123 SimpleNetDevice::GetMtu (void) const
128 SimpleNetDevice::IsLinkUp (void) const
133 SimpleNetDevice::SetLinkChangeCallback (Callback<void> callback)
136 SimpleNetDevice::IsBroadcast (void) const
141 SimpleNetDevice::GetBroadcast (void) const
143 return Mac48Address ("ff:ff:ff:ff:ff:ff");
146 SimpleNetDevice::IsMulticast (void) const
151 SimpleNetDevice::GetMulticast (Ipv4Address multicastGroup) const
153 return Mac48Address::GetMulticast (multicastGroup);
156 Address SimpleNetDevice::GetMulticast (Ipv6Address addr) const
158 return Mac48Address::GetMulticast (addr);
162 SimpleNetDevice::IsPointToPoint (void) const
167 SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
169 Mac48Address to = Mac48Address::ConvertFrom (dest);
170 m_channel->Send (packet, protocolNumber, to, m_address, this);
174 SimpleNetDevice::SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
176 Mac48Address to = Mac48Address::ConvertFrom (dest);
177 Mac48Address from = Mac48Address::ConvertFrom (source);
178 m_channel->Send (packet, protocolNumber, to, from, this);
183 SimpleNetDevice::GetNode (void) const
188 SimpleNetDevice::SetNode (Ptr<Node> node)
193 SimpleNetDevice::NeedsArp (void) const
198 SimpleNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
204 SimpleNetDevice::DoDispose (void)
208 NetDevice::DoDispose ();
213 SimpleNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
215 m_promiscCallback = cb;
219 SimpleNetDevice::SupportsSendFrom (void) const