Ejemplo n.º 1
0
 public function actionSearch($term)
 {
     $term = str_replace("urn:ogf:network:", "", $term);
     $ports = Port::findBySql("SELECT `name`, `device_id`, `network_id` \n            FROM `meican_port` \n            WHERE ((`urn` COLLATE UTF8_GENERAL_CI LIKE :term) \n            OR (`name` LIKE :term)) AND `directionality` = 'BI' AND `type` = 'NSI'\n            LIMIT 5")->addParams([':term' => '%' . $term . '%'])->asArray()->all();
     Yii::trace($ports);
     return json_encode($ports);
 }
Ejemplo n.º 2
0
 public function save()
 {
     $this->reservation = new Reservation();
     $this->reservation->type = Reservation::TYPE_NORMAL;
     $this->reservation->name = $this->name;
     $this->reservation->date = DateUtils::now();
     $this->reservation->bandwidth = $this->bandwidth;
     $this->reservation->requester_nsa = CircuitsPreference::findOneValue(CircuitsPreference::MEICAN_NSA);
     $this->reservation->provider_nsa = CircuitsPreference::findOneValue(CircuitsPreference::CIRCUITS_DEFAULT_PROVIDER_NSA);
     $this->reservation->request_user_id = Yii::$app->user->getId();
     if ($this->reservation->save()) {
         for ($i = 0; $i < count($this->path['port']); $i++) {
             $path = new ReservationPath();
             $path->reservation_id = $this->reservation->id;
             if ($this->path['mode'][$i] == 'normal') {
                 $path->port_urn = Port::find()->where(['id' => $this->path['port'][$i]])->one()->urn;
             } else {
                 $path->port_urn = str_replace('urn:ogf:network:', '', $this->path['urn'][$i]);
             }
             $path->path_order = $i;
             $path->vlan = $this->path['vlan'][$i];
             if (!$path->save()) {
                 Yii::trace($path->getErrors());
             }
         }
         $this->reservation->createConnections($this->events);
     }
     Yii::trace($this->reservation->getErrors());
     return true;
 }
Ejemplo n.º 3
0
 public function actionGetOld($port = null, $dir)
 {
     self::beginAsyncAction();
     $portId = $port;
     $data = Yii::$app->cache->get('monitoring.traffic.port.' . $portId);
     if ($data === false) {
         $port = Port::find()->where(['id' => $port])->select(['id', 'device_id', 'name'])->one();
         $dev = $port->getDevice()->select(['id', 'node'])->asArray()->one();
         $portName = str_replace('/', '@2F', $port->name);
         $ch = curl_init();
         $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERAGENT => 'Meican', CURLOPT_URL => Yii::$app->params['esmond.server.api.url'] . 'device/' . $dev['node'] . '/interface/' . $portName . '/' . $dir . '?format=json&begin=' . strtotime('-90 seconds'));
         curl_setopt_array($ch, $options);
         $output = curl_exec($ch);
         curl_close($ch);
         Yii::trace($output);
         $output = json_decode($output);
         $data = json_encode(['dev' => $dev['id'], 'port' => $portId, 'traffic' => isset($output->data[0]) ? $output->data[0]->val : 0]);
         // store $data in cache so that it can be retrieved next time
         Yii::$app->cache->set('monitoring.traffic.port.' . $portId, $data);
     }
     return $data;
 }
Ejemplo n.º 4
0
 public function getPort()
 {
     return Port::findByUrn($this->port_urn);
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAlias()
 {
     return $this->hasOne(Port::className(), ['id' => 'alias_id']);
 }
Ejemplo n.º 6
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.º 7
0
 public function save()
 {
     $this->reservation = new Reservation();
     $this->reservation->type = Reservation::TYPE_TEST;
     $this->reservation->name = Test::AT_PREFIX;
     $this->reservation->date = DateUtils::now();
     $this->reservation->start = DateUtils::now();
     $this->reservation->finish = DateUtils::now();
     $this->reservation->bandwidth = 10;
     $this->reservation->requester_nsa = CircuitsPreference::findOneValue(CircuitsPreference::MEICAN_NSA);
     $this->reservation->provider_nsa = CircuitsPreference::findOneValue(CircuitsPreference::CIRCUITS_DEFAULT_PROVIDER_NSA);
     $this->reservation->request_user_id = Yii::$app->user->getId();
     //Confere se usuário tem permissão para testar na origem OU no destino
     $source = Port::findOne(['id' => $this->src_port]);
     $destination = Port::findOne(['id' => $this->dst_port]);
     $permission = false;
     if ($source) {
         $source = $source->getDevice()->one();
         if ($source) {
             $domain = $source->getDomain()->one();
             if ($domain && RbacController::can('test/create', $domain->name)) {
                 $permission = true;
             }
         }
     }
     if ($destination) {
         $destination = $destination->getDevice()->one();
         if ($destination) {
             $domain = $destination->getDomain()->one();
             if ($domain && RbacController::can('test/create', $domain->name)) {
                 $permission = true;
             }
         }
     }
     if (!$permission) {
         Yii::$app->getSession()->addFlash("warning", Yii::t("circuits", "You are not allowed to create a automated test involving these selected domains"));
         return false;
     }
     if ($this->reservation->save()) {
         $this->reservation->name .= $this->reservation->id;
         $this->reservation->save();
         $path = new ReservationPath();
         $path->reservation_id = $this->reservation->id;
         $path->port_urn = Port::findOne($this->src_port)->urn;
         $path->path_order = 0;
         $path->vlan = $this->src_vlan;
         if (!$path->save()) {
             Yii::trace($path->getErrors());
             return false;
         }
         $path = new ReservationPath();
         $path->reservation_id = $this->reservation->id;
         $path->port_urn = Port::findOne($this->dst_port)->urn;
         $path->path_order = 1;
         $path->vlan = $this->dst_vlan;
         if (!$path->save()) {
             Yii::trace($path->getErrors());
             return false;
         }
         $task = new ScheduledTask();
         $task->freq = $this->cron_value;
         $task->obj_class = 'meican\\tester\\models\\Test';
         $task->obj_data = $this->reservation->id;
         if (!$task->save()) {
             Yii::trace($task->getErrors());
             return false;
         }
     } else {
         Yii::trace($this->reservation->getErrors());
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPorts()
 {
     return $this->hasMany(Port::className(), ['device_id' => 'id']);
 }
Ejemplo n.º 9
0
 public function checkDevice($flow, $connection)
 {
     Yii::trace("Testando Device");
     $haveDevice = false;
     $paths = ConnectionPath::find()->where(['conn_id' => $connection->id, 'domain' => $flow->domain])->all();
     foreach ($paths as $path) {
         $port = Port::findOne(['urn' => $path->port_urn]);
         if (isset($port)) {
             $device = $port->getDevice()->one();
             if (isset($device)) {
                 if ($device->id == $flow->value) {
                     $haveDevice = true;
                 }
             }
         }
         if ($haveDevice == true) {
             $flow->status = self::STATUS_YES;
             return;
         }
     }
     Yii::trace("Não passou em DEVICE");
     $flow->status = self::STATUS_NO;
 }
Ejemplo n.º 10
0
 public function actionGetAllColor($cols = null)
 {
     $query = Port::find()->orderBy(['name' => 'SORT ASC'])->asArray();
     $cols ? $data = $query->select(array_merge(json_decode($cols), ['device_id']))->all() : ($data = $query->all());
     foreach ($data as &$port) {
         $port['color'] = Domain::find()->where(['id' => $dev['domain_id']])->select(['color'])->asArray()->one()['color'];
     }
     $temp = Json::encode($data);
     Yii::trace($temp);
     return $temp;
 }
Ejemplo n.º 11
0
 public function actionGetPortByDevice($id, $cols = null)
 {
     $query = Port::find()->where(['device_id' => $id])->orderBy(['name' => 'SORT ASC'])->asArray();
     if (!CircuitsPreference::findOne(CircuitsPreference::CIRCUITS_UNIPORT_ENABLED)->getBoolean()) {
         $query->andWhere(['directionality' => Port::DIR_BI]);
     }
     if (CircuitsPreference::findOne(CircuitsPreference::CIRCUITS_PROTOCOL)->value == Service::TYPE_NSI_CSP_2_0) {
         $query->andWhere(['type' => Port::TYPE_NSI]);
     }
     $cols ? $data = $query->select(json_decode($cols))->all() : ($data = $query->all());
     $temp = Json::encode($data);
     Yii::trace($temp);
     return $temp;
 }
Ejemplo n.º 12
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.º 13
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');
             }
     }
 }