#include <BasicMobility.h>
Inheritance diagram for BasicMobility:
It does not provide mobility at all, so you can use it if you only want to simulate static networks.
BasicMobility provides random placement of hosts and display updates as well as registering with the ChannelControl module. Change notifications about position changes are also posted to NotificationBoard.
Public Types | |
enum | BorderPolicy { REFLECT, WRAP, PLACERANDOMLY, RAISEERROR } |
Protected Member Functions | |
void | handleMessage (cMessage *msg) |
This modules should only receive self-messages. | |
virtual void | initialize (int) |
Initializes mobility model parameters. | |
virtual void | finish () |
Delete dynamically allocated objects. | |
virtual void | handleSelfMsg (cMessage *msg) |
Called upon arrival of a self messages. | |
void | updatePosition () |
Update the position information for this node. | |
double | playgroundSizeX () const |
Returns the width of the playground. | |
double | playgroundSizeY () const |
Returns the height of the playground. | |
virtual Coord | getRandomPosition () |
Get a new random position for the host. | |
void | reflectIfOutside (Coord &targetPos, Coord &step, double &angle) |
Utility function to reflect the node if it goes outside the playground. | |
void | wrapIfOutside (Coord &targetPos) |
Utility function to wrap the node to the opposite edge (torus) if it goes outside the playground. | |
void | placeRandomlyIfOutside (Coord &targetPos) |
Utility function to place the node randomly if it goes outside the playground. | |
void | raiseErrorIfOutside () |
Utility function to raise an error if the node gets outside the playground. | |
void | handleIfOutside (BorderPolicy policy, Coord &targetPos, Coord &step, double &angle) |
Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy. | |
Protected Attributes | |
ChannelControl * | cc |
Pointer to ChannelControl -- these two must know each other. | |
ChannelControl::HostRef | myHostRef |
Identifies this host in the ChannelControl module. | |
cModule * | hostPtr |
Pointer to host module, to speed up repeated access. | |
Coord | pos |
Stores the actual position of the host. |
|
Selects how a node should behave if it reaches the edge of the playground.
00055 { 00056 REFLECT, 00057 WRAP, 00058 PLACERANDOMLY, 00059 RAISEERROR 00060 };
|
|
Delete dynamically allocated objects.
00083 {}
|
|
Get a new random position for the host. You can redefine this function if you want to use another calculation 00126 { 00127 Coord p; 00128 p.x = genk_uniform(0, 0, cc->getPgs()->x); 00129 p.y = genk_uniform(0, 0, cc->getPgs()->y); 00130 return p; 00131 }
|
|
Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy.
00209 { 00210 switch (policy) 00211 { 00212 case REFLECT: reflectIfOutside(targetPos, step, angle); break; 00213 case WRAP: wrapIfOutside(targetPos); break; 00214 case PLACERANDOMLY: placeRandomlyIfOutside(targetPos); break; 00215 case RAISEERROR: raiseErrorIfOutside(); break; 00216 } 00217 }
|
|
This modules should only receive self-messages. Dispatches self-messages to handleSelfMsg() 00093 { 00094 if (!msg->isSelfMessage()) 00095 error("mobility modules can only receive self messages"); 00096 00097 handleSelfMsg(msg); 00098 }
|
|
Called upon arrival of a self messages.
Reimplemented in CircleMobility, ConstSpeedMobility, LinearMobility, LineSegmentsMobilityBase, MassMobility, and RectangleMobility. 00087 {delete msg;};
|
|
Initializes mobility model parameters. Assigns a pointer to ChannelControl and gets a pointer to its host. Creates a random position for a host if the position is not given as a parameter in "omnetpp.ini". Additionally the registration with ChannelControl is done and it is assured that the position display string tag (p) exists and contains the exact (x) tag. Reimplemented from BasicModule. Reimplemented in ANSimMobility, BonnMotionMobility, CircleMobility, ConstSpeedMobility, LinearMobility, LineSegmentsMobilityBase, MassMobility, RandomWPMobility, RectangleMobility, and TurtleMobility. 00042 { 00043 BasicModule::initialize(stage); 00044 00045 coreEV << "initializing BasicMobility stage " << stage << endl; 00046 00047 if (stage == 0) 00048 { 00049 cc = dynamic_cast<ChannelControl *>(simulation.moduleByPath("channelcontrol")); 00050 if (cc == 0) 00051 error("Could not find channelcontrol module"); 00052 00053 //get a pointer to the host 00054 hostPtr = findHost(); 00055 myHostRef = cc->registerHost(hostPtr, Coord()); 00056 } 00057 else if (stage == 1) 00058 { 00059 // playground size gets set up by ChannelControl in stage==0 (Andras) 00060 // read the playgroundsize from ChannelControl 00061 Coord pgs = cc->getPgs(); 00062 00063 // reading the out from omnetpp.ini makes predefined scenarios a lot easier 00064 if (hasPar("x") && hasPar("y")) 00065 { 00066 pos.x = par("x"); 00067 pos.y = par("y"); 00068 // -1 indicates start at random position 00069 if (pos.x == -1 || pos.y == -1) 00070 pos = getRandomPosition(); 00071 //we do not have negative positions 00072 //also checks whether position is within the playground 00073 else if (pos.x < 0 || pos.y < 0 || pos.x > pgs.x || pos.y > pgs.y) 00074 error("node position specified in omnetpp.ini exceeds playgroundsize"); 00075 } 00076 else 00077 { 00078 // Start at a random position 00079 pos = getRandomPosition(); 00080 } 00081 00082 // adjusting the display string is no longer needed (Andras) 00083 00084 // print new host position on the screen and update bb info 00085 updatePosition(); 00086 } 00087 }
|
|
Utility function to place the node randomly if it goes outside the playground. Decision is made on pos, but targetPos will also be updated. (Pass a dummy you don't have it). 00190 { 00191 if (pos.x<0 || pos.x>=playgroundSizeX() || pos.y<0 || pos.y>=playgroundSizeY()) 00192 { 00193 Coord newPos = getRandomPosition(); 00194 targetPos += newPos - pos; 00195 pos = newPos; 00196 } 00197 }
|
|
Returns the width of the playground.
|
|
Returns the height of the playground.
|
|
Utility function to raise an error if the node gets outside the playground.
00200 { 00201 if (pos.x<0 || pos.x>=playgroundSizeX() || pos.y<0 || pos.y>=playgroundSizeY()) 00202 { 00203 error("node moved outside the playground of size %gx%g (x=%g,y=%g)", 00204 playgroundSizeX(), playgroundSizeY(), pos.x, pos.y); 00205 } 00206 }
|
|
Utility function to reflect the node if it goes outside the playground. Decision is made on pos, but the variables passed as args will also be updated. (Pass dummies you don't have some of them). 00134 { 00135 if (pos.x < 0) 00136 { 00137 pos.x = -pos.x; 00138 targetPos.x = -targetPos.x; 00139 step.x = -step.x; 00140 angle = 180 - angle; 00141 } 00142 else if (pos.x >= playgroundSizeX()) 00143 { 00144 pos.x = 2*playgroundSizeX() - pos.x; 00145 targetPos.x = 2*playgroundSizeX() - targetPos.x; 00146 step.x = -step.x; 00147 angle = 180 - angle; 00148 } 00149 if (pos.y < 0) 00150 { 00151 pos.y = -pos.y; 00152 targetPos.y = -targetPos.y; 00153 step.y = -step.y; 00154 angle = -angle; 00155 } 00156 else if (pos.y >= playgroundSizeY()) 00157 { 00158 pos.y = 2*playgroundSizeY() - pos.y; 00159 targetPos.y = 2*playgroundSizeY() - targetPos.y; 00160 step.y = -step.y; 00161 angle = -angle; 00162 } 00163 }
|
|
Update the position information for this node. This function tells NotificationBoard that the position has changed, and it also moves the host's icon to the new position on the screen. This function has to be called every time the position of the host changes! 00109 { 00110 cc->updateHostPosition(myHostRef, pos); 00111 00112 double r = cc->getCommunicationRange(myHostRef); 00113 hostPtr->displayString().setTagArg("p", 0, pos.x); 00114 hostPtr->displayString().setTagArg("p", 1, pos.y); 00115 hostPtr->displayString().setTagArg("r", 0, r); 00116 00117 nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED, &pos); 00118 }
|
|
Utility function to wrap the node to the opposite edge (torus) if it goes outside the playground. Decision is made on pos, but targetPos will also be updated. (Pass a dummy you don't have it). 00166 { 00167 if (pos.x < 0) 00168 { 00169 pos.x += playgroundSizeX(); 00170 targetPos.x += playgroundSizeX(); 00171 } 00172 else if (pos.x >= playgroundSizeX()) 00173 { 00174 pos.x -= playgroundSizeX(); 00175 targetPos.x -= playgroundSizeX(); 00176 } 00177 if (pos.y < 0) 00178 { 00179 pos.y += playgroundSizeY(); 00180 targetPos.y += playgroundSizeY(); 00181 } 00182 else if (pos.y >= playgroundSizeY()) 00183 { 00184 pos.y -= playgroundSizeY(); 00185 targetPos.y -= playgroundSizeY(); 00186 } 00187 }
|
|
Pointer to ChannelControl -- these two must know each other.
|
|
Pointer to host module, to speed up repeated access.
|
|
Identifies this host in the ChannelControl module.
|
|
Stores the actual position of the host.
|