Pārlūkot izejas kodu

Se añaden campos de IN/OUT, index y cantidad de ONUs On/Off al listado de PonPorts de las OLTs. Para lograr similitud como la de Interfaces de CMTS.

Maxi Schvindt 7 gadi atpakaļ
vecāks
revīzija
d71e0a1e06

+ 5 - 0
src/StatsBundle/Admin/PonPortAdmin.php

@@ -69,12 +69,17 @@ class PonPortAdmin extends BaseAdmin
         $listMapper
             /* ->add('deviceServer') */
             ->add('oltDeviceId', 'string', array('template' => 'StatsBundle:Onu:base_list_field_olt.html.twig'))
+            ->add('index')
             ->addIdentifier('ponPort')
             ->add('txPower', 'string', array('template' => 'StatsBundle:Onu:field_tx.html.twig'))
             ->add('arrayRxPower', 'ponport-rx-power', array('template' => 'StatsBundle:PonPort:base_list_field_rx.html.twig'))
             ->add('voltage', 'string', array('template' => 'StatsBundle:Onu:field_voltage.html.twig'))
             ->add('temperature', 'string', array('template' => 'StatsBundle:Onu:field_temperature.html.twig'))
             ->add('biasCurrent')
+            ->add('inOctets','string', array('template' => 'StatsBundle:PonPort:interface_field_octets.html.twig'))
+            ->add('outOctets','string', array('template' => 'StatsBundle:PonPort:interface_field_octets.html.twig'))
+            ->add('online','string', array('template' => 'StatsBundle:PonPort:interface_field_count_onu.html.twig','label' => "ONU Online"))
+            ->add('offline','string', array('template' => 'StatsBundle:PonPort:interface_field_count_onu.html.twig','label' => "ONU Offline"))
         ;
     }
 

+ 54 - 4
src/StatsBundle/Command/StatsPonPortCommand.php

@@ -47,12 +47,16 @@ class StatsPonPortCommand extends BaseCommand
         $key_pon_stats = "olt_stats_pons_d_{$oltDeviceId}_s_{$oltServerId}";
         
         $ponsCached = $this->getData($key_pon_stats, true);
-
+        
         if(empty($ponsCached)) {
             $this->output->writeln("Se requiere {$key_pon_stats}.");
             return true;
         }
-
+        
+        $key_olt_pon_bandwidth = "olt_bandwidth_pons_d_{$oltDeviceId}_s_{$oltServerId}";
+        $status = $this->getCountOnus($deviceServerId, $oltDeviceId);
+        $bandwidth = $this->getData($key_olt_pon_bandwidth, true);
+        
         $ponPorts = $doctrine->getRepository('\StatsBundle\Entity\PonPort')->findBy(array('oltDeviceId' => $oltDeviceId, 'deviceServer' => $oltServerId));
         $_ponPorts = array();
         foreach($ponPorts as $k => $pp) {
@@ -83,6 +87,22 @@ class StatsPonPortCommand extends BaseCommand
             (isset($stats['temperature']))? $row['temperature'] = $stats['temperature'] : $row['temperature'] = "NULL";
             (isset($stats['biasCurrent']))? $row['biasCurrent'] = $stats['biasCurrent'] : $row['biasCurrent'] = "NULL";
             
+            if(isset($bandwidth[$index])) {
+                $row['inOctets'] = $bandwidth[$index]['inBand'];
+                $row['outOctets'] = $bandwidth[$index]['outBand'];
+            } else {
+                $row['inOctets'] = $row['outOctets'] = "NULL";
+            }
+            
+            if(isset($status[$ponPort])) {
+                $row['online'] = $status[$ponPort][1];
+                $row['offline'] = $status[$ponPort][0];
+            } else {
+                $row['online'] = $row['offline'] = "NULL";
+            }
+
+            $row['index'] = $index;
+            
             $data[] = "(".implode(",",$row).")".PHP_EOL;
         }
 
@@ -92,14 +112,44 @@ class StatsPonPortCommand extends BaseCommand
         $conn->close();
 
         $conn = $doctrine->getConnection();
-        $sql = "INSERT LOW_PRIORITY IGNORE INTO `pon_port` (`id`,`device_server_id`,`pon_port`,`olt_device_id`,`tenancy_id`,`updated`,`tx_power`,`rx_power`,`voltage`,`temperature`,`bias_current`) VALUES ".  implode(",", $data).";";
+        $sql = "INSERT LOW_PRIORITY IGNORE INTO `pon_port` (`id`,`device_server_id`,`pon_port`,`olt_device_id`,`tenancy_id`,`updated`,`tx_power`,`rx_power`,`voltage`,`temperature`,`bias_current`,`in_octets`,`out_octets`,`online`,`offline`,`index`) VALUES ".  implode(",", $data).";";
         
-        //print_r($sql);
         $conn->query($sql);
         $conn->close();
         
 
     }
 
+    private function getCountOnus($server, $olt) {
+        $key_onu_stats = "onu_status_d_{$olt}_s_{$server}";
+        $key_olt_scan = "olt_scan_d_{$olt}_s_{$server}";
+
+        $status = $this->getData($key_onu_stats, true);
+        $onus = $this->getData($key_olt_scan, true);
+
+        $return = array();
+        foreach($onus as $index => $info) {
+            $pp = explode("/",$info['ponport']);
+            if(count($pp) == 3) {
+                $port = "{$pp[0]}/{$pp[1]}";
+            } elseif(count($pp) == 4) {
+                $port = "{$pp[0]}/{$pp[1]}/{$pp[2]}";
+            } else {
+                continue;
+            }
+            
+            if(!isset($return[$port])) $return[$port] = array(0,0);
+            $sn = $info['serialNumber'];
+            if(isset($status[$sn])) {
+                $state = $status[$sn];
+                $return[$port][$state]++;
+            }
+
+
+        }
+
+        return $return;
+    }
+
 
 }

+ 147 - 0
src/StatsBundle/Entity/PonPort.php

@@ -76,6 +76,33 @@ class PonPort implements TenancyIdTraitInterface
      */
     public $biasCurrent;
 
+    /**
+     * @ORM\Column(type="decimal", precision=16, scale=3, nullable=true)
+     */
+    public $inOctets;
+
+    /**
+     * @ORM\Column(type="decimal", precision=16, scale=3, nullable=true)
+     */
+    public $outOctets;
+    
+    /**
+     * @ORM\Column(type="integer", nullable=true)
+     */
+    public $online;
+    
+    /**
+     * @ORM\Column(type="integer", nullable=true)
+     */
+    public $offline;
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(type="integer", nullable=true)
+     */
+    private $index;
+
 
     /**
      * @return int
@@ -313,4 +340,124 @@ class PonPort implements TenancyIdTraitInterface
         return (float)$this->biasCurrent;
     }
 
+    /**
+     * Set inOctets
+     *
+     * @param string $inOctets
+     *
+     * @return PonPort
+     */
+    public function setInOctets($inOctets)
+    {
+        $this->inOctets = $inOctets;
+
+        return $this;
+    }
+
+    /**
+     * Get inOctets
+     *
+     * @return string
+     */
+    public function getInOctets()
+    {
+        return (float) $this->inOctets;
+    }
+
+    /**
+     * Set outOctets
+     *
+     * @param string $outOctets
+     *
+     * @return PonPort
+     */
+    public function setOutOctets($outOctets)
+    {
+        $this->outOctets = $outOctets;
+
+        return $this;
+    }
+
+    /**
+     * Get outOctets
+     *
+     * @return string
+     */
+    public function getOutOctets()
+    {
+        return (float) $this->outOctets;
+    }
+
+    /**
+     * Set online
+     *
+     * @param integer $online
+     *
+     * @return PonPort
+     */
+    public function setOnline($online)
+    {
+        $this->online = $online;
+
+        return $this;
+    }
+
+    /**
+     * Get online
+     *
+     * @return integer
+     */
+    public function getOnline()
+    {
+        return $this->online;
+    }
+
+    /**
+     * Set offline
+     *
+     * @param integer $offline
+     *
+     * @return PonPort
+     */
+    public function setOffline($offline)
+    {
+        $this->offline = $offline;
+
+        return $this;
+    }
+
+    /**
+     * Get offline
+     *
+     * @return integer
+     */
+    public function getOffline()
+    {
+        return $this->offline;
+    }
+
+    /**
+     * Set index
+     *
+     * @param integer $index
+     *
+     * @return PonPort
+     */
+    public function setIndex($index)
+    {
+        $this->index = $index;
+
+        return $this;
+    }
+
+    /**
+     * Get index
+     *
+     * @return integer
+     */
+    public function getIndex()
+    {
+        return $this->index;
+    }
+
 }

+ 3 - 0
src/StatsBundle/Resources/views/PonPort/base_list.html.twig

@@ -3,6 +3,9 @@
 {% block list_table %}
     <style>
     table.sonata-ba-list {table-layout: fixed}
+    .sonata-ba-list-field-header-ponport-rx-power {
+        width: 35%;
+    }
     </style>
     {{ parent() }}
 {% endblock %}

+ 9 - 0
src/StatsBundle/Resources/views/PonPort/interface_field_count_onu.html.twig

@@ -0,0 +1,9 @@
+{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
+
+{% block field %}
+    {% if value is null %}
+        <span class="text_column_stats">{{ 'macroFields.notavailable'|trans({},'StatsBundle') }}</span>
+    {% else %}
+        <span class="">{{ value|number_format(0, '.', ',')}}</span> <span class="text_column_stats">ONU</span>
+    {% endif %}
+{% endblock %}

+ 10 - 0
src/StatsBundle/Resources/views/PonPort/interface_field_octets.html.twig

@@ -0,0 +1,10 @@
+{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
+
+{% block field %}
+    {% if value is null or value == 0 %}
+        <span class="text_column_stats">{{ 'macroFields.notavailable'|trans({},'StatsBundle') }}</span>
+    {% else %}
+                                        {#   b/s   >  Kb/s > Mb/s #}
+        <span class="">{{ ((value / 1024) / 1024)|number_format(2, '.', ',')}}</span> <span class="text_column_stats">Mb/s</span>
+    {% endif %}
+{% endblock %}