00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #ifndef MOBILITY_HELPER_H 00022 #define MOBILITY_HELPER_H 00023 00024 #include <vector> 00025 #include "ns3/object-factory.h" 00026 #include "ns3/attribute.h" 00027 #include "ns3/position-allocator.h" 00028 #include "node-container.h" 00029 00030 namespace ns3 { 00031 00032 class PositionAllocator; 00033 class MobilityModel; 00034 00035 /** 00036 * \brief assign positions and mobility models to nodes. 00037 * 00038 * MobilityHelper::Install is the most important method here. 00039 */ 00040 class MobilityHelper 00041 { 00042 public: 00043 MobilityHelper (); 00044 ~MobilityHelper (); 00045 00046 /** 00047 * Set the position allocator which will be used to allocate the initial 00048 * position of every node initialized during MobilityModel::Install. 00049 * 00050 * \param allocator allocate initial node positions 00051 */ 00052 void SetPositionAllocator (Ptr<PositionAllocator> allocator); 00053 00054 /** 00055 * \param type the type of mobility model to use. 00056 * \param n1 the name of the attribute to set in the mobility model. 00057 * \param v1 the value of the attribute to set in the mobility model. 00058 * \param n2 the name of the attribute to set in the mobility model. 00059 * \param v2 the value of the attribute to set in the mobility model. 00060 * \param n3 the name of the attribute to set in the mobility model. 00061 * \param v3 the value of the attribute to set in the mobility model. 00062 * \param n4 the name of the attribute to set in the mobility model. 00063 * \param v4 the value of the attribute to set in the mobility model. 00064 * \param n5 the name of the attribute to set in the mobility model. 00065 * \param v5 the value of the attribute to set in the mobility model. 00066 * \param n6 the name of the attribute to set in the mobility model. 00067 * \param v6 the value of the attribute to set in the mobility model. 00068 * \param n7 the name of the attribute to set in the mobility model. 00069 * \param v7 the value of the attribute to set in the mobility model. 00070 * \param n8 the name of the attribute to set in the mobility model. 00071 * \param v8 the value of the attribute to set in the mobility model. 00072 * \param n9 the name of the attribute to set in the mobility model. 00073 * \param v9 the value of the attribute to set in the mobility model. 00074 */ 00075 void SetPositionAllocator (std::string type, 00076 std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), 00077 std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), 00078 std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), 00079 std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), 00080 std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), 00081 std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), 00082 std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue (), 00083 std::string n8 = "", const AttributeValue &v8 = EmptyAttributeValue (), 00084 std::string n9 = "", const AttributeValue &v9 = EmptyAttributeValue ()); 00085 00086 /** 00087 * \param type the type of mobility model to use. 00088 * \param n1 the name of the attribute to set in the mobility model. 00089 * \param v1 the value of the attribute to set in the mobility model. 00090 * \param n2 the name of the attribute to set in the mobility model. 00091 * \param v2 the value of the attribute to set in the mobility model. 00092 * \param n3 the name of the attribute to set in the mobility model. 00093 * \param v3 the value of the attribute to set in the mobility model. 00094 * \param n4 the name of the attribute to set in the mobility model. 00095 * \param v4 the value of the attribute to set in the mobility model. 00096 * \param n5 the name of the attribute to set in the mobility model. 00097 * \param v5 the value of the attribute to set in the mobility model. 00098 * \param n6 the name of the attribute to set in the mobility model. 00099 * \param v6 the value of the attribute to set in the mobility model. 00100 * \param n7 the name of the attribute to set in the mobility model. 00101 * \param v7 the value of the attribute to set in the mobility model. 00102 * \param n8 the name of the attribute to set in the mobility model. 00103 * \param v8 the value of the attribute to set in the mobility model. 00104 * \param n9 the name of the attribute to set in the mobility model. 00105 * \param v9 the value of the attribute to set in the mobility model. 00106 * 00107 * Calls to MobilityHelper::Install will create an instance of a matching 00108 * mobility model for each node. 00109 */ 00110 void SetMobilityModel (std::string type, 00111 std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), 00112 std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), 00113 std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), 00114 std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), 00115 std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), 00116 std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), 00117 std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue (), 00118 std::string n8 = "", const AttributeValue &v8 = EmptyAttributeValue (), 00119 std::string n9 = "", const AttributeValue &v9 = EmptyAttributeValue ()); 00120 00121 /** 00122 * \param reference item to push. 00123 * 00124 * Push an item on the top of the stack of "reference mobility models". 00125 * The input item should be a node instance to which a mobility model 00126 * has already been aggregated (usually by a call to Install). 00127 * 00128 * If this this stack is not empty when MobilityHelper::Install 00129 * is called, the model from the top of the stack is used 00130 * to create a ns3::HierarchicalMobilityModel to make the 00131 * newly-created models define their positions relative to that 00132 * of the parent mobility model. 00133 * 00134 * This method is typically used to create hierarchical mobility 00135 * patterns and positions by starting with the large-scale mobility 00136 * features, and, then, defining the smaller-scale movements relative 00137 * to a few reference points in the large-scale model. 00138 */ 00139 void PushReferenceMobilityModel (Ptr<Object> reference); 00140 /** 00141 * Remove the top item from the top of the stack of 00142 * "reference mobility models". 00143 */ 00144 void PopReferenceMobilityModel (void); 00145 00146 /** 00147 * \returns a string which contains the TypeId of the currently-selected 00148 * mobility model. 00149 */ 00150 std::string GetMobilityModelType (void) const; 00151 00152 /** 00153 * \brief "Layout" a single node according to the current position allocator 00154 * type. 00155 * 00156 * This method creates an instance of a ns3::MobilityModel subclass (the 00157 * type of which was set with MobilityHelper::SetMobilityModel), aggregates 00158 * it to the provided node, and sets an initial position based on the current 00159 * position allocator (set through MobilityHelper::SetPositionAllocator). 00160 * 00161 * \param node The node to "layout." 00162 */ 00163 void Install (Ptr<Node> node) const; 00164 00165 /** 00166 * \brief Layout a collection of nodes according to the current position allocator 00167 * type. 00168 * 00169 * For each node in the provided NodeContainer, this method creates an instance 00170 * of a ns3::MobilityModel subclass (the type of which was set with 00171 * MobilityHelper::SetMobilityModel), aggregates it to the node, and sets an 00172 * initial position based on the current position allocator (set through 00173 * MobilityHelper::SetPositionAllocator). 00174 * 00175 * \param container The set of nodes to layout. 00176 */ 00177 void Install (NodeContainer container) const; 00178 00179 /** 00180 * Perform the work of MobilityHelper::Install on _all_ nodes which 00181 * exist in the simulation. 00182 */ 00183 void InstallAll (void); 00184 00185 /** 00186 * \param os output stream 00187 * \param nodeid the id of the node to generate ascii output for. 00188 * 00189 * Enable ascii output on the mobility model associated to the 00190 * specified nodeid and dump that to the specified stdc++ output 00191 * stream. 00192 */ 00193 static void EnableAscii (std::ostream &os, uint32_t nodeid); 00194 /** 00195 * \param os output stream 00196 * \param n node container 00197 * 00198 * Enable ascii output on the mobility model associated each of 00199 * the nodes in the input container and dump that to the 00200 * specified stdc++ output stream. 00201 */ 00202 static void EnableAscii (std::ostream &os, NodeContainer n); 00203 /** 00204 * \param os output stream 00205 * 00206 * Enable ascii output on the mobility model associated 00207 * every node in the system and dump that to the specified 00208 * stdc++ output stream. 00209 */ 00210 static void EnableAsciiAll (std::ostream &os); 00211 00212 private: 00213 static void CourseChanged (std::ostream *os, Ptr<const MobilityModel> mobility); 00214 std::vector<Ptr<MobilityModel> > m_mobilityStack; 00215 ObjectFactory m_mobility; 00216 Ptr<PositionAllocator> m_position; 00217 }; 00218 00219 } // namespace ns3 00220 00221 #endif /* MOBILITY_HELPER_H */