Changeset 829


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

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r824 r829  
    20202020    ADD CONSTRAINT `NetworkInterfaceLatency_ibfk_1` FOREIGN KEY (`Interface`) REFERENCES `NetworkInterface` (`Id`);');
    20212021}
     2022
     2023/*
     2024function UpdateTo829($Manager)
     2025{
     2026  $Manager->Execute('ALTER TABLE `NetworkLinkType` '.
     2027    'ADD `MaxLinkSpeed` INT NOT NULL AFTER `Name`, '.
     2028    'ADD `MaxRealSpeed` INT NOT NULL AFTER `MaxLinkSpeed`, '.
     2029    'ADD `FullDuplex` INT NOT NULL AFTER `MaxRealSpeed`, '.
     2030    'ADD `Color` VARCHAR(6) NOT NULL AFTER `FullDuplex`');
     2031}
     2032*/
    20222033
    20232034class Updates
     
    21132124      817 => array('Revision' => 818, 'Function' => 'UpdateTo818'),
    21142125      818 => array('Revision' => 824, 'Function' => 'UpdateTo824'),
     2126      //824 => array('Revision' => 829, 'Function' => 'UpdateTo829'),
    21152127    ));
    21162128  }
  • trunk/Modules/Network/Network.php

    r825 r829  
    100100{
    101101  var $MinNotifyTime;
    102  
     102
    103103  function __construct($System)
    104104  {
     
    110110    $this->Description = 'Networking related tools';
    111111    $this->Dependencies = array('Notify');
    112    
     112
    113113    // TODO: Make notify time configurable
    114     $this->MinNotifytime = 2 * 60;
     114    $this->MinNotifyTime = 2 * 60;
    115115  }
    116116
     
    125125  function DoStart()
    126126  {
    127     $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkReachability', 
     127    $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkReachability',
    128128      array($this, 'ReachabilityCheck'));
    129     $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkPort', 
     129    $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkPort',
    130130      array($this, 'PortCheck'));
    131    
    132    
     131
     132
    133133    $this->System->RegisterPage('network', 'PageNetwork');
    134134    $this->System->RegisterPage(array('network', 'administration'), 'PageNetworkAdministration');
     
    297297      'Items' => array(
    298298        'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
     299        'MaxLinkSpeed' => array('Type' => 'Integer', 'Caption' => 'Maximální spojová rychlost', 'Default' => '0', 'Suffix' => 'bits/s'),
     300        'MaxRealSpeed' => array('Type' => 'Integer', 'Caption' => 'Maximální reálná rychlost', 'Default' => '0', 'Suffix' => 'bits/s'),
     301        'FullDuplex' => array('Type' => 'Boolean', 'Caption' => 'Plně duplexní', 'Default' => '0'),
     302        'Color' => array('Type' => 'Color', 'Caption' => 'Barva', 'Default' => '0'),
    299303      ),
    300304    ));
     
    669673      'Filter' => '1',
    670674    ));
    671    
     675
    672676    $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('Network',
    673677      array('ModuleNetwork', 'ShowDashboardItem'));
     
    680684    ));
    681685  }
    682  
     686
    683687  function AfterInsertNetworkDevice($Form)
    684688  {
     
    690694    $this->System->Models['NetworkDevice']->DoOnChange();
    691695  }
    692  
     696
    693697  function AfterInsertNetworkInterface($Form)
    694698  {
     
    700704    $this->System->Models['NetworkInterface']->DoOnChange();
    701705  }
    702  
     706
    703707  function BeforeDeleteNetworkInterface($Form, $Id)
    704708  {
     
    734738  {
    735739  }
    736  
     740
    737741  function OnlineList($Title, $OnlineNow, $OnlinePrevious, $MinDuration)
    738742  {
     
    748752      '(`NetworkInterface`.`LocalIP` != "") AND (`NetworkInterface`.`Enabled`=1)'.
    749753      'ORDER BY `Name` ASC');
    750     if($DbResult3->num_rows > 0) 
     754    if($DbResult3->num_rows > 0)
    751755    {
    752756      $Output .= $Title.'<br/>';
     
    780784    return($Output);
    781785  }
    782  
     786
    783787  function PortCheckList($Title, $OnlineNow, $OnlinePrevious, $MinDuration)
    784788  {
     
    808812        $Days = floor($Duration / (60 * 60 * 24));
    809813        if($Days > 0) $DurationText = $Days.' dnů '.$DurationText;
    810  
     814
    811815        $Output .= '<tr><td>'.$Item['Name'].'</td><td>'.$OnlineText[$Item['Online']].
    812816          '</td><td>'.$Item['LastOnline'].'</td><td>'.$DurationText.'</td></tr>'."\n";
     
    818822    return $Output;
    819823  }
    820  
     824
    821825  function PortCheck()
    822826  {
  • trunk/Modules/NetworkConfigRouterOS/Generators/Netwatch.php

    r790 r829  
    3131          if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    3232          echo($Name.', ');
    33           $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:01:00', 'comment' => $Name);
     33          $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:00:30', 'comment' => $Name);
    3434        }
    3535      }
  • trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php

    r818 r829  
    9191  function Run()
    9292  {
    93     RepeatFunction(60, array($this, 'NetwatchImport'));
     93    RepeatFunction(30, array($this, 'NetwatchImport'));
    9494  }
    9595}
  • 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.