Index: src/csma/model/csma-net-device.cc |
=================================================================== |
--- a/src/csma/model/csma-net-device.cc |
+++ b/src/csma/model/csma-net-device.cc |
@@ -16,6 +16,7 @@ |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> |
+ * Vedran Miletić <rivanvx@gmail.com> |
*/ |
#include "ns3/log.h" |
@@ -33,6 +34,9 @@ |
#include "csma-net-device.h" |
#include "csma-channel.h" |
+#include <cstring> |
+#include <cmath> |
+ |
NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice"); |
namespace ns3 { |
@@ -207,6 +211,23 @@ |
return m_encapMode; |
} |
+void |
+CsmaNetDevice::SetCarrierSense (enum CarrierSense sense) |
+{ |
+ NS_LOG_FUNCTION (this << sense); |
+ |
+ m_carrierSense = sense; |
+ |
+ NS_LOG_LOGIC ("m_carrierSense = " << m_carrierSense); |
+} |
+ |
+CsmaNetDevice::CarrierSense |
+CsmaNetDevice::GetCarrierSense (void) |
+{ |
+ NS_LOG_FUNCTION (this); |
+ return m_carrierSense; |
+} |
+ |
bool |
CsmaNetDevice::SetMtu (uint16_t mtu) |
{ |
@@ -437,11 +458,12 @@ |
NS_ASSERT_MSG ((m_txMachineState == READY) || (m_txMachineState == BACKOFF), |
"Must be READY to transmit. Tx state is: " << m_txMachineState); |
+ NS_LOG_INFO ("CSMA device " << this << " carrier sense is (0 = idle, 1 = busy) " << m_carrierSense); |
// |
// Now we have to sense the state of the medium and either start transmitting |
// if it is idle, or backoff our transmission if someone else is on the wire. |
// |
- if (m_channel->GetState () != IDLE) |
+ if (m_carrierSense != CARRIER_SENSE_IDLE) |
{ |
// |
// The channel is busy -- backoff and rechedule TransmitStart() unless |
@@ -463,7 +485,7 @@ |
m_backoff.IncrNumRetries (); |
Time backoffTime = m_backoff.GetBackoffTime (); |
- NS_LOG_LOGIC ("Channel busy, backing off for " << backoffTime.GetSeconds () << " sec"); |
+ NS_LOG_LOGIC ("CSMA device " << this << " is sensing chanel busy, backing off for " << backoffTime.GetSeconds () << " s"); |
Simulator::Schedule (backoffTime, &CsmaNetDevice::TransmitStart, this); |
} |
@@ -553,7 +575,7 @@ |
// the transmitter after the interframe gap. |
// |
NS_ASSERT_MSG (m_txMachineState == BUSY, "CsmaNetDevice::transmitCompleteEvent(): Must be BUSY if transmitting"); |
- NS_ASSERT (m_channel->GetState () == TRANSMITTING); |
+ NS_ASSERT (m_channel->GetState () == OCCUPIED); |
m_txMachineState = GAP; |
// |
@@ -610,13 +632,13 @@ |
} |
bool |
-CsmaNetDevice::Attach (Ptr<CsmaChannel> ch) |
+CsmaNetDevice::Attach (Ptr<CsmaChannel> ch, double distance) |
{ |
NS_LOG_FUNCTION (this << &ch); |
m_channel = ch; |
- m_deviceId = m_channel->Attach (this); |
+ m_deviceId = m_channel->Attach (this, distance); |
// |
// The channel provides us with the transmitter data rate. |