From 288e4df9d7dc19044d2a706d8be91569d9db60d7 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Thu, 11 Feb 2021 17:04:04 -0800 Subject: [PATCH] add support for NetGear GS724TPv2.. This increases the timeout to 10 seconds to deal w/ slow switches, but also puts in a proper state machine for creating vlans. This deals w/ the fact that this switch can not create the vlan and activate the vlan in a single command... --- NOTES.md | 13 +++++++++++++ vlanmang/__init__.py | 46 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/NOTES.md b/NOTES.md index 74746da..f2a4227 100644 --- a/NOTES.md +++ b/NOTES.md @@ -59,3 +59,16 @@ NetGear GS108Tv2 ---------------- Does not list VLAN 1 under dot1qVlanStaticName. + +NetGear GS724TPv2 +----------------- + +Requires firmware version of at least v1.1.50.39 for SNMPv3 to be +functional. This version of firmware also requires a timeout of 2 +seconds, which is longer than the 1 second default for queries to +complete. An issue with net-snmp has been filed: +https://github.com/net-snmp/net-snmp/issues/194 + +This swich cannot create vlans with the state set to createAndGo, they +must use createAndWait, set the egress ports (even if they are all +empty), before the vlan may be set active. diff --git a/vlanmang/__init__.py b/vlanmang/__init__.py index f13b1ea..ded4a15 100644 --- a/vlanmang/__init__.py +++ b/vlanmang/__init__.py @@ -397,7 +397,7 @@ class SNMPSwitch(object): None else privProtocol self._auth = UsmUserData(*args, **kwargs) - self._targ = UdpTransportTarget((host, 161)) + self._targ = UdpTransportTarget((host, 161), timeout=10) def __repr__(self): # pragma: no cover return '' % (repr(self._auth), repr(self._targ)) @@ -536,9 +536,47 @@ class SNMPSwitch(object): return bytes(v).decode('utf-8') def createvlan(self, vlan, name): - # createAndGo(4) - self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', - int(vlan)), 4) + try: + while True: + try: + status = self._get(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', + int(vlan))) + except ValueError: + status = 0 + + #print('got vlan', vlan, 'status:', status) + # if status == 0, vlan does not exist. + + if status == 1: # active + # vlan is active + return + + elif status == 0: + try: + # createAndGo(4) + self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', + int(vlan)), 4) + except ValueError: + # need to use createAndWait(5) + self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', + int(vlan)), 5) + + elif status == 2: # notInService + # should be able to be marked active(1) + self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', + int(vlan)), 1) + elif status == 3: # notReady + # Set itself, it'll be set more properly later + # This is because a switch requires exact length + mib = ('Q-BRIDGE-MIB', 'dot1qVlanStaticEgressPorts', int(vlan)) + self._set(mib, self._get(mib)) + else: + raise ValueError('do not know how to handle status: %s' % status) + except Exception: + import traceback + traceback.print_exc() + raise + self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticName', int(vlan)), name.encode('utf-8'))