NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
highway-position-allocator.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 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: Lucas Wang <lucas@cs.ucla.edu>
19  */
20 
21 
22 #include "highway-position-allocator.h"
23 #include "ns3/random-variable.h"
24 #include "ns3/log.h"
25 #include "ns3/double.h"
26 #include <math.h>
27 
28 NS_LOG_COMPONENT_DEFINE ("HighwayPositionAllocator");
29 
30 namespace ns3 {
31 
32 NS_OBJECT_ENSURE_REGISTERED (HighwayPositionAllocator);
33 
34 TypeId HighwayPositionAllocator::GetTypeId (void){
35  static TypeId tid = TypeId("ns3::HighwayPositionAllocator").
36  SetParent<PositionAllocator> ().
37  SetGroupName("Mobility").
38  AddConstructor<HighwayPositionAllocator>().
39  AddAttribute("Start", "the start position of the highway",
40  VectorValue (Vector(0.0, 0.0, 0.0)),
41  MakeVectorAccessor(&HighwayPositionAllocator::SetStartPosition,
42  &HighwayPositionAllocator::GetStartPosition),
43  MakeVectorChecker ()).
44  AddAttribute("Direction", "the direction of the highway",
45  DoubleValue (0.0),
46  MakeDoubleAccessor(&HighwayPositionAllocator::SetDirection,
47  &HighwayPositionAllocator::GetDirection),
48  MakeDoubleChecker<double> ()).
49  AddAttribute("Length", "the length of the highway",
50  DoubleValue (0.0),
51  MakeDoubleAccessor(&HighwayPositionAllocator::SetLength,
52  &HighwayPositionAllocator::GetLength),
53  MakeDoubleChecker<double> ());
54 
55  return tid;
56 }
57 
58 HighwayPositionAllocator::HighwayPositionAllocator ()
59  : m_previous_position (Vector (0.0, 0.0, 0.0))
60 {
61 }
62 
63 Vector HighwayPositionAllocator::GetNext (void) const{
64  double random_gap = m_random_gap_var.GetValue (1.0, 10.0);
65 
66  double delta_x = random_gap * cos(m_direction);
67  double delta_y = random_gap * sin(m_direction);
68 
69 
70  Vector new_position(m_previous_position.x - delta_x, m_previous_position.y - delta_y, m_previous_position.z);
71  m_previous_position.x = new_position.x;
72  m_previous_position.y = new_position.y;
73  m_previous_position.z = new_position.z;
74 
75  return new_position;
76 }
77 
78 void HighwayPositionAllocator::SetStartPosition(Vector start){
79  m_start = start;
80  m_previous_position = m_start; // initialize the m_previous_position to be start of the highway
81 }
82 
83 Vector HighwayPositionAllocator::GetStartPosition(void) const {
84  return m_start;
85 }
86 
87 void HighwayPositionAllocator::SetDirection(double direction){
88  m_direction = direction;
89 }
90 
91 double HighwayPositionAllocator::GetDirection(void) const {
92  return m_direction;
93 }
94 
95 void HighwayPositionAllocator::SetLength(double length){
96  m_length = length;
97 }
98 
99 double HighwayPositionAllocator::GetLength(void) const {
100  return m_length;
101 }
102 
103 
104 int64_t
105 HighwayPositionAllocator::AssignStreams (int64_t stream)
106 {
107  m_random_gap_var.SetStream (stream);
108  return 1;
109 }
110 
111 }