<?php

namespace app\models\mikrotik\bridge;

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 Filter extends Model {

    public $_8023_sap;
    public $_8023_type;
    public $arp_dst_address;
    public $arp_dst_mac_address;
    public $arp_gratuitous;
    public $arp_hardware_type;
    public $arp_opcode;
    public $arp_packet_type;
    public $arp_src_address;
    public $arp_src_mac_address;
    public $chain;
    public $dst_address;
    public $dst_mac_address;
    public $dst_port;
    public $in_bridge;
    public $in_interface;
    public $ingress_priority;
    public $ip_protocol;
    public $jump_target;
    public $limit;
    public $log_prefix;
    public $mac_protocol;
    public $out_bridge;
    public $out_interface;
    public $packet_mark;
    public $packet_type;
    public $src_address;
    public $src_mac_address;
    public $src_port;
    public $stp_flags;
    public $stp_forward_delay;
    public $stp_hello_time;
    public $stp_max_age;
    public $stp_msg_age;
    public $stp_port;
    public $stp_root_address;
    public $stp_root_cost;
    public $stp_root_priority;
    public $stp_sender_address;
    public $stp_sender_priority;
    public $stp_type;
    public $vlan_encap;
    public $vlan_id;
    public $vlan_priority;
    public $id;
    public $disabled;
    public $action;

    public function rules() {
        return [
            ['_8023_sap', 'string'],
            ['_8023_type', 'string'],
            ['arp_dst_address', 'string'],
            ['arp_dst_mac_address', 'string'],
            ['arp_gratuitous', 'string'],
            ['arp_hardware_type', 'string'],
            ['arp_opcode', 'string'],
            ['arp_packet_type', 'string'],
            ['arp_src_address', 'string'],
            ['arp_src_mac_address', 'string'],
            ['chain', 'string'],
            ['dst_address', 'string'],
            ['dst_mac_address', 'string'],
            ['dst_port', 'string'],
            ['in_bridge', 'string'],
            ['in_interface', 'string'],
            ['ingress_priority', 'string'],
            ['ip_protocol', 'string'],
            ['jump_target', 'string'],
            ['limit', 'string'],
            ['log_prefix', 'string'],
            ['mac_protocol', 'string'],
            ['out_bridge', 'string'],
            ['out_interface', 'string'],
            ['packet_mark', 'string'],
            ['packet_type', 'string'],
            ['src_address', 'string'],
            ['src_mac_address', 'string'],
            ['src_port', 'string'],
            ['stp_flags', 'string'],
            ['stp_forward_delay', 'string'],
            ['stp_hello_time', 'string'],
            ['stp_max_age', 'string'],
            ['stp_msg_age', 'string'],
            ['stp_port', 'string'],
            ['stp_root_address', 'string'],
            ['stp_root_cost', 'string'],
            ['stp_root_priority', 'string'],
            ['stp_sender_address', 'string'],
            ['stp_sender_priority', 'string'],
            ['stp_type', 'string'],
            ['vlan_encap', 'string'],
            ['vlan_id', 'string'],
            ['vlan_priority', 'string'],
            ['id', 'string'],
            ['disabled', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/bridge/filter/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Filter();
                $c->_8023_sap = $response->getProperty('802.3-sap');
                $c->_8023_type = $response->getProperty('802.3-type');
                $c->arp_dst_address = $response->getProperty('arp-dst-address');
                $c->arp_dst_mac_address = $response->getProperty('arp-dst-mac-address');
                $c->arp_gratuitous = $response->getProperty('arp-gratuitous');
                $c->arp_hardware_type = $response->getProperty('arp-hardware-type');
                $c->arp_opcode = $response->getProperty('arp-opcode');
                $c->arp_packet_type = $response->getProperty('arp-packet-type');
                $c->arp_src_address = $response->getProperty('arp-src-address');
                $c->arp_src_mac_address = $response->getProperty('arp-src-mac-address');
                $c->chain = $response->getProperty('chain');
                $c->dst_address = $response->getProperty('dst-address');
                $c->dst_mac_address = $response->getProperty('dst-mac-address');
                $c->dst_port = $response->getProperty('dst-port');
                $c->in_bridge = $response->getProperty('in-bridge');
                $c->in_interface = $response->getProperty('in-interface');
                $c->ingress_priority = $response->getProperty('ingress-priority');
                $c->ip_protocol = $response->getProperty('ip-protocol');
                $c->jump_target = $response->getProperty('jump-target');
                $c->limit = $response->getProperty('limit');
                $c->log_prefix = $response->getProperty('log-prefix');
                $c->mac_protocol = $response->getProperty('mac-protocol');
                $c->out_bridge = $response->getProperty('out-bridge');
                $c->out_interface = $response->getProperty('out-interface');
                $c->packet_mark = $response->getProperty('packet-mark');
                $c->packet_type = $response->getProperty('packet-type');
                $c->src_address = $response->getProperty('src-address');
                $c->src_mac_address = $response->getProperty('src-mac-address');
                $c->src_port = $response->getProperty('src-port');
                $c->stp_flags = $response->getProperty('stp-flags');
                $c->stp_forward_delay = $response->getProperty('stp-forward-delay');
                $c->stp_hello_time = $response->getProperty('stp-hello-time');
                $c->stp_max_age = $response->getProperty('stp-max-age');
                $c->stp_msg_age = $response->getProperty('stp-msg-age');
                $c->stp_port = $response->getProperty('stp-port');
                $c->stp_root_address = $response->getProperty('stp-root-address');
                $c->stp_root_cost = $response->getProperty('stp-root-cost');
                $c->stp_root_priority = $response->getProperty('stp-root-priority');
                $c->stp_sender_address = $response->getProperty('stp-sender-address');
                $c->stp_sender_priority = $response->getProperty('stp-sender-priority');
                $c->stp_type = $response->getProperty('stp-type');
                $c->vlan_encap = $response->getProperty('vlan-encap');
                $c->vlan_id = $response->getProperty('vlan-id');
                $c->vlan_priority = $response->getProperty('vlan-priority');
                $c->id = $response->getProperty('.id');
                $c->disabled = $response->getProperty('disabled');
                $c->action = $response->getProperty('action');
                $return[] = $c;
            }
        }
        return $return;
    }

    public function get($id) {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/bridge/filter/print');
        $getRequest->setQuery(RouterOS\Query::where('.id', $id));
        $responses = $connect->getConnection()->sendSync($getRequest);
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $this->_8023_sap = $response->getProperty('802.3-sap');
                $this->_8023_type = $response->getProperty('802.3-type');
                $this->arp_dst_address = $response->getProperty('arp-dst-address');
                $this->arp_dst_mac_address = $response->getProperty('arp-dst-mac-address');
                $this->arp_gratuitous = $response->getProperty('arp-gratuitous');
                $this->arp_hardware_type = $response->getProperty('arp-hardware-type');
                $this->arp_opcode = $response->getProperty('arp-opcode');
                $this->arp_packet_type = $response->getProperty('arp-packet-type');
                $this->arp_src_address = $response->getProperty('arp-src-address');
                $this->arp_src_mac_address = $response->getProperty('arp-src-mac-address');
                $this->chain = $response->getProperty('chain');
                $this->dst_address = $response->getProperty('dst-address');
                $this->dst_mac_address = $response->getProperty('dst-mac-address');
                $this->dst_port = $response->getProperty('dst-port');
                $this->in_bridge = $response->getProperty('in-bridge');
                $this->in_interface = $response->getProperty('in-interface');
                $this->ingress_priority = $response->getProperty('ingress-priority');
                $this->ip_protocol = $response->getProperty('ip-protocol');
                $this->jump_target = $response->getProperty('jump-target');
                $this->limit = $response->getProperty('limit');
                $this->log_prefix = $response->getProperty('log-prefix');
                $this->mac_protocol = $response->getProperty('mac-protocol');
                $this->out_bridge = $response->getProperty('out-bridge');
                $this->out_interface = $response->getProperty('out-interface');
                $this->packet_mark = $response->getProperty('packet-mark');
                $this->packet_type = $response->getProperty('packet-type');
                $this->src_address = $response->getProperty('src-address');
                $this->src_mac_address = $response->getProperty('src-mac-address');
                $this->src_port = $response->getProperty('src-port');
                $this->stp_flags = $response->getProperty('stp-flags');
                $this->stp_forward_delay = $response->getProperty('stp-forward-delay');
                $this->stp_hello_time = $response->getProperty('stp-hello-time');
                $this->stp_max_age = $response->getProperty('stp-max-age');
                $this->stp_msg_age = $response->getProperty('stp-msg-age');
                $this->stp_port = $response->getProperty('stp-port');
                $this->stp_root_address = $response->getProperty('stp-root-address');
                $this->stp_root_cost = $response->getProperty('stp-root-cost');
                $this->stp_root_priority = $response->getProperty('stp-root-priority');
                $this->stp_sender_address = $response->getProperty('stp-sender-address');
                $this->stp_sender_priority = $response->getProperty('stp-sender-priority');
                $this->stp_type = $response->getProperty('stp-type');
                $this->vlan_encap = $response->getProperty('vlan-encap');
                $this->vlan_id = $response->getProperty('vlan-id');
                $this->vlan_priority = $response->getProperty('vlan-priority');
                $this->id = $id;
                $this->disabled = $response->getProperty('disabled');
                $this->action = $response->getProperty('action');
            }
        }
        return;
    }

    public function update($id) {
        $c = new Filter();
        $c->get($id);
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/bridge/filter/set');
        $setRequest->setargument('.id', $id);
        if ($this->_8023_sap != $c->_8023_sap) {
            if ($this->_8023_sap == '') {
                $unset[] = '8023-sap';
            } else {
                $setRequest->setargument('8023-sap', $this->_8023_sap);
            }
        }
        if ($this->_8023_type != $c->_8023_type) {
            if ($this->_8023_type == '') {
                $unset[] = '8023-type';
            } else {
                $setRequest->setargument('8023-type', $this->_8023_type);
            }
        }
        if ($this->arp_dst_address != $c->arp_dst_address) {
            if ($this->arp_dst_address == '') {
                $unset[] = 'arp-dst-address';
            } else {
                $setRequest->setargument('arp-dst-address', $this->arp_dst_address);
            }
        }
        if ($this->arp_dst_mac_address != $c->arp_dst_mac_address) {
            if ($this->arp_dst_mac_address == '') {
                $unset[] = 'arp-dst-mac-address';
            } else {
                $setRequest->setargument('arp-dst-mac-address', $this->arp_dst_mac_address);
            }
        }
        if ($this->arp_gratuitous != $c->arp_gratuitous) {
            if ($this->arp_gratuitous == '') {
                $unset[] = 'arp-gratuitous';
            } else {
                $setRequest->setargument('arp-gratuitous', $this->arp_gratuitous);
            }
        }
        if ($this->arp_hardware_type != $c->arp_hardware_type) {
            if ($this->arp_hardware_type == '') {
                $unset[] = 'arp-hardware-type';
            } else {
                $setRequest->setargument('arp-hardware-type', $this->arp_hardware_type);
            }
        }
        if ($this->arp_opcode != $c->arp_opcode) {
            if ($this->arp_opcode == '') {
                $unset[] = 'arp-opcode';
            } else {
                $setRequest->setargument('arp-opcode', $this->arp_opcode);
            }
        }
        if ($this->arp_packet_type != $c->arp_packet_type) {
            if ($this->arp_packet_type == '') {
                $unset[] = 'arp-packet-type';
            } else {
                $setRequest->setargument('arp-packet-type', $this->arp_packet_type);
            }
        }
        if ($this->arp_src_address != $c->arp_src_address) {
            if ($this->arp_src_address == '') {
                $unset[] = 'arp-src-address';
            } else {
                $setRequest->setargument('arp-src-address', $this->arp_src_address);
            }
        }
        if ($this->arp_src_mac_address != $c->arp_src_mac_address) {
            if ($this->arp_src_mac_address == '') {
                $unset[] = 'arp-src-mac-address';
            } else {
                $setRequest->setargument('arp-src-mac-address', $this->arp_src_mac_address);
            }
        }
        if ($this->chain != $c->chain) {

            $setRequest->setargument('chain', $this->chain);
        }
        if ($this->dst_address != $c->dst_address) {
            if ($this->dst_address == '') {
                $unset[] = 'dst-address';
            } else {
                $setRequest->setargument('dst-address', $this->dst_address);
            }
        }
        if ($this->dst_mac_address != $c->dst_mac_address) {
            if ($this->dst_mac_address == '') {
                $unset[] = 'dst-mac-address';
            } else {
                $setRequest->setargument('dst-mac-address', $this->dst_mac_address);
            }
        }
        if ($this->dst_port != $c->dst_port) {
            if ($this->dst_port == '') {
                $unset[] = 'dst-port';
            } else {
                $setRequest->setargument('dst-port', $this->dst_port);
            }
        }
        if ($this->in_bridge != $c->in_bridge) {
            if ($this->in_bridge == '') {
                $unset[] = 'in-bridge';
            } else {
                $setRequest->setargument('in-bridge', $this->in_bridge);
            }
        }
        if ($this->in_interface != $c->in_interface) {
            if ($this->in_interface == '') {
                $unset[] = 'in-interface';
            } else {
                $setRequest->setargument('in-interface', $this->in_interface);
            }
        }
        if ($this->ingress_priority != $c->ingress_priority) {
            if ($this->ingress_priority == '') {
                $unset[] = 'ingress-priority';
            } else {
                $setRequest->setargument('ingress-priority', $this->ingress_priority);
            }
        }
        if ($this->ip_protocol != $c->ip_protocol) {
            if ($this->ip_protocol == '') {
                $unset[] = 'ip-protocol';
            } else {
                $setRequest->setargument('ip-protocol', $this->ip_protocol);
            }
        }
        if ($this->jump_target != $c->jump_target) {

            $setRequest->setargument('jump-target', $this->jump_target);
        }
        if ($this->limit != $c->limit) {
            if ($this->limit == '') {
                $unset[] = 'limit';
            } else {
                $setRequest->setargument('limit', $this->limit);
            }
        }
        if ($this->log_prefix != $c->log_prefix) {

            $setRequest->setargument('log-prefix', $this->log_prefix);
        }
        if ($this->mac_protocol != $c->mac_protocol) {
            if ($this->mac_protocol == '') {
                $unset[] = 'mac-protocol';
            } else {
                $setRequest->setargument('mac-protocol', $this->mac_protocol);
            }
        }
        if ($this->out_bridge != $c->out_bridge) {
            if ($this->out_bridge == '') {
                $unset[] = 'out-bridge';
            } else {
                $setRequest->setargument('out-bridge', $this->out_bridge);
            }
        }
        if ($this->out_interface != $c->out_interface) {
            if ($this->out_interface == '') {
                $unset[] = 'out-interface';
            } else {
                $setRequest->setargument('out-interface', $this->out_interface);
            }
        }
        if ($this->packet_mark != $c->packet_mark) {
            if ($this->packet_mark == '') {
                $unset[] = 'packet-mark';
            } else {
                $setRequest->setargument('packet-mark', $this->packet_mark);
            }
        }
        if ($this->packet_type != $c->packet_type) {
            if ($this->packet_type == '') {
                $unset[] = 'packet-type';
            } else {
                $setRequest->setargument('packet-type', $this->packet_type);
            }
        }
        if ($this->src_address != $c->src_address) {
            if ($this->src_address == '') {
                $unset[] = 'src-address';
            } else {
                $setRequest->setargument('src-address', $this->src_address);
            }
        }
        if ($this->src_mac_address != $c->src_mac_address) {
            if ($this->src_mac_address == '') {
                $unset[] = 'src-mac-address';
            } else {
                $setRequest->setargument('src-mac-address', $this->src_mac_address);
            }
        }
        if ($this->src_port != $c->src_port) {
            if ($this->src_port == '') {
                $unset[] = 'src-port';
            } else {
                $setRequest->setargument('src-port', $this->src_port);
            }
        }
        if ($this->stp_flags != $c->stp_flags) {
            if ($this->stp_flags == '') {
                $unset[] = 'stp-flags';
            } else {
                $setRequest->setargument('stp-flags', $this->stp_flags);
            }
        }
        if ($this->stp_forward_delay != $c->stp_forward_delay) {
            if ($this->stp_forward_delay == '') {
                $unset[] = 'stp-forward-delay';
            } else {
                $setRequest->setargument('stp-forward-delay', $this->stp_forward_delay);
            }
        }
        if ($this->stp_hello_time != $c->stp_hello_time) {
            if ($this->stp_hello_time == '') {
                $unset[] = 'stp-hello-time';
            } else {
                $setRequest->setargument('stp-hello-time', $this->stp_hello_time);
            }
        }
        if ($this->stp_max_age != $c->stp_max_age) {
            if ($this->stp_max_age == '') {
                $unset[] = 'stp-max-age';
            } else {
                $setRequest->setargument('stp-max-age', $this->stp_max_age);
            }
        }
        if ($this->stp_msg_age != $c->stp_msg_age) {
            if ($this->stp_msg_age == '') {
                $unset[] = 'stp-msg-age';
            } else {
                $setRequest->setargument('stp-msg-age', $this->stp_msg_age);
            }
        }
        if ($this->stp_port != $c->stp_port) {
            if ($this->stp_port == '') {
                $unset[] = 'stp-port';
            } else {
                $setRequest->setargument('stp-port', $this->stp_port);
            }
        }
        if ($this->stp_root_address != $c->stp_root_address) {
            if ($this->stp_root_address == '') {
                $unset[] = 'stp-root-address';
            } else {
                $setRequest->setargument('stp-root-address', $this->stp_root_address);
            }
        }
        if ($this->stp_root_cost != $c->stp_root_cost) {
            if ($this->stp_root_cost == '') {
                $unset[] = 'stp-root-cost';
            } else {
                $setRequest->setargument('stp-root-cost', $this->stp_root_cost);
            }
        }
        if ($this->stp_root_priority != $c->stp_root_priority) {
            if ($this->stp_root_priority == '') {
                $unset[] = 'stp-root-priority';
            } else {
                $setRequest->setargument('stp-root-priority', $this->stp_root_priority);
            }
        }
        if ($this->stp_sender_address != $c->stp_sender_address) {
            if ($this->stp_sender_address == '') {
                $unset[] = 'stp-sender-address';
            } else {
                $setRequest->setargument('stp-sender-address', $this->stp_sender_address);
            }
        }
        if ($this->stp_sender_priority != $c->stp_sender_priority) {
            if ($this->stp_sender_priority == '') {
                $unset[] = 'stp-sender-priority';
            } else {
                $setRequest->setargument('stp-sender-priority', $this->stp_sender_priority);
            }
        }
        if ($this->stp_type != $c->stp_type) {
            if ($this->stp_type == '') {
                $unset[] = 'stp-type';
            } else {
                $setRequest->setargument('stp-type', $this->stp_type);
            }
        }
        if ($this->vlan_encap != $c->vlan_encap) {
            if ($this->vlan_encap == '') {
                $unset[] = 'vlan-encap';
            } else {
                $setRequest->setargument('vlan-encap', $this->vlan_encap);
            }
        }
        if ($this->vlan_id != $c->vlan_id) {
            if ($this->vlan_id == '') {
                $unset[] = 'vlan-id';
            } else {
                $setRequest->setargument('vlan-id', $this->vlan_id);
            }
        }
        if ($this->vlan_priority != $c->vlan_priority) {
            if ($this->vlan_priority == '') {
                $unset[] = 'vlan-priority';
            } else {
                $setRequest->setargument('vlan-priority', $this->vlan_priority);
            }
        }
        if (isset($unset)) {
            $unsetRequest = new RouterOS\Request('/interface/bridge/filter/unset');
            foreach ($unset as $value) {
                $unsetRequest->setArgument('.id', $id);
                $unsetRequest->setArgument('value-name', $value);
                $resp = $connect->getConnection()->sendSync($unsetRequest);
                if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
                    if (!isset($re)) {
                        $re = '';
                    } $re.= ' ' . $resp->getProperty('message');
                }
            }
        } $resp = $connect->getConnection()->sendSync($setRequest);
        if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
            if (isset($re)) {
                $re.= ' ' . $resp->getProperty('message');
            } else {
                $re = $resp->getProperty('message');
            }
        } if (isset($re)) {
            return $re;
        } else {
            return '1';
        }
    }

    public function disable($id) {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/bridge/filter/disable');
        $setRequest->setArgument('.id', $id);
        $connect->getConnection()->sendSync($setRequest);
        return;
    }

    public function enable($id) {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/bridge/filter/enable');
        $setRequest->setArgument('.id', $id);
        $connect->getConnection()->sendSync($setRequest);
        return;
    }

    public function create() {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/bridge/filter/add');
        if ($this->_8023_sap != "") {
            $setRequest->setargument('802.3-sap', $this->_8023_sap);
        }
        if ($this->_8023_type != "") {
            $setRequest->setargument('802.3-type', $this->_8023_type);
        }
        if ($this->arp_dst_address != "") {
            $setRequest->setargument('arp-dst-address', $this->arp_dst_address);
        }
        if ($this->arp_dst_mac_address != "") {
            $setRequest->setargument('arp-dst-mac-address', $this->arp_dst_mac_address);
        }
        if ($this->arp_gratuitous != "") {
            $setRequest->setargument('arp-gratuitous', $this->arp_gratuitous);
        }
        if ($this->arp_hardware_type != "") {
            $setRequest->setargument('arp-hardware-type', $this->arp_hardware_type);
        }
        if ($this->arp_opcode != "") {
            $setRequest->setargument('arp-opcode', $this->arp_opcode);
        }
        if ($this->arp_packet_type != "") {
            $setRequest->setargument('arp-packet-type', $this->arp_packet_type);
        }
        if ($this->arp_src_address != "") {
            $setRequest->setargument('arp-src-address', $this->arp_src_address);
        }
        if ($this->arp_src_mac_address != "") {
            $setRequest->setargument('arp-src-mac-address', $this->arp_src_mac_address);
        }
        if ($this->chain != "") {
            $setRequest->setargument('chain', $this->chain);
        }
        if ($this->dst_address != "") {
            $setRequest->setargument('dst-address', $this->dst_address);
        }
        if ($this->dst_mac_address != "") {
            $setRequest->setargument('dst-mac-address', $this->dst_mac_address);
        }
        if ($this->dst_port != "") {
            $setRequest->setargument('dst-port', $this->dst_port);
        }
        if ($this->in_bridge != "") {
            $setRequest->setargument('in-bridge', $this->in_bridge);
        }
        if ($this->in_interface != "") {
            $setRequest->setargument('in-interface', $this->in_interface);
        }
        if ($this->ingress_priority != "") {
            $setRequest->setargument('ingress-priority', $this->ingress_priority);
        }
        if ($this->ip_protocol != "") {
            $setRequest->setargument('ip-protocol', $this->ip_protocol);
        }
        if ($this->jump_target != "") {
            $setRequest->setargument('jump-target', $this->jump_target);
        }
        if ($this->limit != "") {
            $setRequest->setargument('limit', $this->limit);
        }
        if ($this->log_prefix != "") {
            $setRequest->setargument('log-prefix', $this->log_prefix);
        }
        if ($this->mac_protocol != "") {
            $setRequest->setargument('mac-protocol', $this->mac_protocol);
        }
        if ($this->out_bridge != "") {
            $setRequest->setargument('out-bridge', $this->out_bridge);
        }
        if ($this->out_interface != "") {
            $setRequest->setargument('out-interface', $this->out_interface);
        }
        if ($this->packet_mark != "") {
            $setRequest->setargument('packet-mark', $this->packet_mark);
        }
        if ($this->packet_type != "") {
            $setRequest->setargument('packet-type', $this->packet_type);
        }
        if ($this->src_address != "") {
            $setRequest->setargument('src-address', $this->src_address);
        }
        if ($this->src_mac_address != "") {
            $setRequest->setargument('src-mac-address', $this->src_mac_address);
        }
        if ($this->src_port != "") {
            $setRequest->setargument('src-port', $this->src_port);
        }
        if ($this->stp_flags != "") {
            $setRequest->setargument('stp-flags', $this->stp_flags);
        }
        if ($this->stp_forward_delay != "") {
            $setRequest->setargument('stp-forward-delay', $this->stp_forward_delay);
        }
        if ($this->stp_hello_time != "") {
            $setRequest->setargument('stp-hello-time', $this->stp_hello_time);
        }
        if ($this->stp_max_age != "") {
            $setRequest->setargument('stp-max-age', $this->stp_max_age);
        }
        if ($this->stp_msg_age != "") {
            $setRequest->setargument('stp-msg-age', $this->stp_msg_age);
        }
        if ($this->stp_port != "") {
            $setRequest->setargument('stp-port', $this->stp_port);
        }
        if ($this->stp_root_address != "") {
            $setRequest->setargument('stp-root-address', $this->stp_root_address);
        }
        if ($this->stp_root_cost != "") {
            $setRequest->setargument('stp-root-cost', $this->stp_root_cost);
        }
        if ($this->stp_root_priority != "") {
            $setRequest->setargument('stp-root-priority', $this->stp_root_priority);
        }
        if ($this->stp_sender_address != "") {
            $setRequest->setargument('stp-sender-address', $this->stp_sender_address);
        }
        if ($this->stp_sender_priority != "") {
            $setRequest->setargument('stp-sender-priority', $this->stp_sender_priority);
        }
        if ($this->stp_type != "") {
            $setRequest->setargument('stp-type', $this->stp_type);
        }
        if ($this->vlan_encap != "") {
            $setRequest->setargument('vlan-encap', $this->vlan_encap);
        }
        if ($this->vlan_id != "") {
            $setRequest->setargument('vlan-id', $this->vlan_id);
        }
        if ($this->vlan_priority != "") {
            $setRequest->setargument('vlan-priority', $this->vlan_priority);
        }
        if ($this->id != "") {
            $setRequest->setargument('.id', $this->id);
        }
        if ($this->disabled != "") {
            $setRequest->setargument('disabled', $this->disabled);
        }
        $resp = $connect->getConnection()->sendSync($setRequest);
        if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
            return $resp->getProperty('message');
        } else {
            return '1';
        }
    }

    public function delete($id) {
        $connect = MikrotikConnect::Instance();
        $util = new RouterOS\Util($connect->getConnection());
        $util->setMenu('/interface/bridge/filter');
        $util->remove(RouterOS\Query::where('.id', $id));
        return;
    }

    public function reset() {
        $connect = MikrotikConnect::Instance();
        $util = new RouterOS\Util($connect->getConnection());
        $util->setMenu('/interface/bridge/filter/reset-counters-all');
        return;
    }

}
