[posix] get node id from command line argument (#5000)

This simplify manually running posix virtual time mode when debugging.
This commit is contained in:
Yakun Xu
2020-05-25 16:03:27 -07:00
committed by GitHub
parent 7942b00eee
commit 3bc67ee6f9
4 changed files with 6 additions and 12 deletions
+3 -1
View File
@@ -274,8 +274,10 @@ void platformNetifProcess(const fd_set *aReadFdSet, const fd_set *aWriteFdSet, c
/**
* This function initialize virtual time simulation.
*
* @params[in] aNodeId Node id of this simulated device.
*
*/
void virtualTimeInit(void);
void virtualTimeInit(uint16_t aNodeId);
/**
* This function deinitialize virtual time simulation.
+1 -1
View File
@@ -49,7 +49,7 @@ otInstance *otSysInit(otPlatformConfig *aPlatformConfig)
otInstance *instance = NULL;
#if OPENTHREAD_POSIX_VIRTUAL_TIME
virtualTimeInit();
virtualTimeInit(static_cast<uint16_t>(atoi(aPlatformConfig->mRadioConfig)));
#endif
platformAlarmInit(aPlatformConfig->mSpeedUpFactor);
platformRadioInit(aPlatformConfig);
+2 -6
View File
@@ -51,9 +51,8 @@ static const int kUsPerSecond = 1000000; ///< Number of microseconds per sec
static uint64_t sNow = 0; ///< Time of simulation.
static int sSockFd = -1; ///< Socket used to communicating with simulator.
static uint16_t sPortOffset = 0; ///< Port offset for simulation.
static int sNodeId = 0; ///< Node id of this simulated device.
void virtualTimeInit(void)
void virtualTimeInit(uint16_t aNodeId)
{
struct sockaddr_in sockaddr;
char * offset;
@@ -81,10 +80,7 @@ void virtualTimeInit(void)
sPortOffset *= kWellKnownNodeId;
}
// node id is required for virtual time simulation
sNodeId = atoi(getenv("NODE_ID"));
sockaddr.sin_port = htons(kBasePort + sPortOffset + sNodeId);
sockaddr.sin_port = htons(kBasePort + sPortOffset + aNodeId);
sockaddr.sin_addr.s_addr = INADDR_ANY;
sSockFd = SocketWithCloseExec(AF_INET, SOCK_DGRAM, IPPROTO_UDP, kSocketBlock);
-4
View File
@@ -109,7 +109,6 @@ class Node:
if 'RADIO_DEVICE' in os.environ:
cmd += ' -v %s' % os.environ['RADIO_DEVICE']
os.environ['NODE_ID'] = str(nodeid)
# Load Thread 1.1 node when testing Thread 1.2 scenarios for interoperability
elif self.version == '1.1':
@@ -122,7 +121,6 @@ class Node:
if 'RADIO_DEVICE_1_1' in os.environ:
cmd += ' -v %s' % os.environ['RADIO_DEVICE_1_1']
os.environ['NODE_ID'] = str(nodeid)
cmd += ' %d' % nodeid
print("%s" % cmd)
@@ -149,7 +147,6 @@ class Node:
if self.version == self.env_version:
if 'RADIO_DEVICE' in os.environ:
args = ' %s' % os.environ['RADIO_DEVICE']
os.environ['NODE_ID'] = str(nodeid)
else:
args = ''
@@ -188,7 +185,6 @@ class Node:
elif self.version == '1.1':
if 'RADIO_DEVICE_1_1' in os.environ:
args = ' %s' % os.environ['RADIO_DEVICE_1_1']
os.environ['NODE_ID'] = str(nodeid)
else:
args = ''