{ title: 'Correct usage of multiple SARIs', description: 'This test will check if DECT systems are setup, either with a unique SARI or use the same SARI' + 'and are connected via a Mobility Master', todo: 'Please ensure that every DECT Network is setup with proper unique SARIs or connected via Mobility Masters, if so wanted', author: 'pla@innovaphone.com', schedule: '1h', commands: { config: { cmd: "cfg.txt", cat: ["dect"], }, }, test: function(cmd, results) { var success = true; const log = []; const sariTable = { //'31100422072149': { // 'domainId': '1', // 'mmIp': '172.16.176.239' //} }; // Saves Mobility Master interconnectivity const mmPivot = { //'1': { // "172.16.176.239": ["172.16.176.239"] //} }; // If a SARI is in the range of MM1 and a new DECT uses the same SARI but under MM2 this is recorded here and cross-checked at the end const thinIce = { // "1": { // "312213123213": { // 'og': "11.11.11.11", // 'challengers': [{'ip': "12.12.12.12", 'deviceId': '3'}] // } // } }; Object.keys(results.config).forEach(function(deviceId) { const config = results.config[deviceId]; const device = cmd.get_device(deviceId); const pariMaster = /^config change GW-DECT MASTER.*?\/pari-active.*?/m.test(config); const mobMasterLocal = /^config change GW-DECT MOBMASTER \/mm_mode ACTIVE/m.test(config); const mirrorSync = /^vars create MASTER/MIRROR-SYNC p /m.test(config); if(mirrorSync) return; if (!pariMaster && !mobMasterLocal) return; const mobMasterForeign = config.match(/^config change GW-DECT MASTER.*?\/mm-name (\S+).*?\/mm-ip (\S+)/m); const localIp = device.ethIfs[0]["ipv4"]; if (mobMasterLocal && mobMasterForeign) { addToPivot(device.domainId, localIp, mobMasterForeign[2]); } if (pariMaster) { var dectSARIs = config.match(/^config change GW-DECT \/name (\S+)/m); dectSARIs = dectSARIs ? dectSARIs[1] : "DECT"; dectSARIs = config.match(new RegExp('.*\\(cn=' + dectSARIs + '\\).*?\\(pbx=\\)')); if (!dectSARIs) return; dectSARIs = dectSARIs[1].split(","); dectSARIs.forEach(function(sari) { if (!sariTable[sari]) { sariTable[sari] = { "domainId": device.domainId, "mmIp": mobMasterLocal ? localIp : (mobMasterForeign ? mobMasterForeign[2] : null) } } else if (sariTable[sari].domainId != device.domainId) buildErrorMsg(device.id, "Uses a SARI (" + sari + ") which is already used in another Domain(" + sariTable[sari].domainId + ")") else if (!sariTable[sari].mmIp || !mobMasterForeign) buildErrorMsg(device.id, "Uses a SARI (" + sari + ") which is already used without a connecting Mobility Master"); else { const originalOwner = mmPivot[device.domainId][sariTable[sari].mmIp]; if (originalOwner.includes(mobMasterLocal ? localIp : mobMasterForeign[2])) return; else addToThinIce(device, sari, sariTable[sari].mmIp, mobMasterForeign[2]) } return; }); } }); Object.keys(thinIce).forEach(function(domainId) { Object.keys(thinIce[domainId]).forEach(function(sari) { const thinIceSari = thinIce[domainId][sari] thinIceSari.challengers.forEach(function(challenger) { if (mmPivot[domainId][thinIceSari.og].includes(challenger.ip)) return; else buildErrorMsg(challenger.deviceId, "Uses a SARI (" + sari + ") which is already used without a connecting Mobility Master"); }) }); }); return { success: success, msg: success ? "" : "Please properly set up SARIs for the DECT systems in use", log: log } function buildErrorMsg(deviceId, msg) { success = false; const device = cmd.get_device(deviceId); log.push(device.product + " / " + device.hwId + " / " + device.name + " / " + msg); } function addToPivot(domainId, ipLocal, ipForeign) { if (!mmPivot[domainId]) mmPivot[domainId] = {}; if (!mmPivot[domainId][ipForeign]) mmPivot[domainId][ipLocal] = [ipLocal]; else { mmPivot[domainId][ipLocal] = mmPivot[domainId][ipForeign] mmPivot[domainId][ipLocal].push(ipLocal) } } function addToThinIce(device, sari, originalIp, challMMIp) { if (!thinIce[device.domainId]) thinIce[device.domainId] = {}; if (thinIce[device.domainId][sari]) thinIce[device.domainId][sari]['challengers'].push({ 'ip': challMMIp, 'deviceId': device.id }) else thinIce[device.domainId][sari] = { 'og': originalIp, 'challengers': [{ 'ip': challMMIp, 'deviceId': device.id }] } } } }