SUMO - Simulation of Urban MObility
TraCITestClient Class Reference

A test execution class. More...

#include <TraCITestClient.h>

Inheritance diagram for TraCITestClient:
TraCIAPI

Public Types

Structures definitions
typedef std::vector< TraCIPositionTraCIPositionVector
 

Public Member Functions

bool run (std::string fileName, int port, std::string host="localhost")
 Runs a test. More...
 
 TraCITestClient (std::string outputFileName="testclient_result.out")
 Constructor. More...
 
 ~TraCITestClient ()
 Destructor. More...
 
Connection handling
void connect (const std::string &host, int port)
 Connects to the specified SUMO server. More...
 
void close ()
 Closes the connection. More...
 
Atomar getter
SUMOTime getSUMOTime (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
int getUnsignedByte (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
int getByte (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
int getInt (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
SUMOReal getFloat (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
SUMOReal getDouble (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIBoundary getBoundingBox (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIPositionVector getPolygon (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIPosition getPosition (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
std::string getString (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
std::vector< std::string > getStringVector (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIColor getColor (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 

Data Fields

EdgeScope edge
 Scope for interaction with edges. More...
 
GUIScope gui
 Scope for interaction with the gui. More...
 
InductionLoopScope inductionloop
 Scope for interaction with inductive loops. More...
 
JunctionScope junction
 Scope for interaction with junctions. More...
 
LaneScope lane
 Scope for interaction with lanes. More...
 
MeMeScope multientryexit
 Scope for interaction with multi-entry/-exit detectors. More...
 
POIScope poi
 Scope for interaction with POIs. More...
 
PolygonScope polygon
 Scope for interaction with polygons. More...
 
RouteScope route
 Scope for interaction with routes. More...
 
SimulationScope simulation
 Scope for interaction with the simulation. More...
 
TrafficLightScope trafficlights
 Scope for interaction with traffic lights. More...
 
VehicleTypeScope vehicletype
 Scope for interaction with vehicle types. More...
 

Protected Member Functions

Commands handling
void commandSimulationStep (SUMOTime time)
 Sends and validates a simulation step command. More...
 
void commandClose ()
 Sends and validates a Close command. More...
 
void commandGetVariable (int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
 Sends and validates a GetVariable command. More...
 
void commandSetValue (int domID, int varID, const std::string &objID, std::ifstream &defFile)
 Sends and validates a SetVariable command. More...
 
void commandSubscribeObjectVariable (int domID, const std::string &objID, int beginTime, int endTime, int varNo, std::ifstream &defFile)
 Sends and validates a SubscribeVariable command. More...
 
void commandSubscribeContextVariable (int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal range, int varNo, std::ifstream &defFile)
 Sends and validates a SubscribeContext command. More...
 
Command sending methods
void send_commandSimulationStep (SUMOTime time) const
 Sends a SimulationStep command. More...
 
void send_commandClose () const
 Sends a Close command. More...
 
void send_commandGetVariable (int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
 Sends a GetVariable request. More...
 
void send_commandSetValue (int domID, int varID, const std::string &objID, tcpip::Storage &content) const
 Sends a SetVariable request. More...
 
void send_commandSubscribeObjectVariable (int domID, const std::string &objID, int beginTime, int endTime, const std::vector< int > &vars) const
 Sends a SubscribeVariable request. More...
 
void send_commandSubscribeObjectContext (int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal range, const std::vector< int > &vars) const
 Sends a SubscribeContext request. More...
 
void check_resultState (tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const
 Validates the result state of a command. More...
 
void check_commandGetResult (tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
 
void processGET (tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
 

Protected Attributes

tcpip::SocketmySocket
 The socket. More...
 

Private Member Functions

Report helper
void writeResult ()
 Writes the results file. More...
 
void errorMsg (std::stringstream &msg)
 Writes an error message. More...
 
Results validation methods
bool validateSimulationStep2 (tcpip::Storage &inMsg)
 Validates whether the given message is a valid answer to CMD_SIMSTEP2. More...
 
bool validateSubscription (tcpip::Storage &inMsg)
 Validates whether the given message is a valid subscription return message. More...
 
Conversion helper
int setValueTypeDependant (tcpip::Storage &into, std::ifstream &defFile, std::stringstream &msg)
 Parses the next value type / value pair from the stream and inserts it into the storage. More...
 
void readAndReportTypeDependent (tcpip::Storage &inMsg, int valueDataType)
 Reads a value of the given type from the given storage and reports it. More...
 

Private Attributes

std::stringstream answerLog
 Stream containing the log. More...
 
std::string outputFileName
 The name of the file to write the results log into. More...
 

Detailed Description

A test execution class.

Reads a program file and executes the actions stored within it

Definition at line 47 of file TraCITestClient.h.

Member Typedef Documentation

typedef std::vector<TraCIPosition> TraCIAPI::TraCIPositionVector
inherited

Definition at line 76 of file TraCIAPI.h.

Constructor & Destructor Documentation

TraCITestClient::TraCITestClient ( std::string  outputFileName = "testclient_result.out")

Constructor.

Parameters
[in]outputFileNameThe name of the file the outputs will be written into

Definition at line 58 of file TraCITestClient.cpp.

References answerLog.

TraCITestClient::~TraCITestClient ( )

Destructor.

Definition at line 66 of file TraCITestClient.cpp.

References writeResult().

Member Function Documentation

void TraCIAPI::check_commandGetResult ( tcpip::Storage inMsg,
int  command,
int  expectedType = -1,
bool  ignoreCommandId = false 
) const
protectedinherited
void TraCIAPI::check_resultState ( tcpip::Storage inMsg,
int  command,
bool  ignoreCommandId = false,
std::string *  acknowledgement = 0 
) const
protectedinherited

Validates the result state of a command.

Parameters
[in]inMsgThe buffer to read the message from
[in]commandThe original command id
[in]ignoreCommandIdWhether the returning command id shall be validated
[in]acknowledgementPointer to an existing string into which the acknowledgement message shall be inserted

Definition at line 226 of file TraCIAPI.cpp.

References TraCIAPI::mySocket, tcpip::Storage::position(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), tcpip::Socket::receiveExact(), RTYPE_ERR, RTYPE_NOTIMPLEMENTED, RTYPE_OK, and toString().

Referenced by commandClose(), commandGetVariable(), commandSetValue(), commandSimulationStep(), commandSubscribeContextVariable(), commandSubscribeObjectVariable(), and TraCIAPI::processGET().

void TraCIAPI::close ( )
inherited

Closes the connection.

Definition at line 82 of file TraCIAPI.cpp.

References tcpip::Socket::close(), and TraCIAPI::mySocket.

Referenced by run().

void TraCITestClient::commandClose ( )
protected

Sends and validates a Close command.

Definition at line 195 of file TraCITestClient.cpp.

References answerLog, TraCIAPI::check_resultState(), CMD_CLOSE, TraCIAPI::send_commandClose(), and tcpip::SocketException::what().

Referenced by run().

void TraCITestClient::commandGetVariable ( int  domID,
int  varID,
const std::string &  objID,
tcpip::Storage addData = 0 
)
protected

Sends and validates a GetVariable command.

Parameters
[in]domIDThe ID of the domain the addressed object belongs to
[in]varIDThe ID of the variable one asks for
[in]objIDThe ID of the object a variable shall be retrieved from
[in]addDataStorage to read additional data from, if needed

Definition at line 210 of file TraCITestClient.cpp.

References answerLog, TraCIAPI::check_commandGetResult(), TraCIAPI::check_resultState(), errorMsg(), readAndReportTypeDependent(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), TraCIAPI::send_commandGetVariable(), and tcpip::SocketException::what().

Referenced by run().

void TraCITestClient::commandSetValue ( int  domID,
int  varID,
const std::string &  objID,
std::ifstream &  defFile 
)
protected

Sends and validates a SetVariable command.

Parameters
[in]domIDThe ID of the domain the addressed object belongs to
[in]varIDThe ID of the variable to set
[in]objIDThe ID of the object which shall be changed
[in]defFileStorage to read additional data from

Definition at line 243 of file TraCITestClient.cpp.

References answerLog, TraCIAPI::check_resultState(), errorMsg(), TraCIAPI::send_commandSetValue(), setValueTypeDependant(), and tcpip::SocketException::what().

Referenced by run().

void TraCITestClient::commandSimulationStep ( SUMOTime  time)
protected

Sends and validates a simulation step command.

Parameters
[in]timeThe time step to send

Definition at line 179 of file TraCITestClient.cpp.

References answerLog, TraCIAPI::check_resultState(), CMD_SIMSTEP2, TraCIAPI::send_commandSimulationStep(), validateSimulationStep2(), and tcpip::SocketException::what().

Referenced by run().

void TraCITestClient::commandSubscribeContextVariable ( int  domID,
const std::string &  objID,
int  beginTime,
int  endTime,
int  domain,
SUMOReal  range,
int  varNo,
std::ifstream &  defFile 
)
protected

Sends and validates a SubscribeContext command.

Parameters
[in]domIDThe ID of the domain the addressed object belongs to
[in]objIDThe ID of the object a variable shall be subscribed from
[in]beginTimeThe time the subscription shall begin at
[in]endTimeThe time the subscription shall end at
[in]domainThe domain of the objects which shall be reported
[in]rangeThe range within which objects shall be for being reported
[in]varNoThe number of subscribed variables
[in]defFileThe stream to read variable values from

Definition at line 290 of file TraCITestClient.cpp.

References answerLog, TraCIAPI::check_resultState(), TraCIAPI::send_commandSubscribeObjectContext(), validateSubscription(), and tcpip::SocketException::what().

Referenced by run().

void TraCITestClient::commandSubscribeObjectVariable ( int  domID,
const std::string &  objID,
int  beginTime,
int  endTime,
int  varNo,
std::ifstream &  defFile 
)
protected

Sends and validates a SubscribeVariable command.

Parameters
[in]domIDThe ID of the domain the addressed object belongs to
[in]objIDThe ID of the object a variable shall be subscribed from
[in]beginTimeThe time the subscription shall begin at
[in]endTimeThe time the subscription shall end at
[in]varNoThe number of subscribed variables
[in]defFileThe stream to read variable values from

Definition at line 266 of file TraCITestClient.cpp.

References answerLog, TraCIAPI::check_resultState(), TraCIAPI::send_commandSubscribeObjectVariable(), validateSubscription(), and tcpip::SocketException::what().

Referenced by run().

void TraCIAPI::connect ( const std::string &  host,
int  port 
)
inherited

Connects to the specified SUMO server.

Parameters
[in]hostThe name of the host to connect to
[in]portThe port to connect to
Exceptions
tcpip::SocketExceptionif the connection fails

Definition at line 69 of file TraCIAPI.cpp.

References tcpip::Socket::connect(), and TraCIAPI::mySocket.

Referenced by run().

void TraCITestClient::errorMsg ( std::stringstream &  msg)
private

Writes an error message.

Parameters
[in]msgThe message to write

Definition at line 333 of file TraCITestClient.cpp.

References answerLog.

Referenced by commandGetVariable(), commandSetValue(), and run().

int TraCIAPI::getByte ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
SUMOReal TraCIAPI::getDouble ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
SUMOReal TraCIAPI::getFloat ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
int TraCIAPI::getInt ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
TraCIAPI::TraCIPosition TraCIAPI::getPosition ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
std::string TraCIAPI::getString ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
std::vector< std::string > TraCIAPI::getStringVector ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
SUMOTime TraCIAPI::getSUMOTime ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
int TraCIAPI::getUnsignedByte ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
inherited
void TraCITestClient::readAndReportTypeDependent ( tcpip::Storage inMsg,
int  valueDataType 
)
private
bool TraCITestClient::run ( std::string  fileName,
int  port,
std::string  host = "localhost" 
)

Runs a test.

Parameters
[in]fileNameThe name of the file containing the test script
[in]portThe server port to connect to
[in]hostThe server name to connect to

Definition at line 72 of file TraCITestClient.cpp.

References TraCIAPI::close(), commandClose(), commandGetVariable(), commandSetValue(), commandSimulationStep(), commandSubscribeContextVariable(), commandSubscribeObjectVariable(), TraCIAPI::connect(), errorMsg(), setValueTypeDependant(), string2time(), SUMOReal, and tcpip::SocketException::what().

Referenced by main().

void TraCIAPI::send_commandClose ( ) const
protectedinherited

Sends a Close command.

Definition at line 106 of file TraCIAPI.cpp.

References CMD_CLOSE, TraCIAPI::mySocket, tcpip::Socket::sendExact(), and tcpip::Storage::writeUnsignedByte().

Referenced by commandClose().

void TraCIAPI::send_commandGetVariable ( int  domID,
int  varID,
const std::string &  objID,
tcpip::Storage add = 0 
) const
protectedinherited
void TraCIAPI::send_commandSetValue ( int  domID,
int  varID,
const std::string &  objID,
tcpip::Storage content 
) const
protectedinherited

Sends a SetVariable request.

Parameters
[in]domIDThe domain of the variable
[in]varIDThe variable to set
[in]objIDThe object to change
[in]contentThe value of the variable

Definition at line 144 of file TraCIAPI.cpp.

References TraCIAPI::mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by commandSetValue().

void TraCIAPI::send_commandSimulationStep ( SUMOTime  time) const
protectedinherited

Sends a SimulationStep command.

Definition at line 93 of file TraCIAPI.cpp.

References CMD_SIMSTEP2, TraCIAPI::mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeInt(), and tcpip::Storage::writeUnsignedByte().

Referenced by commandSimulationStep().

void TraCIAPI::send_commandSubscribeObjectContext ( int  domID,
const std::string &  objID,
int  beginTime,
int  endTime,
int  domain,
SUMOReal  range,
const std::vector< int > &  vars 
) const
protectedinherited

Sends a SubscribeContext request.

Parameters
[in]domIDThe domain of the variable
[in]objIDThe object to subscribe the variables from
[in]beginTimeThe begin time step of subscriptions
[in]endTimeThe end time step of subscriptions
[in]domainThe domain of the objects which values shall be returned
[in]rangeThe range around the obj to investigate
[in]varsThe variables to subscribe

Definition at line 193 of file TraCIAPI.cpp.

References TraCIAPI::mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeDouble(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by commandSubscribeContextVariable().

void TraCIAPI::send_commandSubscribeObjectVariable ( int  domID,
const std::string &  objID,
int  beginTime,
int  endTime,
const std::vector< int > &  vars 
) const
protectedinherited

Sends a SubscribeVariable request.

Parameters
[in]domIDThe domain of the variable
[in]objIDThe object to subscribe the variables from
[in]beginTimeThe begin time step of subscriptions
[in]endTimeThe end time step of subscriptions
[in]varsThe variables to subscribe

Definition at line 165 of file TraCIAPI.cpp.

References TraCIAPI::mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by commandSubscribeObjectVariable().

int TraCITestClient::setValueTypeDependant ( tcpip::Storage into,
std::ifstream &  defFile,
std::stringstream &  msg 
)
private

Parses the next value type / value pair from the stream and inserts it into the storage.

Parameters
[out]intoThe storage to add the value type and the value into
[in]defFileThe file to read the values from
[out]msgIf any error occurs, this should be filled
Returns
The number of written bytes

Definition at line 419 of file TraCITestClient.cpp.

References POSITION_2D, POSITION_3D, POSITION_ROADMAP, REQUEST_AIRDIST, REQUEST_DRIVINGDIST, TYPE_BYTE, TYPE_COLOR, TYPE_COMPOUND, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_POLYGON, TYPE_STRING, TYPE_STRINGLIST, TYPE_UBYTE, tcpip::Storage::writeByte(), tcpip::Storage::writeDouble(), tcpip::Storage::writeFloat(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), tcpip::Storage::writeStringList(), and tcpip::Storage::writeUnsignedByte().

Referenced by commandSetValue(), and run().

bool TraCITestClient::validateSimulationStep2 ( tcpip::Storage inMsg)
private

Validates whether the given message is a valid answer to CMD_SIMSTEP2.

Parameters
[in]inMsgThe storage contain the message to validate
Returns
Whether the message is valid

Definition at line 344 of file TraCITestClient.cpp.

References answerLog, tcpip::Storage::readInt(), and validateSubscription().

Referenced by commandSimulationStep().

bool TraCITestClient::validateSubscription ( tcpip::Storage inMsg)
private

Validates whether the given message is a valid subscription return message.

Parameters
[in]inMsgThe storage contain the message to validate
Returns
Whether the message is valid

Definition at line 361 of file TraCITestClient.cpp.

References answerLog, readAndReportTypeDependent(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), RESPONSE_SUBSCRIBE_GUI_CONTEXT, RESPONSE_SUBSCRIBE_GUI_VARIABLE, RESPONSE_SUBSCRIBE_INDUCTIONLOOP_CONTEXT, RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, and RTYPE_OK.

Referenced by commandSubscribeContextVariable(), commandSubscribeObjectVariable(), and validateSimulationStep2().

void TraCITestClient::writeResult ( )
private

Writes the results file.

Definition at line 317 of file TraCITestClient.cpp.

References answerLog, and outputFileName.

Referenced by ~TraCITestClient().

Field Documentation

EdgeScope TraCIAPI::edge
inherited

Scope for interaction with edges.

Definition at line 646 of file TraCIAPI.h.

GUIScope TraCIAPI::gui
inherited

Scope for interaction with the gui.

Definition at line 648 of file TraCIAPI.h.

InductionLoopScope TraCIAPI::inductionloop
inherited

Scope for interaction with inductive loops.

Definition at line 650 of file TraCIAPI.h.

JunctionScope TraCIAPI::junction
inherited

Scope for interaction with junctions.

Definition at line 652 of file TraCIAPI.h.

LaneScope TraCIAPI::lane
inherited

Scope for interaction with lanes.

Definition at line 654 of file TraCIAPI.h.

MeMeScope TraCIAPI::multientryexit
inherited

Scope for interaction with multi-entry/-exit detectors.

Definition at line 656 of file TraCIAPI.h.

std::string TraCITestClient::outputFileName
private

The name of the file to write the results log into.

Definition at line 185 of file TraCITestClient.h.

Referenced by writeResult().

POIScope TraCIAPI::poi
inherited

Scope for interaction with POIs.

Definition at line 658 of file TraCIAPI.h.

PolygonScope TraCIAPI::polygon
inherited

Scope for interaction with polygons.

Definition at line 660 of file TraCIAPI.h.

RouteScope TraCIAPI::route
inherited

Scope for interaction with routes.

Definition at line 662 of file TraCIAPI.h.

SimulationScope TraCIAPI::simulation
inherited

Scope for interaction with the simulation.

Definition at line 664 of file TraCIAPI.h.

TrafficLightScope TraCIAPI::trafficlights
inherited

Scope for interaction with traffic lights.

Definition at line 666 of file TraCIAPI.h.

VehicleTypeScope TraCIAPI::vehicletype
inherited

Scope for interaction with vehicle types.

Definition at line 668 of file TraCIAPI.h.


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