Allow Click to pull random numbers from ns-3

This commit is contained in:
Sascha Alexander Jopen
2013-02-07 10:47:08 +01:00
parent 80ca7c14a3
commit 6f03fdaf7e
2 changed files with 24 additions and 1 deletions

View File

@@ -24,6 +24,7 @@
#include "ns3/node.h"
#include "ns3/simulator.h"
#include "ns3/log.h"
#include "ns3/random-variable-stream.h"
#include "ns3/mac48-address.h"
#include "ns3/ipv4-interface.h"
#include "ns3/ipv4-l3-click-protocol.h"
@@ -63,6 +64,7 @@ Ipv4ClickRouting::Ipv4ClickRouting ()
: m_nonDefaultName (false),
m_ipv4 (0)
{
m_random = CreateObject<UniformRandomVariable> ();
}
Ipv4ClickRouting::~Ipv4ClickRouting ()
@@ -111,6 +113,12 @@ Ipv4ClickRouting::SetIpv4 (Ptr<Ipv4> ipv4)
m_ipv4 = ipv4;
}
Ptr<UniformRandomVariable>
Ipv4ClickRouting::GetRandomVariable (void)
{
return m_random;
}
void
Ipv4ClickRouting::DoDispose ()
{
@@ -606,7 +614,7 @@ int simclick_sim_command (simclick_node_t *simnode, int cmd, ...)
case SIMCLICK_SUPPORTS:
{
int othercmd = va_arg (val, int);
retval = (othercmd >= SIMCLICK_VERSION && othercmd <= SIMCLICK_GET_NODE_ID);
retval = (othercmd >= SIMCLICK_VERSION && othercmd <= SIMCLICK_GET_RANDOM_INT);
break;
}
@@ -738,6 +746,17 @@ int simclick_sim_command (simclick_node_t *simnode, int cmd, ...)
NS_LOG_DEBUG (clickInstance->GetNodeName () << " Received a call for SIMCLICK_GET_NODE_ID");
break;
}
case SIMCLICK_GET_RANDOM_INT:
{
uint32_t *randomValue = va_arg (val, uint32_t *);
uint32_t maxValue = va_arg (val, uint32_t);
*randomValue = static_cast<uint32_t> (clickInstance->GetRandomVariable ()->GetValue (0.0, static_cast<double> (maxValue) + 1.0));
retval = 0;
NS_LOG_DEBUG (clickInstance->GetNodeName () << " SIMCLICK_RANDOM: " << *randomValue << " " << maxValue << " " << ns3::Simulator::Now ());
break;
}
}
return retval;
}

View File

@@ -44,6 +44,8 @@ namespace ns3 {
* This section documents the API of the ns-3 click module. For a generic functional description, please refer to the ns-3 manual.
*/
class UniformRandomVariable;
/**
* \ingroup click
* \brief Class to allow a node to use Click for external routing
@@ -63,6 +65,7 @@ public:
Ipv4ClickRouting ();
virtual ~Ipv4ClickRouting ();
Ptr<UniformRandomVariable> GetRandomVariable (void);
protected:
virtual void DoStart (void);
@@ -255,6 +258,7 @@ private:
bool m_nonDefaultName;
Ptr<Ipv4> m_ipv4;
Ptr<UniformRandomVariable> m_random;
#endif /* NS3_CLICK */
};