mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Refactor MAC utils to a new utility class * Apply fixes from StyleCI * Inline functions Add tests Handle bridgeid format * Apply fixes from StyleCI * Dedicated code path for stp bridge parsing, and improve STP output a bit * Correctly parse dot1dBaseBridgeAddress and don't store int in bool field * trim any unexpected character from bridge addresses, add extra test data. * better comment * barsBridge can handle dot1dBaseBridgeAddress correctly now * parseBridge, check for properly formatted mac first. * update test data, empty data = empty mac * Fix new usage after rebase * import --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace LibreNMS\Tests\Unit\Util;
|
|
|
|
use LibreNMS\Tests\TestCase;
|
|
use LibreNMS\Util\Mac;
|
|
|
|
class MacUtilTest extends TestCase
|
|
{
|
|
public function testMacOutput(): void
|
|
{
|
|
$mac = Mac::parse('DeadBeefa0c3');
|
|
$this->assertTrue($mac->isValid());
|
|
$this->assertEquals('de:ad:be:ef:a0:c3', $mac->readable());
|
|
$this->assertEquals('deadbeefa0c3', $mac->hex());
|
|
$this->assertEquals('222.173.190.239.160.195', $mac->oid());
|
|
$this->assertEquals(['de', 'ad', 'be', 'ef', 'a0', 'c3'], $mac->array());
|
|
}
|
|
|
|
public function testBridgeParsing(): void
|
|
{
|
|
$this->assertEquals('0c85255ce500', Mac::parseBridge('80 62 0c 85 25 5c e5 00')->hex());
|
|
$this->assertEquals('000000000001', Mac::parseBridge('00 00 00 00 00 00 00 01 ')->hex());
|
|
$this->assertEquals('000000000002', Mac::parseBridge('0-00.00.00.00.00.02')->hex());
|
|
$this->assertEquals('00186e6449a0', Mac::parseBridge('0:18:6e:64:49:a0')->hex());
|
|
$this->assertEquals('0c85255ce500', Mac::parseBridge('80620c85255ce500')->hex());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*
|
|
* @dataProvider validMacProvider
|
|
*/
|
|
public function testMacToHex(string $from, string $to): void
|
|
{
|
|
$this->assertEquals($to, Mac::parse($from)->hex());
|
|
}
|
|
|
|
public function validMacProvider(): array
|
|
{
|
|
return [
|
|
['00:00:00:00:00:01', '000000000001'],
|
|
['00-00-00-00-00-01', '000000000001'],
|
|
['000000.000001', '000000000001'],
|
|
['000000000001', '000000000001'],
|
|
['00:12:34:ab:cd:ef', '001234abcdef'],
|
|
['00:12:34:AB:CD:EF', '001234abcdef'],
|
|
['0:12:34:AB:CD:EF', '001234abcdef'],
|
|
['00-12-34-AB-CD-EF', '001234abcdef'],
|
|
['001234-ABCDEF', '001234abcdef'],
|
|
['0012.34AB.CDEF', '001234abcdef'],
|
|
['00:02:04:0B:0D:0F', '0002040b0d0f'],
|
|
['0:2:4:B:D:F', '0002040b0d0f'],
|
|
['0:2:4:B:D:F', '0002040b0d0f'],
|
|
];
|
|
}
|
|
}
|