<?php

namespace app\models\mikrotik\mpls\traffic;

use yii\base\Model;
use Yii;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Resv extends Model {

    public $id;
    public $src;
    public $dst;
    public $bandwidth;
    public $label;
    public $interface;
    public $next_hop;

    public function rules() {
        return [
            ['id', 'string'],
            ['src', 'string'],
            ['dst', 'string'],
            ['bandwidth', 'string'],
            ['label', 'string'],
            ['interface', 'string'],
            ['next_hop', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/mpls/traffic-eng/resv-state/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Resv();
                $c->id = $response->getProperty('.id');
                $c->src = $response->getProperty('src');
                $c->dst = $response->getProperty('dst');
                $c->bandwidth = $response->getProperty('bandwidth');
                $c->label = $response->getProperty('label');
                $c->interface = $response->getProperty('interface');
                $c->next_hop = $response->getProperty('next_hop');
                $return[] = $c;
            }
        }
        return $return;
    }

}
