Enh. 2130 - Allow SimpleChannel to simulate hidden terminals.

This commit is contained in:
Tommaso Pecorella
2015-06-11 19:07:25 +02:00
parent c5f127c193
commit d74e9fdf30
5 changed files with 164 additions and 8 deletions

View File

@@ -17,6 +17,7 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include <algorithm>
#include "simple-channel.h"
#include "simple-net-device.h"
#include "ns3/simulator.h"
@@ -63,6 +64,14 @@ SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol,
{
continue;
}
if (m_blackListedDevices.find (tmp) != m_blackListedDevices.end ())
{
if (find (m_blackListedDevices[tmp].begin (), m_blackListedDevices[tmp].end (), sender) !=
m_blackListedDevices[tmp].end () )
{
continue;
}
}
Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), m_delay,
&SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
}
@@ -81,6 +90,7 @@ SimpleChannel::GetNDevices (void) const
NS_LOG_FUNCTION (this);
return m_devices.size ();
}
Ptr<NetDevice>
SimpleChannel::GetDevice (uint32_t i) const
{
@@ -88,4 +98,36 @@ SimpleChannel::GetDevice (uint32_t i) const
return m_devices[i];
}
void
SimpleChannel::BlackList (Ptr<SimpleNetDevice> from, Ptr<SimpleNetDevice> to)
{
if (m_blackListedDevices.find (to) != m_blackListedDevices.end ())
{
if (find (m_blackListedDevices[to].begin (), m_blackListedDevices[to].end (), from) ==
m_blackListedDevices[to].end () )
{
m_blackListedDevices[to].push_back (from);
}
}
else
{
m_blackListedDevices[to].push_back (from);
}
}
void
SimpleChannel::UnBlackList (Ptr<SimpleNetDevice> from, Ptr<SimpleNetDevice> to)
{
if (m_blackListedDevices.find (to) != m_blackListedDevices.end ())
{
std::vector<Ptr<SimpleNetDevice> >::iterator iter;
iter = find (m_blackListedDevices[to].begin (), m_blackListedDevices[to].end (), from);
if (iter != m_blackListedDevices[to].end () )
{
m_blackListedDevices[to].erase (iter);
}
}
}
} // namespace ns3

View File

@@ -24,6 +24,7 @@
#include "ns3/nstime.h"
#include "mac48-address.h"
#include <vector>
#include <map>
namespace ns3 {
@@ -74,6 +75,24 @@ public:
*/
virtual void Add (Ptr<SimpleNetDevice> device);
/**
* Blocks the communications from a NetDevice to another NetDevice.
* The block is unidirectional
*
* \param from the device to BlackList
* \param to the device wanting to block the other one
*/
virtual void BlackList (Ptr<SimpleNetDevice> from, Ptr<SimpleNetDevice> to);
/**
* Un-Blocks the communications from a NetDevice to another NetDevice.
* The block is unidirectional
*
* \param from the device to BlackList
* \param to the device wanting to block the other one
*/
virtual void UnBlackList (Ptr<SimpleNetDevice> from, Ptr<SimpleNetDevice> to);
// inherited from ns3::Channel
virtual uint32_t GetNDevices (void) const;
virtual Ptr<NetDevice> GetDevice (uint32_t i) const;
@@ -81,6 +100,7 @@ public:
private:
Time m_delay; //!< The assigned speed-of-light delay of the channel
std::vector<Ptr<SimpleNetDevice> > m_devices; //!< devices connected by the channel
std::map<Ptr<SimpleNetDevice>, std::vector<Ptr<SimpleNetDevice> > > m_blackListedDevices; //!< devices blocked on a device
};
} // namespace ns3