Ejemplo n.º 1
0
 public function searchByDomains($params, $domains)
 {
     $validDomains = [];
     $this->load($params);
     if ($this->domain_name) {
         Yii::trace($this->domain_name);
         $domain = Domain::findOne(['name' => $this->domain_name]);
         $devices = Device::find()->where(['domain_id' => $domain->id]);
     } else {
         foreach ($domains as $domain) {
             $validDomains[] = $domain->id;
         }
         $devices = Device::find()->where(['in', 'domain_id', $validDomains]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $devices, 'sort' => false, 'pagination' => ['pageSize' => 15]]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDevice()
 {
     return $this->hasOne(Device::className(), ['id' => 'device_id']);
 }
Ejemplo n.º 3
0
 private function importDevices($devicesArray, $domainName, $invalidDevices, $netUrn = null)
 {
     $validDevices = [];
     //VERIFICA PORTAS
     $validBiPorts = [];
     if ($this->parser instanceof NMWGParser) {
         $type = Port::TYPE_NMWG;
         //$invalidBiPorts = Port::find()->where(['type'=>$type]);
         $invalidBiPorts = false;
     } else {
         $type = Port::TYPE_NSI;
         $net = Network::findByUrn($netUrn)->one();
         if ($net) {
             $invalidBiPorts = Port::find()->where(['type' => $type, 'directionality' => Port::DIR_BI, 'network_id' => $net->id]);
         } else {
             $invalidBiPorts = false;
         }
     }
     foreach ($devicesArray as $deviceNode => $deviceData) {
         $device = Device::findOneByDomainAndNode($domainName, $deviceNode);
         if (!$device) {
             $change = $this->buildChange();
             $change->type = Change::TYPE_CREATE;
             $change->domain = $domainName;
             $change->item_type = Change::ITEM_TYPE_DEVICE;
             $change->data = json_encode(['node' => $deviceNode, 'lat' => isset($deviceData["lat"]) ? $deviceData['lat'] : null, 'lng' => isset($deviceData["lng"]) ? $deviceData['lng'] : null, 'address' => isset($deviceData["address"]) ? $deviceData['address'] : null]);
             $change->save();
         } else {
             $validDevices[] = $device->id;
             if (isset($deviceData['lat']) && isset($deviceData['lng']) && (intval($device->latitude) != intval($deviceData['lat']) || intval($device->longitude) != intval($deviceData['lng']))) {
                 $change = $this->buildChange();
                 $change->type = Change::TYPE_UPDATE;
                 $change->domain = $domainName;
                 $change->item_type = Change::ITEM_TYPE_DEVICE;
                 $change->item_id = $device->id;
                 $change->data = json_encode(['node' => $deviceNode, 'lat' => $deviceData['lat'], 'lng' => $deviceData['lng'], 'address' => $deviceData['address']]);
                 $change->save();
             }
         }
         foreach ($deviceData["biports"] as $urnString => $portData) {
             $port = Port::findByUrn($urnString)->one();
             if (!$port) {
                 $change = $this->buildChange();
                 $change->type = Change::TYPE_CREATE;
                 $change->domain = $domainName;
                 $change->item_type = Change::ITEM_TYPE_BIPORT;
                 $change->data = json_encode(['netUrn' => $netUrn, 'node' => $deviceNode, 'urn' => $urnString, 'type' => $type, 'name' => $portData["port"], 'cap_max' => isset($portData["capMax"]) ? $portData["capMax"] : null, 'cap_min' => isset($portData["capMin"]) ? $portData["capMin"] : null, 'granu' => isset($portData["granu"]) ? $portData["granu"] : null, 'vlan' => isset($portData["vlan"]) ? $portData["vlan"] : null]);
                 $change->save();
             } else {
                 $validBiPorts[] = $port->id;
             }
             if ($this->parser instanceof NMWGParser) {
                 //PERFSONAR
                 $srcPort = Port::findByUrn($urnString)->one();
                 if (isset($portData['aliasUrn'])) {
                     $dstPort = Port::findByUrn($portData['aliasUrn'])->one();
                     if (!$dstPort || !$srcPort || $srcPort->alias_id != $dstPort->id) {
                         $change = $this->buildChange();
                         $change->domain = $domainName;
                         $change->type = $srcPort ? $srcPort->alias_id ? Change::TYPE_UPDATE : Change::TYPE_CREATE : Change::TYPE_CREATE;
                         $change->item_type = Change::ITEM_TYPE_LINK;
                         $change->data = json_encode(['node' => $deviceNode, 'port' => $portData["port"], 'urn' => $urnString, 'dst_urn' => $portData['aliasUrn']]);
                         $change->save();
                     }
                 } elseif ($srcPort && $srcPort->alias_id) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_DELETE;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_LINK;
                     $change->item_id = $srcPort->id;
                     $change->data = json_encode(['' => '']);
                     $change->save();
                 }
             } else {
                 foreach ($portData["uniports"] as $uniPortUrn => $uniPortData) {
                     $uniport = Port::findByUrn($uniPortUrn)->one();
                     if (!$uniport) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_UNIPORT;
                         $change->data = json_encode(['netUrn' => $netUrn, 'node' => $deviceNode, 'type' => Port::TYPE_NSI, 'dir' => $uniPortData['type'], 'urn' => $uniPortUrn, 'biPortUrn' => $urnString, 'biPort' => $portData["port"], 'name' => $uniPortData["port"], 'cap_max' => isset($uniPortData["capMax"]) ? $uniPortData["capMax"] : null, 'cap_min' => isset($uniPortData["capMin"]) ? $uniPortData["capMin"] : null, 'granu' => isset($uniPortData["granu"]) ? $uniPortData["granu"] : null, 'vlan' => isset($uniPortData["vlan"]) ? $uniPortData["vlan"] : null]);
                         $change->save();
                     } else {
                         //update port
                         if (isset($uniPortData["vlan"]) && $uniport->vlan_range != $uniPortData['vlan']) {
                             $change = $this->buildChange();
                             $change->type = Change::TYPE_UPDATE;
                             $change->domain = $domainName;
                             $change->item_type = Change::ITEM_TYPE_UNIPORT;
                             $change->item_id = $uniport->id;
                             $change->data = json_encode(['vlan' => $uniPortData["vlan"]]);
                             $change->save();
                         }
                     }
                     if (isset($uniPortData['aliasUrn'])) {
                         $dstPort = Port::findByUrn($uniPortData['aliasUrn'])->one();
                         if (!$dstPort || !$uniport || $uniport->alias_id != $dstPort->id) {
                             $change = $this->buildChange();
                             $change->type = $uniport ? $uniport->alias_id ? Change::TYPE_UPDATE : Change::TYPE_CREATE : Change::TYPE_CREATE;
                             $change->domain = $domainName;
                             $change->item_type = Change::ITEM_TYPE_LINK;
                             $change->data = json_encode(['node' => $deviceNode, 'port' => $uniPortData["port"], 'urn' => $uniPortUrn, 'dst_urn' => $uniPortData['aliasUrn']]);
                             $change->save();
                         }
                     } elseif ($uniport && $uniport->alias_id) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_LINK;
                         $change->item_id = $uniport->id;
                         $change->data = json_encode(['' => '']);
                         $change->save();
                     }
                 }
             }
         }
     }
     if ($invalidBiPorts) {
         $invalidBiPorts = $invalidBiPorts->andWhere(['not in', 'id', $validBiPorts])->all();
         foreach ($invalidBiPorts as $port) {
             $change = $this->buildChange();
             $change->type = Change::TYPE_DELETE;
             $change->domain = $domainName;
             $change->item_type = Change::ITEM_TYPE_BIPORT;
             $change->item_id = $port->id;
             $change->data = json_encode(["node" => $port]);
             $change->save();
         }
     }
     if ($invalidDevices) {
         $invalidDevices->andWhere(['not in', 'id', $validDevices]);
     }
 }
Ejemplo n.º 4
0
 public function actionGetParentLocation($id)
 {
     $temp = Json::encode(Device::findOneParentLocation($id));
     Yii::trace($temp);
     return $temp;
 }
Ejemplo n.º 5
0
 public function actionGetDevicePorts($dom = null, $type = null)
 {
     if ($dom != null) {
         $validDevs = Device::find()->where(['domain_id' => $dom])->asArray()->select('id')->all();
         $devs = [];
         foreach ($validDevs as $value) {
             $devs[] = $value['id'];
         }
         $portsWithAlias = Port::find()->where(['in', 'device_id', $devs])->andWhere(['type' => $type])->select(['id', 'name', 'directionality', 'max_capacity', 'device_id', 'alias_id'])->all();
     } else {
         $portsWithAlias = Port::find()->select(['id', 'name', 'directionality', 'max_capacity', 'device_id', 'alias_id'])->all();
     }
     $ports = [];
     foreach ($portsWithAlias as $port) {
         $devId1 = $port->device_id;
         $aliasPort = $port->getAlias()->select(['id', 'device_id'])->asArray()->one();
         $devId2 = $aliasPort['device_id'];
         isset($ports[$devId1]) ? null : ($ports[$devId1] = []);
         $devId2 ? isset($ports[$devId2]) ? null : ($ports[$devId2] = []) : null;
         if (!in_array($port->id, $ports[$devId1])) {
             $ports[$devId1][$port->id] = ['dir' => $port->directionality, 'name' => $port->name, 'cap' => $port->max_capacity, 'link' => ['dev' => $devId2, 'port' => $aliasPort['id']]];
         }
     }
     Yii::trace($ports);
     return json_encode($ports);
 }
Ejemplo n.º 6
0
 static function findOneParentLocation($id)
 {
     $dev = Device::find()->where(['id' => $id])->select(['id', 'name', 'latitude', 'longitude', 'domain_id'])->one();
     if (!$dev) {
         return null;
     }
     if ($dev->latitude != null) {
         return $dev;
     }
     foreach ($dev->getPorts()->select(['network_id'])->distinct(true)->all() as $port) {
         $net = $port->getNetwork()->select(['latitude', 'longitude'])->asArray()->one();
         if ($net && $net['latitude']) {
             $dev->latitude = $net['latitude'];
             $dev->longitude = $net['longitude'];
             return $dev;
         }
     }
     $prov = Provider::find()->where(['domain_id' => $dev->domain_id])->select(['latitude', 'longitude'])->asArray()->one();
     if ($prov) {
         $dev->latitude = $prov['latitude'];
         $dev->longitude = $prov['longitude'];
     }
     return $dev;
 }
Ejemplo n.º 7
0
 public function actionGetStp($id)
 {
     $dev = Device::findOneParentLocation($id);
     $dom = $dev->getDomain()->select(['name'])->one()->name;
     $data = [];
     $data['id'] = $id;
     $data["dom"] = $dom;
     $data["name"] = $dev->name;
     $data['lat'] = $dev->latitude;
     $data['lng'] = $dev->longitude;
     $data = json_encode($data);
     Yii::trace($data);
     return $data;
 }
Ejemplo n.º 8
0
 public function actionEditorUpdate($id = null)
 {
     $this->layout = 'wireit';
     if ($id) {
         $workflow = BpmWorkflow::findOne(['id' => $id]);
         if ($workflow) {
             $domain = Domain::findOne(['name' => $workflow->domain]);
             if ($domain) {
                 if (!self::can('workflow/update', $domain->name)) {
                     if (!self::can("workflow/read")) {
                         return $this->goHome();
                     } else {
                         Yii::$app->getSession()->setFlash('warning', Yii::t("bpm", 'You are not allowed to edit in domain {domain}', ['domain' => $domain->name]));
                         return $this->redirect(array('/bpm/workflow/index'));
                     }
                 }
                 $ownerDomain = [];
                 $ownerDomain[$domain->name] = $domain->name;
                 $domains = Domain::find()->orderBy(['name' => SORT_ASC])->all();
                 $allDomains = [];
                 foreach ($domains as $dom) {
                     $allDomains[$dom->name] = $dom->name;
                 }
                 $roles = $domain->getUserDomainsRoles()->all();
                 $adminsNames = [];
                 foreach ($roles as $role) {
                     $adminsNames[$role->getUser()->id] = $role->getUser()->name;
                 }
                 foreach (User::find()->all() as $user) {
                     $usersNames[$user->id] = $user->name;
                 }
                 $groupsNames = [];
                 foreach (Group::find()->where(['type' => Group::TYPE_DOMAIN, 'domain' => $domain->name])->orWhere(['type' => Group::TYPE_DOMAIN, 'domain' => null])->all() as $group) {
                     $groupsNames[$group->id] = $group->name;
                 }
                 $devicesNames = [];
                 foreach (Device::find()->where(['domain_id' => $domain->id])->all() as $device) {
                     $devicesNames[$device->id] = $device->name;
                 }
                 Yii::trace($roles);
                 Yii::trace($usersNames);
                 Yii::trace($groupsNames);
                 Yii::trace($devicesNames);
                 return $this->render('editor', array('owner_domain' => $ownerDomain, 'domains' => $allDomains, 'groups' => $groupsNames, 'users' => $usersNames, 'admins' => $adminsNames, 'devices' => $devicesNames, 'id' => $_GET['id']));
             }
         }
     }
     if (!self::can("workflow/read")) {
         return $this->goHome();
     } else {
         return $this->redirect(array('/bpm/workflow/index'));
     }
 }
Ejemplo n.º 9
0
 public function getBiPorts()
 {
     $portsArray = [];
     $devices = Device::find()->where(['domain_id' => $this->id])->all();
     foreach ($devices as $device) {
         $ports = Port::find()->where(['device_id' => $device->id, 'type' => Port::TYPE_NSI, 'directionality' => Port::DIR_BI])->all();
         foreach ($ports as $port) {
             $portsArray[$port->id] = $port;
         }
     }
     return $portsArray;
 }
Ejemplo n.º 10
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');
             }
     }
 }