/** */ public function portRolesAction() { if ($this->getRequest()->isPost()) { $this->view->portRolesDevice = $device = $this->_getParam('portRolesDevice'); $this->view->limitToInstance = $limitToInstance = $this->_getParam('limitToInstance', false); $this->view->type = $type = $this->getParam('type', 'rstp'); try { $host = new \OSS_SNMP\SNMP($device, $this->_options['community']); switch ($type) { case 'mst': $instances = $host->useCisco_SMST()->instances(); break; case 'rstp': default: $instances = $host->useCisco_VTP()->vlanNames(); } } catch (\OSS_SNMP\Exception $e) { $this->addMessage("Could not query instance and port role information via SNMP from " . $device, OSS_Message::ERROR); return; } $roles = []; $unknowns = []; $portsInSTP = []; if ($limitToInstance && isset($instances[$limitToInstance])) { $doInstances[$limitToInstance] = $instances[$limitToInstance]; } else { $doInstances = $instances; } foreach ($doInstances as $iid => $iname) { try { if ($type == 'mst') { $roles[$iid] = $host->useCisco_MST()->portRoles($iid, true); } else { $roles[$iid] = $host->useCisco_RSTP()->portRoles($iid, true); } foreach ($roles[$iid] as $portId => $role) { if (!isset($portsInSTP[$portId])) { $portsInSTP[$portId] = $portId; } } } catch (\OSS_SNMP\Exception $e) { $unknowns[$iid] = $iname; } } ksort($portsInSTP, SORT_NUMERIC); $this->view->portsInSTP = $portsInSTP; $this->view->ports = $host->useIface()->names(); $this->view->instances = $instances; $this->view->roles = $roles; $this->view->unknowns = $unknowns; unset($host); } }
/** * Similar to L2 Topology above but this takes a specific VLAN / instance and identifies and graphs Per-VLAN/instance Spanning Tree port roles. * * @see https://github.com/opensolutions/NOCtools/wiki/CDP-RSTP-Port-Roles */ public function stpTopologyAction() { $this->view->cdp_root = $host = $this->getParam('cdp_root', ''); $this->view->type = $type = $this->getParam('type', 'rstp'); $this->view->instance = $instance = $this->getParam('instance', false); $this->view->excludeNonParticipants = true; $this->view->showPortRoles = true; $this->view->ignoreList = implode("\n", $this->_getIgnoreList()); if (strlen($host)) { $root = new \OSS_SNMP\SNMP($host, $this->_options['community']); if ($type == 'mst') { $this->view->instances = $instances = $root->useCisco_SMST()->instances(); } else { $this->view->instances = $instances = $root->useCisco_VTP()->vlanNames(); } } if ($this->getRequest()->isPost()) { do { if ($instance !== false && $this->getParam('excludeNonParticipants', null) === null) { $this->view->excludeNonParticipants = $excludeNonParticipants = false; } if ($instance !== false && $this->getParam('showPortRoles', null) === null) { $this->view->showPortRoles = $showPortRoles = false; } $this->view->ignoreList = isset($this->view->ignoreList) ? $this->view->ignoreList : $this->getParam('ignoreList'); $ignoreList = array(); foreach (explode("\n", $this->getParam('ignoreList')) as $i) { $ignoreList[] = trim($i); } if (!strlen($host)) { $this->addMessage('You must select a device as the root for CDP neighbour discovery and a VLAN / instance', OSS_Message::ERROR); break; } if ($instance === false) { break; } $devices = array(); $root->useCisco_CDP()->crawl($devices, null, $ignoreList); // we're not splitting LAGs, we need to sanitise the links $devices = $root->useCisco_CDP()->collapseDevicesLAGs($devices); // now, find the links which are participating in RSTP / MST and their roles $portRoles = []; foreach ($devices as $aDevice => $neighbours) { if (!isset($portRoles[$aDevice])) { $portRoles[$aDevice] = $this->_stpTopologyPortRoles($aDevice, $type, $instance); } foreach ($neighbours as $bDevice => $ports) { if (!isset($portRoles[$bDevice])) { $portRoles[$bDevice] = $this->_stpTopologyPortRoles($bDevice, $type, $instance); } } } foreach ($devices as $aDevice => $neighbours) { foreach ($neighbours as $bDevice => $ports) { foreach ($ports as $idx => $portDetails) { if (isset($portRoles[$aDevice][$portDetails['localPortId']]) && isset($portRoles[$bDevice][$portDetails['remotePortId']])) { $devices[$aDevice][$bDevice][$idx]['localRSTP'] = $portRoles[$aDevice][$portDetails['localPortId']]; $devices[$aDevice][$bDevice][$idx]['remoteRSTP'] = $portRoles[$bDevice][$portDetails['remotePortId']]; // indicate if the link is passing traffic or not if (in_array($devices[$aDevice][$bDevice][$idx]['localRSTP'], \OSS_SNMP\MIBS\Cisco\RSTP::$STP_X_RSTP_PASSING_PORT_ROLES) && in_array($devices[$aDevice][$bDevice][$idx]['remoteRSTP'], \OSS_SNMP\MIBS\Cisco\RSTP::$STP_X_RSTP_PASSING_PORT_ROLES)) { $devices[$aDevice][$bDevice][$idx]['RSTPpassing'] = true; } else { $devices[$aDevice][$bDevice][$idx]['RSTPpassing'] = false; } } else { $devices[$aDevice][$bDevice][$idx]['localRSTP'] = false; $devices[$aDevice][$bDevice][$idx]['remoteRSTP'] = false; $devices[$aDevice][$bDevice][$idx]['RSTPpassing'] = null; } } } } $links = $root->useCisco_CDP()->linkTopology($devices); $this->view->devices = $devices; $this->view->links = $links; $this->view->locations = call_user_func("{$this->_options['utilsClass']}::extractLocations", $devices); $this->view->file = $file = $this->generateGraphFilename(array($host, $vlanid)); if ($this->_getParam('submit') == 'Download DOT File') { header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="' . $file . '.dot"'); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); echo $this->view->render('cdp/stp-topology-graph.dot'); return; } $this->getSessionNamespace()->stp_topology_file = $this->generateDotGraph($file, $this->view->render('cdp/stp-topology-graph.dot'), APPLICATION_PATH . '/../var/tmp'); } while (false); } }
/** * AJAX function to provide a JSON list of VLANs configured on a particular device. * * For example, used to dynamically populate dropdowns in @see VlanController::compareAction() * * @param string $host The SNMP addressable hostname of the device to query for VLAN IDs and names * @return JSON Encoded array of [vlanId] => 'vlanName' entries. */ public function ajaxGetForHostAction() { $host = $this->_getParam('host', null); if ($host) { try { $device = new \OSS_SNMP\SNMP($host, $this->_options['community']); $vlans = $device->useCisco_VTP()->vlanNames(); unset($device); } catch (\OSS_SNMP\Exception $e) { return; } $this->getResponse()->setHeader('Content-Type', 'application/json')->setBody(Zend_Json::encode($vlans))->sendResponse(); exit(0); } }