Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1944)

Unified Diff: src/devices/simple-wireless/simple-wireless-net-device.cc

Issue 1587041: Simple Wireless and RangeLossModel
Patch Set: Created 13 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/devices/simple-wireless/simple-wireless-net-device.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/devices/simple-wireless/simple-wireless-net-device.cc
@@ -0,0 +1,253 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include "simple-wireless-net-device.h"
+#include "simple-wireless-channel.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/log.h"
+#include "ns3/pointer.h"
+#include "ns3/error-model.h"
+#include "ns3/trace-source-accessor.h"
+
+NS_LOG_COMPONENT_DEFINE ("SimpleWirelessNetDevice");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (SimpleWirelessNetDevice);
+
+TypeId
+SimpleWirelessNetDevice::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::SimpleWirelessNetDevice")
+ .SetParent<NetDevice> ()
+ .AddConstructor<SimpleWirelessNetDevice> ()
+ .AddAttribute ("ReceiveErrorModel",
+ "The receiver error model used to simulate packet loss",
+ PointerValue (),
+ MakePointerAccessor (&SimpleWirelessNetDevice::m_receiveErrorModel),
+ MakePointerChecker<ErrorModel> ())
+ .AddTraceSource ("PhyRxDrop",
+ "Trace source indicating a packet has been dropped by the device during reception",
+ MakeTraceSourceAccessor (&SimpleWirelessNetDevice::m_phyRxDropTrace))
+ ;
+ return tid;
+}
+
+SimpleWirelessNetDevice::SimpleWirelessNetDevice ()
+ : m_channel (0),
+ m_node (0),
+ m_mtu (0xffff),
+ m_ifIndex (0)
+{}
+
+void
+SimpleWirelessNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
+ Mac48Address to, Mac48Address from)
+{
+ NS_LOG_FUNCTION (packet << protocol << to << from);
+ NetDevice::PacketType packetType;
+
+ if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
+ {
+ m_phyRxDropTrace (packet);
+ return;
+ }
+
+ if (to == m_address)
+ {
+ packetType = NetDevice::PACKET_HOST;
+ }
+ else if (to.IsBroadcast ())
+ {
+ packetType = NetDevice::PACKET_HOST;
+ }
+ else if (to.IsGroup ())
+ {
+ packetType = NetDevice::PACKET_MULTICAST;
+ }
+ else
+ {
+ packetType = NetDevice::PACKET_OTHERHOST;
+ }
+ m_rxCallback (this, packet, protocol, from);
Nicola Baldo 2010/06/21 23:39:40 no collision model? Not even a simple protocol int
+ if (!m_promiscCallback.IsNull ())
+ {
+ m_promiscCallback (this, packet, protocol, from, to, packetType);
+ }
+}
+
+void
+SimpleWirelessNetDevice::SetChannel (Ptr<SimpleWirelessChannel> channel)
+{
+ m_channel = channel;
+ m_channel->Add (this);
+}
+
+void
+SimpleWirelessNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em)
+{
+ m_receiveErrorModel = em;
+}
+
+void
+SimpleWirelessNetDevice::SetIfIndex(const uint32_t index)
+{
+ m_ifIndex = index;
+}
+uint32_t
+SimpleWirelessNetDevice::GetIfIndex(void) const
+{
+ return m_ifIndex;
+}
+Ptr<Channel>
+SimpleWirelessNetDevice::GetChannel (void) const
+{
+ return m_channel;
+}
+void
+SimpleWirelessNetDevice::SetAddress (Address address)
+{
+ m_address = Mac48Address::ConvertFrom(address);
+}
+Address
+SimpleWirelessNetDevice::GetAddress (void) const
+{
+ //
+ // Implicit conversion from Mac48Address to Address
+ //
+ return m_address;
+}
+bool
+SimpleWirelessNetDevice::SetMtu (const uint16_t mtu)
+{
+ m_mtu = mtu;
+ return true;
+}
+uint16_t
+SimpleWirelessNetDevice::GetMtu (void) const
+{
+ return m_mtu;
+}
+bool
+SimpleWirelessNetDevice::IsLinkUp (void) const
+{
+ return true;
+}
+void
+SimpleWirelessNetDevice::AddLinkChangeCallback (Callback<void> callback)
+{}
+bool
+SimpleWirelessNetDevice::IsBroadcast (void) const
+{
+ return true;
+}
+Address
+SimpleWirelessNetDevice::GetBroadcast (void) const
+{
+ return Mac48Address ("ff:ff:ff:ff:ff:ff");
+}
+bool
+SimpleWirelessNetDevice::IsMulticast (void) const
+{
+ return false;
+}
+Address
+SimpleWirelessNetDevice::GetMulticast (Ipv4Address multicastGroup) const
+{
+ return Mac48Address::GetMulticast (multicastGroup);
+}
+
+Address SimpleWirelessNetDevice::GetMulticast (Ipv6Address addr) const
+{
+ return Mac48Address::GetMulticast (addr);
+}
+
+bool
+SimpleWirelessNetDevice::IsPointToPoint (void) const
+{
+ return false;
+}
+
+bool
+SimpleWirelessNetDevice::IsBridge (void) const
+{
+ return false;
+}
+
+bool
+SimpleWirelessNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
+{
+ NS_LOG_FUNCTION (packet << dest << protocolNumber);
+ Mac48Address to = Mac48Address::ConvertFrom (dest);
+ m_channel->Send (packet, protocolNumber, to, m_address, this);
+ return true;
+}
+bool
+SimpleWirelessNetDevice::SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+{
+ Mac48Address to = Mac48Address::ConvertFrom (dest);
+ Mac48Address from = Mac48Address::ConvertFrom (source);
+ m_channel->Send (packet, protocolNumber, to, from, this);
+ return true;
+}
+
+Ptr<Node>
+SimpleWirelessNetDevice::GetNode (void) const
+{
+ return m_node;
+}
+void
+SimpleWirelessNetDevice::SetNode (Ptr<Node> node)
+{
+ m_node = node;
+}
+bool
+SimpleWirelessNetDevice::NeedsArp (void) const
+{
+ return false;
+}
+void
+SimpleWirelessNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
+{
+ m_rxCallback = cb;
+}
+
+void
+SimpleWirelessNetDevice::DoDispose (void)
+{
+ m_channel = 0;
+ m_node = 0;
+ m_receiveErrorModel = 0;
+ NetDevice::DoDispose ();
+}
+
+
+void
+SimpleWirelessNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
+{
+ m_promiscCallback = cb;
+}
+
+bool
+SimpleWirelessNetDevice::SupportsSendFrom (void) const
+{
+ return true;
+}
+
+} // namespace ns3

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b