
from vpp_interface import VppInterface
import socket
from vpp_papi import VppEnum


class VppGreInterface(VppInterface):
    """
    VPP GRE interface
    """

    def __init__(self, test, src_ip, dst_ip, outer_table_id=0,
                 type=None, mode=None,
                 session=0):
        """ Create VPP GRE interface """
        super(VppGreInterface, self).__init__(test)
        self.t_src = src_ip
        self.t_dst = dst_ip
        self.t_outer_table = outer_table_id
        self.t_session = session
        self.t_type = type
        if not self.t_type:
            self.t_type = (VppEnum.vl_api_gre_tunnel_type_t.
                           GRE_API_TUNNEL_TYPE_L3)
        self.t_mode = mode
        if not self.t_mode:
            self.t_mode = (VppEnum.vl_api_gre_tunnel_mode_t.
                           GRE_API_TUNNEL_MODE_P2P)

    def add_vpp_config(self):
        r = self.test.vapi.gre_tunnel_add_del(
            self.t_src,
            self.t_dst,
            outer_table_id=self.t_outer_table,
            type=self.t_type,
            mode=self.t_mode,
            session_id=self.t_session)
        self.set_sw_if_index(r.sw_if_index)
        self.generate_remote_hosts()
        self.test.registry.register(self, self.test.logger)
        return self

    def remove_vpp_config(self):
        self.unconfig()
        self.test.vapi.gre_tunnel_add_del(self.t_src,
                                          self.t_dst,
                                          outer_table_id=self.t_outer_table,
                                          type=self.t_type,
                                          mode=self.t_mode,
                                          session_id=self.t_session,
                                          is_add=0)

    def object_id(self):
        return "gre-%d" % self.sw_if_index

    def query_vpp_config(self):
        return (self.test.vapi.gre_tunnel_dump(
            sw_if_index=self._sw_if_index))

    @property
    def remote_ip(self):
        return self.t_dst

    @property
    def local_ip(self):
        return self.t_src
