MeshProtocolSimulator
1.0.0
|
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 NodeConnections * | GetConnectionsPtr () |
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. | |
NodeSimulator * | GetNodeSimulatorsPtr () |
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 NodeConnections * | Connections = NULL |
Pointer to array with network connections. | |
int | NodesCount = 0 |
Count of nodes in network. This value is established when begin() is called. | |
NodeSimulator * | nodeSimulators = 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 |
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.
|
inline |
Starts simulation.
autoPause | Enables 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. |
|
inline |
Starts simulation.
loggerPath_ | Path to file, where logs will be written. Set to empty string to disable logs. |
autoPause | Enables 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. |
bool Emulator::Begin | ( | std::string | scenarioPath, |
std::string | loggerPath, | ||
int | autoPause = -1 , |
||
bool | logOnly_ = false , |
||
bool | rawOutput_ = false |
||
) |
Starts simulation.
scenarioPath | Path 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. |
autoPause | 1 - 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. |
std::chrono::seconds Emulator::GetElapsedTime | ( | ) |
Gets real time, that elapsed during simulation except moments when simulation was paused.
int Emulator::indexOfNode | ( | MeshMAC | mac | ) |
Gets index of node in nodeSimulators by it's mac address.
mac | MAC address of node. |
int Emulator::indexOfNode | ( | MeshNet * | node | ) |
Gets index of node in nodeSimulators by MeshNet pointer.
node | Pointer to mesh net. |
int Emulator::indexOfNode | ( | RFInterface * | nodeInterface | ) |
Gets index of node in nodeSimulators by RFInterface pointer.
nodeInterface | Pointer to RFInterface. |
int Emulator::indexOfNode | ( | uint8_t | address, |
MeshMAC | bssid | ||
) |
Gets index of node in nodeSimulators by it's address and network BSSID.
address | Address of node (not MAC). |
bssid | BSSID of node's network. |
bool Emulator::InvokeConnect | ( | int | currentNodeIndex, |
MeshMAC | networkBSSID | ||
) |
Invokes node connection to specified node.
currentNodeAddress | Index of node (from nodeSimulators), which wants to connect. |
networkBSSID | BSSID of network, the node has to connect. |
bool Emulator::InvokeConnect | ( | MeshMAC | currentNodeAddress, |
MeshMAC | networkBSSID | ||
) |
Invokes node connection to specified node.
currentNodeAddress | MAC address of node, which wants to connect. |
networkBSSID | BSSID of network, the node has to connect. |
bool Emulator::InvokeDisconnect | ( | int | currentNodeIndex | ) |
Invokes node disconnection.
currentNodeAddress | Index of node (from nodeSimulators), which wants to disconnect. |
bool Emulator::InvokeDisconnect | ( | MeshMAC | currentNodeAddress | ) |
Invokes node disconnection.
currentNodeAddress | MAC address of node, which wants to disconnect. |
bool Emulator::InvokeNetScan | ( | int | currentNodeIndex, |
uint32_t | timeout | ||
) |
Invokes network scan on specified node.
currentNodeAddress | Index of node (from nodeSimulators), which wants to perform scan. |
timeout | Timeout in milliseconds. After this time, all scan responses are ignored. Min: 500ms, max: 10000ms, recommended: 2000ms. |
bool Emulator::InvokeNetScan | ( | MeshMAC | currentNodeAddress, |
uint32_t | timeout | ||
) |
Invokes network scan on specified node.
currentNodeAddress | MAC address of node, which wants to perform scan. |
timeout | Timeout in milliseconds. After this time, all scan responses are ignored. Min: 500ms, max: 10000ms, recommended: 2000ms. |
bool Emulator::InvokeNetworkDrop | ( | int | gatewayNodeInde, |
bool | forced | ||
) |
Invokes network drop. This can be called only by gateway node.
gatewayNodeIndex | Index of gateway node (from nodeSimulators). |
forced | True if network drop has to be forced. |
bool Emulator::InvokeNetworkDrop | ( | MeshMAC | gatewayNodeAddress, |
bool | forced | ||
) |
Invokes network drop. This can be called only by gateway node.
currentNodeAddress | MAC address of gateway node. |
forced | True if network drop has to be forced. |
bool Emulator::InvokeNodeDisconnectRequest | ( | int | gatewayNodeIndex, |
MeshMAC | nodeToDisconnect | ||
) |
Invokes node disconnection request. This can be called only by gateway node.
gatewayNodeIndex | Index of gateway node (from nodeSimulators). |
nodeToDisconnect | MAC address of node which will be disconnected. |
bool Emulator::InvokeNodeDisconnectRequest | ( | MeshMAC | gatewayNodeAddress, |
MeshMAC | nodeToDisconnect | ||
) |
Invokes node disconnection request. This can be called only by gateway node.
currentNodeAddress | MAC address of gateway node. |
nodeToDisconnect | MAC address of node which will be disconnected. |
bool Emulator::InvokePing | ( | int | senderNodeIndex, |
int | destNodeIndex, | ||
uint32_t | timeout, | ||
int16_t | testDataLength = 0 |
||
) |
Invokes ping packet.
senderNodeIndex | Index of node (from nodeSimulators), which wants to send ping packet. |
destNodeIndex | Index of node (from nodeSimulators), which have to receive ping packet. |
timeout | Ping timeout in ms. Minimum value is 1s (1000ms). |
testDataLength | Length of test data, that are randomly generated. |
bool Emulator::InvokePing | ( | MeshMAC | senderNodeAddress, |
MeshMAC | destNodeAddress, | ||
uint32_t | timeout, | ||
int16_t | testDataLength = 0 |
||
) |
Invokes ping packet.
senderNodeAddress | MAC address of node, which wants to send ping packet. |
destNodeAddress | MAC address of node, which have to receive ping packet. |
timeout | Ping timeout in ms. Minimum value is 1s (1000ms). |
testDataLength | Length of test data, that are randomly generated. |
bool Emulator::InvokeSend | ( | int | senderNodeIndex, |
int | destNodeIndex, | ||
const char * | message, | ||
uint8_t | size | ||
) |
Invokes selected node to send message.
senderNodeIndex | Index of node (from nodeSimulators), which has to send message. |
destNodeIndex | Index of destination node (from nodeSimulators). |
message | Message to send. |
size | Size of message buffer. |
bool Emulator::InvokeSend | ( | int | senderNodeIndex, |
int | destNodeIndex, | ||
const uint8_t * | message, | ||
uint16_t | messageLength | ||
) |
Invokes selected node to send message.
senderNodeIndex | Index of node (from nodeSimulators), which has to send message. |
destNodeIndex | Index of destination node (from nodeSimulators). |
message | Message to send. |
messageLength | Length of message. |
bool Emulator::InvokeSend | ( | MeshMAC | senderNodeAddress, |
MeshMAC | destNodeAddress, | ||
const char * | message, | ||
uint8_t | size | ||
) |
Invokes selected node to send message.
senderNodeAddress | MAC address of node, which has to send message. |
destNodeAddress | Destination node address (index of node). |
message | Message to send. |
size | Size of message buffer. |
bool Emulator::InvokeSend | ( | MeshMAC | senderNodeAddress, |
MeshMAC | destNodeAddress, | ||
const uint8_t * | message, | ||
uint16_t | messageLength | ||
) |
Invokes selected node to send message.
senderNodeAddress | MAC address of node, which has to send message. |
destNodeAddress | Destination node address (index of node). |
message | Message to send. |
messageLength | Length of message. |
bool Emulator::ResumeUntil | ( | std::chrono::nanoseconds | time | ) |
Resumes simulation until specified time.
time | Time until which simulation will be resumed. |
|
inline |
Checks if simulation was started by calling begin().
bool Emulator::TablePrint | ( | int | index, |
TableType | table | ||
) |
Prints table of selected node.
index | Index of node in nodeSimulators, which has to print table. |
table | Table, which needs to be printerd. |
bool Emulator::TablePrint | ( | MeshMAC | nodeAddress, |
TableType | table | ||
) |
Prints table of selected node.
nodeAddress | MAC address of node, which table will be print. |
table | Table, which needs to be printerd. |
|
static |
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 | └───┘ └───┘