View | Details | Raw Unified | Return to bug 2390
Collapse All | Expand All

(-)a/src/mobility/model/waypoint-mobility-model.cc (-1 / +1 lines)
 Lines 95-101    Link Here 
95
95
96
  if ( !m_lazyNotify )
96
  if ( !m_lazyNotify )
97
    {
97
    {
98
      Simulator::Schedule (waypoint.time, &WaypointMobilityModel::Update, this);
98
      Simulator::Schedule (waypoint.time - Simulator::Now (), &WaypointMobilityModel::Update, this);
99
    }
99
    }
100
}
100
}
101
Waypoint
101
Waypoint
(-)a/src/mobility/test/waypoint-mobility-model-test.cc (-6 / +79 lines)
 Lines 49-55    Link Here 
49
  virtual void DoRun (void);
49
  virtual void DoRun (void);
50
  virtual void DoTeardown (void);
50
  virtual void DoTeardown (void);
51
  void ForceUpdates (void);
51
  void ForceUpdates (void);
52
  void CourseChangeCallback (std::string path, Ptr<const MobilityModel> model);
52
  void CourseChangeCallback (Ptr<const MobilityModel> model);
53
};
53
};
54
54
55
void
55
void
 Lines 94-99    Link Here 
94
  for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i)
94
  for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i)
95
    {
95
    {
96
      Ptr<WaypointMobilityModel> mob = (*i)->GetObject<WaypointMobilityModel> ();
96
      Ptr<WaypointMobilityModel> mob = (*i)->GetObject<WaypointMobilityModel> ();
97
      mob->TraceConnectWithoutContext ("CourseChange", MakeCallback (&WaypointMobilityModelNotifyTest::CourseChangeCallback, this));
97
98
98
      for ( std::deque<Waypoint>::iterator w = waypoints.begin (); w != waypoints.end (); ++w )
99
      for ( std::deque<Waypoint>::iterator w = waypoints.begin (); w != waypoints.end (); ++w )
99
        {
100
        {
 Lines 107-115    Link Here 
107
      Simulator::Schedule (Seconds (updateTime), &WaypointMobilityModelNotifyTest::ForceUpdates, this);
108
      Simulator::Schedule (Seconds (updateTime), &WaypointMobilityModelNotifyTest::ForceUpdates, this);
108
    }
109
    }
109
110
110
  Config::Connect ("/NodeList/*/$ns3::WaypointMobilityModel/CourseChange",
111
                   MakeCallback (&WaypointMobilityModelNotifyTest::CourseChangeCallback, this));
112
113
  Simulator::Stop (Seconds ((double)waypointCount + 2.0));
111
  Simulator::Stop (Seconds ((double)waypointCount + 2.0));
114
  Simulator::Run ();
112
  Simulator::Run ();
115
  Simulator::Destroy ();
113
  Simulator::Destroy ();
 Lines 125-131    Link Here 
125
    }
123
    }
126
}
124
}
127
void
125
void
128
WaypointMobilityModelNotifyTest::CourseChangeCallback (std::string path, Ptr<const MobilityModel> model)
126
WaypointMobilityModelNotifyTest::CourseChangeCallback (Ptr<const MobilityModel> model)
129
{
127
{
130
  const Time now = Simulator::Now ();
128
  const Time now = Simulator::Now ();
131
  const double sec = now.GetSeconds ();
129
  const double sec = now.GetSeconds ();
 Lines 137-143    Link Here 
137
    {
135
    {
138
      // All waypoints are on second boundaries only
136
      // All waypoints are on second boundaries only
139
      NS_TEST_EXPECT_MSG_EQ (sec - ((double)((int)sec)) + sec, sec,
137
      NS_TEST_EXPECT_MSG_EQ (sec - ((double)((int)sec)) + sec, sec,
140
                             "Course didn't change on one second time boundary with NON-LAZY notifcations");
138
                             "Course didn't change on one second time boundary with NON-LAZY notifications");
141
    }
139
    }
142
  else
140
  else
143
    {
141
    {
 Lines 147-157    Link Here 
147
    }
145
    }
148
}
146
}
149
147
148
class WaypointMobilityModelAddWaypointTest : public TestCase
149
{
150
public:
151
  WaypointMobilityModelAddWaypointTest ()
152
    : TestCase ("Check Waypoint Mobility Model waypoint add")
153
  {
154
  }
155
  virtual ~WaypointMobilityModelAddWaypointTest ()
156
  {
157
  }
158
159
private:
160
  Ptr<MobilityModel> m_mobilityModel;
161
  uint32_t m_waypointCount;
162
  uint32_t m_waypointCounter;
163
  Waypoint m_nextWaypoint;
164
private:
165
  virtual void DoRun (void);
166
  virtual void DoTeardown (void);
167
  void CourseChangeCallback (Ptr<const MobilityModel> model);
168
};
169
170
171
void
172
WaypointMobilityModelAddWaypointTest::DoTeardown (void)
173
{
174
  m_mobilityModel = 0;
175
}
176
177
void
178
WaypointMobilityModelAddWaypointTest::DoRun (void)
179
{
180
  m_waypointCount = 10;
181
  m_waypointCounter = 1;
182
183
  ObjectFactory mobilityFactory;
184
  mobilityFactory.SetTypeId ("ns3::WaypointMobilityModel");
185
  mobilityFactory.Set ("LazyNotify", BooleanValue (false));
186
187
  // Create a new mobility model.
188
  m_mobilityModel = mobilityFactory.Create ()->GetObject<MobilityModel> ();
189
  m_mobilityModel->TraceConnectWithoutContext ("CourseChange", MakeCallback (&WaypointMobilityModelAddWaypointTest::CourseChangeCallback, this));
190
191
  // Add this mobility model to the stack.
192
  Simulator::Schedule (Seconds (0.0), &Object::Initialize, m_mobilityModel);
193
194
  Ptr<WaypointMobilityModel> mob = DynamicCast<WaypointMobilityModel> (m_mobilityModel);
195
  Waypoint m_nextWaypoint (Seconds (m_waypointCounter), Vector (0.0, 0.0, 0.0));
196
  mob->AddWaypoint (m_nextWaypoint);
197
198
  Simulator::Stop (Seconds ((double)m_waypointCount + 2.0));
199
  Simulator::Run ();
200
  Simulator::Destroy ();
201
}
202
203
void
204
WaypointMobilityModelAddWaypointTest::CourseChangeCallback (Ptr<const MobilityModel> model)
205
{
206
  const Time now = Simulator::Now ();
207
  Ptr<WaypointMobilityModel> mob = DynamicCast<WaypointMobilityModel> (m_mobilityModel);
208
209
  std::cout << now << " CourseChangeCallback" << std::endl;
210
211
  NS_TEST_EXPECT_MSG_EQ (now, Seconds (m_waypointCounter), "Waypoint time not properly set");
212
213
  if (now < Seconds ((double)m_waypointCount) )
214
    {
215
      m_waypointCounter ++;
216
      m_nextWaypoint = Waypoint (Seconds (m_waypointCounter), Vector (0.0, 0.0, 0.0));
217
      mob->AddWaypoint (m_nextWaypoint);
218
219
    }
220
}
221
150
static struct WaypointMobilityModelTestSuite : public TestSuite
222
static struct WaypointMobilityModelTestSuite : public TestSuite
151
{
223
{
152
  WaypointMobilityModelTestSuite () : TestSuite ("waypoint-mobility-model", UNIT)
224
  WaypointMobilityModelTestSuite () : TestSuite ("waypoint-mobility-model", UNIT)
153
  {
225
  {
154
    AddTestCase (new WaypointMobilityModelNotifyTest (true), TestCase::QUICK);
226
    AddTestCase (new WaypointMobilityModelNotifyTest (true), TestCase::QUICK);
155
    AddTestCase (new WaypointMobilityModelNotifyTest (false), TestCase::QUICK);
227
    AddTestCase (new WaypointMobilityModelNotifyTest (false), TestCase::QUICK);
228
    AddTestCase (new WaypointMobilityModelAddWaypointTest (), TestCase::QUICK);
156
  }
229
  }
157
} g_waypointMobilityModelTestSuite;
230
} g_waypointMobilityModelTestSuite;

Return to bug 2390