Files
librenms-librenms/LibreNMS/OS/Traits/ResolvesPortIds.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/*
* ResolvesPortIds.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2021 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\OS\Traits;
trait ResolvesPortIds
{
/**
* @var array
*/
private $ifIndexPortIdMap;
/**
* @var array
*/
private $basePortIdMap;
Migrate xDSL code to module, and add support for VDSL2 MIB (#14207) * use component to discover if xDSL polling is needed use component to discover if xDSL polling is needed * Components OK, Polling in correct files, no DB for VDSL * GUI GUI_suite * per port as well * rename * interface listing * draytek_snmpsim * fix arraymerge fix names and max value * schema schema style * remove one dbFetchRows remove 2x dbFetchCell style style remove Legacy dbFetchRow tests tests eloquent more eloquent more eloquent one more gone * fix properties access eloquent_insert_update style tests tests tests tests * tests tests tests * adslLineCoding * Models * fix not nullable cols in DB from code default values typo rename typo schema fix fix vdsl fix now typo typo fix size fix size * Power values for VDSL Power values for VDSL Power values for VDSL DB * cleanup * Rrd::checkRrdExists * always enable DSL discovery style * xdsl module * cleanup and move to Module cleanup and move to Module cleanup and move to Module cleanup and move to Module * Fix display * fix polling and tenth * remove legacy poller * Style and Cosmetics Cosmetics Cleanup * Translations Translations * exists exists * add test support for xdsl * remove last component call unused * translations * remove non standard onclick event on xdsl line * Update Discovery Support.md Update Poller Support.md toner_gone * Notification for removal of lnms config:set enable_ports_adsl true * enable on devices with potential DSL interfaces * tests are working now fix teldat tests * os_schema * teldat * move to new module structure * move to new module structure * wrong dump function * wrong dump function * laravel_through_key hidden * Update notifications.rss * Update notifications.rss Co-authored-by: Tony Murray <murraytony@gmail.com>
2022-09-08 02:29:17 +02:00
/** @var string[] */
private $ifIndexToNameMap;
/**
* Figure out the port_id from the BRIDGE-MIB::dot1dBasePort
*
* @param int|string $port
* @return int
*/
public function basePortToId($port): int
{
return $this->basePortToPortIdMap()[$port] ?? 0;
}
/**
* Figure out the port_id from IF-MIB::ifIndex
*
* @param int|string $ifIndex
* @return int
*/
public function ifIndexToId($ifIndex): int
{
return $this->ifIndexToPortIdMap()[$ifIndex] ?? 0;
}
Migrate xDSL code to module, and add support for VDSL2 MIB (#14207) * use component to discover if xDSL polling is needed use component to discover if xDSL polling is needed * Components OK, Polling in correct files, no DB for VDSL * GUI GUI_suite * per port as well * rename * interface listing * draytek_snmpsim * fix arraymerge fix names and max value * schema schema style * remove one dbFetchRows remove 2x dbFetchCell style style remove Legacy dbFetchRow tests tests eloquent more eloquent more eloquent one more gone * fix properties access eloquent_insert_update style tests tests tests tests * tests tests tests * adslLineCoding * Models * fix not nullable cols in DB from code default values typo rename typo schema fix fix vdsl fix now typo typo fix size fix size * Power values for VDSL Power values for VDSL Power values for VDSL DB * cleanup * Rrd::checkRrdExists * always enable DSL discovery style * xdsl module * cleanup and move to Module cleanup and move to Module cleanup and move to Module cleanup and move to Module * Fix display * fix polling and tenth * remove legacy poller * Style and Cosmetics Cosmetics Cleanup * Translations Translations * exists exists * add test support for xdsl * remove last component call unused * translations * remove non standard onclick event on xdsl line * Update Discovery Support.md Update Poller Support.md toner_gone * Notification for removal of lnms config:set enable_ports_adsl true * enable on devices with potential DSL interfaces * tests are working now fix teldat tests * os_schema * teldat * move to new module structure * move to new module structure * wrong dump function * wrong dump function * laravel_through_key hidden * Update notifications.rss * Update notifications.rss Co-authored-by: Tony Murray <murraytony@gmail.com>
2022-09-08 02:29:17 +02:00
/**
* Get IF-MIB::ifName from IF-MIB::ifIndex
*
* @param int|string $ifIndex
* @return string
*/
public function ifIndexToName($ifIndex): string
{
if ($this->ifIndexToNameMap === null) {
$this->ifIndexToNameMap = $this->getDevice()->ports()->pluck('ifName', 'ifIndex')->all();
}
return $this->ifIndexToNameMap[$ifIndex] ?? '';
}
private function ifIndexToPortIdMap(): array
{
if ($this->ifIndexPortIdMap === null) {
$this->ifIndexPortIdMap = $this->getDevice()->ports()->pluck('port_id', 'ifIndex')->all();
}
return $this->ifIndexPortIdMap;
}
private function basePortToPortIdMap(): array
{
if ($this->basePortIdMap === null) {
$base = $this->getCacheByIndex('BRIDGE-MIB::dot1dBasePortIfIndex');
$this->basePortIdMap = array_map(function ($ifIndex) {
return $this->ifIndexToId($ifIndex);
}, $base);
}
return $this->basePortIdMap;
}
}