Ver código fonte

Se agrega mta enabled en host. Se renombran suboptions en la config de kea

Guillermo Espinoza 6 anos atrás
pai
commit
505c0e0fd6

+ 42 - 17
src/HostBundle/Entity/Host.php

@@ -83,12 +83,12 @@ class Host implements WorkflowInterface
      * @JMS\Exclude
      */
     protected $currentState = null;
-        
+
     /**
      * @ORM\Column(type="boolean", nullable=true)
      */
     protected $fixedIP = false;
-    
+
     /**
      * @ORM\ManyToOne(targetEntity="Host", inversedBy="associatedHosts", fetch="EXTRA_LAZY")
      * @ORM\JoinColumn(name="host_id", referencedColumnName="id", onDelete="SET NULL")
@@ -96,7 +96,7 @@ class Host implements WorkflowInterface
      * @JMS\MaxDepth(1)
      */
     protected $host;
-    
+
     /**
      * @ORM\OneToMany(targetEntity="Host", mappedBy="host", fetch="EXTRA_LAZY")
      *
@@ -118,8 +118,13 @@ class Host implements WorkflowInterface
      */
     protected $updated;
 
+    /**
+     * @ORM\Column(type="boolean", nullable=true)
+     */
+    protected $mtaEnabled = false;
+
 
-    public function __construct() 
+    public function __construct()
     {
         $this->associatedHosts = new \Doctrine\Common\Collections\ArrayCollection();
     }
@@ -219,7 +224,7 @@ class Host implements WorkflowInterface
 
         return $this;
     }
-        
+
     /**
      * @return boolean
      */
@@ -227,7 +232,7 @@ class Host implements WorkflowInterface
     {
         return $this->fixedIP;
     }
-    
+
     /**
      * @param boolean $fixedIP
      *
@@ -236,10 +241,10 @@ class Host implements WorkflowInterface
     public function setFixedIP($fixedIP = null)
     {
         $this->fixedIP = $fixedIP;
-        
+
         return $this;
     }
-        
+
     /**
      * @return boolean
      */
@@ -247,7 +252,7 @@ class Host implements WorkflowInterface
     {
         return $this->host;
     }
-    
+
     /**
      * @param Host $host
      *
@@ -256,10 +261,10 @@ class Host implements WorkflowInterface
     public function setHost($host = null)
     {
         $this->host = $host;
-        
+
         return $this;
     }
-    
+
     /**
      * @return array<Host>
      */
@@ -267,7 +272,7 @@ class Host implements WorkflowInterface
     {
         return $this->associatedHosts;
     }
-    
+
     /**
      * @return integer
      */
@@ -291,7 +296,7 @@ class Host implements WorkflowInterface
     function setFixedIntegerAddress()
     {
         $options = $this->getDHCPOption();
-        
+
         if(isset($options['fixed_address']) && !empty($options['fixed_address'])) {
             // IPV4
             $this->setIpv4Address(ip2long($options['fixed_address']));
@@ -307,7 +312,7 @@ class Host implements WorkflowInterface
     {
         return $this->updated;
     }
-    
+
     /**
      * @param integer $updated
      *
@@ -319,14 +324,34 @@ class Host implements WorkflowInterface
 
         return $this;
     }
-        
+
+    /**
+     * @return boolean
+     */
+    public function getMtaEnabled()
+    {
+        return $this->mtaEnabled;
+    }
+
+    /**
+     * @param boolean $mtaEnabled
+     *
+     * @return Cablemodem
+     */
+    public function setMtaEnabled($mtaEnabled)
+    {
+        $this->mtaEnabled = $mtaEnabled;
+
+        return $this;
+    }
+
     /**
      * @param ExecutionContextInterface $context
      */
     public function validateFixedAddress(ExecutionContextInterface $context)
     {
         global $kernel;
-        
+
         if (!$kernel->getContainer()) {
             // fix para los tests
             return;
@@ -344,7 +369,7 @@ class Host implements WorkflowInterface
             }
         }
     }
-    
+
     /**
      * Si el host type es distinto de cablemodem tiene que tener host asociado
      * @param ExecutionContextInterface $context

+ 1 - 0
src/HostBundle/Form/HostType.php

@@ -27,6 +27,7 @@ class HostType extends AbstractType
             ->add('fixedIP', TextType::class, [
                 'required' => false,
             ])
+            ->add('mtaEnabled')
             ;
         foreach (DHCPOptions::getConstants() as $opt) {
             $builder->add($opt, TextType::class, array(

+ 57 - 57
src/KeaBundle/Services/BaseKea.php

@@ -33,7 +33,7 @@ class BaseKea implements KeaConfigInterface
      */
     private $option_def = [
         [
-            "name" => "subopt1",
+            "name" => "subopt3",
             "code" => 3,
             "space" => "pcc",
             "type" => "binary",
@@ -42,7 +42,7 @@ class BaseKea implements KeaConfigInterface
             "encapsulate"  => "",
         ],
         [
-            "name" => "subopt2",
+            "name" => "subopt6",
             "code" => 6,
             "space" => "pcc",
             "type" => "binary",
@@ -51,7 +51,7 @@ class BaseKea implements KeaConfigInterface
             "encapsulate" => "",
         ],
         [
-            "name" =>"clabs",
+            "name" =>"option122",
             "code" => 122,
             "space" => "dhcp4",
             "type" => "empty",
@@ -174,15 +174,15 @@ class BaseKea implements KeaConfigInterface
     private function hooksLibrariesConfig($data)
     {
         $this->hooks_libraries = [
-            [
-                'library' => '/opt/hooks/mysql/kea-hook-flowdat3-mysql.so',
-                'parameters' => [
-                    "host" => $data['db']['host'],
-                    "database" => $data['db']['database'],
-                    "user" => $data['db']['user'],
-                    "password" => $data['db']['password'],
-                ]
-            ],
+            // [
+            //     'library' => '/opt/hooks/mysql/kea-hook-flowdat3-mysql.so',
+            //     'parameters' => [
+            //         "host" => $data['db']['host'],
+            //         "database" => $data['db']['database'],
+            //         "user" => $data['db']['user'],
+            //         "password" => $data['db']['password'],
+            //     ]
+            // ],
             [
                 "library" => "/opt/hooks/amqp/kea-hook-flowdat3.so",
                 "parameters" => [
@@ -193,48 +193,48 @@ class BaseKea implements KeaConfigInterface
             ],
         ];
 
-        // $dhcp = $data['dhcp'];
-        // $hosts = $data['hosts'];
-        //
-        // $hook = [
-        //     'library' => $data['library'],
-        // ];
-        //
-        // $dhcpModelParams = $dhcp && $dhcp->getDhcpModel() ? $dhcp->getDhcpModel()->getData('parameters') : null;
-        //
-        // $option122 = isset($dhcpModelParams['option122']) ? $dhcpModelParams['option122'] : null;
-        // $ip = isset($dhcpModelParams['ip']) ? $dhcpModelParams['ip'] : null;
-        // if ($option122 && $ip) {
-        //     $macs = [];
-        //     foreach ($hosts as $host) {
-        //         if ($host->getMac()) {
-        //             $macs[] = $host->getMac();
-        //         }
-        //     }
-        //
-        //     $hook['parameters']['option122'] = [
-        //         $ip => $macs
-        //     ];
-        // }
-        //
-        // $remote_id_map = isset($dhcpModelParams['remote-id-map']) ? $dhcpModelParams['remote-id-map'] : null;
-        // if ($remote_id_map) {
-        //     $hostConfig = [];
-        //     foreach ($hosts as $host) {
-        //         if ($host->getMac()) {
-        //             $mac = $host->getMac();
-        //             $state = $host->getState();
-        //             $shortname = $host->getHostType()->getShortname();
-        //
-        //             $client_class = $state != HostStatus::STATE_NONE ? $state : $shortname;
-        //
-        //             $hostConfig[$client_class][] = $mac;
-        //         }
-        //     }
-        //     $hook['parameters']['remote-id-map'] = $hostConfig;
-        // }
-        //
-        // $this->hooks_libraries[] = $hook;
+        $dhcp = $data['dhcp'];
+        $hosts = $data['hosts'];
+
+        $hook = [
+            'library' => $data['library'],
+        ];
+
+        $dhcpModelParams = $dhcp && $dhcp->getDhcpModel() ? $dhcp->getDhcpModel()->getData('parameters') : null;
+
+        $option122 = isset($dhcpModelParams['option122']) ? $dhcpModelParams['option122'] : null;
+        $ip = isset($dhcpModelParams['ip']) ? $dhcpModelParams['ip'] : null;
+        if ($option122 && $ip) {
+            $macs = [];
+            foreach ($hosts as $host) {
+                if ($host->getMac() != '' && $host->getMtaEnabled() == true) {
+                    $macs[] = $host->getMac();
+                }
+            }
+
+            $hook['parameters']['option122'] = [
+                $ip => $macs
+            ];
+        }
+
+        $remote_id_map = isset($dhcpModelParams['remote-id-map']) ? $dhcpModelParams['remote-id-map'] : null;
+        if ($remote_id_map) {
+            $hostConfig = [];
+            foreach ($hosts as $host) {
+                if ($host->getMac()) {
+                    $mac = $host->getMac();
+                    $state = $host->getState();
+                    $shortname = $host->getHostType()->getShortname();
+
+                    $client_class = $state != HostStatus::STATE_NONE ? $state : $shortname;
+
+                    $hostConfig[$client_class][] = $mac;
+                }
+            }
+            $hook['parameters']['remote-id-map'] = $hostConfig;
+        }
+
+        $this->hooks_libraries[] = $hook;
     }
 
     /**
@@ -366,21 +366,21 @@ class BaseKea implements KeaConfigInterface
 
             $option_122_data = [
                 [
-                    "name" => "subopt1",
+                    "name" => "subopt3",
                     "space" => "pcc",
                     "code" => 3,
                     "csv-format" => false,
                     "data" => $provisioningServerBinary,
                 ],
                 [
-                    "name" => "subopt2",
+                    "name" => "subopt6",
                     "space" => "pcc",
                     "code" => 6,
                     "csv-format" => false,
                     "data" => $provisioningTypeBinary,
                 ],
                 [
-                    "name" => "clabs",
+                    "name" => "option122",
                     "space" => "dhcp4",
                     "code" => 122,
                     "csv-format" => false,