Ejemplo n.º 1
0
 public function actionDelete()
 {
     if (isset($_POST['delete'])) {
         foreach ($_POST['delete'] as $id) {
             $service = Service::findOne($id);
             if ($service->delete()) {
                 Yii::$app->getSession()->addFlash('success', Yii::t("topology", "Service {type} deleted successfully", ['type' => $service->getType()]));
             } else {
                 Yii::$app->getSession()->setFlash('error', 'Error deleting service ' . $service->getType());
             }
         }
     }
     return $this->redirect(array('/topology/provider/view', 'id' => $service->provider_id));
 }
Ejemplo n.º 2
0
 public function actionAddService($id)
 {
     $service = Service::findOne($id);
     if ($service) {
         $sync = new TopologySynchronizer();
         $sync->url = $service->url;
         $sync->type = $service->type;
         $sync->name = $service->getType();
         $sync->auto_apply = 0;
         if ($sync->save()) {
             Yii::$app->getSession()->addFlash("success", Yii::t("topology", "Service {name} added successfully", ['name' => $sync->name]));
         } else {
             Yii::$app->getSession()->addFlash("error", Yii::t("topology", "Service {name} was not added", ['name' => $sync->name]));
         }
     }
     return $this->redirect(array('index'));
 }
Ejemplo n.º 3
0
 private function search()
 {
     foreach ($this->parser->getData()['domains'] as $domainName => $domainData) {
         $domain = Domain::findByName($domainName)->one();
         if ($domain == null) {
             $change = $this->buildChange();
             $change->domain = $domainName;
             $change->item_type = Change::ITEM_TYPE_DOMAIN;
             $change->data = json_encode(['' => '']);
             $change->type = Change::TYPE_CREATE;
             $change->save();
             $invalidDevices = false;
         } else {
             //VERIFICA DEVICES
             if ($this->parser instanceof NSIParser) {
                 $invalidDevices = Device::find()->where(['domain_id' => $domain->id]);
             } else {
                 $invalidDevices = false;
             }
             ///////////
         }
         if ($this->parser instanceof NSIParser && isset($domainData['nsa'])) {
             foreach ($domainData['nsa'] as $nsaId => $nsaData) {
                 $provider = Provider::find()->where(['nsa' => $nsaId])->one();
                 if (!$provider) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_CREATE;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_PROVIDER;
                     $change->data = json_encode(['name' => $nsaData['name'], 'type' => $nsaData['type'], 'lat' => $nsaData["lat"], 'lng' => $nsaData["lng"], 'nsa' => $nsaId]);
                     $change->save();
                 } elseif ($nsaData['lat'] && $nsaData['lng'] && intval($provider->latitude) != intval($nsaData['lat']) || intval($provider->longitude) != intval($nsaData['lng'])) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_UPDATE;
                     $change->item_id = $provider->id;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_PROVIDER;
                     $change->data = json_encode(['name' => $nsaData['name'], 'type' => $nsaData['type'], 'lat' => $nsaData["lat"], 'lng' => $nsaData["lng"], 'nsa' => $nsaId]);
                     $change->save();
                 }
                 if ($provider) {
                     $oldPeerings = $provider->getPeerings();
                     $oldServices = $provider->getServices();
                 }
                 $newPeerings = [];
                 $newServices = [];
                 if (isset($nsaData['peerings'])) {
                     foreach ($nsaData['peerings'] as $dstNsaId) {
                         if ($provider) {
                             $dstProv = Provider::findOneByNsa($dstNsaId);
                             if ($dstProv) {
                                 $peering = Peering::findOne(['src_id' => $provider->id, 'dst_id' => $dstProv->id]);
                                 if ($peering) {
                                     //$newPeerings[] = $peering->id;
                                     continue;
                                 }
                             }
                         }
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_PEERING;
                         $change->data = json_encode(['srcNsaId' => $nsaId, 'dstNsaId' => $dstNsaId]);
                         $change->save();
                     }
                 }
                 foreach ($nsaData['services'] as $serviceUrl => $serviceType) {
                     $service = Service::findOneByUrl($serviceUrl);
                     if (!$service) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_SERVICE;
                         $change->data = json_encode(['provName' => $nsaData['name'], 'provNsa' => $nsaId, 'type' => $serviceType, 'url' => $serviceUrl]);
                         $change->save();
                     } else {
                         $newServices[] = $service->id;
                     }
                 }
                 if ($provider) {
                     $oldServices = $oldServices->andWhere(['not in', 'id', $newServices])->select(['id'])->asArray()->all();
                     foreach ($oldServices as $invalidService) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_id = $invalidService['id'];
                         $change->item_type = Change::ITEM_TYPE_SERVICE;
                         $change->data = json_encode(['' => '']);
                         $change->save();
                     }
                 }
             }
         }
         //PERFSONAR
         if ($this->parser instanceof NMWGParser) {
             if (isset($domainData['devices'])) {
                 $this->importDevices($domainData["devices"], $domainName, $invalidDevices);
             }
             //NSI
         } else {
             if (isset($domainData['nets'])) {
                 $this->importNetworks($domainData["nets"], $domainName, $invalidDevices);
                 if ($invalidDevices) {
                     $invalidDevices = $invalidDevices->select(['id', 'node'])->asArray()->all();
                     foreach ($invalidDevices as $device) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_DEVICE;
                         $change->item_id = $device['id'];
                         $change->data = json_encode(["node" => $device['node']]);
                         $change->save();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 static function getTypes()
 {
     return [['id' => Service::TYPE_NSI_CSP_2_0, 'name' => Service::getTypeLabels()[Service::TYPE_NSI_CSP_2_0]]];
 }
Ejemplo n.º 5
0
 public function getServices()
 {
     return $this->hasMany(Service::className(), ['provider_id' => 'id']);
 }
Ejemplo n.º 6
0
 public function getDetails()
 {
     $data = json_decode($this->data);
     switch ($this->type) {
         case self::TYPE_DELETE:
             switch ($this->item_type) {
                 case self::ITEM_TYPE_DOMAIN:
                     return Yii::t('topology', 'Domain');
                 case self::ITEM_TYPE_PROVIDER:
                     return Yii::t('topology', '<b>Provider</b>: {name}, <b>Type</b>: {type}', ['name' => $data->name, 'type' => $data->type]);
                 case self::ITEM_TYPE_PEERING:
                     return "";
                 case self::ITEM_TYPE_SERVICE:
                     return Yii::t('topology', 'Domain');
                 case self::ITEM_TYPE_NETWORK:
                     return Yii::t('topology', 'Network');
                 case self::ITEM_TYPE_DEVICE:
                     return $data->node;
                 case self::ITEM_TYPE_BIPORT:
                     $port = Port::findOne($this->item_id);
                     return $port ? $port->name : '';
                 case self::ITEM_TYPE_UNIPORT:
                     return Yii::t('topology', 'Port');
                 case self::ITEM_TYPE_LINK:
                     return '';
                 default:
                     return Yii::t('topology', 'Error');
             }
         case self::TYPE_UPDATE:
             switch ($this->item_type) {
                 case self::ITEM_TYPE_DOMAIN:
                     return Yii::t('topology', 'Domain');
                 case self::ITEM_TYPE_PROVIDER:
                     $prov = Provider::findOne($this->item_id);
                     return Yii::t('topology', 'To: <b>Provider</b>: {name}, <b>Type</b>: {type}, <b>Latitude</b>: {lat}' . ', <b>Longitude</b>: {lng}', ['name' => $data->name, 'type' => $data->type, 'lat' => $data->lat, 'lng' => $data->lng]);
                 case self::ITEM_TYPE_PEERING:
                     return "";
                 case self::ITEM_TYPE_SERVICE:
                     return Yii::t('topology', 'Domain');
                 case self::ITEM_TYPE_NETWORK:
                     return Yii::t('topology', 'Network');
                 case self::ITEM_TYPE_DEVICE:
                     $dev = Device::findOne($this->item_id);
                     return Yii::t('topology', '<b>Device</b>: {node}<br><b>Latitude</b>: {lat}, <b>Longitude</b>: {lng}', ['node' => $data->node, 'lat' => $data->lat, 'lng' => $data->lng]);
                 case self::ITEM_TYPE_BIPORT:
                     return Yii::t('topology', 'Port');
                 case self::ITEM_TYPE_UNIPORT:
                     $port = Port::findOneArraySelect($this->item_id, ['urn']);
                     $vlan = $data->vlan ? Yii::t('topology', ' - <b>VLAN Range</b>: {vlan}', ['vlan' => $data->vlan]) : "";
                     return Yii::t('topology', '<b>Unidirectional Port</b>: {urn}', ['urn' => $port['urn']]) . $vlan;
                 case self::ITEM_TYPE_LINK:
                     return Yii::t('topology', '<b>Link to Port</b>: {dst_urn}', ['dst_urn' => $data->dst_urn]);
                 default:
                     return Yii::t('topology', 'Error');
             }
         case self::TYPE_CREATE:
             switch ($this->item_type) {
                 case self::ITEM_TYPE_DOMAIN:
                     return "";
                 case self::ITEM_TYPE_PROVIDER:
                     return Yii::t('topology', '<b>Provider</b>: {name}<br><b>Type</b>: {type}<br><b>Latitude</b>: {lat}' . ', <b>Longitude</b>: {lng}', ['name' => $data->name, 'type' => Provider::getTypeLabels()[$data->type], 'lat' => $data->lat, 'lng' => $data->lng]);
                 case self::ITEM_TYPE_PEERING:
                     return Yii::t('topology', '<b>Provider</b>: {nsa}<br><b>Peering with</b>: {dstNsaId}', ['nsa' => $data->srcNsaId, 'dstNsaId' => $data->dstNsaId]);
                 case self::ITEM_TYPE_SERVICE:
                     return Yii::t('topology', '<b>Provider</b>: {nsa}<br><b>Service</b>: {type}<br><b>URL</b>: {url}', ['nsa' => $data->provNsa, 'url' => $data->url, 'type' => Service::getTypeLabels()[$data->type]]);
                 case self::ITEM_TYPE_NETWORK:
                     $location = $data->lat ? Yii::t('topology', '<br><b>Latitude</b>: {lat}, <b>Longitude</b>: {lng}', ['lat' => $data->lat, 'lng' => $data->lng]) : "";
                     return Yii::t('topology', '<b>Network</b>: {urn}', ['urn' => $data->urn]) . $location;
                 case self::ITEM_TYPE_DEVICE:
                     $location = $data->lat ? Yii::t('topology', '<br><b>Latitude</b>: {lat}, <b>Longitude</b>: {lng}', ['lat' => $data->lat, 'lng' => $data->lng]) : "";
                     return Yii::t('topology', '<b>Device</b>: {node}', ['node' => $data->node]) . $location;
                 case self::ITEM_TYPE_BIPORT:
                     $vlan = $data->vlan ? Yii::t('topology', '<br><b>VLAN Range</b>: {vlan}', ['vlan' => $data->vlan]) : "";
                     return Yii::t('topology', '<b>Device</b>: {node}<br><b>Port</b>: {urn}', ['urn' => $data->urn, 'node' => $data->node]) . $vlan;
                 case self::ITEM_TYPE_UNIPORT:
                     $vlan = $data->vlan ? Yii::t('topology', '<br><b>VLAN Range</b>: {vlan}', ['vlan' => $data->vlan]) : "";
                     return Yii::t('topology', '<b>Bidirectional Port</b>: {biPortUrn}<br><b>Port</b>: {urn}', ['urn' => $data->urn, 'biPortUrn' => $data->biPortUrn]) . $vlan;
                 case self::ITEM_TYPE_LINK:
                     return Yii::t('topology', '<b>From</b>: {src}<br><b>To</b>: {dst}', ['dst' => $data->dst_urn, 'src' => $data->urn]);
                 default:
                     return Yii::t('topology', 'Error');
             }
     }
 }