
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, flags=0,
                 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_flags = flags
        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_tunnel_mode_t.
                           TUNNEL_API_MODE_P2P)

    def add_vpp_config(self):
        r = self.test.vapi.gre_tunnel_add_del(
            is_add=1,
            tunnel={
                'src': self.t_src,
                'dst': self.t_dst,
                'outer_table_id': self.t_outer_table,
                'instance': 0xffffffff,
                'type': self.t_type,
                'mode': self.t_mode,
                'flags': self.t_flags,
                '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(
            is_add=0,
            tunnel={
                'src': self.t_src,
                'dst': self.t_dst,
                'outer_table_id': self.t_outer_table,
                'instance': 0xffffffff,
                'type': self.t_type,
                'mode': self.t_mode,
                'flags': self.t_flags,
                'session_id': self.t_session})

    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
