예제 #1
0
 /**
  */
 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);
     }
 }
예제 #2
0
 /**
  * Utility function to get the RSTP port roles for a given device on a given VLAN
  *
  * @see rstpTopologyAction()
  * @param string $device The device to query
  *@param string $type Either 'mst' or else 'rstp' assumed
  * @param int $instance The VLAN / MST instance id to query
  * @return array Array of roles for participating ports (empty array of none or if device could not be queried)
  */
 private function _stpTopologyPortRoles($device, $type, $instance)
 {
     try {
         $_h = new \OSS_SNMP\SNMP($device, $this->_options['community']);
         if ($type == 'mst') {
             return $_h->useCisco_MST()->portRoles($instance, true);
         } else {
             return $_h->useCisco_RSTP()->portRoles($instance, true);
         }
     } catch (Exception $e) {
         return array();
     }
 }