--- a/src/devices/csma/csma-net-device.cc Sun Feb 24 20:18:02 2008 +0100
+++ b/src/devices/csma/csma-net-device.cc Mon Feb 25 19:33:46 2008 +0100
@@ -81,22 +81,15 @@
return m_type;
}
-CsmaNetDevice::CsmaNetDevice (Ptr<Node> node)
- : NetDevice (node, Mac48Address::Allocate ()),
- m_bps (DataRate (0xffffffff)),
- m_receiveErrorModel (0)
-{
- NS_LOG_FUNCTION;
- NS_LOG_PARAMS (this << node);
- m_encapMode = IP_ARP;
- Init(true, true);
-}
-
CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr,
- CsmaEncapsulationMode encapMode)
- : NetDevice(node, addr),
- m_bps (DataRate (0xffffffff)),
- m_receiveErrorModel (0)
+ CsmaEncapsulationMode encapMode)
+ : m_bps (DataRate (0xffffffff)),
+ m_receiveErrorModel (0),
+ m_node (node),
+ m_address (addr),
+ m_name (""),
+ m_linkUp (false),
+ m_mtu (0xffff)
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << node);
@@ -105,19 +98,6 @@
Init(true, true);
}
-CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr,
- CsmaEncapsulationMode encapMode,
- bool sendEnable, bool receiveEnable)
- : NetDevice(node, addr),
- m_bps (DataRate (0xffffffff))
-{
- NS_LOG_FUNCTION;
- NS_LOG_PARAMS (this << node);
- m_encapMode = encapMode;
-
- Init(sendEnable, receiveEnable);
-}
-
CsmaNetDevice::~CsmaNetDevice()
{
NS_LOG_FUNCTION;
@@ -129,27 +109,10 @@
{
NS_LOG_FUNCTION;
m_channel = 0;
+ m_node = 0;
NetDevice::DoDispose ();
}
-//
-// Assignment operator for CsmaNetDevice.
-//
-// This uses the non-obvious trick of taking the source net device passed by
-// value instead of by reference. This causes the copy constructor to be
-// invoked (where the real work is done -- see above). All we have to do
-// here is to return the newly constructed net device.
-//
-/*
-CsmaNetDevice&
-CsmaNetDevice::operator= (const CsmaNetDevice nd)
-{
- NS_LOG_FUNCTION;
- NS_LOG_PARAMS (this << &nd);
- return *this;
-}
-*/
-
void
CsmaNetDevice::Init(bool sendEnable, bool receiveEnable)
{
@@ -159,9 +122,6 @@
m_channel = 0;
m_queue = 0;
- EnableBroadcast (Mac48Address ("ff:ff:ff:ff:ff:ff"));
- EnableMulticast (Mac48Address ("01:00:5e:00:00:00"));
-
SetSendEnable (sendEnable);
SetReceiveEnable (receiveEnable);
}
@@ -302,58 +262,6 @@
return true;
}
-bool
-CsmaNetDevice::DoNeedsArp (void) const
-{
- NS_LOG_FUNCTION;
- if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
-bool
-CsmaNetDevice::SendTo (Ptr<Packet> packet,
- const Address& dest,
- uint16_t protocolNumber)
-{
- NS_LOG_FUNCTION;
- NS_LOG_LOGIC ("p=" << packet);
- NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
-
- NS_ASSERT (IsLinkUp ());
-
- // Only transmit if send side of net device is enabled
- if (!IsSendEnabled())
- return false;
-
- Mac48Address destination = Mac48Address::ConvertFrom (dest);
- AddHeader(packet, destination, protocolNumber);
-
- // Place the packet to be sent on the send queue
- if (m_queue->Enqueue(packet) == false )
- {
- return false;
- }
- // If the device is idle, we need to start a transmission. Otherwise,
- // the transmission will be started when the current packet finished
- // transmission (see TransmitCompleteEvent)
- if (m_txMachineState == READY)
- {
- // Store the next packet to be transmitted
- m_currentPkt = m_queue->Dequeue ();
- if (m_currentPkt != 0)
- {
- TransmitStart();
- }
- }
- return true;
-}
-
void
CsmaNetDevice::TransmitStart ()
{
@@ -565,7 +473,7 @@
if (m_encapMode == RAW)
{
- ForwardUp (packet, 0, GetBroadcast ());
+ m_rxCallback (this, packet, 0, GetBroadcast ());
m_dropTrace (packet);
return;
}
@@ -636,12 +544,100 @@
NS_ASSERT (false);
break;
}
- ForwardUp (packet, protocol, header.GetSource ());
+ m_rxCallback (this, packet, protocol, header.GetSource ());
+ }
+}
+
+Ptr<Queue>
+CsmaNetDevice::GetQueue(void) const
+{
+ NS_LOG_FUNCTION;
+ return m_queue;
+}
+
+void
+CsmaNetDevice::NotifyLinkUp (void)
+{
+ m_linkUp = true;
+ if (!m_linkChangeCallback.IsNull ())
+ {
+ m_linkChangeCallback ();
}
}
+void
+CsmaNetDevice::SetName(const std::string name)
+{
+ m_name = name;
+}
+std::string
+CsmaNetDevice::GetName(void) const
+{
+ return m_name;
+}
+void
+CsmaNetDevice::SetIfIndex(const uint32_t index)
+{
+ m_ifIndex = index;
+}
+uint32_t
+CsmaNetDevice::GetIfIndex(void) const
+{
+ return m_ifIndex;
+}
+Ptr<Channel>
+CsmaNetDevice::GetChannel (void) const
+{
+ return m_channel;
+}
+Address
+CsmaNetDevice::GetAddress (void) const
+{
+ return m_address;
+}
+bool
+CsmaNetDevice::SetMtu (const uint16_t mtu)
+{
+ m_mtu = mtu;
+ return true;
+}
+uint16_t
+CsmaNetDevice::GetMtu (void) const
+{
+ return m_mtu;
+}
+bool
+CsmaNetDevice::IsLinkUp (void) const
+{
+ return m_linkUp;
+}
+void
+CsmaNetDevice::SetLinkChangeCallback (Callback<void> callback)
+{
+ m_linkChangeCallback = callback;
+}
+bool
+CsmaNetDevice::IsBroadcast (void) const
+{
+ return true;
+}
Address
-CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
+CsmaNetDevice::GetBroadcast (void) const
+{
+ return Mac48Address ("ff:ff:ff:ff:ff:ff");
+}
+bool
+CsmaNetDevice::IsMulticast (void) const
+{
+ return false;
+}
+Address
+CsmaNetDevice::GetMulticast (void) const
+{
+ return Mac48Address ("01:00:5e:00:00:00");
+}
+Address
+CsmaNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << multicastGroup);
@@ -692,20 +688,67 @@
return etherAddr;
}
+bool
+CsmaNetDevice::IsPointToPoint (void) const
+{
+ return false;
+}
+bool
+CsmaNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_LOGIC ("p=" << packet);
+ NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
-Ptr<Queue>
-CsmaNetDevice::GetQueue(void) const
-{
- NS_LOG_FUNCTION;
- return m_queue;
+ NS_ASSERT (IsLinkUp ());
+
+ // Only transmit if send side of net device is enabled
+ if (!IsSendEnabled())
+ return false;
+
+ Mac48Address destination = Mac48Address::ConvertFrom (dest);
+ AddHeader(packet, destination, protocolNumber);
+
+ // Place the packet to be sent on the send queue
+ if (m_queue->Enqueue(packet) == false )
+ {
+ return false;
+ }
+ // If the device is idle, we need to start a transmission. Otherwise,
+ // the transmission will be started when the current packet finished
+ // transmission (see TransmitCompleteEvent)
+ if (m_txMachineState == READY)
+ {
+ // Store the next packet to be transmitted
+ m_currentPkt = m_queue->Dequeue ();
+ if (m_currentPkt != 0)
+ {
+ TransmitStart();
+ }
+ }
+ return true;
+}
+Ptr<Node>
+CsmaNetDevice::GetNode (void) const
+{
+ return m_node;
+}
+bool
+CsmaNetDevice::NeedsArp (void) const
+{
+ if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+void
+CsmaNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
+{
+ m_rxCallback = cb;
}
-Ptr<Channel>
-CsmaNetDevice::DoGetChannel(void) const
-{
- NS_LOG_FUNCTION;
- return m_channel;
-}
-
-
} // namespace ns3