Пример #1
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;
 }
Пример #2
0
 public function actionGetDeviceLinks()
 {
     $portsWithAlias = Port::find()->where(['not', ['alias_id' => null]])->select(['id', 'device_id', 'alias_id'])->all();
     $deviceLinks = [];
     foreach ($portsWithAlias as $port) {
         $devId1 = $port->device_id;
         $devId2 = $port->getAlias()->select(['device_id'])->one()->device_id;
         if ($devId1 <= $devId2) {
             $deviceLinks[$devId1 . "to" . $devId2] = [$devId1, $devId2];
         } else {
             $deviceLinks[$devId2 . "to" . $devId1] = [$devId2, $devId1];
         }
     }
     Yii::trace($deviceLinks);
     return json_encode($deviceLinks);
 }
Пример #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;
 }
Пример #4
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]);
     }
 }
Пример #5
0
 public function actionGetPortLinks()
 {
     $portsWithAlias = Port::find()->where(['not', ['alias_id' => null]])->select(['id', 'directionality', 'alias_id', 'biport_id'])->asArray()->all();
     $links = [];
     $passedPorts = [];
     foreach ($portsWithAlias as $port) {
         $srcBiPortId = $port['biport_id'] ? $port['biport_id'] : $port['id'];
         $dstPort = Port::find()->where(['id' => $port['alias_id']])->select(['id', 'biport_id'])->asArray()->one();
         $dstBiPortId = $dstPort['biport_id'] ? $dstPort['biport_id'] : $dstPort['id'];
         isset($links[$srcBiPortId]) ? null : ($links[$srcBiPortId] = []);
         isset($links[$dstBiPortId]) ? null : ($links[$dstBiPortId] = []);
         switch ($port['directionality']) {
             case Port::DIR_UNI_OUT:
                 if (!in_array($dstBiPortId, $links[$srcBiPortId])) {
                     $links[$srcBiPortId][] = $dstBiPortId;
                 }
                 break;
             case Port::DIR_UNI_IN:
                 if (!in_array($srcBiPortId, $links[$dstBiPortId])) {
                     $links[$dstBiPortId][] = $srcBiPortId;
                 }
                 break;
             case Port::DIR_BI:
                 if (!in_array($dstBiPortId, $links[$srcBiPortId])) {
                     $links[$srcBiPortId][] = $dstBiPortId;
                 }
                 break;
                 if (!in_array($srcBiPortId, $links[$dstBiPortId])) {
                     $links[$dstBiPortId][] = $srcBiPortId;
                 }
                 break;
             default:
                 break;
         }
     }
     Yii::trace($links);
     return json_encode($links);
 }
Пример #6
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;
 }
Пример #7
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;
 }
Пример #8
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;
 }