mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
114
includes/discovery/vlans/jetstream.inc.php
Normal file
114
includes/discovery/vlans/jetstream.inc.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* jetstream.inc.php
|
||||
*
|
||||
* LibreNMS vlan discovery module for Jetstream TPLINK
|
||||
*
|
||||
* 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
|
||||
* @author peca.nesovanovic@sattrakt.com
|
||||
* @author mtammasss@gmail.com
|
||||
* @author PipoCanaja
|
||||
*/
|
||||
|
||||
# first release by (peca.nesovanovic@sattrakt.com) # 2020/05/25
|
||||
# jetstreamExpand function by Molnar Tamas (mtammasss@gmail.com) # 2020/05/25
|
||||
#
|
||||
# tested on: T1600G-28TS 3.0; T2600G-18TS 2.0;
|
||||
#
|
||||
# todo: detect LAG ports ??? now parser assume that there is no LAG port
|
||||
#
|
||||
|
||||
if (!function_exists("jetstreamExpand")) {
|
||||
function jetstreamExpand($var)
|
||||
{
|
||||
$arr = explode(',', trim($var)); //array of x/y/a-z
|
||||
|
||||
unset($result);
|
||||
foreach ($arr as $element) {
|
||||
$element = trim($element);
|
||||
if (strpos($element, '-') !== false) {
|
||||
$tmp = explode('-', $element); // left part is a fully defined port, right is the end number of the serie
|
||||
$port_start_array = explode('/', $tmp[0]);
|
||||
$port_id = trim(array_pop($port_start_array)); // $port_start_array is "[x, y]", $port_id is "a";
|
||||
|
||||
for ($i = $port_id; $i <= $tmp[1]; $i++) {
|
||||
$result[] = implode("/", array_merge($port_start_array, [$i]));
|
||||
}
|
||||
} else {
|
||||
$result[] = $element;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
echo 'Jetstream VLANs: ';
|
||||
|
||||
$vlanversion = snmp_get($device, 'dot1qVlanVersionNumber.0', '-Oqv', 'IEEE8021-Q-BRIDGE-MIB');
|
||||
|
||||
if ($vlanversion == 'version1' || $vlanversion == '2') {
|
||||
d_echo("\n $vlanversion \n");
|
||||
$vtpdomain_id = 1;
|
||||
|
||||
$jet_vlanDb = snmpwalk_cache_oid($device, 'vlanConfigEntry', [], 'TPLINK-DOT1Q-VLAN-MIB');
|
||||
$jet_portMapping = snmpwalk_cache_oid($device, 'vlanPortConfigTable', [], 'TPLINK-DOT1Q-VLAN-MIB');
|
||||
foreach ($jet_portMapping as $jet_ifindex => $jet_port) {
|
||||
$jet_stringPortMapping[$jet_port["vlanPortNumber"]] = $jet_port;
|
||||
$jet_stringPortMapping[$jet_port["vlanPortNumber"]]["ifindex"] = $jet_ifindex;
|
||||
}
|
||||
foreach ($jet_vlanDb as $jet_vlan_id => $jet_vlan_data) {
|
||||
d_echo(" $jet_vlan_id ");
|
||||
|
||||
if (is_array($vlans_db[$vtpdomain_id][$jet_vlan_id])) {
|
||||
$vlan_data = $vlans_db[$vtpdomain_id][$jet_vlan_id];
|
||||
|
||||
if ($vlan_data['vlan_name'] != $jet_vlan_data['dot1qVlanDescription']) {
|
||||
$vlan_upd['vlan_name'] = $jet_vlan_data['dot1qVlanDescription'];
|
||||
dbUpdate($vlan_upd, 'vlans', '`vlan_id` = ?', array($vlan_data['jet_vlan_id']));
|
||||
log_event("VLAN $vlan_id changed name {$vlan_data['vlan_name']} -> " . $jet_vlan_data['dot1qVlanDescription'], $device, 'vlan');
|
||||
echo "U";
|
||||
} else {
|
||||
echo ".";
|
||||
}
|
||||
} else {
|
||||
dbInsert([
|
||||
'device_id' => $device['device_id'],
|
||||
'vlan_domain' => $vtpdomain_id,
|
||||
'vlan_vlan' => $jet_vlan_id,
|
||||
'vlan_name' => $jet_vlan_data['dot1qVlanDescription'],
|
||||
'vlan_type' => array('NULL')
|
||||
], 'vlans');
|
||||
|
||||
log_event("VLAN added: " . $jet_vlan_data['dot1qVlanDescription'] . ", $vlan_id", $device, 'vlan');
|
||||
echo "+";
|
||||
}
|
||||
$device['vlans'][$vtpdomain_id][$jet_vlan_id] = $jet_vlan_id;
|
||||
|
||||
foreach (jetstreamExpand($jet_vlan_data['vlanTagPortMemberAdd']) as $port_nr) {
|
||||
if (isset($jet_stringPortMapping[$port_nr])) {
|
||||
d_echo("ID: $jet_vlan_id -> PORT: ".$port_nr.", ifindex: ".$jet_stringPortMapping[$port_nr]['ifindex']." \n");
|
||||
$per_vlan_data[$jet_vlan_id][$jet_stringPortMapping[$port_nr]['ifindex']]['untagged']=0;
|
||||
}
|
||||
}
|
||||
foreach (jetstreamExpand($jet_vlan_data['vlanUntagPortMemberAdd']) as $port_nr) {
|
||||
if (isset($jet_stringPortMapping[$port_nr])) {
|
||||
d_echo("ID: $jet_vlan_id -> PORT: ".$port_nr.", ifindex: ".$jet_stringPortMapping[$port_nr]['ifindex']." \n");
|
||||
$per_vlan_data[$jet_vlan_id][$jet_stringPortMapping[$port_nr]['ifindex']]['untagged']=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
239
mibs/tplink/TPLINK-DOT1Q-VLAN-MIB
Normal file
239
mibs/tplink/TPLINK-DOT1Q-VLAN-MIB
Normal file
@@ -0,0 +1,239 @@
|
||||
-- ==================================================================
|
||||
-- Copyright(c) 2008-2010 Shenzhen TP-LINK Technologies Co.Ltd.
|
||||
--
|
||||
-- Description: Lan Switch VLAN MIB
|
||||
-- Reference:
|
||||
-- Version: V0.1
|
||||
-- History: Create by weishuifeng, 2102.11.28
|
||||
-- ==================================================================
|
||||
|
||||
TPLINK-DOT1Q-VLAN-MIB DEFINITIONS ::= BEGIN
|
||||
|
||||
IMPORTS
|
||||
ifIndex
|
||||
FROM RFC1213-MIB
|
||||
MODULE-IDENTITY, OBJECT-TYPE, Counter32, Integer32, OBJECT-IDENTITY, NOTIFICATION-TYPE
|
||||
FROM SNMPv2-SMI
|
||||
TPRowStatus
|
||||
FROM TPLINK-TC-MIB
|
||||
DisplayString
|
||||
FROM SNMPv2-TC
|
||||
tplinkMgmt
|
||||
FROM TPLINK-MIB;
|
||||
|
||||
|
||||
tplinkDot1qVlanMIB MODULE-IDENTITY
|
||||
LAST-UPDATED "200812160000Z"
|
||||
ORGANIZATION "Shenzhen TP-LINK Technologies Co.Ltd."
|
||||
CONTACT-INFO "www.tplink.com.cn"
|
||||
DESCRIPTION
|
||||
"VLAN (Virtual Local Area Network) technology is developed for
|
||||
the switch to divide the LAN into multiple logical LANs flexibly.
|
||||
Hosts in the same VLAN can communicate with each other, regardless
|
||||
of their physical locations. VLAN can enhance performance by conserving
|
||||
bandwidth, and improve security by limiting traffic to specific domains."
|
||||
REVISION "200908030000Z"
|
||||
DESCRIPTION
|
||||
"Initial version of this MIB module."
|
||||
::= { tplinkMgmt 14 }
|
||||
|
||||
tplinkDot1qVlanMIBObjects OBJECT IDENTIFIER ::= { tplinkDot1qVlanMIB 1 }
|
||||
tplinkDot1qVlanNotifications OBJECT IDENTIFIER ::= { tplinkDot1qVlanMIB 2}
|
||||
|
||||
vlanTableCreate NOTIFICATION-TYPE
|
||||
OBJECTS {
|
||||
dot1qVlanId
|
||||
}
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
""
|
||||
::= { tplinkDot1qVlanNotifications 1}
|
||||
|
||||
vlanPortConfig OBJECT IDENTIFIER ::= {tplinkDot1qVlanMIBObjects 1}
|
||||
vlanConfig OBJECT IDENTIFIER ::= {tplinkDot1qVlanMIBObjects 2}
|
||||
|
||||
|
||||
vlanPortConfigTable OBJECT-TYPE
|
||||
SYNTAX SEQUENCE OF VLANPORTCONFIGENTRY
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The switch provides three Link Types for the ports. Usually,
|
||||
the ACCESS port is to connect to the terminal hosts, such as
|
||||
PC and Server; the TRUNK port is to connect to the switch;
|
||||
the GENERAL port can connect to the terminal hosts or the
|
||||
switch also."
|
||||
::= { vlanPortConfig 1 }
|
||||
|
||||
vlanPortConifgEntry OBJECT-TYPE
|
||||
SYNTAX VLANPORTCONFIGENTRY
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"An entry contains of the information of a port parameter."
|
||||
INDEX { ifIndex }
|
||||
::= { vlanPortConfigTable 1 }
|
||||
|
||||
VLANPORTCONFIGENTRY ::=
|
||||
SEQUENCE {
|
||||
vlanPortNumber
|
||||
OCTET STRING,
|
||||
vlanPortType
|
||||
INTEGER,
|
||||
vlanPortPvid
|
||||
INTEGER,
|
||||
vlanPortLag
|
||||
DisplayString ( SIZE (0..10) )
|
||||
}
|
||||
|
||||
vlanPortNumber OBJECT-TYPE
|
||||
SYNTAX OCTET STRING (SIZE (0..16))
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The port id."
|
||||
::= { vlanPortConifgEntry 1}
|
||||
|
||||
|
||||
vlanPortType OBJECT-TYPE
|
||||
SYNTAX INTEGER{
|
||||
access(0), --ACCESS
|
||||
trunk(1), --TRUNK
|
||||
general(2) --GENERAL
|
||||
}
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"0.ACCESS:The ACCESS port can be added in a single VLAN,and the
|
||||
egress rule of the port is UNTAG. The PVID is same as the current
|
||||
VLAN ID. If the current VLAN is deleted,the PVID will be set to 1
|
||||
by default.
|
||||
1.TRUNK:The TRUNK port can be added in multiple VLANs, and the
|
||||
egress rule of the port is TAG. The PVID can be set as the VID
|
||||
number of any VLAN the port belongs to.
|
||||
2.GENERAL:The GENERAL port can be added in multiple VLANs and set
|
||||
various egress rules according to the different VLANs. The default
|
||||
egress rule is UNTAG. The PVID can be set as the VID number of any
|
||||
VLAN the port belongs to."
|
||||
::= { vlanPortConifgEntry 2 }
|
||||
|
||||
vlanPortPvid OBJECT-TYPE
|
||||
SYNTAX INTEGER(1..4094)
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Enter the PVID number of the port, 1-4094"
|
||||
::= { vlanPortConifgEntry 3 }
|
||||
|
||||
vlanPortLag OBJECT-TYPE
|
||||
SYNTAX DisplayString (SIZE (0..10))
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Displays the LAG to which the port belongs."
|
||||
::= { vlanPortConifgEntry 4 }
|
||||
|
||||
vlanPortUnknown OBJECT-TYPE
|
||||
SYNTAX DisplayString (SIZE (0..256))
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
""
|
||||
::= { vlanPortConifgEntry 5 }
|
||||
|
||||
vlanConfigTable OBJECT-TYPE
|
||||
SYNTAX SEQUENCE OF DOT1QVLANCONFIGENTRY
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Here you can view and modify the VLAN Table."
|
||||
::= { vlanConfig 1 }
|
||||
|
||||
vlanConfigEntry OBJECT-TYPE
|
||||
SYNTAX DOT1QVLANCONFIGENTRY
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"An entry contains of the information of a vlan."
|
||||
INDEX { dot1qVlanId }
|
||||
::= { vlanConfigTable 1 }
|
||||
|
||||
DOT1QVLANCONFIGENTRY ::=
|
||||
SEQUENCE {
|
||||
dot1qVlanId
|
||||
INTEGER(1..4094),
|
||||
dot1qVlanDescription
|
||||
OCTET STRING (SIZE (0..64)),
|
||||
vlanTagPortMemberAdd
|
||||
OCTET STRING,
|
||||
vlanUntagPortMemberAdd
|
||||
OCTET STRING,
|
||||
vlanPortMemberRemove
|
||||
OCTET STRING,
|
||||
dot1qVlanStatus
|
||||
TPRowStatus
|
||||
}
|
||||
|
||||
dot1qVlanId OBJECT-TYPE
|
||||
SYNTAX INTEGER(1..4094)
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Enter the ID number of VLAN,2-4094."
|
||||
::= { vlanConfigEntry 1 }
|
||||
|
||||
dot1qVlanDescription OBJECT-TYPE
|
||||
SYNTAX OCTET STRING (SIZE (0..64))
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Give a description to the VLAN for identification,1-16 characters"
|
||||
::= { vlanConfigEntry 2 }
|
||||
|
||||
vlanTagPortMemberAdd OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Enter the desired port to be a tag member of VLAN,The format of input
|
||||
port number shoud be like '1, 3, 4-7, 11'.
|
||||
tag:All packets forwarded by the port are tagged. The packets contain
|
||||
VLAN information."
|
||||
::= { vlanConfigEntry 3 }
|
||||
|
||||
vlanUntagPortMemberAdd OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Enter the desired port to be a untag member of VLAN,The format of input
|
||||
port number shoud be like '1, 3, 4-7, 11'.
|
||||
untag:Packets forwarded by the port are untagged."
|
||||
::= { vlanConfigEntry 4 }
|
||||
vlanPortMemberRemove OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Remove port member of vlan,The format of input port number shoud be like
|
||||
'1, 3, 4-7, 11'."
|
||||
::= { vlanConfigEntry 5 }
|
||||
|
||||
dot1qVlanStatus OBJECT-TYPE
|
||||
SYNTAX TPRowStatus
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"the following two values are states:
|
||||
these values may be read or written
|
||||
active(1),
|
||||
|
||||
the following three values are
|
||||
actions: these values may be written,
|
||||
but are never read
|
||||
createAndGo(4),
|
||||
|
||||
destroy(6)"
|
||||
::= { vlanConfigEntry 6 }
|
||||
|
||||
END
|
41
mibs/tplink/TPLINK-TC-MIB
Normal file
41
mibs/tplink/TPLINK-TC-MIB
Normal file
@@ -0,0 +1,41 @@
|
||||
TPLINK-TC-MIB DEFINITIONS ::= BEGIN
|
||||
|
||||
IMPORTS
|
||||
TEXTUAL-CONVENTION FROM SNMPv2-TC;
|
||||
|
||||
--TPLINK TYPE
|
||||
TPRowStatus ::= TEXTUAL-CONVENTION
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The status column has three defined values:
|
||||
- `active(1)', which indicates that the conceptual row is
|
||||
available for using by the managed device;
|
||||
|
||||
- `createAndGo(4)', which is supplied by a management
|
||||
station wishing to create a new instance of a
|
||||
conceptual row and to have its status automatically set
|
||||
to active, making it available for using by the managed
|
||||
device;
|
||||
|
||||
- `destroy(6)', which is supplied by a management station
|
||||
wishing to delete all of the instances associated with
|
||||
an existing conceptual row."
|
||||
SYNTAX INTEGER{
|
||||
active(1),
|
||||
createAndGo(4),
|
||||
destroy(6)
|
||||
}
|
||||
|
||||
|
||||
TPMacAddress ::= TEXTUAL-CONVENTION
|
||||
DISPLAY-HINT "1x-1x-1x-1x-1x-1x"
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"Represents an 802 MAC address represented in the
|
||||
`canonical' order defined by IEEE 802.1a, i.e., as if it
|
||||
were transmitted least significant bit first, even though
|
||||
802.5 (in contrast to other 802.x protocols) requires MAC
|
||||
addresses to be transmitted most significant bit first."
|
||||
SYNTAX OCTET STRING (SIZE (6))
|
||||
|
||||
END
|
4193
tests/data/jetstream_vlans.json
Normal file
4193
tests/data/jetstream_vlans.json
Normal file
File diff suppressed because it is too large
Load Diff
1076
tests/snmpsim/jetstream_vlans.snmprec
Normal file
1076
tests/snmpsim/jetstream_vlans.snmprec
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user