Index: src/devices/uan/uan-net-device.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/devices/uan/uan-net-device.cc
@@ -0,0 +1,374 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 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 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see .
+ *
+ * Author: Leonard Tracy
+ *
+ *
+ */
+
+
+#include "ns3/trace-source-accessor.h"
+#include "ns3/traced-callback.h"
+#include "ns3/pointer.h"
+#include "ns3/node.h"
+#include "ns3/assert.h"
+#include "uan-net-device.h"
+#include "uan-phy.h"
+#include "uan-mac.h"
+#include "uan-channel.h"
+#include "uan-transducer.h"
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("UanNetDevice");
+
+namespace ns3
+{
+
+NS_OBJECT_ENSURE_REGISTERED (UanNetDevice);
+
+UanNetDevice::UanNetDevice ()
+: NetDevice (),
+ m_mtu (64000)
+{ }
+
+UanNetDevice::~UanNetDevice ()
+{ }
+
+void
+UanNetDevice::DoDispose ()
+{
+ m_node = 0;
+ m_channel = 0;
+ m_mac->Dispose ();
+ m_mac = 0;
+ m_phy->Dispose ();
+ m_phy = 0;
+ m_trans->Dispose ();
+ m_trans = 0;
+ NetDevice::DoDispose ();
+}
+
+TypeId
+UanNetDevice::GetTypeId ()
+{
+
+
+ static TypeId tid = TypeId ("ns3::UanNetDevice")
+ .SetParent ()
+ .AddAttribute ("Channel", "The channel attached to this device",
+ PointerValue (),
+ MakePointerAccessor(&UanNetDevice::DoGetChannel, &UanNetDevice::SetChannel),
+ MakePointerChecker ())
+ .AddAttribute ("Phy", "The PHY layer attached to this device.",
+ PointerValue (),
+ MakePointerAccessor (&UanNetDevice::GetPhy, &UanNetDevice::SetPhy),
+ MakePointerChecker ())
+ .AddAttribute ("Mac", "The MAC layer attached to this device.",
+ PointerValue (),
+ MakePointerAccessor (&UanNetDevice::GetMac, &UanNetDevice::SetMac),
+ MakePointerChecker ())
+ .AddAttribute("Transducer", "The Transducer attached to this device.",
+ PointerValue (),
+ MakePointerAccessor (&UanNetDevice::GetTransducer,
+ &UanNetDevice::SetTransducer),
+ MakePointerChecker ())
+ .AddTraceSource ("Rx", "Received payload from the MAC layer.",
+ MakeTraceSourceAccessor (&UanNetDevice::m_rxLogger))
+ .AddTraceSource ("Tx", "Send payload to the MAC layer.",
+ MakeTraceSourceAccessor (&UanNetDevice::m_txLogger))
+ ;
+ return tid;
+}
+
+void
+UanNetDevice::SetMac (Ptr mac)
+{
+ if (mac != 0)
+ {
+ m_mac = mac;
+ NS_LOG_DEBUG ("Set MAC");
+
+ if (m_phy != 0)
+ {
+ m_phy->SetMac (mac);
+ m_mac->AttachPhy (m_phy);
+ NS_LOG_DEBUG ("Attached MAC to PHY");
+ }
+ m_mac->SetForwardUpCb (MakeCallback (&UanNetDevice::ForwardUp, this));
+ }
+
+}
+
+void
+UanNetDevice::SetPhy (Ptr phy)
+{
+ if (phy != 0)
+ {
+ m_phy = phy;
+ m_phy->SetDevice (Ptr (this));
+ NS_LOG_DEBUG ("Set PHY");
+ if (m_mac != 0)
+ {
+ m_mac->AttachPhy (phy);
+ m_phy->SetMac (m_mac);
+ NS_LOG_DEBUG ("Attached PHY to MAC");
+ }
+ if (m_trans != 0)
+ {
+ m_phy->SetTransducer (m_trans);
+ NS_LOG_DEBUG ("Added PHY to trans");
+ }
+
+ }
+}
+
+void
+UanNetDevice::SetChannel (Ptr channel)
+{
+ if (channel != 0)
+ {
+ m_channel = channel;
+ NS_LOG_DEBUG ("Set CHANNEL");
+ if (m_trans != 0)
+ {
+
+ m_channel->AddDevice (this, m_trans);
+ NS_LOG_DEBUG ("Added self to channel device list");
+ m_trans->SetChannel (m_channel);
+ NS_LOG_DEBUG ("Set Transducer channel");
+ }
+ if (m_phy !=0 )
+ {
+ m_phy->SetChannel (channel);
+ }
+ }
+}
+
+Ptr
+UanNetDevice::DoGetChannel (void) const
+{
+ return m_channel;
+
+}
+Ptr
+UanNetDevice::GetMac () const
+{
+ return m_mac;
+}
+
+Ptr
+UanNetDevice::GetPhy () const
+{
+ return m_phy;
+}
+
+void
+UanNetDevice::SetName (std::string name)
+{
+ m_name = name;
+}
+
+std::string
+UanNetDevice::GetName () const
+{
+ return m_name;
+}
+
+void
+UanNetDevice::SetIfIndex (uint32_t index)
+{
+ m_ifIndex = index;
+}
+
+uint32_t
+UanNetDevice::GetIfIndex () const
+{
+ return m_ifIndex;
+}
+
+Ptr
+UanNetDevice::GetChannel () const
+{
+ return m_channel;
+}
+
+Address
+UanNetDevice::GetAddress () const
+{
+ return m_mac->GetAddress ();
+}
+
+bool
+UanNetDevice::SetMtu (uint16_t mtu)
+{
+ //TODO: Check this in MAC
+ NS_LOG_WARN ("UanNetDevice: MTU is not implemented");
+ m_mtu = mtu;
+ return true;
+}
+
+uint16_t
+UanNetDevice::GetMtu () const
+{
+ return m_mtu;
+}
+
+bool
+UanNetDevice::IsLinkUp () const
+{
+ return (m_linkup && (m_phy != 0));
+}
+
+bool
+UanNetDevice::IsBroadcast () const
+{
+ return true;
+}
+
+Address
+UanNetDevice::GetBroadcast () const
+{
+ return m_mac->GetBroadcast ();
+}
+
+bool
+UanNetDevice::IsMulticast () const
+{
+ return false;
+}
+
+Address
+UanNetDevice::GetMulticast (Ipv4Address multicastGroup) const
+{
+ NS_FATAL_ERROR ("UanNetDevice does not support multicast");
+ return m_mac->GetBroadcast ();
+}
+
+Address
+UanNetDevice::GetMulticast (Ipv6Address addr) const
+{
+ NS_FATAL_ERROR ("UanNetDevice does not support multicast");
+ return m_mac->GetBroadcast ();
+}
+
+bool
+UanNetDevice::IsBridge (void) const
+{
+ return false;
+}
+bool
+UanNetDevice::IsPointToPoint () const
+{
+ return false;
+}
+
+bool
+UanNetDevice::Send (Ptr packet, const Address &dest, uint16_t protocolNumber)
+{
+ return m_mac->Enqueue (packet, dest, protocolNumber);
+}
+
+bool
+UanNetDevice::SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+{
+ //Not yet implemented
+ NS_ASSERT_MSG (0, "Not yet implemented");
+ return false;
+}
+Ptr
+UanNetDevice::GetNode () const
+{
+ return m_node;
+}
+
+void
+UanNetDevice::SetNode (Ptr node)
+{
+ m_node = node;
+}
+
+bool
+UanNetDevice::NeedsArp () const
+{
+ return false;
+}
+
+void
+UanNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
+{
+ m_forwardUp = cb;
+}
+
+void
+UanNetDevice::ForwardUp (Ptr pkt, const UanAddress &src)
+{
+ NS_LOG_DEBUG ("Forwarding packet up to application");
+ m_rxLogger (pkt, src);
+ m_forwardUp (this, pkt, 0, src);
+
+}
+
+Ptr
+UanNetDevice::GetTransducer (void) const
+{
+ return m_trans;
+}
+void
+UanNetDevice::SetTransducer (Ptr trans)
+{
+
+ if (trans != 0)
+ {
+ m_trans = trans;
+ NS_LOG_DEBUG ("Set Transducer");
+ if (m_phy != 0)
+ {
+ m_phy->SetTransducer (m_trans);
+ NS_LOG_DEBUG ("Attached Phy to transducer");
+ }
+
+ if (m_channel != 0)
+ {
+ m_channel->AddDevice (this, m_trans);
+ m_trans->SetChannel (m_channel);
+ NS_LOG_DEBUG ("Added self to channel device list");
+ }
+ }
+
+}
+
+void
+UanNetDevice::SetLinkChangeCallback (Callback callback)
+{
+ m_linkchange = callback;
+}
+
+
+void
+UanNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
+{
+ //Not implemented yet
+ NS_ASSERT_MSG (0, "Not yet implemented");
+}
+
+bool
+UanNetDevice::SupportsSendFrom (void) const
+{
+ return false;
+}
+} //namespace ns3
+