ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
process-delay-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "process-delay-model.h"
21 #include "ns3/log.h"
22 #include <sys/time.h>
23 #include <time.h>
24 
25 namespace ns3 {
26 
27 NS_OBJECT_ENSURE_REGISTERED (ProcessDelayModel);
28 NS_LOG_COMPONENT_DEFINE ("ProcessDelayModel");
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::ProcessDelayModel")
34  .SetParent<Object> ()
35  ;
36  return tid;
37 }
38 
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::RandomProcessDelayModel")
45  .SetParent<ProcessDelayModel> ()
46  .AddConstructor<RandomProcessDelayModel> ()
47  .AddAttribute ("Variable", "Pick the process delay at random.",
48  RandomVariableValue (ConstantVariable (0.0)),
49  MakeRandomVariableAccessor (&RandomProcessDelayModel::m_variable),
50  MakeRandomVariableChecker ())
51  ;
52  return tid;
53 }
54 
56 {
57 }
58 
59 void
60 RandomProcessDelayModel::SetVariable (RandomVariable variable)
61 {
62 }
63 
64 void
66 {
67 }
68 Time
70 {
71  return Seconds (m_variable.GetValue ());
72 }
73 
75 
76 TypeId
78 {
79  static TypeId tid = TypeId ("ns3::TimeOfDayProcessDelayModel")
80  .SetParent<ProcessDelayModel> ()
81  .AddConstructor<TimeOfDayProcessDelayModel> ()
82  ;
83  return tid;
84 }
85 
87 {
88 }
89 
90 Time
92 {
93  struct timezone tz;
94  struct timeval timeval;
95  gettimeofday (&timeval, &tz);
96  Time s = Seconds (timeval.tv_sec);
97  Time us = MicroSeconds (timeval.tv_usec);
98  return s + us;
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION (this);
105  m_start = GetTimeOfDay ();
106 }
107 Time
109 {
110  NS_LOG_FUNCTION (this);
111  Time delay = GetTimeOfDay () - m_start;
112  if (delay.IsZero ())
113  {
114  delay = MicroSeconds (1);
115  }
116  return delay;
117 }
118 
119 
120 } // namespace ns3