# -*- coding: utf-8 -*-
from operator import attrgetter
from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType
from pyangbind.lib.yangtypes import RestrictedClassType
from pyangbind.lib.yangtypes import TypedListType
from pyangbind.lib.yangtypes import YANGBool
from pyangbind.lib.yangtypes import YANGListType
from pyangbind.lib.yangtypes import YANGDynClass
from pyangbind.lib.yangtypes import ReferenceType
from pyangbind.lib.base import PybindBase
from collections import OrderedDict
from decimal import Decimal
from bitarray import bitarray
import six

# PY3 support of some PY2 keywords (needs improved)
if six.PY3:
    import builtins as __builtin__

    long = int
elif six.PY2:
    import __builtin__


class state(PybindBase):
    """
  This class was auto-generated by the PythonClass plugin for PYANG
  from YANG module openconfig-network-instance - based on the path /network-instances/network-instance/afts/aft/entries/entry/state. Each member element of
  the container is represented as a class variable - with a specific
  YANG type.

  YANG Description: Operational state parameters relating to the forwarding
entry
  """
    __slots__ = (
        "_path_helper",
        "_extmethods",
        "__index",
        "__packets_forwarded",
        "__octets_forwarded",
    )

    _yang_name = "state"

    _pybind_generated_by = "container"

    def __init__(self, *args, **kwargs):

        self._path_helper = False

        self._extmethods = False
        self.__index = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="index",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="uint64",
            is_config=False,
        )
        self.__packets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="packets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )
        self.__octets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="octets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )

        load = kwargs.pop("load", None)
        if args:
            if len(args) > 1:
                raise TypeError("cannot create a YANG container with >1 argument")
            all_attr = True
            for e in self._pyangbind_elements:
                if not hasattr(args[0], e):
                    all_attr = False
                    break
            if not all_attr:
                raise ValueError("Supplied object did not have the correct attributes")
            for e in self._pyangbind_elements:
                nobj = getattr(args[0], e)
                if nobj._changed() is False:
                    continue
                setmethod = getattr(self, "_set_%s" % e)
                if load is None:
                    setmethod(getattr(args[0], e))
                else:
                    setmethod(getattr(args[0], e), load=load)

    def _path(self):
        if hasattr(self, "_parent"):
            return self._parent._path() + [self._yang_name]
        else:
            return [
                "network-instances",
                "network-instance",
                "afts",
                "aft",
                "entries",
                "entry",
                "state",
            ]

    def _get_index(self):
        """
    Getter method for index, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/index (uint64)

    YANG Description: A unique index referring to the AFT entry
    """
        return self.__index

    def _set_index(self, v, load=False):
        """
    Setter method for index, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/index (uint64)
    If this variable is read-only (config: false) in the
    source YANG file, then _set_index is considered as a private
    method. Backends looking to populate this variable should
    do so via calling thisObj._set_index() directly.

    YANG Description: A unique index referring to the AFT entry
    """
        if hasattr(v, "_utype"):
            v = v._utype(v)
        try:
            t = YANGDynClass(
                v,
                base=RestrictedClassType(
                    base_type=long,
                    restriction_dict={"range": ["0..18446744073709551615"]},
                    int_size=64,
                ),
                is_leaf=True,
                yang_name="index",
                parent=self,
                path_helper=self._path_helper,
                extmethods=self._extmethods,
                register_paths=True,
                namespace="http://openconfig.net/yang/network-instance",
                defining_module="openconfig-network-instance",
                yang_type="uint64",
                is_config=False,
            )
        except (TypeError, ValueError):
            raise ValueError(
                {
                    "error-string": """index must be of a type compatible with uint64""",
                    "defined-type": "uint64",
                    "generated-type": """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range':  ['0..18446744073709551615']}, int_size=64), is_leaf=True, yang_name="index", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='uint64', is_config=False)""",
                }
            )

        self.__index = t
        if hasattr(self, "_set"):
            self._set()

    def _unset_index(self):
        self.__index = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="index",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="uint64",
            is_config=False,
        )

    def _get_packets_forwarded(self):
        """
    Getter method for packets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/packets_forwarded (yang:counter64)

    YANG Description: The number of packets which have matched, and been forwarded,
based on the AFT entry.
    """
        return self.__packets_forwarded

    def _set_packets_forwarded(self, v, load=False):
        """
    Setter method for packets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/packets_forwarded (yang:counter64)
    If this variable is read-only (config: false) in the
    source YANG file, then _set_packets_forwarded is considered as a private
    method. Backends looking to populate this variable should
    do so via calling thisObj._set_packets_forwarded() directly.

    YANG Description: The number of packets which have matched, and been forwarded,
based on the AFT entry.
    """
        if hasattr(v, "_utype"):
            v = v._utype(v)
        try:
            t = YANGDynClass(
                v,
                base=RestrictedClassType(
                    base_type=long,
                    restriction_dict={"range": ["0..18446744073709551615"]},
                    int_size=64,
                ),
                is_leaf=True,
                yang_name="packets-forwarded",
                parent=self,
                path_helper=self._path_helper,
                extmethods=self._extmethods,
                register_paths=True,
                namespace="http://openconfig.net/yang/network-instance",
                defining_module="openconfig-network-instance",
                yang_type="yang:counter64",
                is_config=False,
            )
        except (TypeError, ValueError):
            raise ValueError(
                {
                    "error-string": """packets_forwarded must be of a type compatible with yang:counter64""",
                    "defined-type": "yang:counter64",
                    "generated-type": """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range':  ['0..18446744073709551615']}, int_size=64), is_leaf=True, yang_name="packets-forwarded", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='yang:counter64', is_config=False)""",
                }
            )

        self.__packets_forwarded = t
        if hasattr(self, "_set"):
            self._set()

    def _unset_packets_forwarded(self):
        self.__packets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="packets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )

    def _get_octets_forwarded(self):
        """
    Getter method for octets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/octets_forwarded (yang:counter64)

    YANG Description: The number of octets which have matched, and been forwarded,
based on the AFT entry
    """
        return self.__octets_forwarded

    def _set_octets_forwarded(self, v, load=False):
        """
    Setter method for octets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/octets_forwarded (yang:counter64)
    If this variable is read-only (config: false) in the
    source YANG file, then _set_octets_forwarded is considered as a private
    method. Backends looking to populate this variable should
    do so via calling thisObj._set_octets_forwarded() directly.

    YANG Description: The number of octets which have matched, and been forwarded,
based on the AFT entry
    """
        if hasattr(v, "_utype"):
            v = v._utype(v)
        try:
            t = YANGDynClass(
                v,
                base=RestrictedClassType(
                    base_type=long,
                    restriction_dict={"range": ["0..18446744073709551615"]},
                    int_size=64,
                ),
                is_leaf=True,
                yang_name="octets-forwarded",
                parent=self,
                path_helper=self._path_helper,
                extmethods=self._extmethods,
                register_paths=True,
                namespace="http://openconfig.net/yang/network-instance",
                defining_module="openconfig-network-instance",
                yang_type="yang:counter64",
                is_config=False,
            )
        except (TypeError, ValueError):
            raise ValueError(
                {
                    "error-string": """octets_forwarded must be of a type compatible with yang:counter64""",
                    "defined-type": "yang:counter64",
                    "generated-type": """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range':  ['0..18446744073709551615']}, int_size=64), is_leaf=True, yang_name="octets-forwarded", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='yang:counter64', is_config=False)""",
                }
            )

        self.__octets_forwarded = t
        if hasattr(self, "_set"):
            self._set()

    def _unset_octets_forwarded(self):
        self.__octets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="octets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )

    index = __builtin__.property(_get_index)
    packets_forwarded = __builtin__.property(_get_packets_forwarded)
    octets_forwarded = __builtin__.property(_get_octets_forwarded)

    _pyangbind_elements = OrderedDict(
        [
            ("index", index),
            ("packets_forwarded", packets_forwarded),
            ("octets_forwarded", octets_forwarded),
        ]
    )


class state(PybindBase):
    """
  This class was auto-generated by the PythonClass plugin for PYANG
  from YANG module openconfig-network-instance-l2 - based on the path /network-instances/network-instance/afts/aft/entries/entry/state. Each member element of
  the container is represented as a class variable - with a specific
  YANG type.

  YANG Description: Operational state parameters relating to the forwarding
entry
  """
    __slots__ = (
        "_path_helper",
        "_extmethods",
        "__index",
        "__packets_forwarded",
        "__octets_forwarded",
    )

    _yang_name = "state"

    _pybind_generated_by = "container"

    def __init__(self, *args, **kwargs):

        self._path_helper = False

        self._extmethods = False
        self.__index = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="index",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="uint64",
            is_config=False,
        )
        self.__packets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="packets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )
        self.__octets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="octets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )

        load = kwargs.pop("load", None)
        if args:
            if len(args) > 1:
                raise TypeError("cannot create a YANG container with >1 argument")
            all_attr = True
            for e in self._pyangbind_elements:
                if not hasattr(args[0], e):
                    all_attr = False
                    break
            if not all_attr:
                raise ValueError("Supplied object did not have the correct attributes")
            for e in self._pyangbind_elements:
                nobj = getattr(args[0], e)
                if nobj._changed() is False:
                    continue
                setmethod = getattr(self, "_set_%s" % e)
                if load is None:
                    setmethod(getattr(args[0], e))
                else:
                    setmethod(getattr(args[0], e), load=load)

    def _path(self):
        if hasattr(self, "_parent"):
            return self._parent._path() + [self._yang_name]
        else:
            return [
                "network-instances",
                "network-instance",
                "afts",
                "aft",
                "entries",
                "entry",
                "state",
            ]

    def _get_index(self):
        """
    Getter method for index, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/index (uint64)

    YANG Description: A unique index referring to the AFT entry
    """
        return self.__index

    def _set_index(self, v, load=False):
        """
    Setter method for index, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/index (uint64)
    If this variable is read-only (config: false) in the
    source YANG file, then _set_index is considered as a private
    method. Backends looking to populate this variable should
    do so via calling thisObj._set_index() directly.

    YANG Description: A unique index referring to the AFT entry
    """
        if hasattr(v, "_utype"):
            v = v._utype(v)
        try:
            t = YANGDynClass(
                v,
                base=RestrictedClassType(
                    base_type=long,
                    restriction_dict={"range": ["0..18446744073709551615"]},
                    int_size=64,
                ),
                is_leaf=True,
                yang_name="index",
                parent=self,
                path_helper=self._path_helper,
                extmethods=self._extmethods,
                register_paths=True,
                namespace="http://openconfig.net/yang/network-instance",
                defining_module="openconfig-network-instance",
                yang_type="uint64",
                is_config=False,
            )
        except (TypeError, ValueError):
            raise ValueError(
                {
                    "error-string": """index must be of a type compatible with uint64""",
                    "defined-type": "uint64",
                    "generated-type": """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range':  ['0..18446744073709551615']}, int_size=64), is_leaf=True, yang_name="index", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='uint64', is_config=False)""",
                }
            )

        self.__index = t
        if hasattr(self, "_set"):
            self._set()

    def _unset_index(self):
        self.__index = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="index",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="uint64",
            is_config=False,
        )

    def _get_packets_forwarded(self):
        """
    Getter method for packets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/packets_forwarded (yang:counter64)

    YANG Description: The number of packets which have matched, and been forwarded,
based on the AFT entry.
    """
        return self.__packets_forwarded

    def _set_packets_forwarded(self, v, load=False):
        """
    Setter method for packets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/packets_forwarded (yang:counter64)
    If this variable is read-only (config: false) in the
    source YANG file, then _set_packets_forwarded is considered as a private
    method. Backends looking to populate this variable should
    do so via calling thisObj._set_packets_forwarded() directly.

    YANG Description: The number of packets which have matched, and been forwarded,
based on the AFT entry.
    """
        if hasattr(v, "_utype"):
            v = v._utype(v)
        try:
            t = YANGDynClass(
                v,
                base=RestrictedClassType(
                    base_type=long,
                    restriction_dict={"range": ["0..18446744073709551615"]},
                    int_size=64,
                ),
                is_leaf=True,
                yang_name="packets-forwarded",
                parent=self,
                path_helper=self._path_helper,
                extmethods=self._extmethods,
                register_paths=True,
                namespace="http://openconfig.net/yang/network-instance",
                defining_module="openconfig-network-instance",
                yang_type="yang:counter64",
                is_config=False,
            )
        except (TypeError, ValueError):
            raise ValueError(
                {
                    "error-string": """packets_forwarded must be of a type compatible with yang:counter64""",
                    "defined-type": "yang:counter64",
                    "generated-type": """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range':  ['0..18446744073709551615']}, int_size=64), is_leaf=True, yang_name="packets-forwarded", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='yang:counter64', is_config=False)""",
                }
            )

        self.__packets_forwarded = t
        if hasattr(self, "_set"):
            self._set()

    def _unset_packets_forwarded(self):
        self.__packets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="packets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )

    def _get_octets_forwarded(self):
        """
    Getter method for octets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/octets_forwarded (yang:counter64)

    YANG Description: The number of octets which have matched, and been forwarded,
based on the AFT entry
    """
        return self.__octets_forwarded

    def _set_octets_forwarded(self, v, load=False):
        """
    Setter method for octets_forwarded, mapped from YANG variable /network_instances/network_instance/afts/aft/entries/entry/state/octets_forwarded (yang:counter64)
    If this variable is read-only (config: false) in the
    source YANG file, then _set_octets_forwarded is considered as a private
    method. Backends looking to populate this variable should
    do so via calling thisObj._set_octets_forwarded() directly.

    YANG Description: The number of octets which have matched, and been forwarded,
based on the AFT entry
    """
        if hasattr(v, "_utype"):
            v = v._utype(v)
        try:
            t = YANGDynClass(
                v,
                base=RestrictedClassType(
                    base_type=long,
                    restriction_dict={"range": ["0..18446744073709551615"]},
                    int_size=64,
                ),
                is_leaf=True,
                yang_name="octets-forwarded",
                parent=self,
                path_helper=self._path_helper,
                extmethods=self._extmethods,
                register_paths=True,
                namespace="http://openconfig.net/yang/network-instance",
                defining_module="openconfig-network-instance",
                yang_type="yang:counter64",
                is_config=False,
            )
        except (TypeError, ValueError):
            raise ValueError(
                {
                    "error-string": """octets_forwarded must be of a type compatible with yang:counter64""",
                    "defined-type": "yang:counter64",
                    "generated-type": """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range':  ['0..18446744073709551615']}, int_size=64), is_leaf=True, yang_name="octets-forwarded", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='yang:counter64', is_config=False)""",
                }
            )

        self.__octets_forwarded = t
        if hasattr(self, "_set"):
            self._set()

    def _unset_octets_forwarded(self):
        self.__octets_forwarded = YANGDynClass(
            base=RestrictedClassType(
                base_type=long,
                restriction_dict={"range": ["0..18446744073709551615"]},
                int_size=64,
            ),
            is_leaf=True,
            yang_name="octets-forwarded",
            parent=self,
            path_helper=self._path_helper,
            extmethods=self._extmethods,
            register_paths=True,
            namespace="http://openconfig.net/yang/network-instance",
            defining_module="openconfig-network-instance",
            yang_type="yang:counter64",
            is_config=False,
        )

    index = __builtin__.property(_get_index)
    packets_forwarded = __builtin__.property(_get_packets_forwarded)
    octets_forwarded = __builtin__.property(_get_octets_forwarded)

    _pyangbind_elements = OrderedDict(
        [
            ("index", index),
            ("packets_forwarded", packets_forwarded),
            ("octets_forwarded", octets_forwarded),
        ]
    )
