Luciano Andrade %!s(int64=7) %!d(string=hai) anos
pai
achega
7497b38c15

+ 29 - 1
app/DoctrineMigrations/Version20180221174411.php

@@ -19,10 +19,38 @@ class Version20180221174411 extends AbstractMigration
         $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
 
 	if (!$schema->hasTable('service_port') == true) {
-		$this->addSql('CREATE TABLE service_port (id INT AUTO_INCREMENT NOT NULL, olt_id BIGINT DEFAULT NULL, onu_id INT DEFAULT NULL, number INT DEFAULT 0 NOT NULL, type VARCHAR(255) NOT NULL, INDEX IDX_8DD2E92069FFAD89 (olt_id), INDEX IDX_8DD2E920AB83998C (onu_id), UNIQUE INDEX sp_unique (olt_id, number), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+		$this->addSql('CREATE TABLE service_port (id INT AUTO_INCREMENT NOT NULL, olt_id BIGINT DEFAULT NULL, onu_id INT DEFAULT NULL, number INT DEFAULT 0 NOT NULL, gemport INT DEFAULT 0 NOT NULL, vlan INT DEFAULT 0 NOT NULL, type VARCHAR(255) NOT NULL, INDEX IDX_8DD2E92069FFAD89 (olt_id), INDEX IDX_8DD2E920AB83998C (onu_id), UNIQUE INDEX sp_unique (olt_id, number), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
 		$this->addSql('ALTER TABLE service_port ADD CONSTRAINT FK_8DD2E92069FFAD89 FOREIGN KEY (olt_id) REFERENCES olt (id)');
 		$this->addSql('ALTER TABLE service_port ADD CONSTRAINT FK_8DD2E920AB83998C FOREIGN KEY (onu_id) REFERENCES onu (id)');
+		$this->addSql('ALTER TABLE olt CHANGE execute_snmp execute_snmp BOOLEAN DEFAULT TRUE');
+		$this->addSql('ALTER TABLE olt_audit CHANGE execute_snmp execute_snmp BOOLEAN DEFAULT TRUE');
+	}
+
+	$result = $this->connection->query("select o.id id, o.olt_id, nap_id, pon_serial_number, position, slot, link FROM onu o JOIN nap n ON (n.id = o.nap_id) WHERE  o.deleted_at IS NULL;");
+
+	$i = 0;
+	$vlangemport_config = array('voip' => array('gemport' => 0, 'vlan' => 13), 'data' => array('gemport' => 1, 'vlan' => 10));
+	while($rtr = $result->fetch()){
+		$i++;
+		$pon_serial_number = $rtr['pon_serial_number'];
+		$slot = $rtr['slot'];
+		$link = $rtr['link'];
+		$position = $rtr['position'];
+		$olt_id = $rtr['olt_id'];
+		$onu_id = $rtr['id'];
+		$service_port = array(
+			//{% set service_port_data =  "1" ~  slot  ~  link  ~  ("%02d" | format(onu)) %}
+			"data" => "1" .  $slot  . $link  . sprintf ("%02d",  $position),
 
+			//{% set service_port_voip =  "2" ~  slot  ~  link  ~  ("%02d" | format(onu)) %}
+			"voip" => "2" .  $slot  . $link  . sprintf ("%02d",  $position),
+		);
+		foreach($service_port as $type => $number){
+			$gemport = $vlangemport_config[$type]['gemport'];
+			$vlan = $vlangemport_config[$type]['vlan'];
+			$sql = "INSERT INTO service_port (olt_id, onu_id, number, type, gemport, vlan) VALUES ($olt_id, $onu_id, $number, '$type', $gemport, $vlan);";
+			$this->addSql($sql);
+		}
 	}
     }
 

+ 4 - 1
src/FTTHBundle/Admin/ONUAdmin.php

@@ -90,7 +90,9 @@ class ONUAdmin extends WorkflowBaseAdmin
             ->end()
             ->end()
             ->setHelps(array(
-                'nap' => $this->trans("helps.check_address")));
+                'nap' => $this->trans("helps.check_address"),
+                'service_port' => $this->trans("helps.service_port"),
+		));
 
 
         /*
@@ -190,6 +192,7 @@ class ONUAdmin extends WorkflowBaseAdmin
 
 	foreach($object->getServicePort() as $sp){
 		$sp->setOnu($object);
+		$em->persist($sp);
 		if(!$sp->getOlt()){
 			$sp->setOlt($object->getOlt());
 		}

+ 1 - 1
src/FTTHBundle/Entity/ONU.php

@@ -631,7 +631,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
      * @param \Doctrine\Common\Collections\Collection
      * @return ONU
      */
-    public function setServicePort(\Common\Collections\Collection $servicePort)
+    public function setServicePort(\Doctrine\Common\Collections\Collection $servicePort)
     {
         $this->service_port = $service_port;
 	return $this;

+ 70 - 0
src/FTTHBundle/Entity/ServicePort.php

@@ -40,6 +40,28 @@ class ServicePort{
      */
     protected $number = 0;
 
+    /**
+     * @var int
+     *
+     * @ORM\Column(type="integer", options={"default": "0"})
+     *
+     * @Assert\NotNull
+     */
+    protected $gemport= 0;
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(type="integer", options={"default": "0"})
+     *
+     * @Assert\NotNull
+     */
+    protected $vlan = 0;
+
+
+
+
+
     /** @ORM\Column(type="string") */
     private $type;
 
@@ -158,4 +180,52 @@ class ServicePort{
     public function __toString(){
 	return (string)$this->number;
     }
+
+    /**
+     * Set gemport
+     *
+     * @param integer $gemport
+     *
+     * @return ServicePort
+     */
+    public function setGemport($gemport)
+    {
+        $this->gemport = $gemport;
+
+        return $this;
+    }
+
+    /**
+     * Get gemport
+     *
+     * @return integer
+     */
+    public function getGemport()
+    {
+        return $this->gemport;
+    }
+
+    /**
+     * Set vlan
+     *
+     * @param integer $vlan
+     *
+     * @return ServicePort
+     */
+    public function setVlan($vlan)
+    {
+        $this->vlan = $vlan;
+
+        return $this;
+    }
+
+    /**
+     * Get vlan
+     *
+     * @return integer
+     */
+    public function getVlan()
+    {
+        return $this->vlan;
+    }
 }

+ 72 - 53
src/FTTHBundle/EventListener/ONUSubscriber.php

@@ -47,6 +47,7 @@ class ONUSubscriber implements EventSubscriber
     {
         return array(
             DoctrineEvents::PRE_PERSIST,
+            DoctrineEvents::POST_PERSIST,
             DoctrineEvents::PRE_UPDATE,
         );
     }
@@ -59,6 +60,21 @@ class ONUSubscriber implements EventSubscriber
         $this->execute($args, DoctrineEvents::PRE_PERSIST);
     }
 
+    /**
+     * @param LifecycleEventArgs $args
+     */
+    public function postPersist(LifecycleEventArgs $args)
+    {
+	$entity = $args->getEntity();
+        if ($entity instanceof ONU) {
+
+                $this->em = $args->getEntityManager();
+ 		$this->setSerivcePorts($entity);
+	}
+    }
+
+
+
     /**
      * @param LifecycleEventArgs $args
      */
@@ -96,8 +112,6 @@ class ONUSubscriber implements EventSubscriber
                 }
             }
 
-	    $this->setSerivcePorts($entity);
-
             if ($eventName == DoctrineEvents::PRE_UPDATE) {
                 $uow = $this->em->getUnitOfWork();
                 $meta = $this->em->getClassMetadata(get_class($entity));
@@ -147,56 +161,61 @@ class ONUSubscriber implements EventSubscriber
      */ 
     public function setSerivcePorts(ONU $onu)
     {
-	if($onu->getNAP() and $onu->getOLT()){
-		$sp = $onu->getServicePort();
-		if(count($sp) == 0){
-			$olt = $onu->getNAP()->getOLT();
-			$used_sp = $this->em->getRepository(ServicePort::class)->findBy(
-				array("olt" => $olt)
-			);
-			$services = array();
-			foreach($used_sp as $used_service_port){
-				$services[$used_service_port->getNumber()] = $used_service_port;
-			}
-
-			$foundit = array();
-			$found_at_least = 2;
-			$service_type = array( "data", "voip", /*'iptv'*/);
-
-			$max_n = @max(array_keys($services)); //Warning: max(): Array must contain at least one element
-
-			for($i = 1; $i <= $max_n; $i++){
-				if(!isset($services[$i])){
-					$foundit[] = $i;
-				}
-				if($found_at_least == count($foundit)){
-					break;
-				}
-			}
-
-			for($i = count($foundit) ; $i < $found_at_least; $i++){
-				$foundit[] = 1 + $max_n + $i;	
-			}
-
-			foreach($foundit as $key => $num){
-				$sp = new ServicePort();
-				$sp->setOlt($olt);
-				$ok = list($skey, $ser) = each($service_type);
-				if($ok === false){
-					reset($service_type);
-					$ok = list($skey, $ser) = current($service_type);
-				}
-				$sp->setNumber($num);
-				$sp->setType($ser);
-				$onu->addServicePort($sp);
-				$this->em->persist($sp);
-				
-			}
-		}
-		
-	}
-    }
-
-
+	if($onu->getNAP() and $onu->getNAP()->getOLT()){
+	    $sp = $onu->getServicePort();
+	    if(count($sp) == 0){
+	    	$olt = $onu->getNAP()->getOLT();
+	    	$used_sp = $this->em->getRepository(ServicePort::class)->findBy(
+	    		array("olt" => $olt)
+	    	);
+	    	$services = array();
+	    	foreach($used_sp as $used_service_port){
+	    		$services[$used_service_port->getNumber()] = $used_service_port;
+	    	}
+
+	    	$foundit = array();
+	    	$found_at_least = 2;
+	    	$service_type = array( "data", "voip", /*'iptv'*/);
+	    	$vlangemport_config = array(
+	    			'voip' => array('gemport' => 0, 'vlan' => 13), 
+	    			'data' => array('gemport' => 1, 'vlan' => 10)
+	    		);
+
+	    	$max_n = @max(array_keys($services)); //Warning: max(): Array must contain at least one element
+
+	    	for($i = 1; $i <= $max_n; $i++){
+	    		if(!isset($services[$i])){
+	    			$foundit[] = $i;
+	    		}
+	    		if($found_at_least == count($foundit)){
+	    			break;
+	    		}
+	    	}
+
+	    	for($i = count($foundit) ; $i < $found_at_least; $i++){
+	    		$foundit[] = 1 + $max_n + $i;	
+	    	}
+
+	    	foreach($foundit as $key => $num){
+	    		$sp = new ServicePort();
+	    		$sp->setOlt($olt);
+	    		$sp->setOnu($onu);
+	    		$ok = list($skey, $ser) = each($service_type);
+	    		if($ok === false){
+	    			reset($service_type);
+	    			$ok = list($skey, $ser) = current($service_type);
+	    		}
+	    		$sp->setNumber($num);
+	    		$sp->setGemport($vlangemport_config[$ser]['gemport']);
+	    		$sp->setVlan($vlangemport_config[$ser]['vlan']);
+	    		$sp->setType($ser);
+	    		$onu->addServicePort($sp);
+	    		$this->em->persist($sp);
+	    		
+	    	}
+		$this->em->flush();
+	    }
 
+        }
+    }
 }

+ 16 - 3
src/FTTHBundle/Form/ServicePortType.php

@@ -16,14 +16,27 @@ class ServicePortType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder
-            ->add('number')
             ->add('type', ChoiceType::class, array(
 		    'choices'  => array(
 			'Data' => 'data',
 			'VoIP' => 'voip',
 			'IPTV' => 'iptv',
-		    ))
-	)
+		    ),
+		    'label' => 'form.service_port.type',
+			))
+            ->add('number', null, array(
+			'attr' => array('maxlength' => 6),
+			'label'=> 'form.service_port.number'
+		))
+	    ->add('gemport', null, array(
+			'attr' => array('maxlength' => 6),
+			'label'=> 'form.service_port.gemport'
+		))
+	    ->add('vlan', null, array(
+			'attr' => array('maxlength' => 6),
+			'label'=> 'form.service_port.vlan'
+		))
+
 
         ;
     }

+ 3 - 0
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -108,6 +108,8 @@ form:
     label_link: Link
     label_enable: Enable
     label_address: Dirección
+    label_service_port: Service Port
+    label_position: Posición dentro del puerto
 
 list:
     label_id: Id
@@ -189,6 +191,7 @@ show:
     
 helps:
     check_address: Verifique la dirección para el cálculo de distancias.
+    service_port: Los services ports son creados automaticamente, en caso de modificarlos <b>no</b> se actualizaran en la OLT, sino que seran utilizados en el siguiente comando.
 error:
     address_not_found: La dirección "%client_address%" no fue encontrada en los servicios de google.
 Distance: Distancia