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