MeshProtocolSimulator  1.0.0
Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | List of all members
Emulator Class Reference

This class emulates virtual wireless environment for MeshNet nodes (MNodes) with virtual radios. Nodes are represented by class NodeSimulator. Emulation can run only on one thread, for proper simulation timing. More...

#include <Emulator.h>

Public Member Functions

 Emulator ()
 Constructor.
 
 ~Emulator ()
 Destructor.
 
bool Begin (std::string scenarioPath, std::string loggerPath, int autoPause=-1, bool logOnly_=false, bool rawOutput_=false)
 Starts simulation. More...
 
bool Begin (std::string loggerPath, bool autoPause=true, bool logOnly_=false, bool rawOutput_=false)
 Starts simulation. More...
 
bool Begin (bool autoPause=true, bool logOnly_=false, bool rawOutput_=false)
 Starts simulation. More...
 
void End ()
 Ends simulation. This has to be called when logging is enabled.
 
bool SimulationStarted ()
 Checks if simulation was started by calling begin(). More...
 
void Pause ()
 Pauses simulation.
 
bool isPaused ()
 Returns true if simulation is paused.
 
void Resume ()
 Resumes simulation.
 
bool ResumeUntil (std::chrono::nanoseconds time)
 Resumes simulation until specified time. More...
 
void Handle ()
 Processes main simulation loop.
 
bool InvokeNetScan (MeshMAC currentNodeAddress, uint32_t timeout)
 Invokes network scan on specified node. More...
 
bool InvokeNetScan (int currentNodeIndex, uint32_t timeout)
 Invokes network scan on specified node. More...
 
bool InvokeConnect (MeshMAC currentNodeAddress, MeshMAC networkBSSID)
 Invokes node connection to specified node. More...
 
bool InvokeConnect (int currentNodeIndex, MeshMAC networkBSSID)
 Invokes node connection to specified node. More...
 
bool InvokeDisconnect (MeshMAC currentNodeAddress)
 Invokes node disconnection. More...
 
bool InvokeDisconnect (int currentNodeIndex)
 Invokes node disconnection. More...
 
bool InvokeNodeDisconnectRequest (MeshMAC gatewayNodeAddress, MeshMAC nodeToDisconnect)
 Invokes node disconnection request. This can be called only by gateway node. More...
 
bool InvokeNodeDisconnectRequest (int gatewayNodeIndex, MeshMAC nodeToDisconnect)
 Invokes node disconnection request. This can be called only by gateway node. More...
 
bool InvokeNetworkDrop (MeshMAC gatewayNodeAddress, bool forced)
 Invokes network drop. This can be called only by gateway node. More...
 
bool InvokeNetworkDrop (int gatewayNodeInde, bool forced)
 Invokes network drop. This can be called only by gateway node. More...
 
bool InvokeSend (MeshMAC senderNodeAddress, MeshMAC destNodeAddress, const char *message, uint8_t size)
 Invokes selected node to send message. More...
 
bool InvokeSend (int senderNodeIndex, int destNodeIndex, const char *message, uint8_t size)
 Invokes selected node to send message. More...
 
bool InvokeSend (MeshMAC senderNodeAddress, MeshMAC destNodeAddress, const uint8_t *message, uint16_t messageLength)
 Invokes selected node to send message. More...
 
bool InvokeSend (int senderNodeIndex, int destNodeIndex, const uint8_t *message, uint16_t messageLength)
 Invokes selected node to send message. More...
 
bool InvokePing (MeshMAC senderNodeAddress, MeshMAC destNodeAddress, uint32_t timeout, int16_t testDataLength=0)
 Invokes ping packet. More...
 
bool InvokePing (int senderNodeIndex, int destNodeIndex, uint32_t timeout, int16_t testDataLength=0)
 Invokes ping packet. More...
 
bool TablePrint (MeshMAC nodeAddress, TableType table)
 Prints table of selected node. More...
 
bool TablePrint (int index, TableType table)
 Prints table of selected node. More...
 
int indexOfNode (MeshNet *node)
 Gets index of node in nodeSimulators by MeshNet pointer. More...
 
int indexOfNode (RFInterface *nodeInterface)
 Gets index of node in nodeSimulators by RFInterface pointer. More...
 
int indexOfNode (MeshMAC mac)
 Gets index of node in nodeSimulators by it's mac address. More...
 
int indexOfNode (uint8_t address, MeshMAC bssid)
 Gets index of node in nodeSimulators by it's address and network BSSID. More...
 
int GetConnectionsCount ()
 Count of connections between nodes in network.
 
const NodeConnectionsGetConnectionsPtr ()
 Pointer to array with network connections. Connections can be set from scenario file or can be set to default. To get size of this array, call GetConnectionsCount() method.
 
int GetNodesCount ()
 Count of nodes in network. This value is established when begin() is called.
 
NodeSimulatorGetNodeSimulatorsPtr ()
 Array with node simulators for each node. Simulators are created when begin() is called and destructed when end() is called. To get size of this array, call GetConnectionsCount() method.
 
std::chrono::seconds GetElapsedTime ()
 Gets real time, that elapsed during simulation except moments when simulation was paused. More...
 
std::chrono::nanoseconds GetMinSimulationTime ()
 Minimum simulation time elapsed in nanoseconds.
 
std::chrono::nanoseconds GetMaxSimulationTime ()
 Maximum simulation time elapsed in nanoseconds.
 
bool isRawOutput ()
 True if output to cout should be in raw for, which can be easily read by computer in another application.
 
bool isLogOnly ()
 True if output to console is disabled and only logs has to be done. This can be true only if logger is enabled.
 

Public Attributes

bool AutoPause = false
 True to auto pause simulation after 1 second of inactivity.
 
std::chrono::seconds SimulationLimit = std::chrono::seconds::zero()
 Maximum simulation limit in seconds. After this time, simulation is aborted.
 
std::mutex Mutex
 Global mutex for current class variables.
 
std::mutex StreamMutex
 Global mutex for stream.
 

Static Public Attributes

const static NodeConnections DefaultNodeConnections [9]
 Default node connections, when connections are not specified in JSON scenario file. Numbers in squares are MAC addresses of each node. Square with double border is gateway node. More...
 

Protected Attributes

int ConnectionsCount = 0
 Count of connections in network.
 
const NodeConnectionsConnections = NULL
 Pointer to array with network connections.
 
int NodesCount = 0
 Count of nodes in network. This value is established when begin() is called.
 
NodeSimulatornodeSimulators = NULL
 Array with node simulators for each node. This value is established when begin() is called using Connections array.
 
std::chrono::system_clock::time_point SimulationResumeTime
 Time, when simulation was last resumed.
 
std::chrono::seconds ElapsedTimeUntilLastPause = std::chrono::seconds::zero()
 Time, that elapsed until last pause except time, when simulation was paused.
 
bool Paused = false
 True to pause simulation or when simulation is paused.
 
std::chrono::nanoseconds runUntil = std::chrono::nanoseconds::zero()
 Time, the simulation will run until and after that time it is paused.
 
std::chrono::nanoseconds minSimulationTime = std::chrono::nanoseconds::zero()
 Minimum simulation time elapsed in nanoseconds.
 
std::chrono::nanoseconds maxSimulationTime = std::chrono::nanoseconds::zero()
 Maximum simulation time elapsed in nanoseconds.
 
std::chrono::nanoseconds lastSentTime = std::chrono::nanoseconds::zero()
 Time, when message was sent last.
 
bool RawOutput = false
 True to print raw output for computer.
 
bool logOnly = false
 True to redirect logs to file only.
 
bool AbortThreads = false
 True to abort all threads.
 
JSONLogsWriter logger
 Output logger.
 
JSONScenarioReader scenarioReader
 JSON scenario reader.
 
friend NodeSimulator
 
friend Simulation_RFI
 

Detailed Description

This class emulates virtual wireless environment for MeshNet nodes (MNodes) with virtual radios. Nodes are represented by class NodeSimulator. Emulation can run only on one thread, for proper simulation timing.

Member Function Documentation

◆ Begin() [1/3]

bool Emulator::Begin ( bool  autoPause = true,
bool  logOnly_ = false,
bool  rawOutput_ = false 
)
inline

Starts simulation.

Parameters
autoPauseEnables or disables auto pause.
logOnly_Set to true to disable output to screen. Only logs will be done. This can be set only if logging is enabled.
rawOutput_Set to true, when output to console should be in raw form, that can be easily read in another programs.
Returns
Returns true when simulation started successfully.

◆ Begin() [2/3]

bool Emulator::Begin ( std::string  loggerPath,
bool  autoPause = true,
bool  logOnly_ = false,
bool  rawOutput_ = false 
)
inline

Starts simulation.

Parameters
loggerPath_Path to file, where logs will be written. Set to empty string to disable logs.
autoPauseEnables or disables auto pause.
logOnly_Set to true to disable output to screen. Only logs will be done. This can be set only if logging is enabled.
rawOutput_Set to true, when output to console should be in raw form, that can be easily read in another programs.
Returns
Returns true when simulation started successfully.

◆ Begin() [3/3]

bool Emulator::Begin ( std::string  scenarioPath,
std::string  loggerPath,
int  autoPause = -1,
bool  logOnly_ = false,
bool  rawOutput_ = false 
)

Starts simulation.

Parameters
scenarioPathPath to file with scenario. Set to empty string with no sceanrio.
loggerPath_Path to file, where logs will be written. Set to empty string to disable logs.
autoPause1 - auto pause enabled, 0 - auto pause disabled, -1 - auto pause setting read from scenario.
logOnly_Set to true to disable output to screen. Only logs will be done. This can be set only if logging is enabled.
rawOutput_Set to true, when output to console should be in raw form, that can be easily read in another programs.
Returns
Returns true when simulation started successfully.

◆ GetElapsedTime()

std::chrono::seconds Emulator::GetElapsedTime ( )

Gets real time, that elapsed during simulation except moments when simulation was paused.

Returns
Returns real time, that elapsed during simulation in seconds.

◆ indexOfNode() [1/4]

int Emulator::indexOfNode ( MeshMAC  mac)

Gets index of node in nodeSimulators by it's mac address.

Parameters
macMAC address of node.
Returns
Returns index of mesh net in nodeSimulators or -1 when node was not found.

◆ indexOfNode() [2/4]

int Emulator::indexOfNode ( MeshNet *  node)

Gets index of node in nodeSimulators by MeshNet pointer.

Parameters
nodePointer to mesh net.
Returns
Returns index of mesh net in nodeSimulators or -1 when node was not found.

◆ indexOfNode() [3/4]

int Emulator::indexOfNode ( RFInterface *  nodeInterface)

Gets index of node in nodeSimulators by RFInterface pointer.

Parameters
nodeInterfacePointer to RFInterface.
Returns
Returns index of mesh net in nodeSimulators or -1 when node was not found.

◆ indexOfNode() [4/4]

int Emulator::indexOfNode ( uint8_t  address,
MeshMAC  bssid 
)

Gets index of node in nodeSimulators by it's address and network BSSID.

Parameters
addressAddress of node (not MAC).
bssidBSSID of node's network.
Returns
Returns index of mesh net in nodeSimulators or -1 when node was not found.

◆ InvokeConnect() [1/2]

bool Emulator::InvokeConnect ( int  currentNodeIndex,
MeshMAC  networkBSSID 
)

Invokes node connection to specified node.

Parameters
currentNodeAddressIndex of node (from nodeSimulators), which wants to connect.
networkBSSIDBSSID of network, the node has to connect.
Returns
Returns true when connect command was invoked correctly.

◆ InvokeConnect() [2/2]

bool Emulator::InvokeConnect ( MeshMAC  currentNodeAddress,
MeshMAC  networkBSSID 
)

Invokes node connection to specified node.

Parameters
currentNodeAddressMAC address of node, which wants to connect.
networkBSSIDBSSID of network, the node has to connect.
Returns
Returns true when connect command was invoked correctly.

◆ InvokeDisconnect() [1/2]

bool Emulator::InvokeDisconnect ( int  currentNodeIndex)

Invokes node disconnection.

Parameters
currentNodeAddressIndex of node (from nodeSimulators), which wants to disconnect.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokeDisconnect() [2/2]

bool Emulator::InvokeDisconnect ( MeshMAC  currentNodeAddress)

Invokes node disconnection.

Parameters
currentNodeAddressMAC address of node, which wants to disconnect.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokeNetScan() [1/2]

bool Emulator::InvokeNetScan ( int  currentNodeIndex,
uint32_t  timeout 
)

Invokes network scan on specified node.

Parameters
currentNodeAddressIndex of node (from nodeSimulators), which wants to perform scan.
timeoutTimeout in milliseconds. After this time, all scan responses are ignored. Min: 500ms, max: 10000ms, recommended: 2000ms.
Returns
Returns true when connect command was invoked correctly.

◆ InvokeNetScan() [2/2]

bool Emulator::InvokeNetScan ( MeshMAC  currentNodeAddress,
uint32_t  timeout 
)

Invokes network scan on specified node.

Parameters
currentNodeAddressMAC address of node, which wants to perform scan.
timeoutTimeout in milliseconds. After this time, all scan responses are ignored. Min: 500ms, max: 10000ms, recommended: 2000ms.
Returns
Returns true when scan command was invoked correctly.

◆ InvokeNetworkDrop() [1/2]

bool Emulator::InvokeNetworkDrop ( int  gatewayNodeInde,
bool  forced 
)

Invokes network drop. This can be called only by gateway node.

Parameters
gatewayNodeIndexIndex of gateway node (from nodeSimulators).
forcedTrue if network drop has to be forced.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokeNetworkDrop() [2/2]

bool Emulator::InvokeNetworkDrop ( MeshMAC  gatewayNodeAddress,
bool  forced 
)

Invokes network drop. This can be called only by gateway node.

Parameters
currentNodeAddressMAC address of gateway node.
forcedTrue if network drop has to be forced.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokeNodeDisconnectRequest() [1/2]

bool Emulator::InvokeNodeDisconnectRequest ( int  gatewayNodeIndex,
MeshMAC  nodeToDisconnect 
)

Invokes node disconnection request. This can be called only by gateway node.

Parameters
gatewayNodeIndexIndex of gateway node (from nodeSimulators).
nodeToDisconnectMAC address of node which will be disconnected.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokeNodeDisconnectRequest() [2/2]

bool Emulator::InvokeNodeDisconnectRequest ( MeshMAC  gatewayNodeAddress,
MeshMAC  nodeToDisconnect 
)

Invokes node disconnection request. This can be called only by gateway node.

Parameters
currentNodeAddressMAC address of gateway node.
nodeToDisconnectMAC address of node which will be disconnected.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokePing() [1/2]

bool Emulator::InvokePing ( int  senderNodeIndex,
int  destNodeIndex,
uint32_t  timeout,
int16_t  testDataLength = 0 
)

Invokes ping packet.

Parameters
senderNodeIndexIndex of node (from nodeSimulators), which wants to send ping packet.
destNodeIndexIndex of node (from nodeSimulators), which have to receive ping packet.
timeoutPing timeout in ms. Minimum value is 1s (1000ms).
testDataLengthLength of test data, that are randomly generated.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokePing() [2/2]

bool Emulator::InvokePing ( MeshMAC  senderNodeAddress,
MeshMAC  destNodeAddress,
uint32_t  timeout,
int16_t  testDataLength = 0 
)

Invokes ping packet.

Parameters
senderNodeAddressMAC address of node, which wants to send ping packet.
destNodeAddressMAC address of node, which have to receive ping packet.
timeoutPing timeout in ms. Minimum value is 1s (1000ms).
testDataLengthLength of test data, that are randomly generated.
Returns
Returns true when disconnect command was invoked correctly.

◆ InvokeSend() [1/4]

bool Emulator::InvokeSend ( int  senderNodeIndex,
int  destNodeIndex,
const char *  message,
uint8_t  size 
)

Invokes selected node to send message.

Parameters
senderNodeIndexIndex of node (from nodeSimulators), which has to send message.
destNodeIndexIndex of destination node (from nodeSimulators).
messageMessage to send.
sizeSize of message buffer.
Returns
Returns true when message sending was invoked.

◆ InvokeSend() [2/4]

bool Emulator::InvokeSend ( int  senderNodeIndex,
int  destNodeIndex,
const uint8_t *  message,
uint16_t  messageLength 
)

Invokes selected node to send message.

Parameters
senderNodeIndexIndex of node (from nodeSimulators), which has to send message.
destNodeIndexIndex of destination node (from nodeSimulators).
messageMessage to send.
messageLengthLength of message.
Returns
Returns true when message sending was invoked.

◆ InvokeSend() [3/4]

bool Emulator::InvokeSend ( MeshMAC  senderNodeAddress,
MeshMAC  destNodeAddress,
const char *  message,
uint8_t  size 
)

Invokes selected node to send message.

Parameters
senderNodeAddressMAC address of node, which has to send message.
destNodeAddressDestination node address (index of node).
messageMessage to send.
sizeSize of message buffer.
Returns
Returns true when message sending was invoked.

◆ InvokeSend() [4/4]

bool Emulator::InvokeSend ( MeshMAC  senderNodeAddress,
MeshMAC  destNodeAddress,
const uint8_t *  message,
uint16_t  messageLength 
)

Invokes selected node to send message.

Parameters
senderNodeAddressMAC address of node, which has to send message.
destNodeAddressDestination node address (index of node).
messageMessage to send.
messageLengthLength of message.
Returns
Returns true when message sending was invoked.

◆ ResumeUntil()

bool Emulator::ResumeUntil ( std::chrono::nanoseconds  time)

Resumes simulation until specified time.

Parameters
timeTime until which simulation will be resumed.
Returns
Returns true when simulation was resumed.

◆ SimulationStarted()

bool Emulator::SimulationStarted ( )
inline

Checks if simulation was started by calling begin().

Returns
Returns true when simulaton was started successfully.

◆ TablePrint() [1/2]

bool Emulator::TablePrint ( int  index,
TableType  table 
)

Prints table of selected node.

Parameters
indexIndex of node in nodeSimulators, which has to print table.
tableTable, which needs to be printerd.
Returns
Returns true when table was print.

◆ TablePrint() [2/2]

bool Emulator::TablePrint ( MeshMAC  nodeAddress,
TableType  table 
)

Prints table of selected node.

Parameters
nodeAddressMAC address of node, which table will be print.
tableTable, which needs to be printerd.
Returns
Returns true when table was print.

Member Data Documentation

◆ DefaultNodeConnections

const NodeConnections Emulator::DefaultNodeConnections
static
Initial value:

Default node connections, when connections are not specified in JSON scenario file. Numbers in squares are MAC addresses of each node. Square with double border is gateway node.

┌───┐         ┌───┐         ┌───┐
| 8 |═════════| 7 |═════════| 2 |
└───┘         └───┘         └───┘
                ║             ║
                ║             ║
┌───┐         ┌───┐         ╔═══╗
| 5 |═════════| 3 |═════════║ 1 ║
└───┘         └───┘         ╚═══╝
  ║                           ║
  ║                           ║
┌───┐                       ┌───┐
| 6 |═══════════════════════| 4 |
└───┘                       └───┘

The documentation for this class was generated from the following files:
NodeConnections
This structure represents link connection between two nodes. Nodes are indentified by it's MeshMAC ad...
Definition: Emulator_helpers.h:47