from vpp_object import VppObject
from vpp_interface import VppInterface


class VppBondInterface(VppInterface):
    """VPP bond interface."""

    def __init__(self, test, mode, lb=0, numa_only=0, enable_gso=0,
                 use_custom_mac=0, mac_address='', id=0xFFFFFFFF):

        """ Create VPP Bond interface """
        super(VppBondInterface, self).__init__(test)
        self.mode = mode
        self.lb = lb
        self.numa_only = numa_only
        self.enable_gso = enable_gso
        self.use_custom_mac = use_custom_mac
        self.mac_address = mac_address
        self.id = id

    def add_vpp_config(self):
        r = self.test.vapi.bond_create2(self.mode,
                                        self.lb,
                                        self.numa_only,
                                        self.enable_gso,
                                        self.use_custom_mac,
                                        self.mac_address,
                                        self.id)
        self.set_sw_if_index(r.sw_if_index)

    def remove_vpp_config(self):
        self.test.vapi.bond_delete(self.sw_if_index)

    def add_member_vpp_bond_interface(self,
                                      sw_if_index,
                                      is_passive=0,
                                      is_long_timeout=0):
        self.test.vapi.bond_add_member(sw_if_index,
                                       self.sw_if_index,
                                       is_passive,
                                       is_long_timeout)

    def detach_vpp_bond_interface(self,
                                  sw_if_index):
        self.test.vapi.bond_detach_member(sw_if_index)

    def is_interface_config_in_dump(self, dump):
        for i in dump:
            if i.sw_if_index == self.sw_if_index:
                return True
        else:
            return False
