[simulation] enhance simulation for OTNS (#4268)

This commit is to support OTNS by:
- raising the max number of simulating nodes to 999 if OTNS=1
- implementing the status-push mechanism

To build:

$ make -f examples/Makefile-simulation OTNS=1

This commit should have no change of OpenThread behaviors on platforms
except simulation.
This commit is contained in:
Simon Lin
2020-04-02 01:19:36 +08:00
committed by GitHub
parent daa626b504
commit 8423ed3042
25 changed files with 597 additions and 12 deletions
+41 -3
View File
@@ -65,6 +65,7 @@
#include "common/new.hpp"
#include "net/ip6.hpp"
#include "utils/otns.hpp"
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#include <openthread/backbone_router.h>
@@ -2164,13 +2165,14 @@ void Interpreter::HandleIcmpReceive(otMessage * aMessage,
const otMessageInfo *aMessageInfo,
const otIcmp6Header *aIcmpHeader)
{
uint32_t timestamp;
uint32_t timestamp = 0;
uint16_t dataSize;
VerifyOrExit(aIcmpHeader->mType == OT_ICMP6_TYPE_ECHO_REPLY);
VerifyOrExit((mPingIdentifier != 0) && (mPingIdentifier == HostSwap16(aIcmpHeader->mData.m16[0])));
mServer->OutputFormat("%u bytes from ", otMessageGetLength(aMessage) - otMessageGetOffset(aMessage) +
static_cast<uint16_t>(sizeof(otIcmp6Header)));
dataSize = otMessageGetLength(aMessage) - otMessageGetOffset(aMessage);
mServer->OutputFormat("%u bytes from ", dataSize + static_cast<uint16_t>(sizeof(otIcmp6Header)));
OutputIp6Address(aMessageInfo->mPeerAddr);
@@ -2183,6 +2185,9 @@ void Interpreter::HandleIcmpReceive(otMessage * aMessage,
mServer->OutputFormat("\r\n");
SignalPingReply(static_cast<const Ip6::MessageInfo *>(aMessageInfo)->GetPeerAddr(), dataSize, HostSwap32(timestamp),
aMessageInfo->mHopLimit);
exit:
return;
}
@@ -2284,6 +2289,9 @@ void Interpreter::SendPing(void)
SuccessOrExit(otMessageSetLength(message, mPingLength));
SuccessOrExit(otIcmp6SendEchoRequest(mInstance, message, &messageInfo, mPingIdentifier));
SignalPingRequest(static_cast<Ip6::MessageInfo *>(&messageInfo)->GetPeerAddr(), mPingLength, HostSwap32(timestamp),
messageInfo.mHopLimit);
message = NULL;
exit:
@@ -4175,6 +4183,36 @@ Interpreter &Interpreter::GetOwner(OwnerLocator &aOwnerLocator)
return interpreter;
}
void Interpreter::SignalPingRequest(const Ip6::Address &aPeerAddress,
uint16_t aPingLength,
uint32_t aTimestamp,
uint8_t aHopLimit)
{
OT_UNUSED_VARIABLE(aPeerAddress);
OT_UNUSED_VARIABLE(aPingLength);
OT_UNUSED_VARIABLE(aTimestamp);
OT_UNUSED_VARIABLE(aHopLimit);
#if OPENTHREAD_CONFIG_OTNS_ENABLE
mInstance->Get<Utils::Otns>().EmitPingRequest(aPeerAddress, aPingLength, aTimestamp, aHopLimit);
#endif
}
void Interpreter::SignalPingReply(const Ip6::Address &aPeerAddress,
uint16_t aPingLength,
uint32_t aTimestamp,
uint8_t aHopLimit)
{
OT_UNUSED_VARIABLE(aPeerAddress);
OT_UNUSED_VARIABLE(aPingLength);
OT_UNUSED_VARIABLE(aTimestamp);
OT_UNUSED_VARIABLE(aHopLimit);
#if OPENTHREAD_CONFIG_OTNS_ENABLE
mInstance->Get<Utils::Otns>().EmitPingReply(aPeerAddress, aPingLength, aTimestamp, aHopLimit);
#endif
}
extern "C" void otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength)
{
Server::sServer->GetInterpreter().SetUserCommands(aUserCommands, aLength);