Ignore:
Timestamp:
Apr 29, 2016, 11:54:31 PM (9 years ago)
Author:
chronos
Message:
  • Added: Experimental metod for calculating maximum speed limit according network links.
  • Modified: Lowered routeros netwatch period to 30 seconds.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php

    r781 r829  
    1313  function Run()
    1414  {
     15    //print_r($this->BuildTree($this->System->Config['MainRouter']['DeviceId'], 140 * 1000 * 1000));
     16    //die();
     17
    1518    $PathQueue = array('queue', 'tree');
    1619
     
    7477      echo('Zákazník '.$Member['Name']."\n");
    7578      $DbResult4 = $this->Database->query('SELECT `Service`.*, `ServiceCustomerRel`.`Id` AS `RelId` FROM `ServiceCustomerRel` '.
    76           'JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` '.
    77           'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) '.
    78           'AND (`Service`.`InternetSpeedMax` > 0) AND (`Service`.`InternetSpeedMin` > 0)');
     79        'JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` '.
     80        'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) '.
     81        'AND (`Service`.`InternetSpeedMax` > 0) AND (`Service`.`InternetSpeedMin` > 0)');
    7982      while($Service = $DbResult4->fetch_assoc())
    8083      {
     
    147150    $Routerboard->ListUpdate($PathQueue, array('name', 'limit-at', 'max-limit', 'parent', 'packet-mark'), $ItemsQueue, array(), true);
    148151  }
     152
     153  // Calculate maximum real speed available for each network device Start with main router and continue with adjecement nodes.
     154  function BuildTree($RootDeviceId, $BaseSpeed)
     155  {
     156    // Load network devices
     157    $Devices = array();
     158    $DbResult = $this->Database->query('SELECT `Name`,`Id` FROM `NetworkDevice`');
     159    while($Device = $DbResult->fetch_assoc())
     160    {
     161      $Device['Interfaces'] = array();
     162      $Device['Calculated'] = false;
     163      $Device['MaxSpeed'] = 0;
     164      $Devices[$Device['Id']] = $Device;
     165    }
     166
     167    // Load network interfaces and assign them to device
     168    $Interfaces = array();
     169    $DbResult = $this->Database->query('SELECT `Device`,`Name`,`Id` FROM `NetworkInterface`');
     170    while($Interface = $DbResult->fetch_assoc())
     171    {
     172      $Interface['Links'] = array();
     173      $Interfaces[$Interface['Id']] = $Interface;
     174      $Devices[$Interface['Device']]['Interfaces'][] = $Interface['Id'];
     175    }
     176
     177    // Load network links and assign them to interfaces
     178    $Links = array();
     179    $DbResult = $this->Database->query('SELECT `NetworkLink`.`Id`,`NetworkLink`.`Interface1`,'.
     180      '`NetworkLink`.`Interface2`,`NetworkLinkType`.`MaxRealSpeed` FROM `NetworkLink` '.
     181      'LEFT JOIN `NetworkLinkType` ON `NetworkLinkType`.`Id`=`NetworkLink`.`Type`');
     182    while($Link = $DbResult->fetch_assoc())
     183    {
     184      $Links[$Link['Id']] = $Link;
     185      $Interfaces[$Link['Interface1']]['Links'][] = $Link['Id'];
     186      $Interfaces[$Link['Interface2']]['Links'][] = $Link['Id'];
     187    }
     188
     189    $DevicesToCheck = array($RootDeviceId);
     190    $Devices[$RootDeviceId]['MaxSpeed'] = $BaseSpeed;
     191    $Devices[$RootDeviceId]['Calculated'] = true;
     192
     193    while(count($DevicesToCheck) > 0)
     194    {
     195      echo('Pass'."\n");
     196      $NewDevicesToCheck = array();
     197      foreach($DevicesToCheck as $DeviceId)
     198      {
     199        echo($Devices[$DeviceId]['Name'].': ');
     200        foreach($Devices[$DeviceId]['Interfaces'] as $InterfaceId)
     201        {
     202          foreach($Interfaces[$InterfaceId]['Links'] as $LinkId)
     203          {
     204            $Link = $Links[$LinkId];
     205            $Interface2Id = $Link['Interface1'];
     206            if($Interface2Id == $InterfaceId) $Interface2Id = $Links[$LinkId]['Interface2'];
     207
     208            $Device2Id = $Interfaces[$Interface2Id]['Device'];
     209            if($Devices[$Device2Id]['Calculated'] == false)
     210            {
     211              $Devices[$Device2Id]['Calculated'] = true;
     212              $NewMaxSpeed = $Devices[$DeviceId]['MaxSpeed'];
     213              if($NewMaxSpeed > $Link['MaxRealSpeed'])
     214                $NewMaxSpeed = $Link['MaxRealSpeed'];
     215              echo($Devices[$Device2Id]['Name'].' '.$Device2Id.', ');
     216              $Devices[$Device2Id]['MaxSpeed'] = $NewMaxSpeed;
     217              echo($NewMaxSpeed.", ".count($NewDevicesToCheck).' ');
     218              $NewDevicesToCheck[] = $Device2Id;
     219            }
     220          }
     221        }
     222        echo("\n");
     223      }
     224      $DevicesToCheck = $NewDevicesToCheck;
     225    }
     226    //print_r($Devices);
     227
     228    echo('Not linked network devices: ');
     229    foreach($Devices as $Device)
     230    {
     231      if($Device['MaxSpeed'] == 0) echo($Device['Name'].', ');
     232    }
     233    echo("\n");
     234
     235    $Tree = array();
     236    return($Tree);
     237  }
    149238}
Note: See TracChangeset for help on using the changeset viewer.