<?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 Path extends Model {

    public $id;
    public $src;
    public $dst;
    public $bandwidth;
    public $out_interface;
    public $out_next_hop;

    public function rules() {
        return [
            ['id', 'string'],
            ['src', 'string'],
            ['dst', 'string'],
            ['bandwidth', 'string'],
            ['out_interface', 'string'],
            ['out_next_hop', 'string'],
        ];
    }

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

}
