Compare commits

...

17 Commits

Author SHA1 Message Date
f0f6d58ca4 LAPI:705: Update .gitignore 2023-05-15 20:48:37 +03:00
2a22d7a209 LAPI:705: Generate GPS and voice are two separate process; Added exit function 2023-05-15 20:44:50 +03:00
0c62a937ec Merge pull request 'LINXD-2396: Get Hub address from asset configuration; Take default main group if not specified in config; Update config to not declare hub address and voice server' (#6) from LINXD-2396-simulator-improvements into master
Reviewed-on: #6
2023-05-10 07:18:02 +00:00
8793db7c00 LAPI-633: Add config for no gps 2023-05-03 17:59:13 +03:00
e2b3b35e33 LINXD-2396: Added error informations; Update to send gps from interval(min-max) 2023-05-03 17:20:46 +03:00
faa8e8099e LINXD-2396: Added error informations; Update to send gps from interval(min-max) 2023-05-03 17:17:11 +03:00
30198d1b1a LINXD-2396: Get Hub address from asset configuration; Take default main group if not specified in config; Update config to not declare hub address and voice server 2023-04-30 14:26:44 +03:00
c5153bc48b revert certs for default openssl and change only if needed 2023-03-29 00:54:56 +03:00
5732742ec4 converted audio files to 56kbs 2023-03-29 00:43:41 +03:00
7f1fb02af1 workaround for certs newer ubuntu >18 2023-03-28 23:04:56 +03:00
6e5361e085 Fix merge with master 2023-03-28 14:41:42 +03:00
e54bdeeef1 Update config 2023-03-28 14:37:43 +03:00
702cd0efe4 Added new configuration to allow custom group join and individual asset ptt/gps 2023-03-27 22:35:18 +03:00
0a9975425c LAPI-633: Allow to simulate only GPS 2022-03-17 08:50:10 +00:00
636e3cce1a LAPI-633: Fix merge conflict 2022-03-16 12:28:31 +02:00
9eae897232 Update 'src/asset.js' 2022-01-13 16:04:32 +00:00
6f69e77506 Merge pull request 'LINXD-1921-update-simulator-post-enter-group' (#3) from LINXD-1921-update-simulator-post-enter-group into master
Reviewed-on: #3
2022-01-13 15:29:02 +00:00
32 changed files with 1103 additions and 169 deletions

6
.gitignore vendored
View File

@ -1,6 +1,6 @@
node_modules
.vscode
logs/*
!logs
config/default.toml
certs
certs
logs/*
!logs

View File

@ -0,0 +1,440 @@
[elogs]
name = 'dev'
[api]
port = ''
host = 'node.dev.linx.safemobile.com/api'
use_secure = true
accept_untrusted_certs = true
[settings]
max_fails = 3
send_group_monitoring_before_each_call = 'false'
gps_report_interval = ''
gps_min_interval = 1000
gps_max_interval = 10000
gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126
delay_between_clients = 500
testing_duration = 240 # seconds
# group 1 / 1 send / 10 listen
[[assets]]
asset_id = 7516
group_id = 2561
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7517
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7518
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7519
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7520
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7521
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7522
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7523
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7524
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7525
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7526
group_id = 2561
generate_voice = false
# group 2 / 1 send / 10 listen
[[assets]]
asset_id = 7536
group_id = 2560
generate_voice = true
[[assets]]
asset_id = 7537
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7538
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7539
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7540
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7541
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7542
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7543
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7544
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7545
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7546
group_id = 2560
generate_voice = false
# group 3 / 1 send / 10 listen
[[assets]]
asset_id = 7556
group_id = 2559
generate_voice = true
[[assets]]
asset_id = 7557
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7558
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7559
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7560
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7561
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7562
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7563
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7564
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7565
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7566
group_id = 2559
generate_voice = false
# group 4 / 1 send / 10 listen
[[assets]]
asset_id = 7576
group_id = 2558
generate_voice = true
[[assets]]
asset_id = 7577
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7578
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7579
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7580
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7581
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7582
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7583
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7584
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7585
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7586
group_id = 2558
generate_voice = false
# group 5 / 1 send / 10 listen
# group 6 / 1 send / 10 listen
# group 7 / 1 send / 10 listen
# group 8 / 1 send / 10 listen
# group 9 / 1 send / 10 listen
# group 10 / 1 send / 10 listen
[[assets]]
asset_id = 7715
group_id = 2552
generate_voice = true
[[assets]]
asset_id = 7714
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7713
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7712
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7711
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7710
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7709
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7708
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7707
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7706
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7705
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7704
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7703
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7702
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7701
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7700
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7699
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7698
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7697
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7696
group_id = 2552
generate_voice = false
[sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -0,0 +1,28 @@
[elogs]
name = 'dev'
[api]
port = ''
host = 'node.dev.linx.safemobile.com/api'
use_secure = true
accept_untrusted_certs = true
[settings]
max_fails = 3
send_group_monitoring_before_each_call = 'false'
gps_report_interval = ''
gps_min_interval = 500
gps_max_interval = 1000
gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126
delay_between_clients = 500
testing_duration = 10 # seconds
[[assets]]
asset_id = 60
group_id = 1
generate_voice = true
generate_gps = true
[sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -1,39 +1,440 @@
[mumble]
port = '5668'
host = 'dev.linx.safemobile.com'
[hub]
address = 'https://hub.dev.linx.safemobile.com/'
[elogs]
name = 'dev'
[api]
port = ''
host = 'dev.linx.safemobile.com/api'
host = 'node.dev.linx.safemobile.com/api'
use_secure = true
accept_untrusted_certs = true
[settings]
max_fails = 3
send_voice = false
send_gps = true
send_group_monitoring_before_each_call = 'true'
gps_report_interval = 300 # The interval in which the GPS is sent
send_group_monitoring_before_each_call = 'false'
gps_report_interval = ''
gps_min_interval = 1000
gps_max_interval = 10000
gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126
delay_between_clients = 300
testing_duration = 600 # seconds
delay_between_clients = 500
testing_duration = 240 # seconds
# group 1 / 1 send / 10 listen
[[assets]]
asset_id = 7516
group_id = 2561
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7517
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7518
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7519
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7520
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7521
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7522
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7523
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7524
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7525
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7526
group_id = 2561
generate_voice = false
generate_gps = true
# group 2 / 1 send / 10 listen
[[assets]]
asset_id = 7536
group_id = 2560
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7537
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7538
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7539
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7540
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7541
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7542
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7543
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7544
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7545
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7546
group_id = 2560
generate_voice = false
generate_gps = true
# group 3 / 1 send / 10 listen
[[assets]]
asset_id = 7556
group_id = 2559
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7557
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7558
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7559
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7560
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7561
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7562
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7563
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7564
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7565
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7566
group_id = 2559
generate_voice = false
generate_gps = true
# group 4 / 1 send / 10 listen
[[assets]]
asset_id = 7576
group_id = 2558
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7577
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7578
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7579
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7580
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7581
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7582
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7583
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7584
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7585
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7586
group_id = 2558
generate_voice = false
generate_gps = true
# group 5 / 1 send / 10 listen
# group 6 / 1 send / 10 listen
# group 7 / 1 send / 10 listen
# group 8 / 1 send / 10 listen
# group 9 / 1 send / 10 listen
# group 10 / 1 send / 10 listen
[[assets]]
asset_id = 7715
group_id = 2552
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7714
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7713
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7712
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7711
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7710
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7709
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7708
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7707
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7706
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7705
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7704
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7703
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7702
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7701
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7700
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7699
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7698
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7697
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7696
group_id = 2552
generate_voice = false
generate_gps = true
[assets]
#ids = [
# 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499, 5500, 5501, 5502
#]
ids = [
1868
]
[sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -1,4 +1,6 @@
#!/bin/sh
OPENSSL_PATH="/usr/bin" #default install path
#OPENSSL_PATH="/usr/local/ssl/bin" #workaround for dual openssl install
DAYS=$((10*365))
LEVELS=1
@ -12,10 +14,10 @@ OPENSSL_CNF="/etc/ssl/openssl.cnf"
mkdir -p $CERTS_PATH
#generate root key pair
openssl genrsa -out "$CERTS_PATH/root-key.pem" 4096
$OPENSSL_PATH/openssl genrsa -out "$CERTS_PATH/root-key.pem" 4096
#generate root self-signed cert
openssl req -new -x509 -days $DAYS -key "$CERTS_PATH/root-key.pem" -subj "$DN/CN=Root" -out "$CERTS_PATH/root-cert.pem"
$OPENSSL_PATH/openssl req -new -x509 -days $DAYS -key "$CERTS_PATH/root-key.pem" -subj "$DN/CN=Root" -out "$CERTS_PATH/root-cert.pem"
cat "$CERTS_PATH/root-cert.pem" > $CHAIN
@ -30,17 +32,17 @@ for i in `seq 1 $LEVELS`; do
fi
#generate key pair
openssl genrsa -out "$CERTS_PATH/ca$i-key.pem" 4096
$OPENSSL_PATH/openssl genrsa -out "$CERTS_PATH/ca$i-key.pem" 4096
#generate signing request
openssl req -new -key "$CERTS_PATH/ca$i-key.pem" -subj "$DN/CN=Level$i" -out "$CERTS_PATH/ca$i-csr.pem"
$OPENSSL_PATH/openssl req -new -key "$CERTS_PATH/ca$i-key.pem" -subj "$DN/CN=Level$i" -out "$CERTS_PATH/ca$i-csr.pem"
echo "-------------"
echo ">>>>>>>>>>>>>>>>>"$SIGNER_CERT
echo ">>>>>>>>>>>>>>>>>"$SIGNER_KEY
#sign new cert
openssl x509 -req -days $DAYS -in "$CERTS_PATH/ca$i-csr.pem" -CA $SIGNER_CERT -CAkey $SIGNER_KEY \
$OPENSSL_PATH/openssl x509 -req -days $DAYS -in "$CERTS_PATH/ca$i-csr.pem" -CA $SIGNER_CERT -CAkey $SIGNER_KEY \
-set_serial $i -out "$CERTS_PATH/ca$i-cert.pem" -extfile $OPENSSL_CNF -extensions v3_ca
cat "$CERTS_PATH/ca$i-cert.pem" >> $CHAIN
echo "-------------"

View File

@ -1,5 +1,6 @@
#!/bin/sh
OPENSSL_PATH="/usr/bin" #default install path
#OPENSSL_PATH="/usr/local/ssl/bin" #workaround for dual openssl install
if test "$#" -ne 1; then
echo "Error: Wrong parameters --> You must provide the certificate name."
echo "Please use: ./createCerts.sh 18"
@ -13,11 +14,11 @@ ID=$1
CERTS_PATH=certs
#generate key pair
openssl genrsa -out "$CERTS_PATH/$ID-key.pem" 4096
$OPENSSL_PATH/openssl genrsa -out "$CERTS_PATH/$ID-key.pem" 4096
#generate signing request
openssl req -new -key "$CERTS_PATH/$ID-key.pem" -subj "$DN/CN=$ID" -out "$CERTS_PATH/$ID-csr.pem"
$OPENSSL_PATH/openssl req -new -key "$CERTS_PATH/$ID-key.pem" -subj "$DN/CN=$ID" -out "$CERTS_PATH/$ID-csr.pem"
#sign new cert
openssl x509 -req -days $DAYS -in "$CERTS_PATH/$ID-csr.pem" -CA "$CERTS_PATH/ca1-cert.pem" \
$OPENSSL_PATH/openssl x509 -req -days $DAYS -in "$CERTS_PATH/$ID-csr.pem" -CA "$CERTS_PATH/ca1-cert.pem" \
-CAkey "$CERTS_PATH/ca1-key.pem" -set_serial 500 -out "$CERTS_PATH/$ID-cert.pem"

View File

@ -6,8 +6,8 @@ const Simulator = require('./src/simulator');
// Read configs.
let configs = {
mumble: config.get('mumble'),
hub: config.get('hub'),
// mumble: config.get('mumble'),
// hub: config.get('hub'),
api: config.get('api'),
assets: config.get('assets'),
sounds: config.get('sounds'),
@ -15,6 +15,9 @@ let configs = {
elogs: config.get('elogs'),
}
console.log('configs', configs)
// Start simulation.
console.log('Starting simulation...');
var simulator = new Simulator(configs);

10
installOpenSSL1.02.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/sh
cd /usr/local/
wget https://www.openssl.org/source/openssl-1.0.2g.tar.gz
tar -xzvf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g/
./config
make install
/usr/local/ssl/bin/openssl version

0
logs/error_dev.log Normal file
View File

0
logs/simulator_dev.log Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -18,23 +18,32 @@ const log = require('./utils').log
class Asset {
constructor(id, configs, token) {
constructor(asset, configs, token) {
this.id = id;
this.id = asset.asset_id;
this.mumbleHost = null;
this.mumblePort = null;
this.murmurUser = null;
this.murmurPassword = null;
this.hubAddress = null;
this.group_id = asset.group_id;
this.generate_voice = asset.generate_voice || false;
this.generate_gps = asset.generate_gps || false;
this.token = token;
this.configs = configs
this._processConfigs();
this.pttEndSuccessfully = false;
this.assetProps = {};
this.murmurPassword = '';
this.startTime = null; // Will be set at the initialization of ptt(_start -> on_tt)
this.endTime = +new Date() + (this.configs.settings.testing_duration * 1000)
utils.writeLog(`Creating asset ${id}`)
utils.writeLog(`Creating asset ${this.id}`)
// Do async work: Init asset.
async.waterfall([
this._getConfiguration.bind(this),
this._getDataFromApi.bind(this),
this._checkGroupToJoin.bind(this),
this._connectToHub.bind(this),
this._connectToMurmur.bind(this),
this._register.bind(this),
@ -54,12 +63,72 @@ class Asset {
});
}
_processConfigs() {
_processConfigs(callback) {
let apiConfig = this.configs.api;
this.apiEndpoint = apiConfig.use_secure ? 'https' : 'http';
this.apiEndpoint += '://' + apiConfig.host + (apiConfig.port ? (':' + apiConfig.port) : '');
}
_getConfiguration(callback) {
console.log('_getConfiguration', this.id);
Request.get(
this.apiEndpoint + '/asset/' + this.id + '/account',
{
headers: {
Authorization: `Bearer ${this.token}`
}
},
(error, response, body) => {
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
const bodyObj = JSON.parse(body);
const data = bodyObj.data;
// console.log('_getConfiguration', data);
this.mumbleHost = data.configuration.mumble_address;
this.mumblePort = data.configuration.voice_rtp_port;
this.murmurUser = bodyObj.data.configuration.mumble_username;
this.murmurPassword = bodyObj.data.configuration.mumble_password;
this.hubAddress = data.configuration.hub_address;
return callback();
} else {
utils.writeLog(`ERROR | _getConfiguration | response ${JSON.stringify(response)} | body: ${JSON.stringify(body)}`)
utils.writeLog(`ERROR | _getConfiguration | Getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _getConfiguration`);
return callback(error);
}
}
);
}
_checkGroupToJoin(callback) {
console.log('_checkGroupToJoin', this.id);
Request.get(
this.apiEndpoint + '/assets/' + this.id + '/groups',
{
headers: {
Authorization: `Bearer ${this.token}`
}
},
(error, response, body) => {
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
const bodyObj = JSON.parse(body);
const data = bodyObj.data.map(group => group.group_id);
if (data.includes(this.group_id)) {
utils.writeLog(`Asset ${this.id} have group ${this.group_id}`);
return callback();
} else {
utils.writeLog(`ERROR Asset ${this.id} is not in group ${this.group_id}`);
return;
}
} else {
utils.writeLog(`_checkGroupToJoin | response ${JSON.stringify(response)} | body: ${JSON.stringify(body)}`)
utils.writeLog(`ERROR | _checkGroupToJoin | Getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _checkGroupToJoin`);
return callback(error);
}
}
);
}
_getDataFromApi(callback) {
utils.writeLog(`Get informations about asset ${this.id}`);
Request.get(
@ -72,39 +141,11 @@ class Asset {
(error, response, body) => {
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
let bodyObj = JSON.parse(body);
// Here are the asset fields.
this.assetProps = bodyObj.data;
// console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!', this.assetProps)
return this._getMumblePassword(callback);
} else {
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API`);
return callback(error);
}
}
);
}
_getMumblePassword(callback) {
utils.writeLog(`Get Mumble password for asset ${this.id}`);
Request.get(
this.apiEndpoint + '/asset/' + this.id + '/account',
{
headers: {
Authorization: `Bearer ${this.token}`
}
},
(error, response, body) => {
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
let bodyObj = JSON.parse(body);
// Here are the asset fields.
this.murmurPassword = bodyObj.data.configuration.mumble_password;
// console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!', this.assetProps)
return this._getGroupsFromApi(callback);
} else {
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API`);
utils.writeLog(`ERROR | _getDataFromApi | Getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _getDataFromApi`);
return callback(error);
}
}
@ -127,23 +168,33 @@ class Asset {
this.groups = bodyObj.data;
// Find what group this asset is monitoring.
this.groups.forEach((g) => {
if (g.is_talk_group && g.monitoring.indexOf(this.id) != -1) {
this.groupId = g.id;
this.groupSipId = g.sip_id;
this.groupName = g.name;
}
});
if (!this.groupId) {
return callback('No talk group assigned to ' + this.id);
if (this.group_id) {
this.groups.forEach((g) => {
if (g.id === this.group_id) {
this.groupSipId = g.sip_id;
this.groupName = g.name;
}
});
} else {
this.groups.forEach((g) => {
if (g.is_talk_group && g.monitoring.indexOf(this.id) != -1) {
this.groupSipId = g.sip_id;
this.groupName = g.name;
this.group_id = g.id;
}
})
}
utils.writeLog(`Informations about asset ${this.id} received`)
if (!this.group_id) {
utils.writeLog(`Group/Default voice group not found for asset: ${this.group_id}`);
}
utils.writeLog(`Group: ${this.group_id} found for asset: ${this.id}`);
utils.writeLog(`Informations about asset ${this.id} received | groupId: ${this.group_id} | groupName: ${this.groupName}`);
return callback();
} else {
utils.writeLog(`Error getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API`);
utils.writeLog(`ERROR | _getGroupsFromApi | Getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _getGroupsFromApi`);
return callback(error);
}
}
@ -151,10 +202,8 @@ class Asset {
}
_connectToHub(callback) {
let hubAddress = this.configs.hub.address;
let options = {rejectUnauthorized: false, secure: true};
let hub = io(hubAddress, options);
let hub = io(this.hubAddress, options);
this.hub = hub;
// Disconnect event
@ -164,12 +213,12 @@ class Asset {
hub.on('connect_timeout', () => {
utils.writeLog(`Asset ${this.id} connect_timeout from HUB`);
utils.writeErrorLog(`ERROR_HUB`);
utils.writeErrorLog(`ERROR_HUB | _connectToHub`);
});
hub.on('connect_error', () => {
utils.writeLog(`Asset ${this.id} connect_error from HUB`);
utils.writeErrorLog(`ERROR_HUB`);
utils.writeErrorLog(`ERROR_HUB | _connectToHub`);
});
hub.once('connect', () => {
@ -209,23 +258,30 @@ class Asset {
}
_connectToMurmur(callback) {
this.configs.murmurPassword = this.murmurPassword;
if (!this.group_id) { return callback(); }
this.mumble = new Mumble(this.id, this.configs, (err) => {
console.log(`Asset ${this.id} connecting to Murmur`);
const murmurConnectionDetails = {
mumbleHost: this.mumbleHost,
mumblePort: this.mumblePort,
murmurUser: this.murmurUser,
murmurPassword: this.murmurPassword
};
this.mumble = new Mumble(this.id, murmurConnectionDetails, (err) => {
if (err) {
utils.writeLog(`Asset ${this.id} Murmur connection error`, err);
utils.writeErrorLog(`ERROR_MURMUR`);
utils.writeLog(`ERROR | _connectToMurmur | Asset ${this.id} Murmur connection error`, err);
utils.writeErrorLog(`ERROR_MURMUR | _connectToMurmur`);
return callback(err);
} else {
// return callback();
setTimeout(()=> {
return callback();
}, 400);
}, 500);
}
});
}
_register(callback) {
console.log(`Asset ${this.id} connecting to Register`);
Request.post(
this.apiEndpoint + '/audio/register/' + this.id,
{
@ -238,21 +294,19 @@ class Asset {
utils.writeLog(`Asset ${this.id} audio registered`);
return callback();
} else {
console.log('_register--------------------')
console.log('error---', error)
console.log('response---', response)
console.log('body---', body)
// utils.writeLog(`Asset ${this.id} audio registered error`, error);
// utils.writeErrorLog(`ERROR_API`);
// return callback(error);
utils.writeLog(`ERROR | _register | Asset ${this.id} audio registered error`, error);
utils.writeErrorLog(`ERROR_AUDIO | _register`);
return callback(error);
}
}
);
}
_moveToChannel(callback) {
console.log(`Asset ${this.id} move to Channel ${this.group_id}`);
// console.log('_moveToChannel', this.apiEndpoint + '/audio/enter-group/' + this.id + '/' + this.group_id)
Request.post(
this.apiEndpoint + '/audio/enter-group/' + this.id + '/' + this.groupId,
this.apiEndpoint + '/audio/enter-group/' + this.id + '/' + this.group_id,
{
headers: {
Authorization: `Bearer ${this.token}`
@ -270,55 +324,37 @@ class Asset {
asset_alias : this.assetProps.name,
request_ptt_groups_status: false,
group_sip_id: this.groupSipId,
group_id: this.groupId,
group_id: this.group_id,
group_name: this.groupName,
scan_group_ids: null
}
));
utils.writeLog(`Asset ${this.id} mmonitoring group ${this.groupId}`)
utils.writeLog(`Asset ${this.id} monitoring group ${this.group_id}`)
if (callback) return callback();
} else {
if (callback) return callback('Cannot send group-monitoring: Hub not connected');
}
} else {
console.log('_moveToChannel--------------------')
console.log('error---', error)
console.log('response---', response)
console.log('body---', body)
// utils.writeLog(`Asset ${this.id} audio enter group error`, error);
// utils.writeErrorLog(`ERROR_API`);
// return callback(error);
utils.writeLog(`ERROR | _moveToChannel | Asset ${this.id} audio enter group error`, error);
utils.writeErrorLog(`ERROR_AUDIO | _moveToChannel`);
return callback(error);
}
}
);
}
_start() {
this.startTime = +new Date();
if(this.endTime > this.startTime) {
if(this.configs.settings.send_voice) {
this._makePtt(() => {
if(this.pttEndSuccessfully) {
this._verifyRecorder();
}
});
}
this.generate_voice && this._makePtt(); // Generate voce
this.generate_gps && this._sendGPS(); // Generate GPS
this._measuringTestTime(); // Process exit base on this.endTime and current date
}
if(this.configs.settings.send_gps) {
this._sendGPS();
_measuringTestTime() {
setInterval(() => {
if(Date.now() > this.endTime + 18000) {
process.exit(0)
}
} else {
const assetIds = this.configs.assets.ids;
if(Math.max(...assetIds) == this.id) {
setTimeout(() => {
utils.writeLog('STOP')
.then(() => {
process.exit(0);
});
}, 10000);
}
}
}, 1000);
}
_verifyRecorder(callback) {
@ -361,8 +397,8 @@ class Asset {
console.log(chalk.yellow(`[RECORDER] for asset ${this.id} not found`));
}
} else {
utils.writeLog(`Error getting record for asset ${this.id} | ${error}`);
utils.writeErrorLog(`ERROR_RECORDER`);
utils.writeLog(`ERROR | _getRecord | Error getting record for asset ${this.id} | ${error}`);
utils.writeErrorLog(`ERROR_RECORDER | _getRecord`);
}
let assetIds = configs.assets.ids;
@ -387,7 +423,6 @@ class Asset {
// Send ptt-press and wait for it to be accepted.
this._sendPttPress((isAccepted) => {
if (!isAccepted) {
return callback();
}
@ -432,7 +467,11 @@ class Asset {
this.pttEndSuccessfully = true;
setTimeout(() => {
this._sendPttRelease();
callback();
if(this.endTime > +new Date()) {
this._makePtt(callback);
} else {
utils.writeLog(`Asset ${this.id} Voice sleeping...`);
}
}, 1500); // Hangtime
});
@ -495,13 +534,23 @@ class Asset {
})
}
_sendGPS(callback) {
_sendGPS() {
let hub = this.hub;
if (hub && hub.connected) {
let lat = this.configs.settings.gps_lat_start_point;
let lng = this.configs.settings.gps_lng_start_point;
const max = this.configs.settings.gps_max_interval;
const min = this.configs.settings.gps_min_interval;
setTimeout(() => {
let interval = null;
if (!this.configs.settings.gps_report_interval) {
interval = Math.floor(Math.random() * (max - min + 1) + min);
} else {
interval = this.configs.settings.gps_report_interval;
}
const now = +new Date();
if(this.endTime > now) {
var new_lat = this._randomCoordinates(lat);
var new_lng = this._randomCoordinates(lng);
@ -520,10 +569,10 @@ class Asset {
));
lat = new_lat;
lng = new_lng;
if (!this.configs.settings.send_voice) {
this._start();
}
}, this.configs.settings.gps_report_interval);
setTimeout(() => { this._sendGPS(); }, interval);
} else {
utils.writeLog(`Asset ${this.id} GPS sleeping...`);
}
}
}
@ -544,7 +593,7 @@ class Asset {
if (data.asset_id != this.id) {
return;
}
utils.writeLog(`Asset ${this.id} sending PTT-PRESS to group ${this.groupId}`)
utils.writeLog(`Asset ${this.id} sending PTT-PRESS to group ${this.group_id}`)
hub.removeListener('ptt-deny', pttDenyHandler);
callback(true);
};
@ -563,7 +612,7 @@ class Asset {
hub.emit('ptt-press', JSON.stringify(
{
destination_group_id: this.groupId,
destination_group_id: this.group_id,
destination_group_sip_id: this.groupSipId,
destination_asset_id: 0,
destination_asset_sip_id: 0,
@ -582,10 +631,10 @@ class Asset {
let hub = this.hub;
if (hub && hub.connected) {
utils.writeLog(`Asset ${this.id} sending PTT-RELEASE to group ${this.groupId}`);
utils.writeLog(`Asset ${this.id} sending PTT-RELEASE to group ${this.group_id}`);
hub.emit('ptt-release', JSON.stringify(
{
destination_group_id: this.groupId,
destination_group_id: this.group_id,
destination_group_sip_id: this.groupSipId,
destination_asset_id: 0,
destination_asset_sip_id: 0,

View File

@ -11,13 +11,19 @@ const OpusEncoder = require('node-opus').OpusEncoder;
class Mumble {
constructor(id, configs, connectedCallback) {
console.log('------', configs)
constructor(id, murmurConnectionDetails, connectedCallback) {
this.id = id;
this.configs = configs;
let mumble = configs.mumble;
this.mumbleHost = murmurConnectionDetails.mumbleHost;
this.mumblePort = murmurConnectionDetails.mumblePort;
this.murmurUser = murmurConnectionDetails.murmurUser;
this.murmurPassword = murmurConnectionDetails.murmurPassword;
// console.log('mumbleHost', this.mumbleHost)
// console.log('mumblePort', this.mumblePort)
// console.log('murmurUser', this.murmurUser)
// console.log('murmurPassword', this.murmurPassword)
this._createCertificatesForUser(id, () => {
this._makeMumbleConnection(id, mumble.port, mumble.host, id, this.configs.murmurPassword, connectedCallback);
this._makeMumbleConnection(id, this.mumblePort, this.mumbleHost, id, this.murmurPassword, connectedCallback);
})
}
@ -104,7 +110,7 @@ class Mumble {
.on('reconnect', function (n, delay) {
// n = current number of reconnect
// delay = delay used before reconnect
console.log('------ Server reconnect...');
// console.log('------ Server reconnect...');
// utils.writeErrorLog(`ERROR_MUMBLE_RECONNECT`);
// utils.exitWriteErrorLog(`ERROR_MUMBLE_RECONNECT`);
})

View File

@ -12,12 +12,12 @@ class Simulator {
this.configs = configs;
this.token;
// Read assets ids from configs
this.assetIds = configs.assets.ids;
this.assets = configs.assets;
this.assetIds = this.assets.map(asset => asset.asset_id);
this.apiEndpoint = this.configs.api.use_secure ? 'https' : 'http';
this.apiEndpoint += '://' + this.configs.api.host + (this.configs.api.port ? (':' + this.configs.api.port) : '');
async.waterfall([
this._manageLogs.bind(this),
this._unregisterAsstes.bind(this),
@ -36,18 +36,11 @@ class Simulator {
_start() {
const settings = this.configs.settings;
this.assetIds.forEach((id, i) => {
let delay_between_clients = 500;
if(settings.hasOwnProperty('delay_between_clients')) {
delay_between_clients = parseInt(settings.delay_between_clients, 10);
}
console.log('id', id, i * delay_between_clients+'ms')
delay_between_clients = this._getRandomInt(delay_between_clients);
this.assets.forEach((asset, i) => {
console.log('asset_id', asset.asset_id, i * settings.delay_between_clients + 'ms');
setTimeout(() => {
new Asset(id, this.configs, this.token);
// console.log('id, this.configs, this.token', id, this.configs, this.token)
}, i * delay_between_clients);
new Asset(asset, this.configs, this.token);
}, i * settings.delay_between_clients);
})
}
@ -74,6 +67,7 @@ class Simulator {
}
_unregisterAsstes(callback) {
let url = this.apiEndpoint + '/audio/un-register/[' + this.assetIds + ']/';
Request.post(
url,