ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ns3::DceManager Class Reference

Manages a set of virtual POSIX processes within the same address space. More...

#include <dce-manager.h>

+ Collaboration diagram for ns3::DceManager:

Public Types

enum  ProcessEndCause { PEC_EXIT, PEC_NS3_END, PEC_NS3_STOP }
typedef Callback< void > Runnable

Public Member Functions

 DceManager ()
virtual ~DceManager ()
uint16_t Clone (Thread *thread)
struct ProcessCreateProcess (std::string name, std::string stdinfilename, std::vector< std::string > args, std::vector< std::pair< std::string, std::string > > envs, int pid)
struct ThreadCreateThread (struct Process *process)
void DeleteProcess (struct Process *process, ProcessEndCause type)
void DeleteThread (struct Thread *thread)
int Execve (const char *path, const char *argv0, char *const argv[], char *const envp[])
void Exit (void)
void FinishChild (uint16_t pid)
std::map< uint16_t, Process * > GetProcs ()
std::string GetVirtualPath () const
void ResumeTemporaryTask (uint16_t pid)
ProcessSearchProcess (uint16_t pid)
ThreadSearchThread (uint16_t pid, uint16_t tid)
void SetFinishedCallback (uint16_t pid, Callback< void, uint16_t, int > cb)
void SetVirtualPath (std::string p)
uint16_t Start (std::string name, std::string stdinfilename, std::vector< std::string > args, std::vector< std::pair< std::string, std::string > > envs, uid_t uid, uid_t euid, uid_t gid, uid_t egid)
uint16_t Start (std::string name, std::string stdinfilename, uint32_t stackSize, std::vector< std::string > args, std::vector< std::pair< std::string, std::string > > envs, uid_t uid, uid_t euid, uid_t gid, uid_t egid)
uint16_t StartInternalTask ()
uint16_t StartTemporaryTask ()
void Stop (uint16_t pid)
void StopTemporaryTask (uint16_t pid)
void SuspendTemporaryTask (uint16_t pid)
void Wait (void)
Time Wait (Time timeout)
void Wakeup (Thread *thread)
void Yield (void)

Static Public Member Functions

static void AppendProcFile (Process *p)
static void AppendStatusFile (uint16_t pid, uint32_t nodeId, std::string &line)
static TypeId GetTypeId (void)

Private Member Functions

uint16_t AllocatePid (void)
uint16_t AllocateTid (const struct Process *process) const
bool CheckProcessContext (void) const
void ChildFinished (uint16_t pid)
void CleanupThread (struct Thread *thread)
std::vector< std::string > CopyArgs (char *const argv[])
int CopyEnv (char *const envp[], std::vector< std::pair< std::string, std::string > > &res)
virtual void DoDispose (void)
void SetArgv (struct Process *process, std::string filename, std::vector< std::string > args)
void SetEnvp (struct Process *process, std::vector< std::pair< std::string, std::string > > envp)
bool ThreadExists (Thread *thread)
bool WakeupChildWaiters (struct Process *p)

Static Private Member Functions

static int CreatePidFile (struct Thread *current, std::string prefix)
static void DoExecProcess (void *c)
static void DoStartProcess (void *context)
static void EnsureDirectoryExists (struct Thread *current, std::string dirName)
static struct::Libc * GetLibc (void)
static void * LoadMain (Loader *ld, std::string filename, Process *proc, int &err)
static void SetDefaultSigHandler (std::vector< SignalHandler > &signalHandlers)
static void SigabrtHandler (int signal)
static void SigkillHandler (int signal)
static void StartProcessDebugHook (void)
static void TaskSwitch (enum Task::SwitchType type, void *context)

Private Attributes

bool m_minimizeFiles
uint16_t m_nextPid
std::map< uint16_t, Process * > m_processes
TracedCallback< uint16_t, int > m_processExit
std::string m_virtualPath

Static Private Attributes

static int(*)(int, char **) PrepareDoStartProcess (Thread *current)

Detailed Description

Manages a set of virtual POSIX processes within the same address space.

Functionality provided by this class:

  • a non-preemptive process scheduler. By default, this scheduler is a round robin scheduler. This scheduler allows a 'synchronous' programming style where functions can block until certain conditions are verified as opposed to event-driven programming as is common in most simulators.
  • user-space thread library (named fibers) used by the process scheduler to allocate stack space to each thread within each process. The default implementation uses in fact kernel-space POSIX threads but it's easy to switch to a real userspace implementation using the FiberManagerType attribute.
  • an ELF loader which controls how each user binary is loaded in memory and makes sure that each instance of the same binary has private global variables. The default implementation is ns3::ElfLoaderCopy but a more efficient implementation (both cpu and memory-wise can be found in ns3::ElfLoaderSmart) and it's easy to control which implementation is used with the LoaderType attribute.

A couple of applications which you can try with this loader:

  • iperf: recompile with: "CFLAGS=-fPIC CXXFLAGS=-fPIC LDFLAGS=-pie ./configure && make"
  • ip: recompile iproute2 with: "make CCOPTS='-fPIC' LDFLAGS=-pie" Note: to get tc recompiled, it seems that you need to run bison by hand: "cd tc && bison -d -t -v -o emp_ematch.yacc.c emp_ematch.y"
  • ping: recompile iputils: edit Makefile: replace "CFLAGS=" with "CFLAGS+=" and run: "make CFLAGS=-fPIC LDFLAGS=-pie"

Definition at line 73 of file dce-manager.h.

Member Typedef Documentation

typedef Callback<void> ns3::DceManager::Runnable

Definition at line 76 of file dce-manager.h.

Member Enumeration Documentation

Enumerator:
PEC_EXIT 
PEC_NS3_END 
PEC_NS3_STOP 

Definition at line 77 of file dce-manager.h.

Constructor & Destructor Documentation

ns3::DceManager::DceManager ( )

Definition at line 91 of file dce-manager.cc.

ns3::DceManager::~DceManager ( )
virtual

Definition at line 95 of file dce-manager.cc.

Member Function Documentation

uint16_t ns3::DceManager::AllocatePid ( void  )
private

Definition at line 475 of file dce-manager.cc.

References m_nextPid, and SearchProcess().

Referenced by Clone(), and CreateProcess().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint16_t ns3::DceManager::AllocateTid ( const struct Process process) const
private

Definition at line 494 of file dce-manager.cc.

References ns3::Process::threads, and ns3::Thread::tid.

Referenced by CreateThread().

+ Here is the caller graph for this function:

void ns3::DceManager::AppendStatusFile ( uint16_t  pid,
uint32_t  nodeId,
std::string &  line 
)
static

Definition at line 1028 of file dce-manager.cc.

References ns3::GetTimeStamp().

Referenced by dce_exit(), DoDispose(), Execve(), and Stop().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::DceManager::CheckProcessContext ( void  ) const
private

Definition at line 943 of file dce-manager.cc.

References ns3::Current().

Referenced by SearchThread().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::ChildFinished ( uint16_t  pid)
private

Definition at line 1093 of file dce-manager.cc.

References ns3::Process::children, m_processes, ns3::Process::ppid, SearchProcess(), and WakeupChildWaiters().

Referenced by DeleteProcess().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::CleanupThread ( struct Thread thread)
private

Definition at line 721 of file dce-manager.cc.

References ns3::PollTable::FreeWait(), ns3::Thread::ioWait, and ns3::Thread::pollTable.

Referenced by DeleteProcess(), and Execve().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > ns3::DceManager::CopyArgs ( char *const  argv[])
private

Definition at line 1141 of file dce-manager.cc.

Referenced by Execve().

+ Here is the caller graph for this function:

int ns3::DceManager::CopyEnv ( char *const  envp[],
std::vector< std::pair< std::string, std::string > > &  res 
)
private

Definition at line 1162 of file dce-manager.cc.

References ns3::Current(), and ns3::Thread::err.

Referenced by Execve().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int ns3::DceManager::CreatePidFile ( struct Thread current,
std::string  prefix 
)
staticprivate

Definition at line 154 of file dce-manager.cc.

References dce_creat(), EnsureDirectoryExists(), ns3::Process::pid, and ns3::Thread::process.

+ Here is the call graph for this function:

void ns3::DceManager::DeleteThread ( struct Thread thread)

Definition at line 743 of file dce-manager.cc.

References ns3::Thread::childWaiter, ns3::Thread::process, Stop(), ns3::Thread::task, and ns3::Process::threads.

Referenced by dce_pthread_exit(), dce_pthread_join(), DeleteProcess(), and Execve().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::DoDispose ( void  )
privatevirtual

Definition at line 100 of file dce-manager.cc.

References AppendStatusFile(), DeleteProcess(), m_processes, ns3::Process::nodeId, PEC_NS3_END, and ns3::Process::pid.

+ Here is the call graph for this function:

void ns3::DceManager::DoExecProcess ( void *  c)
staticprivate

Definition at line 1284 of file dce-manager.cc.

References ns3::Current(), dce_exit(), main(), ns3::Process::originalArgc, ns3::Process::originalArgv, ns3::Thread::process, and StartProcessDebugHook().

Referenced by Execve().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::DoStartProcess ( void *  context)
staticprivate

Definition at line 272 of file dce-manager.cc.

References dce_exit(), main(), ns3::Process::originalArgc, ns3::Process::originalArgv, PrepareDoStartProcess, ns3::Thread::process, and StartProcessDebugHook().

Referenced by Start().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::EnsureDirectoryExists ( struct Thread current,
std::string  dirName 
)
staticprivate

Definition at line 131 of file dce-manager.cc.

References dce_close(), dce_mkdir(), dce_open(), and ns3::Thread::err.

Referenced by CreatePidFile().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::Exit ( void  )

Definition at line 552 of file dce-manager.cc.

References ns3::Current().

+ Here is the call graph for this function:

void ns3::DceManager::FinishChild ( uint16_t  pid)

Definition at line 1130 of file dce-manager.cc.

References m_processes, and SearchProcess().

Referenced by dce_waitpid().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

struct::Libc * ns3::DceManager::GetLibc ( void  )
staticprivate

Definition at line 119 of file dce-manager.cc.

References libc_dce().

Referenced by LoadMain().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::map< uint16_t, Process * > ns3::DceManager::GetProcs ( )

Definition at line 1087 of file dce-manager.cc.

References m_processes.

TypeId ns3::DceManager::GetTypeId ( void  )
static

Definition at line 70 of file dce-manager.cc.

References m_minimizeFiles, m_nextPid, and m_processExit.

std::string ns3::DceManager::GetVirtualPath ( ) const

Definition at line 1534 of file dce-manager.cc.

References m_virtualPath.

Referenced by ns3::SearchExecFile().

+ Here is the caller graph for this function:

void * ns3::DceManager::LoadMain ( Loader ld,
std::string  filename,
Process proc,
int &  err 
)
staticprivate

Definition at line 1192 of file dce-manager.cc.

References GetLibc(), ns3::Loader::Load(), ns3::Loader::Lookup(), and ns3::Process::mainHandle.

Referenced by Execve().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::ResumeTemporaryTask ( uint16_t  pid)
Process * ns3::DceManager::SearchProcess ( uint16_t  pid)
Thread * ns3::DceManager::SearchThread ( uint16_t  pid,
uint16_t  tid 
)

Definition at line 949 of file dce-manager.cc.

References CheckProcessContext(), SearchProcess(), ns3::Process::threads, and ns3::Thread::tid.

Referenced by dce_pthread_detach(), dce_pthread_join(), and dce_pthread_kill().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::SetArgv ( struct Process process,
std::string  filename,
std::vector< std::string >  args 
)
private

Definition at line 984 of file dce-manager.cc.

References ns3::Process::allocated, ns3::Process::originalArgc, ns3::Process::originalArgv, and ns3::Process::originalProgname.

Referenced by CreateProcess(), and Execve().

+ Here is the caller graph for this function:

void ns3::DceManager::SetDefaultSigHandler ( std::vector< SignalHandler > &  signalHandlers)
staticprivate

Definition at line 1295 of file dce-manager.cc.

References ns3::SignalHandler::flags, ns3::SignalHandler::handler, ns3::SignalHandler::mask, SigabrtHandler(), SigkillHandler(), and ns3::SignalHandler::signal.

Referenced by Clone(), CreateProcess(), and Execve().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::SetEnvp ( struct Process process,
std::vector< std::pair< std::string, std::string > >  envp 
)
private

Definition at line 1006 of file dce-manager.cc.

References ns3::Process::allocated, and ns3::Process::originalEnvp.

Referenced by CreateProcess(), and Execve().

+ Here is the caller graph for this function:

void ns3::DceManager::SetFinishedCallback ( uint16_t  pid,
Callback< void, uint16_t, int >  cb 
)

Definition at line 685 of file dce-manager.cc.

References ns3::Process::finished, and SearchProcess().

+ Here is the call graph for this function:

void ns3::DceManager::SetVirtualPath ( std::string  p)

Definition at line 1529 of file dce-manager.cc.

References m_virtualPath.

void ns3::DceManager::SigabrtHandler ( int  signal)
staticprivate

Definition at line 715 of file dce-manager.cc.

References dce_exit().

Referenced by SetDefaultSigHandler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::SigkillHandler ( int  signal)
staticprivate

Definition at line 709 of file dce-manager.cc.

References dce_exit().

Referenced by SetDefaultSigHandler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint16_t ns3::DceManager::Start ( std::string  name,
std::string  stdinfilename,
std::vector< std::string >  args,
std::vector< std::pair< std::string, std::string > >  envs,
uid_t  uid,
uid_t  euid,
uid_t  gid,
uid_t  egid 
)
uint16_t ns3::DceManager::Start ( std::string  name,
std::string  stdinfilename,
uint32_t  stackSize,
std::vector< std::string >  args,
std::vector< std::pair< std::string, std::string > >  envs,
uid_t  uid,
uid_t  euid,
uid_t  gid,
uid_t  egid 
)
uint16_t ns3::DceManager::StartInternalTask ( )

Definition at line 417 of file dce-manager.cc.

References CreateProcess(), CreateThread(), ns3::Process::pid, and ns3::Task::SetContext().

+ Here is the call graph for this function:

void ns3::DceManager::StartProcessDebugHook ( void  )
staticprivate

Definition at line 287 of file dce-manager.cc.

Referenced by DoExecProcess(), and DoStartProcess().

+ Here is the caller graph for this function:

uint16_t ns3::DceManager::StartTemporaryTask ( )
void ns3::DceManager::Stop ( uint16_t  pid)

Definition at line 695 of file dce-manager.cc.

References AppendStatusFile(), DeleteProcess(), ns3::Process::nodeId, PEC_NS3_STOP, ns3::Process::pid, and SearchProcess().

Referenced by DeleteThread(), and ns3::DceApplication::StopApplication().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::StopTemporaryTask ( uint16_t  pid)
void ns3::DceManager::SuspendTemporaryTask ( uint16_t  pid)

Definition at line 453 of file dce-manager.cc.

References ns3::Current(), ns3::TaskManager::Current(), ns3::TaskManager::CurrentTask(), ns3::Process::pid, SearchProcess(), ns3::Thread::task, and ns3::Process::threads.

Referenced by ns3::LinuxSocketImpl::LeaveFakeTask().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::TaskSwitch ( enum Task::SwitchType  type,
void *  context 
)
staticprivate

Definition at line 365 of file dce-manager.cc.

References ns3::Process::alloc, ns3::Task::FROM, ns3::Process::loader, ns3::Loader::NotifyEndExecute(), ns3::Loader::NotifyStartExecute(), KingsleyAlloc::SwitchTo(), and ns3::Task::TO.

Referenced by Clone(), Execve(), and Start().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::DceManager::ThreadExists ( Thread thread)
private

Definition at line 558 of file dce-manager.cc.

References ns3::Thread::process, and ns3::Process::threads.

Referenced by Wakeup().

+ Here is the caller graph for this function:

void ns3::DceManager::Wait ( void  )
Time ns3::DceManager::Wait ( Time  timeout)

Definition at line 672 of file dce-manager.cc.

References ns3::Current().

+ Here is the call graph for this function:

void ns3::DceManager::Wakeup ( Thread thread)
bool ns3::DceManager::WakeupChildWaiters ( struct Process p)
private

Definition at line 1113 of file dce-manager.cc.

References ns3::Thread::childWaiter, ns3::Process::threads, and ns3::Waiter::Wakeup().

Referenced by ChildFinished().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::DceManager::Yield ( void  )

Definition at line 660 of file dce-manager.cc.

References ns3::Current().

Referenced by dce_pthread_mutex_unlock(), dce_sched_yield(), and dce_sem_post().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool ns3::DceManager::m_minimizeFiles
private

Definition at line 162 of file dce-manager.h.

Referenced by CreateProcess(), and GetTypeId().

uint16_t ns3::DceManager::m_nextPid
private

Definition at line 159 of file dce-manager.h.

Referenced by AllocatePid(), and GetTypeId().

std::map<uint16_t, Process *> ns3::DceManager::m_processes
private
TracedCallback<uint16_t, int> ns3::DceManager::m_processExit
private

Definition at line 160 of file dce-manager.h.

Referenced by DeleteProcess(), and GetTypeId().

std::string ns3::DceManager::m_virtualPath
private

Definition at line 163 of file dce-manager.h.

Referenced by GetVirtualPath(), and SetVirtualPath().

int(*)(int, char **) ns3::DceManager::PrepareDoStartProcess(Thread *current)
staticprivate

Definition at line 133 of file dce-manager.h.

Referenced by DoStartProcess().


The documentation for this class was generated from the following files: