"""
Copyright 2021 Open Networking Foundation (ONF)

Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>

"""

import pexpect
import os
from drivers.common.clidriver import CLI


class P4RuntimeCliDriver(CLI):
    """
    Implements a P4Runtime Client CLI-based driver to control devices that uses
    the P4Runtime Protocol, using the P4Runtime shell CLI.

    This driver requires that P4Runtime CLI is configured to not generated colored
    text. To do so, add the following lines to a file in
    ~/.ipython/profile_default/ipython_config.py:
        c.InteractiveShell.color_info = False
        c.InteractiveShell.colors = 'NoColor'
        c.TerminalInteractiveShell.color_info = False
        c.TerminalInteractiveShell.colors = 'NoColor'
    """

    def __init__(self):
        """
        Initialize client
        """
        super(P4RuntimeCliDriver, self).__init__()
        self.name = None
        self.handle = None
        self.p4rtAddress = "localhost"
        self.p4rtPort = "9559"  # Default P4RT server port
        self.prompt = "\$"
        self.p4rtShPrompt = ">>>"
        self.p4rtDeviceId = "1"
        self.p4rtElectionId = "0,100"  # (high,low)
        self.p4rtConfig = None  # Can be used to pass a path to the P4Info and pipeline config

    def connect(self, **connectargs):
        """
        Creates the ssh handle for the P4Runtime CLI
        The ip_address would come from the topo file using the host tag, the
        value can be an environment variable as well as a "localhost" to get
        the ip address needed to ssh to the "bench"
        """
        try:
            for key in connectargs:
                vars(self)[key] = connectargs[key]
            self.name = self.options.get("name", "")
            self.p4rtAddress = self.options.get("p4rt_address", "localhost")
            self.p4rtPort = self.options.get("p4rt_port", "9559")
            self.p4rtShPrompt = self.options.get("p4rt_sh_prompt", ">>>")
            self.p4rtDeviceId = self.options.get("p4rt_device_id", "1")
            self.p4rtElectionId = self.options.get("p4rt_election_id", "0,100")
            self.p4rtConfig = self.options.get("p4rt_config", None)
            try:
                if os.getenv(str(self.ip_address)) is not None:
                    self.ip_address = os.getenv(str(self.ip_address))
                else:
                    main.log.info(self.name + ": ip set to " + self.ip_address)
            except KeyError:
                main.log.info(self.name + ": Invalid host name," +
                              "defaulting to 'localhost' instead")
                self.ip_address = 'localhost'
            except Exception as inst:
                main.log.error("Uncaught exception: " + str(inst))

            self.handle = super(P4RuntimeCliDriver, self).connect(
                user_name=self.user_name,
                ip_address=self.ip_address,
                port=None,
                pwd=self.pwd)
            if self.handle:
                main.log.info("Connection successful to the host " +
                              self.user_name +
                              "@" +
                              self.ip_address)
                self.handle.sendline("")
                self.handle.expect(self.prompt)
                return main.TRUE
            else:
                main.log.error("Connection failed to " +
                               self.user_name +
                               "@" +
                               self.ip_address)
                return main.FALSE
        except pexpect.EOF:
            main.log.error(self.name + ": EOF exception found")
            main.log.error(self.name + ":     " + self.handle.before)
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def startP4RtClient(self, pushConfig=False):
        """
        Start the P4Runtime shell CLI client

        :param pushConfig: True if you want to push the pipeline config, False otherwise
            requires the p4rt_config configuration parameter to be set
        :return:
        """
        try:
            main.log.debug(self.name + ": Starting P4Runtime Shell CLI")
            grpcAddr = "%s:%s" % (self.p4rtAddress, self.p4rtPort)
            startP4RtShLine = "python3 -m p4runtime_sh -v --grpc-addr " + grpcAddr + \
                              " --device-id " + self.p4rtDeviceId + \
                              " --election-id " + self.p4rtElectionId
            if pushConfig:
                if self.p4rtConfig:
                    startP4RtShLine += " --config " + self.p4rtConfig
                else:
                    main.log.error(
                        "You should provide a P4 Runtime config to push!")
                    main.cleanAndExit()
            response = self.__clearSendAndExpect(startP4RtShLine)
            if "CRITICAL" in response:
                main.log.exception(self.name + ": Connection error.")
                main.cleanAndExit()
            self.preDisconnect = self.stopP4RtClient
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            main.cleanAndExit()
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def stopP4RtClient(self):
        """
        Exit the P4Runtime shell CLI
        """
        try:
            main.log.debug(self.name + ": Stopping P4Runtime Shell CLI")
            self.handle.sendline("exit")
            self.handle.expect(self.prompt)
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def pushTableEntry(self, tableEntry=None, debug=True):
        """
        Push a table entry with either the given table entry or use the saved
        table entry in the variable 'te'.

        Example of a valid tableEntry string:
        te = table_entry["FabricIngress.forwarding.routing_v4"](action="set_next_id_routing_v4"); te.action["next_id"] = "10"; te.match["ipv4_dst"] = "10.0.0.0" # nopep8

        :param tableEntry: the string table entry, if None it uses the table
            entry saved in the 'te' variable
        :param debug: True to enable debug logging, False otherwise
        :return: main.TRUE or main.FALSE on error
        """
        try:
            main.log.debug(self.name + ": Pushing Table Entry")
            if debug:
                self.handle.sendline("te")
                self.handle.expect(self.p4rtShPrompt)
            pushCmd = ""
            if tableEntry:
                pushCmd = tableEntry + ";"
            pushCmd += "te.insert()"
            response = self.__clearSendAndExpect(pushCmd)
            if "Traceback" in response or "Error" in response:
                # TODO: other possibile errors?
                # NameError...
                main.log.error(
                    self.name + ": Error in pushing table entry: " + response)
                return main.FALSE
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def deleteTableEntry(self, tableEntry=None, debug=True):
        """
        Deletes a table entry with either the given table entry or use the saved
        table entry in the variable 'te'.

        Example of a valid tableEntry string:
        te = table_entry["FabricIngress.forwarding.routing_v4"](action="set_next_id_routing_v4"); te.action["next_id"] = "10"; te.match["ipv4_dst"] = "10.0.0.0" # nopep8

        :param tableEntry: the string table entry, if None it uses the table
            entry saved in the 'te' variable
        :param debug: True to enable debug logging, False otherwise
        :return: main.TRUE or main.FALSE on error
        """
        try:
            main.log.debug(self.name + ": Deleting Table Entry")
            if debug:
                self.__clearSendAndExpect("te")
            pushCmd = ""
            if tableEntry:
                pushCmd = tableEntry + ";"
            pushCmd += "te.delete()"
            response = self.__clearSendAndExpect(pushCmd)
            main.log.debug(
                self.name + ": Delete table entry response: {}".format(
                    response))
            if "Traceback" in response or "Error" in response:
                # TODO: other possibile errors?
                # NameError...
                main.log.error(
                    self.name + ": Error in deleting table entry: " + response)
                return main.FALSE
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def modifyMeterEntry(self, meterEntry=None, debug=True):
        """
        Modify a meter entry with either the given meter entry or use the saved
        meter entry in the variable 'me'.

        Example of a valid tableEntry string:
        me = meter_entry["FabricIngress.upf.app_meter"]; me.cir = 1; me.cburst=1; me.pir=1; me.pburst=1; # nopep8

        :param meterEntry: the string meter entry, if None it uses the meter
            entry saved in the 'me' variable
        :param debug: True to enable debug logging, False otherwise
        :return: main.TRUE or main.FALSE on error
        """
        try:
            main.log.debug(self.name + ": Pushing Meter Entry")
            if debug:
                self.handle.sendline("me")
                self.handle.expect(self.p4rtShPrompt)
            pushCmd = ""
            if meterEntry:
                pushCmd = meterEntry + ";"
            pushCmd += "me.modify()"
            response = self.__clearSendAndExpect(pushCmd)
            if "Traceback" in response or "Error" in response or "INVALID_ARGUMENT" in response:
                # TODO: other possibile errors?
                # NameError...
                main.log.error(
                    self.name + ": Error in modifying meter entry: " + response)
                return main.FALSE
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def buildP4RtTableEntry(self, tableName, actionName, actionParams={},
                            matchFields={}, priority=0):
        """
        Build a Table Entry
        :param tableName: The name of table
        :param actionName: The name of the action
        :param actionParams: A dictionary containing name and values for the action parameters
        :param matchFields: A dictionary containing name and values for the match fields
        :param priority: for ternary match entries
        :return: main.TRUE or main.FALSE on error
        """
        # TODO: improve error checking when creating the table entry, add
        #  params, and match fields.
        try:
            main.log.debug("%s: Building P4RT Table Entry "
                           "(table=%s, match=%s, priority=%s, action=%s, params=%s)" % (
                               self.name, tableName, matchFields, priority,
                               actionName, actionParams))
            cmd = 'te = table_entry["%s"](action="%s"); ' % (
                tableName, actionName)

            # Action Parameters
            for name, value in actionParams.items():
                cmd += 'te.action["%s"]="%s";' % (name, str(value))

            # Match Fields
            for name, value in matchFields.items():
                cmd += 'te.match["%s"]="%s";' % (name, str(value))

            if priority:
                cmd += 'te.priority=%s;' % priority

            response = self.__clearSendAndExpect(cmd)
            if "Unknown action" in response:
                main.log.error("Unknown action: " + response)
                return main.FALSE
            if "AttributeError" in response:
                main.log.error("Wrong action: " + response)
                return main.FALSE
            if "Invalid value" in response:
                main.log.error("Invalid action value: " + response)
                return main.FALSE
            if "Action parameter value must be a string" in response:
                main.log.error(
                    "Action parameter value must be a string: " + response)
                return main.FALSE
            if "table" in response and "does not exist" in response:
                main.log.error("Unknown table: " + response)
                return main.FALSE
            if "not a valid match field name" in response:
                main.log.error("Invalid match field name: " + response)
                return main.FALSE
            if "is not a valid" in response:
                main.log.error("Invalid match field: " + response)
                return main.FALSE
            if "Traceback" in response:
                main.log.error("Error in creating the table entry: " + response)
                return main.FALSE
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def buildP4RtMeterEntry(self, meterName, index, cir=None, cburst=None, pir=None,
                            pburst=None):
        # TODO: improve error checking
        try:
            main.log.debug(
                "%s: Building P4RT Meter Entry (meter=%s, index=%d, cir=%s, "
                "cburst=%s, pir=%s, pburst=%s)" % (
                    self.name, meterName, index, str(cir), str(cburst), str(pir), str(pburst)
                )
            )
            cmd = 'me = meter_entry["%s"]; ' % meterName
            cmd += 'me.index=%d; ' % index
            if cir is not None:
                cmd += 'me.cir=%d; ' % cir
            if cburst is not None:
                cmd += 'me.cburst=%d; ' % cburst
            if pir is not None:
                cmd += 'me.pir=%d; ' % pir
            if pburst is not None:
                cmd += 'me.pburst=%d; ' % pburst

            response = self.__clearSendAndExpect(cmd)
            if "meter" in response and "does not exist" in response:
                main.log.error("Unknown meter: " + response)
                return main.FALSE
            if "UNIMPLEMENTED" in response:
                main.log.error("Error in creating the meter entry: " + response)
                return main.FALSE
            if "Traceback" in response:
                main.log.error("Error in creating the meter entry: " + response)
                return main.FALSE
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def readNumberTableEntries(self, tableName):
        """
        Read table entries and return the number of entries present in a table.

        :param tableName: Name of table to read from
        :return: Number of entries,
        """
        try:
            main.log.debug(
                self.name + ": Reading table entries from " + tableName)
            cmd = 'table_entry["%s"].read(lambda te: print(te))' % tableName
            response = self.__clearSendAndExpect(cmd, clearBufferAfter=True)
            # Every table entries starts with "table_id: [P4RT obj ID] ("[tableName]")"
            return response.count("table_id")
        except pexpect.TIMEOUT:
            main.log.exception(self.name + ": Command timed out")
            return main.FALSE
        except pexpect.EOF:
            main.log.exception(self.name + ": connection closed.")
            main.cleanAndExit()
        except Exception:
            main.log.exception(self.name + ": Uncaught exception!")
            main.cleanAndExit()

    def disconnect(self):
        """
        Called at the end of the test to stop the p4rt CLI component and
        disconnect the handle.
        """
        response = main.TRUE
        try:
            if self.handle:
                self.handle.sendline("")
                i = self.handle.expect([self.p4rtShPrompt, pexpect.TIMEOUT],
                                       timeout=2)
                if i != 1:
                    # If the p4rtShell is still connected make sure to
                    # disconnect it before
                    self.stopP4RtClient()
                i = self.handle.expect([self.prompt, pexpect.TIMEOUT],
                                       timeout=2)
                if i == 1:
                    main.log.warn(
                        self.name + ": timeout when waiting for response")
                    main.log.warn(
                        self.name + ": response: " + str(self.handle.before))
                self.handle.sendline("exit")
                i = self.handle.expect(["closed", pexpect.TIMEOUT], timeout=2)
                if i == 1:
                    main.log.warn(
                        self.name + ": timeout when waiting for response")
                    main.log.warn(
                        self.name + ": response: " + str(self.handle.before))
            return main.TRUE
        except TypeError:
            main.log.exception(self.name + ": Object not as expected")
            response = main.FALSE
        except pexpect.EOF:
            main.log.error(self.name + ": EOF exception found")
            main.log.error(self.name + ":     " + self.handle.before)
        except ValueError:
            main.log.exception("Exception in disconnect of " + self.name)
            response = main.TRUE
        except Exception:
            main.log.exception(self.name + ": Connection failed to the host")
            response = main.FALSE
        return response

    def __clearSendAndExpect(self, cmd, clearBufferAfter=False, debug=False):
        self.clearBuffer(debug)
        self.handle.sendline(cmd)
        self.handle.expect(self.p4rtShPrompt)
        if clearBufferAfter:
            return self.clearBuffer()
        return self.handle.before

    def clearBuffer(self, debug=False):
        """
        Keep reading from buffer until it's empty
        """
        i = 0
        response = ''
        while True:
            try:
                i += 1
                # clear buffer
                if debug:
                    main.log.warn("%s expect loop iteration" % i)
                self.handle.expect(self.p4rtShPrompt, timeout=2)
                response += self.cleanOutput(self.handle.before, debug)
            except pexpect.TIMEOUT:
                return response
