Beispiel #1
0
 /**
  * Return an array of all switch names where the array key is the switch id
  *
  * @param bool          $active If `true`, return only active switches
  * @param int           $type   If `0`, all types otherwise limit to specific type
  * @param \Entities\IXP $ixp    IXP to filter vlan names
  * @return array An array of all switch names with the switch id as the key.
  */
 public function getNames($active = false, $type = 0, $ixp = false)
 {
     $switches = [];
     foreach ($this->getAndCache($active, $type) as $a) {
         if (!$ixp || $ixp->getInfrastructures()->contains($a->getInfrastructure())) {
             $switches[$a->getId()] = $a->getName();
         }
     }
     asort($switches);
     return $switches;
 }
 /**
  * Utility function to slurp all VLAN interfaces ports from the database and arrange them in
  * arrays by infrastructure.
  *
  * @param \Entities\IXP $ixp
  */
 public static function genConf_getTargets($ixp)
 {
     $data = [];
     foreach ($ixp->getInfrastructures() as $infra) {
         $data[$infra->getId()]['name'] = preg_replace('/#/', '', $infra->getName());
         $data[$infra->getId()]['shortname'] = preg_replace('/#/', '', $infra->getShortname());
         $data[$infra->getId()]['vlans'] = [];
         foreach ($infra->getVLANs() as $v) {
             if ($v->getPrivate()) {
                 continue;
             }
             $vlan = [];
             $vlan['name'] = preg_replace('/#/', '', $v->getName());
             $vlan['number'] = preg_replace('/#/', '', $v->getNumber());
             $vlan['ints'] = [];
             foreach ($v->getVlanInterfaces() as $vli) {
                 if ($vli->getVirtualInterface()->getCustomer()->getStatus() != \Entities\Customer::STATUS_NORMAL) {
                     continue;
                 }
                 $havePhysInt = false;
                 foreach ($vli->getVirtualInterface()->getPhysicalInterfaces() as $pi) {
                     if ($pi->getStatus() == \Entities\PhysicalInterface::STATUS_CONNECTED) {
                         $havePhysInt = true;
                         break;
                     }
                 }
                 if (!$havePhysInt) {
                     continue;
                 }
                 $key = $vli->getVirtualInterface()->getCustomer()->getName() . '___' . $vli->getId();
                 $vlan['ints'][$key]['vliid'] = $vli->getId();
                 $vlan['ints'][$key]['name'] = preg_replace('/#/', '', $vli->getVirtualInterface()->getCustomer()->getName());
                 $vlan['ints'][$key]['shortname'] = preg_replace('/#/', '', $vli->getVirtualInterface()->getCustomer()->getShortname());
                 $vlan['ints'][$key]['abbreviatedname'] = preg_replace('/#/', '', $vli->getVirtualInterface()->getCustomer()->getAbbreviatedName());
                 if ($vli->getIpv4enabled() && $vli->getIpv4canping()) {
                     $vlan['ints'][$key]['ipv4'] = $vli->getIpv4Address()->getAddress();
                 } else {
                     $vlan['ints'][$key]['ipv4'] = false;
                 }
                 if ($vli->getIpv6enabled() && $vli->getIpv6canping()) {
                     $vlan['ints'][$key]['ipv6'] = $vli->getIpv6Address()->getAddress();
                 } else {
                     $vlan['ints'][$key]['ipv6'] = false;
                 }
             }
             ksort($vlan['ints'], SORT_STRING | SORT_FLAG_CASE);
             $data[$infra->getId()]['vlans'][$v->getId()] = $vlan;
         }
     }
     return $data;
 }
 public function getInfrastructures()
 {
     $this->__load();
     return parent::getInfrastructures();
 }
 /**
  * Utility function to slurp all peering ports from the database and arrange them in
  * arrays by infrastructure and switch.
  *
  * @param \Entities\IXP $ixp
  */
 private function genMrtgConf_getPeeringPortsByInfrastructure($ixp)
 {
     $data = [];
     foreach ($ixp->getInfrastructures() as $infra) {
         if (!$infra->getAggregateGraphName()) {
             continue;
         }
         $data[$infra->getId()]['mrtgIds'] = [];
         $data[$infra->getId()]['name'] = $infra->getName();
         $data[$infra->getId()]['aggregate_graph_name'] = $infra->getAggregateGraphName();
         $data[$infra->getId()]['maxbytes'] = 0;
         $data[$infra->getId()]['switches'] = '';
         foreach ($infra->getSwitchers() as $switch) {
             if ($switch->getSwitchtype() != \Entities\Switcher::TYPE_SWITCH || !$switch->getActive()) {
                 continue;
             }
             $data[$infra->getId()]['switches'][$switch->getId()] = [];
             $data[$infra->getId()]['switches'][$switch->getId()]['name'] = $switch->getName();
             $data[$infra->getId()]['switches'][$switch->getId()]['maxbytes'] = 0;
             $data[$infra->getId()]['switches'][$switch->getId()]['mrtgIds'] = [];
             foreach ($switch->getPorts() as $port) {
                 if ($port->getIfName()) {
                     $snmpId = $port->ifnameToSNMPIdentifier();
                     $data[$infra->getId()]['maxbytes'] += $port->getIfHighSpeed() * 1000000 / 8;
                     // Mbps * bps / to bytes
                     $data[$infra->getId()]['switches'][$switch->getId()]['maxbytes'] += $port->getIfHighSpeed() * 1000000 / 8;
                     foreach (IXP_Mrtg::$TRAFFIC_TYPES as $type => $vars) {
                         $id = "{$vars['in']}#{$snmpId}&{$vars['out']}#{$snmpId}:{$switch->getSnmppasswd()}@{$switch->getHostname()}:::::2";
                         if ($port->getType() == \Entities\SwitchPort::TYPE_PEERING) {
                             $data[$infra->getId()]['mrtgIds'][$type][] = $id;
                         }
                         $data[$infra->getId()]['switches'][$switch->getId()]['mrtgIds'][$type][] = $id;
                     }
                 }
             }
         }
     }
     return $data;
 }