Exemplo n.º 1
0
 /**
  * @param $providerURL Endereço do Discovery remoto
  * @param $requesterNSA NSA ID do requisitante
  * @param $requesterURL Endereço do Discovery local para receber notificações
  */
 static function subscribe($providerURL, $requesterNSA, $requesterURL)
 {
     $ch = curl_init();
     $message = '<?xml version="1.0" encoding="UTF-8"?><tns:subscriptionRequest ' . 'xmlns:tns="http://schemas.ogf.org/nsi/2014/02/discovery/types">' . '<requesterId>urn:ogf:network:' . Preference::findOneValue(Preference::MEICAN_NSA) . '</requesterId>' . '<callback>' . Url::toRoute("/topology/discovery/notification", "http") . '</callback>' . '<filter>' . '<include>' . '<event>All</event>' . '</include>' . '</filter>' . '</tns:subscriptionRequest>';
     $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $message, CURLOPT_HTTPHEADER => array('Accept-encoding: application/xml;charset=utf-8', 'Content-Type: application/xml;charset=utf-8'), CURLOPT_USERAGENT => 'Meican', CURLOPT_URL => $providerURL . '/subscriptions');
     curl_setopt_array($ch, $options);
     Yii::trace($message);
     $output = curl_exec($ch);
     Yii::trace($output);
     curl_close($ch);
     $parser = new NSIParser();
     $parser->loadXml($output);
     $parser->parseSubscriptions();
     foreach ($parser->getData()['subs'] as $subId => $sub) {
         return (string) $subId;
     }
 }
Exemplo n.º 2
0
 private function getSynchronizer($notificationXml)
 {
     $parser = new NSIParser();
     $parser->loadXml($notificationXml);
     if ($parser->isTD()) {
         $parser->parseNotifications();
         Yii::trace($parser->getData());
         foreach ($parser->getData()['nots'] as $subId => $notsData) {
             $sync = TopologySynchronizer::find()->where(['provider_nsa' => $notsData['providerId']])->andWhere(['subscription_id' => $subId])->one();
             if ($sync) {
                 Yii::trace("achou sync ativo, sincronizando...");
                 $parser->parseTopology();
                 $sync->parser = $parser;
                 return $sync;
             }
             break;
             //VERIFICAR CASO EM QUE DUAS NOTIFICATIONS SAO RECEBIDAS NUMA MESMA MSG
         }
     }
     return null;
 }
Exemplo n.º 3
0
 public function validateUrl($att, $params)
 {
     switch ($this->type) {
         case DiscoveryRule::DESC_TYPE_NSI:
             $parser = new NSIParser();
             if (!$parser->loadFile($this->url)) {
                 $this->addError('url', 'Check your URL and try again.');
                 return false;
             }
             switch ($this->protocol) {
                 case DiscoveryRule::PROTOCOL_HTTP:
                     if (!$parser->isTD()) {
                         $this->addError('url', 'The inserted URL does not contains a valid NSI Topology.');
                         return false;
                     }
                     return true;
                     break;
                 case DiscoveryRule::PROTOCOL_NSI_DS:
                     if (!$parser->isDS()) {
                         $this->addError('url', 'The inserted URL does not contains a valid service.');
                         return false;
                     }
                     $parser->parseLocalProvider();
                     $this->provider_nsa = $parser->getData()['local']['nsa'];
                     return true;
             }
             break;
         case DiscoveryRule::DESC_TYPE_NMWG:
             $parser = new NMWGParser();
             if (!$parser->loadFile($this->url)) {
                 $this->addError('url', 'Check your URL and try again.');
                 return false;
             }
             if (!$parser->isTD()) {
                 $this->addError('url', 'The inserted URL does not contains a valid NMWG Topology.');
                 return false;
             }
             return true;
     }
 }