helper/dce-manager-helper.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 19 Apr 2011 14:49:49 +0200
changeset 64 015a353a487b
parent 6 64c6f4f78c91
permissions -rw-r--r--
initial build of module
mathieu@0
     1
#include "dce-manager-helper.h"
mathieu@64
     2
#include "dce-manager.h"
mathieu@64
     3
#include "socket-fd-factory.h"
mathieu@64
     4
#include "task-scheduler.h"
mathieu@64
     5
#include "task-manager.h"
mathieu@64
     6
#include "loader-factory.h"
mathieu@0
     7
#include "ns3/random-variable.h"
mathieu@0
     8
#include "ns3/uinteger.h"
mathieu@6
     9
#include "ns3/string.h"
mathieu@6
    10
#include "ns3/config.h"
mathieu@0
    11
mathieu@0
    12
namespace ns3 {
mathieu@0
    13
mathieu@0
    14
UniformVariable g_firstPid;
mathieu@0
    15
mathieu@6
    16
NS_OBJECT_ENSURE_REGISTERED (DceManagerHelper);
mathieu@6
    17
mathieu@6
    18
TypeId 
mathieu@6
    19
DceManagerHelper::GetTypeId (void)
mathieu@6
    20
{
mathieu@6
    21
  static TypeId tid = TypeId ("ns3::DceManagerHelper")
mathieu@6
    22
    .SetParent<ObjectBase> ()
mathieu@6
    23
    .AddAttribute ("LoaderFactory", 
mathieu@6
    24
		   "The kind of loader factory created when Install is called", 
mathieu@6
    25
		   StringValue ("ns3::CoojaLoaderFactory[]"),
mathieu@6
    26
		   MakeObjectFactoryAccessor (&DceManagerHelper::m_loaderFactory),
mathieu@6
    27
		   MakeObjectFactoryChecker ())
mathieu@6
    28
    ;
mathieu@6
    29
  return tid;
mathieu@6
    30
}
mathieu@6
    31
TypeId 
mathieu@6
    32
DceManagerHelper::GetInstanceTypeId (void) const
mathieu@6
    33
{
mathieu@6
    34
  return DceManagerHelper::GetTypeId ();
mathieu@6
    35
}
mathieu@6
    36
mathieu@0
    37
DceManagerHelper::DceManagerHelper ()
mathieu@0
    38
{
mathieu@6
    39
  ConstructSelf (AttributeList ());
mathieu@0
    40
  m_taskManagerFactory.SetTypeId ("ns3::TaskManager");
mathieu@0
    41
  m_schedulerFactory.SetTypeId ("ns3::RrTaskScheduler");
mathieu@0
    42
  m_managerFactory.SetTypeId ("ns3::DceManager");
mathieu@0
    43
  m_networkStackFactory.SetTypeId ("ns3::Ns3SocketFdFactory");
mathieu@0
    44
}
mathieu@0
    45
void 
mathieu@0
    46
DceManagerHelper::SetScheduler (std::string type, 
mathieu@0
    47
				    std::string n0, const AttributeValue &v0,
mathieu@0
    48
				    std::string n1, const AttributeValue &v1)
mathieu@0
    49
{
mathieu@0
    50
  m_schedulerFactory.SetTypeId (type);
mathieu@0
    51
  m_schedulerFactory.Set (n0, v0);
mathieu@0
    52
  m_schedulerFactory.Set (n1, v1);
mathieu@0
    53
}
mathieu@0
    54
void 
mathieu@0
    55
DceManagerHelper::SetTaskManagerAttribute (std::string n0, const AttributeValue &v0)
mathieu@0
    56
{
mathieu@0
    57
  m_taskManagerFactory.Set (n0, v0);
mathieu@0
    58
}
mathieu@0
    59
void 
mathieu@0
    60
DceManagerHelper::SetLoader (std::string type)
mathieu@0
    61
{
mathieu@0
    62
  m_loaderFactory.SetTypeId (type);
mathieu@0
    63
}
mathieu@0
    64
void 
mathieu@0
    65
DceManagerHelper::SetNetworkStack (std::string type,
mathieu@0
    66
				       std::string n0, const AttributeValue &v0)
mathieu@0
    67
{
mathieu@0
    68
  m_networkStackFactory.SetTypeId (type);
mathieu@0
    69
  m_networkStackFactory.Set (n0, v0);
mathieu@0
    70
}
mathieu@0
    71
void 
mathieu@0
    72
DceManagerHelper::SetAttribute (std::string n1, const AttributeValue &v1)
mathieu@0
    73
{
mathieu@0
    74
  m_managerFactory.Set (n1, v1);
mathieu@0
    75
}
mathieu@0
    76
void
mathieu@0
    77
DceManagerHelper::Install (NodeContainer nodes)
mathieu@0
    78
{
mathieu@0
    79
  for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
mathieu@0
    80
    {
mathieu@0
    81
      Ptr<DceManager> manager = m_managerFactory.Create<DceManager> ();
mathieu@0
    82
      Ptr<TaskManager> taskManager = m_taskManagerFactory.Create<TaskManager> ();
mathieu@0
    83
      Ptr<TaskScheduler> scheduler = m_schedulerFactory.Create<TaskScheduler> ();
mathieu@0
    84
      Ptr<LoaderFactory> loader = m_loaderFactory.Create<LoaderFactory> ();
mathieu@0
    85
      Ptr<SocketFdFactory> networkStack = m_networkStackFactory.Create<SocketFdFactory> ();
mathieu@0
    86
      taskManager->SetScheduler (scheduler);
mathieu@0
    87
      manager->SetAttribute ("FirstPid", UintegerValue (g_firstPid.GetInteger (0, 0xffff)));
mathieu@0
    88
      Ptr<Node> node = *i;
mathieu@0
    89
      node->AggregateObject (taskManager);
mathieu@0
    90
      node->AggregateObject (loader);
mathieu@0
    91
      node->AggregateObject (manager);
mathieu@0
    92
      node->AggregateObject (networkStack);
mathieu@0
    93
    }
mathieu@0
    94
}
mathieu@0
    95
mathieu@0
    96
} // namespace ns3