Skip to content

Commit

Permalink
Added _ident, Remove _onu_num
Browse files Browse the repository at this point in the history
  • Loading branch information
meklis committed May 7, 2024
1 parent 25844b7 commit 5a33e28
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Modules/BDcom/BDcomAbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private function loadInterfaces($useCache = true)
'parent' => $this->findParentByName($name),
'_slot' => $slot,
'_port' => $port,
'_onu_num' => $onuNum,
'_onu' => $onuNum,
'_technology' => 'epon',
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/BDcom/GP3600/BDcomAbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private function loadInterfaces($useCache = true) {
'parent' => $this->findParentByName($iface->getValue()),
'_slot' => 0,
'_port' => (int)$m[1],
'_onu_num' => (int)$m[2],
'_onu' => (int)$m[2],
'_type' => 'gpon',
'_technology' => 'gpon',
];
Expand Down
1 change: 1 addition & 0 deletions src/Modules/BDcom/GP3600/UnregisteredOnts.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function getGponUnregisteredFromResponses($response)
'_serial_ascii' => $sn->getValue(),
'_serial_hex' => $hexVal,
'serial' => str_replace(":", "", $sn->getValue()),
'_ident' => str_replace(":", "", $sn->getValue()),
'interface' => $iface,
'password' => null,
'version' => null,
Expand Down
1 change: 1 addition & 0 deletions src/Modules/BDcom/UnregisteredOnts.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function ($e) {
unset($un['bind_status']);
$un['_mac_address_hex'] = str_replace(":", "", $mac);
$un['mac_address'] = $mac;
$un['_ident'] = $mac;
return $un;
}, $unregistered));

Expand Down
12 changes: 6 additions & 6 deletions src/Modules/CData/CDataAbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function parseInterface($input)
'type' => $interface['type'],
'_port' => isset($interface['_port']) ? $interface['_port'] : null,
'_slot' => isset($interface['_slot']) ? $interface['_slot'] : null,
'_onu_num' => null,
'_onu' => null,
'onu_id' => null,
'uni' => null,
'parent' => null,
Expand All @@ -80,7 +80,7 @@ protected function parseInterface($input)
'type' => $interface['type'],
'_port' => isset($interface['_port']) ? $interface['_port'] : null,
'_slot' => isset($interface['_slot']) ? $interface['_slot'] : null,
'_onu_num' => null,
'_onu' => null,
'uni' => null,
'pontype' => isset($interface['pontype']) ? $interface['pontype'] : null,
'_technology' => isset($interface['pontype']) ? $interface['pontype'] : null,
Expand All @@ -98,7 +98,7 @@ protected function parseInterface($input)
'xid' => $interface['xid'],
'_port' => isset($interface['_port']) ? $interface['_port'] : null,
'_slot' => isset($interface['_slot']) ? $interface['_slot'] : null,
'_onu_num' => $onuNum,
'_onu' => $onuNum,
'type' => 'ONU',
'uni' => null,
'pontype' => isset($interface['pontype']) ? $interface['pontype'] : null,
Expand All @@ -116,7 +116,7 @@ protected function parseInterface($input)
'type' => $interface['type'],
'_port' => isset($interface['_port']) ? $interface['_port'] : null,
'_slot' => isset($interface['_slot']) ? $interface['_slot'] : null,
'_onu_num' => null,
'_onu' => null,
'uni' => null,
'pontype' => isset($interface['pontype']) ? $interface['pontype'] : null,
'_technology' => isset($interface['pontype']) ? $interface['pontype'] : null,
Expand All @@ -125,13 +125,13 @@ protected function parseInterface($input)
case 7:
$response['name'] .= ":{$m[5]}";
$response['uni'] = (int)$m[6];
$response['_onu_num'] = (int)$m[5];
$response['_onu'] = (int)$m[5];
$response['type'] = 'UNI';
$response['id'] = (int)$m[5] + $response['id'];
break;
case 6:
$response['name'] .= ":{$m[5]}";
$response['_onu_num'] = (int)$m[5];
$response['_onu'] = (int)$m[5];
$response['type'] = 'ONU';
$response['id'] = (int)$m[5] + $response['id'];
break;
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/CData/FD11XX/CDataAbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function parseInterface($input, $parseBy = 'xid')
'xid' => $interface['xid'],
'type' => $interface['type'],
'phys_snmp_id' => $interface['phys_snmp_id'],
'_onu_num' => null,
'_onu' => null,
'parent' => null,
'_snmp_id' => null,
];
Expand All @@ -87,7 +87,7 @@ protected function parseInterface($input, $parseBy = 'xid')
'id' => ($interface['xid'] * 1000) + $onuNum,
'xid' => null,
'type' => 'ONU',
'_onu_num' => $onuNum,
'_onu' => $onuNum,
'phys_snmp_id' => $interface['phys_snmp_id'],
'_snmp_id' => "{$interface['xid']}.{$onuNum}",
];
Expand All @@ -102,14 +102,14 @@ protected function parseInterface($input, $parseBy = 'xid')
'xid' => $interface['xid'],
'type' => $interface['type'],
'phys_snmp_id' => $interface['phys_snmp_id'],
'_onu_num' => null,
'_onu' => null,
'_snmp_id' => null,
];
switch (count($m)) {
case 3:
$response['name'] .= ":{$m[2]}";
$response['parent'] = $interface['id'];
$response['_onu_num'] = (int)$m[2];
$response['_onu'] = (int)$m[2];
$response['type'] = 'ONU';
$response['_snmp_id'] = "{$response['xid']}.{$m[2]}";
$response['id'] = ((int)$response['xid'] * 1000) + $m[2];
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/CData/FD11XX/OntListWithStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function formate($resp, $filter) {
'xid' => $interface['xid'],
'_snmp_id' => "{$interface['xid']}.{$ontNum}",
'type' => 'ONU',
'_onu_num' => $ontNum,
'_onu' => $ontNum,
],
'status' => $statusText,
'admin_state' => null,
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/CData/FD16xxV3/CDataAbstractModuleFD16xxV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function getPhysicalInterfaces()
'_shelf' => $m[2],
'_slot' => $m[3],
'_port' => $m[4],
'_onu_num' => null,
'_onu' => null,
'_technology' => 'gpon',
];
}
Expand Down Expand Up @@ -136,7 +136,7 @@ function decodeSnmpOid($oid)
'parent' => $iface['id'],
'type' => 'ONU',
'_snmp_id' => $oid,
'_onu_num' => $onuNum,
'_onu' => $onuNum,
'_type' => $iface['_type'],
'_shelf' => $iface['_shelf'],
'_slot' => $iface['_slot'],
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function parseInterface($input, $searchBy=null)
$interface['id'] = $input;
$interface['name'] .= ":{$onu}";
$interface['_snmp_id'] = $this->encodeSnmpOid($interface['name']);
$interface['_onu_num'] = $onu;
$interface['_onu'] = $onu;
return $interface;
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ protected function parseInterface($input, $searchBy=null)
$interface['id'] = $interface['id'] + (int)$m[5];
$interface['name'] .= ":{$m[5]}";
$interface['_snmp_id'] = $this->encodeSnmpOid($interface['name']);
$interface['_onu_num'] = (int)$m[5];
$interface['_onu'] = (int)$m[5];
}
return $interface;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/CData/FD16xxV3/FdbTableConsoleFD1616.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function run($filter = [])
}
$telnetIdent = "{$iface['_type']} 0/0/{$iface['_port']}";
if ($iface['type'] === 'ONU') {
$resp = $this->console->exec("show mac-address port {$telnetIdent} ont {$iface['_onu_num']}");
$resp = $this->console->exec("show mac-address port {$telnetIdent} ont {$iface['_onu']}");
} else {
$resp = $this->console->exec("show mac-address port {$telnetIdent}");
}
Expand Down
3 changes: 3 additions & 0 deletions src/Modules/CData/FD16xxV3/GponOntSerial.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private function processNoInterface($response) {
$onuId = Helper::getIndexByOid($r->getOid());
$interface = $this->parseInterface($onuId);
$interface['onu_id'] = $onuId;
if(!$interface) {
continue;
}
$return[] = [
'interface' => $interface,
'serial' => Helper::hexToStr(substr($r->getHexValue(), 0, 12)) . substr(str_replace(":", "", $r->getHexValue()), 8),
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/CData/FD16xxV3/OntDeleteGpon.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function run($filter = [])
if(!$interface['id']) {
throw new \Exception("Incorrect ONU number");
}
if (!preg_match('/^(pon|xge|ge)([0-9])\/([0-9])\/([0-9]){1,}\:?([0-9]{1,3})?\/?([0-9]{1,3})?$/', $interface['name'], $m)) {
if (!preg_match('/^(pon|xge|ge|gpon) ([0-9])\/([0-9])\/([0-9]){1,}\:?([0-9]{1,3})?\/?([0-9]{1,3})?$/', $interface['name'], $m)) {
throw new \Exception("Interface {$filter['interface']} not supported!");
}
if(count($m) < 5) {
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/CData/FD16xxV3/OntListWithStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function formate($resp) {
'id' => $interface['id'] + $ontNum,
'xid' => $interface['xid'],
'type' => 'ONU',
'_onu_num' => $ontNum,
'_onu' => $ontNum,
'uni' => null,
],
'status' => $statusText,
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/CData/FD16xxV3/OntUniPortsStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getUniDataByConsole($iface){


$this->console->exec("interface {$iface['_type']} 0/0");
$resp = $this->console->exec("show ont port state {$iface['_port']} {$iface['_onu_num']} eth all");
$resp = $this->console->exec("show ont port state {$iface['_port']} {$iface['_onu']} eth all");
$response = [];
$lines = explode("\n", $resp);

Expand Down
1 change: 1 addition & 0 deletions src/Modules/CData/FD16xxV3/RawConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function validResponse($response)
if (preg_match('/Command incomplete/', $response)) return false;
if (preg_match('/Unknown command/', $response)) return false;
if (preg_match('/Error/', $response)) return false;
if (preg_match('/failed/i', $response)) return false;
return true;
}

Expand Down
96 changes: 96 additions & 0 deletions src/Modules/CData/FD16xxV3/SnmpUnregisteredOnts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php


namespace SwitcherCore\Modules\CData\FD16xxV3;


use Exception;
use SnmpWrapper\Oid;
use SwitcherCore\Modules\AbstractModule;
use SwitcherCore\Modules\Helper;
use SwitcherCore\Switcher\Objects\WrappedResponse;

class SnmpUnregisteredOnts extends CDataAbstractModuleFD16xxV3
{
/**
* @var WrappedResponse[]
*/
protected $response = null;

function getRaw()
{
return $this->response;
}

function getPretty()
{
return $this->response;
}

/**
* @param array $filter
* @return $this|AbstractModule
* @throws Exception
*/
public function run($filter = [])
{
$oids = array_map(function ($e) {
return Oid::init($e->getOid());
}, $this->oids->getOidsByRegex('ont.autofind..*'));
$response = $this->formatResponse($this->snmp->walk($oids));
$this->response = array_values($this->getGponUnregisteredFromResponses($response));
return $this;
}

function getGponUnregisteredFromResponses($response)
{
$data = [];
if (isset($response['ont.autofind.ident'])) {
if ($response['ont.autofind.ident']->error()) {
return [];
}
foreach ($response['ont.autofind.ident']->fetchAll() as $onuId => $sn) {
$uniqId = Helper::getIndexByOid($sn->getOid());
$ifacePort = explode(":", $this->parseInterface($uniqId, '_snmp_id')['name'])[0];
$iface = $this->parseInterface($ifacePort . ":" . ($onuId + 1));
$val = $sn->getValue();
$hexVal = strtoupper(bin2hex(substr($val, 0, 4))) . substr($val, 5);
$data[$uniqId] = [
'_serial_ascii' => $sn->getValue(),
'_serial_hex' => $hexVal,
'serial' => str_replace("-", "", $sn->getValue()),
'_ident' => str_replace("-", "", $sn->getValue()),
'interface' => $iface,
'password' => null,
'version' => null,
'equipment_id' => null,
'fw_version' => null,
'check_code' => null,
'loid' => null,
'reg_time' => null,
'model' => null,
'type' => null,
];
}
}
foreach ($response['ont.autofind.equipmentId']->fetchAll() as $d) {
$uniqId = Helper::getIndexByOid($d->getOid());
$data[$uniqId]['equipment_id'] = $this->convertHexToString($d->getHexValue());
}
foreach ($response['ont.autofind.password']->fetchAll() as $d) {
$uniqId = Helper::getIndexByOid($d->getOid());
$data[$uniqId]['password'] = $this->convertHexToString($d->getHexValue());
}
foreach ($response['ont.autofind.softwareVer']->fetchAll() as $d) {
$uniqId = Helper::getIndexByOid($d->getOid());
$data[$uniqId]['fw_version'] = $this->convertHexToString($d->getHexValue());
}
return $data;
}

function getPrettyFiltered($filter = [], $fromCache = false)
{
return parent::getPrettyFiltered($filter, $fromCache); // TODO: Change the autogenerated stub
}
}

Loading

0 comments on commit 5a33e28

Please sign in to comment.