prompthuawei-mobile-servicesphpseclibhuawei-developerslibssh2

Connection with Net/SSH2.php to Huawei Olt MA5680T is very slow


I implemented a php script to communicate with my Huawei Olt MA5680T through the phpseclib SSH2.php library but the execution time of any remote operation on the Olt is extremely slow, about 40 seconds. I tried sending simpler commands but the result doesn't change.

I'm currently using this function to connect via ssh to the device:

function sessione_ssh($olt_id) {
global $ssh;
global $ip_olt;

$ssh = new Net_SSH2($row_olt['olt_ip']);
if (!$ssh->login($row_olt['olt_user'], $row_olt['olt_pass'])) {
exit('Login Failed');}
$ssh->setWindowColumns(200);
$ssh->read('MA5680T>');
$ssh->write("enable\n");
$ssh->read('MA5680T#');
$ssh->write("mmi-mode enable\n");
$ssh->read('MA5680T#');
}





function check($pppoe) {
global $ssh;
global $frame;
global $board;
global $port;
global $ontid;
global $ifindex;
global $ip_olt;
$ont_eth_port='1';
// restituisce solo il valore senza tipo stringa
snmp_set_quick_print(1);
snmp_read_mib ( 'ma5600t.txt');
ricava_info_ont($pppoe);
$ssh->disconnect();
//ont_descrizione
echo 'PPPoE Cliente: ' . str_replace('"','',snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.43.1.9." . $ifindex . "." . $ontid)) . "<br>";
echo 'Indirizzo Ip: ' . snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.3.27.1.3." . $ifindex . "." . $ontid) . "<br>";
//ont_seriale
echo 'Seriale ONT: ' . str_replace('"','',str_replace(" ","",snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.43.1.3." . $ifindex . "." . $ontid))) . "<br>";
$ont_status= snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.46.1.15." . $ifindex . "." . $ontid);  //1 online  2 offline
if ($ont_status=='1') {
echo 'Stato: Online<br>';
}
if ($ont_status=='2') {
echo 'Stato: Offline<br>';
}
//ont_rx_segnale
echo 'Segnale RX: ' . (snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.4." . $ifindex . "." . $ontid))/100 . " db<br>";
//ont_distanza
echo 'Distanza: ' . snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.46.1.20." . $ifindex . "." . $ontid) . " metri<br>";
//ont_ultimo_uptime
echo 'Ultimo Uptime: ' . converti_data(snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.46.1.22." . $ifindex . "." . $ontid)) . "<br>";
//ont_ultimo_downtime
echo 'Ultimo Downtime: ' . converti_data(snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.46.1.23." . $ifindex . "." . $ontid)) . "<br>";
$ont_motivo_disconnessione=snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.46.1.24." . $ifindex . "." . $ontid); //,15 LOKI(Loss of key synch with ONUi),18 deactived ONT due to the ring,30 shut down ONT optical module,31 reset ONT by ONT command,32 reset ONT by ONT reset button,33 reset ONT by ONT software,34 deactived ONT due to broadcast attack,35 operator check fail,37 rogue ONT detected by itself,-1 query fails.
if ($ont_motivo_disconnessione=='1') {
echo 'Causa disconnessione: LOS (Loss of signal)<br>';
}
if ($ont_motivo_disconnessione=='2') {
echo 'Causa disconnessione: LOSi (Loss of signal for ONUi) or LOBi (Loss of burst for ONUi)<br>';
}
if ($ont_motivo_disconnessione=='3') {
echo 'Causa disconnessione: LOFI (Loss of frame of ONUi)<br>';
}
if ($ont_motivo_disconnessione=='4') {
echo 'Causa disconnessione: SFI (Signal fail of ONUi)<br>';
}
if ($ont_motivo_disconnessione=='5') {
echo 'Causa disconnessione: LOAI (Loss of acknowledge with ONUi)<br>';
}
if ($ont_motivo_disconnessione=='6') {
echo 'Causa disconnessione: LOAMI (Loss of PLOAM for ONUi)<br>';
}
if ($ont_motivo_disconnessione=='7') {
echo 'Causa disconnessione: Deactive ONT fails<br>';
}
if ($ont_motivo_disconnessione=='8') {
echo 'Causa disconnessione: Deactive ONT success<br>';
}
if ($ont_motivo_disconnessione=='9') {
echo 'Causa disconnessione: Reset ONT<br>';
}
if ($ont_motivo_disconnessione=='10') {
echo 'Causa disconnessione: Re-register ONT<br>';
}
if ($ont_motivo_disconnessione=='11') {
echo 'Causa disconnessione: Pop up fail<br>';
}
if ($ont_motivo_disconnessione=='13') {
echo 'Causa disconnessione: Dying-Gasp<br>';
}
//ont_uptime_tratta
echo 'Uptime tratta Pon: ' . date_format (new DateTime(str_replace('"','',snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.101.1.6." . $ifindex . "." . $ontid . ".0"))), 'd/m/Y H:i:s') . "<br>";
$ont_power_eth=snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.62.1.5." . $ifindex . "." . $ontid . "." . $ont_eth_port); //1on,2off
if ($ont_power_eth=='1') {
echo 'Porta Eth: On<br>';
}
if ($ont_power_eth=='2') {
echo 'Porta Eth: Off<br>';
}
$ont_registrazione_eth=snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.62.1.22." . $ifindex . "." . $ontid . "." . $ont_eth_port); //1linkup,2linkdown
if ($ont_registrazione_eth=='1') {
echo 'Registrazione Eth: On<br>';
}
if ($ont_registrazione_eth=='2') {
echo 'Registrazione Eth: Off<br>';
}
$ont_speed_eth=snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.62.1.4." . $ifindex . "." . $ontid . "." . $ont_eth_port);
if ($ont_speed_eth=='1') {
echo 'Negoziazione Eth: 10M manuale<br>';
}
if ($ont_speed_eth=='2') {
echo 'Negoziazione Eth: 100M manuale<br>';
}
if ($ont_speed_eth=='3') {
echo 'Negoziazione Eth: 1000M manuale<br>';
}
if ($ont_speed_eth=='4') {
echo 'Negoziazione Eth: Autonegoziazione<br>';
}
if ($ont_speed_eth=='5') {
echo 'Negoziazione Eth: 10M Autonegoziazione<br>';
}
if ($ont_speed_eth=='6') {
echo 'Negoziazione Eth: 100M Autonegoziazione<br>';
}
if ($ont_speed_eth=='7') {
echo 'Negoziazione Eth: 1000M Autonegoziazione<br>';
}
if ($ont_speed_eth=='8') {
echo 'Negoziazione Eth: 10000M manuale<br>';
}
if ($ont_speed_eth=='9') {
echo 'Negoziazione Eth: 10000M Autonegoziazione<br>';
}
if ($ont_speed_eth=='10') {
echo 'Negoziazione Eth: 2500M manuale<br>';
}
if ($ont_speed_eth=='11') {
echo 'Negoziazione Eth: 2500M Autonegoziazione<br>';
}
if ($ont_speed_eth=='-1') {
echo 'Negoziazione Eth: invalid<br>';
}
//ont_password_pon
echo 'Password Pon: ' . snmp2_get ($ip_olt, "private", "1.3.6.1.4.1.2011.6.128.1.1.2.43.1.4." . $ifindex . "." . $ontid) . "<br>";
}
// fine function check



unction ricava_info_ont($pppoe) {
global $ssh;
global $frame;
global $board;
global $port;
global $ontid;
global $ifindex;

//determina $id_olt

//per carcolare id olt se si tratta di cambio impianto usare var session per impianto vecchio e primaria vecchia altrimenti procedi normalmente
if($_SESSION['vecchioimpianto']) {
//decodifica impianto
$primariavecchia=explode("-",$_SESSION['vecchioimpianto']);
$primariavecchia=$primariavecchia['0'];
unset($_SESSION['vecchioimpianto']);
$sql_id_olt="select id_olt from ftth_fibre_primarie where id_fibra_primaria ='" . $primariavecchia . "'";
}
else {
$sql_id_olt="select id_olt from ftth_fibre_primarie where id_fibra_primaria = (select SUBSTR(impianto, 1, 4) from ftth_ont where pppoe='" . $pppoe . "')";
}
// fine se si tratta di cambio pacchetto
$rs_id_olt=CustomQuery($sql_id_olt);
$row_id_olt = db_fetch_array($rs_id_olt);
sessione_ssh($row_id_olt['id_olt']);
$ssh->write("display ont info by-desc " . $pppoe . "\n");
$out=nl2br($ssh->read());
// crea array con righe output
$logline = explode("\n",$out);
//ricava $ontid, $frame, $board e $port da descrizione (pppoe)
$parziale = explode(" ",$logline['9']);
$ontid=$parziale['9'];
$parziale2=explode("/",$parziale['2']);
$frame=$parziale2['0'];
$board=$parziale2['1'];
$port=$parziale2['2'];
$ifindex=4194304000 + ($board * (256 * 32) + $port * 256);
}
// fine function ricava_info_ont


With the same library I connect to other devices and execute scripts that are executed quickly, the problem occurs only with this device. I tried reading the logs but I don't detect any errors in the communication between the ssh2.php library and the olt MA5680T.

What could be the problem? this is the logs: https://pastebin.com/n9wHdLaj

Thank you so much for the support I receive from you for my project

UPDATE

The suggestion received from @neubert seems like the right way to decrease the script execution time. With the function I posted above I now actually have an execution time of about 3 seconds (absolutely acceptable). so using the same logic I inserted the correct prompt into all read() calls but it doesn't always work! when I enter a submenu of the prompt example: $ssh->write("interface gpon " . $frame . "/" . $board . "\n"); then I set the read call like this: $ssh->read('MA5680T(config-if-gpon-' . $frame_ont . '/' . $board_ont . ')#'); but I always get long times with 10 second timeouts like before. This is the link to the prompt from the terminal https://pasteboard.co/ldCa4JlnsfnL.jpg What could be the problem? this is the log:

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.03, network: 0.0003s)
00000000  00:00:00:02:00:00:00:14:0d:0a:0d:0a:4d:41:35:36  ............MA56
00000010  38:30:54:28:63:6f:6e:66:69:67:29:23              80T(config)#

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0122, network: 0.0001s)
00000000  00:00:00:02:00:00:00:13:69:6e:74:65:72:66:61:63  ........interfac
00000010  65:20:67:70:6f:6e:20:30:2f:31:33                 e gpon 0/13

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0181, network: 0.0003s)
00000000  00:00:00:02:00:00:00:21:0d:0a:0d:0a:4d:41:35:36  .......!....MA56
00000010  38:30:54:28:63:6f:6e:66:69:67:2d:69:66:2d:67:70  80T(config-if-gp
00000020  6f:6e:2d:30:2f:31:33:29:23                       on-0/13)#

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 9.9108, network: 0.0002s)
00000000  00:00:00:01:00:00:00:0f:6f:6e:74:20:64:65:6c:65  ........ont dele
00000010  74:65:20:31:20:30:0a                             te 1 0.

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0303, network: 0.0001s)
00000000  00:00:00:02:00:00:00:0e:6f:6e:74:20:64:65:6c:65  ........ont dele
00000010  74:65:20:31:20:30                                te 1 0

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0744, network: 0.0001s)
00000000  00:00:00:02:00:00:00:35:0d:0a:20:20:4e:75:6d:62  .......5..  Numb
00000010  65:72:20:6f:66:20:4f:4e:54:73:20:74:68:61:74:20  er of ONTs that 
00000020  63:61:6e:20:62:65:20:64:65:6c:65:74:65:64:3a:20  can be deleted: 
00000030  31:2c:20:73:75:63:63:65:73:73:3a:20:31           1, success: 1

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0241, network: 0.0001s)
00000000  00:00:00:02:00:00:00:21:0d:0a:0d:0a:4d:41:35:36  .......!....MA56
00000010  38:30:54:28:63:6f:6e:66:69:67:2d:69:66:2d:67:70  80T(config-if-gp
00000020  6f:6e:2d:30:2f:31:33:29:23                       on-0/13)#

-> NET_SSH2_MSG_DISCONNECT (since last: 9.8742, network: 0.0002s)
00000000  00:00:00:0b:00:00:00:00:00:00:00:00              ............

I notice the presence of this strange exclamation point before each timeout .......!....MA5680T(config-if-gpon-0/13)#


Solution

  • I solved it thanks to @nubert by setting the correct prompt for each $ssh->read(); Example: $ssh->read('MA5680T>');,$ssh->read('MA5680T(config)#');