INET Framework for OMNeT++/OMNEST
ANSimMobility Class Reference

Uses the <position_change> elements of the ANSim tool's trace file. See NED file for more info. More...

#include <ANSimMobility.h>

Inheritance diagram for ANSimMobility:
LineSegmentsMobilityBase BasicMobility BasicModule INotifiable

List of all members.

Protected Member Functions

virtual void initialize (int)
 Initializes mobility model parameters.
virtual void setTargetPosition ()
 Overridden from LineSegmentsMobilityBase.
virtual void extractDataFrom (cXMLElement *node)
 Utility: extract data from given <position_update> element.
virtual void fixIfHostGetsOutside ()
 Overridden from LineSegmentsMobilityBase.

Protected Attributes

int nodeId
 we'll have to compare this to the <node_id> elements
cXMLElement * nextPosChange
 points to the next <position_change> element

Detailed Description

Uses the <position_change> elements of the ANSim tool's trace file. See NED file for more info.

Author:
Andras Varga

Member Function Documentation

void ANSimMobility::extractDataFrom ( cXMLElement *  node) [protected, virtual]

Utility: extract data from given <position_update> element.

Referenced by setTargetPosition().

{
    // extract data from <position_update> element
    // FIXME start_time has to be taken into account too! as pause from prev element's end_time
    const char *startTimeStr = firstChildWithTag(node, "start_time")->getNodeValue();
    const char *endTimeStr = firstChildWithTag(node, "end_time")->getNodeValue();
    cXMLElement *destElem = firstChildWithTag(node, "destination");
    const char *xStr = firstChildWithTag(destElem, "xpos")->getNodeValue();
    const char *yStr = firstChildWithTag(destElem, "ypos")->getNodeValue();

    if (!endTimeStr || !xStr || !yStr)
        error("no content in <end_time>, <destination>/<xpos> or <ypos> element at %s", node->getSourceLocation());

    targetTime = atof(endTimeStr);
    targetPos.x = atof(xStr);
    targetPos.y = atof(yStr);
}
void ANSimMobility::fixIfHostGetsOutside ( ) [protected, virtual]
void ANSimMobility::initialize ( int  stage) [protected, virtual]

Initializes mobility model parameters.

Reimplemented from LineSegmentsMobilityBase.

{
    LineSegmentsMobilityBase::initialize(stage);

    EV << "initializing ANSimMobility stage " << stage << endl;

    if (stage == 1)
    {
        nodeId = par("nodeId");
        if (nodeId == -1)
            nodeId = getParentModule()->getIndex();

        // get script: param should point to <simulation> element
        cXMLElement *rootElem = par("ansimTrace");
        if (strcmp(rootElem->getTagName(),"simulation")!=0)
            error("ansimTrace: <simulation> is expected as root element not <%s> at %s",
                  rootElem->getTagName(), rootElem->getSourceLocation());
        nextPosChange = rootElem->getElementByPath("mobility/position_change");
        if (!nextPosChange)
            error("element doesn't have <mobility> child or <position_change> grandchild at %s",
                  rootElem->getSourceLocation());

        // set initial position;
        setTargetPosition();
        pos = targetPos;
        updatePosition();
    }
}
void ANSimMobility::setTargetPosition ( ) [protected, virtual]

Overridden from LineSegmentsMobilityBase.

Implements LineSegmentsMobilityBase.

Referenced by initialize().

{
    // find next <position_update> element with matching <node_id> tag (current one also OK)
    while (nextPosChange)
    {
        const char *nodeIdStr = firstChildWithTag(nextPosChange, "node_id")->getNodeValue();
        if (nodeIdStr && atoi(nodeIdStr)==nodeId)
            break;
        nextPosChange = nextPosChange->getNextSibling();
    }

    if (!nextPosChange)
    {
        stationary = true;
        return;
    }

    // extract data from it
    extractDataFrom(nextPosChange);

    // skip this one
    nextPosChange = nextPosChange->getNextSibling();
}

Member Data Documentation

cXMLElement* ANSimMobility::nextPosChange [protected]

points to the next <position_change> element

Referenced by initialize(), and setTargetPosition().

int ANSimMobility::nodeId [protected]

we'll have to compare this to the <node_id> elements

Referenced by initialize(), and setTargetPosition().


The documentation for this class was generated from the following files: