.. versionchanged:: 2016.3.2
        Return the network device stats for this minion

    .. versionchanged:: 2016.11.4
        Added support for AIX

    CLI Example:

    .. code-block:: bash

        salt '*' status.netdev

def netdev():
    '''
    .. versionchanged:: 2016.3.2
        Return the network device stats for this minion

    .. versionchanged:: 2016.11.4
        Added support for AIX

    CLI Example:

    .. code-block:: bash

        salt '*' status.netdev
    '''
    def linux_netdev():
        '''
        linux specific implementation of netdev
        '''
        ret = {}
        try:
            with salt.utils.files.fopen('/proc/net/dev', 'r') as fp_:
                stats = salt.utils.stringutils.to_unicode(fp_.read())
        except IOError:
            pass
        else:
            for line in stats.splitlines():
                if not line:
                    continue
                if line.find(':') < 0:
                    continue
                comps = line.split()
                # Fix lines like eth0:9999..'
                comps[0] = line.split(':')[0].strip()
                # Support lines both like eth0:999 and eth0: 9999
                comps.insert(1, line.split(':')[1].strip().split()[0])
                ret[comps[0]] = {'iface': comps[0],
                                 'rx_bytes': _number(comps[2]),
                                 'rx_compressed': _number(comps[8]),
                                 'rx_drop': _number(comps[5]),
                                 'rx_errs': _number(comps[4]),
                                 'rx_fifo': _number(comps[6]),
                                 'rx_frame': _number(comps[7]),
                                 'rx_multicast': _number(comps[9]),
                                 'rx_packets': _number(comps[3]),
                                 'tx_bytes': _number(comps[10]),
                                 'tx_carrier': _number(comps[16]),
                                 'tx_colls': _number(comps[15]),
                                 'tx_compressed': _number(comps[17]),
                                 'tx_drop': _number(comps[13]),
                                 'tx_errs': _number(comps[12]),
                                 'tx_fifo': _number(comps[14]),
                                 'tx_packets': _number(comps[11])}
        return ret

    def freebsd_netdev():
        '''
        freebsd specific implementation of netdev
        '''
        _dict_tree = lambda: collections.defaultdict(_dict_tree)
        ret = _dict_tree()
        netstat = __salt__['cmd.run']('netstat -i -n -4 -b -d').splitlines()
        netstat += __salt__['cmd.run']('netstat -i -n -6 -b -d').splitlines()[1:]
        header = netstat[0].split()
        for line in netstat[1:]:
            comps = line.split()
            for i in range(4, 13):  # The columns we want
                ret[comps[0]][comps[2]][comps[3]][header[i]] = _number(comps[i])
        return ret

    def sunos_netdev():
        '''
        sunos specific implementation of netdev
        '''
        ret = {}
        ##NOTE: we cannot use hwaddr_interfaces here, so we grab both ip4 and ip6
        for dev in __grains__['ip4_interfaces'].keys() + __grains__['ip6_interfaces']:
            # fetch device info
            netstat_ipv4 = __salt__['cmd.run']('netstat -i -I {dev} -n -f inet'.format(dev=dev)).splitlines()
            netstat_ipv6 = __salt__['cmd.run']('netstat -i -I {dev} -n -f inet6'.format(dev=dev)).splitlines()

            # prepare data
            netstat_ipv4[0] = netstat_ipv4[0].split()
            netstat_ipv4[1] = netstat_ipv4[1].split()
            netstat_ipv6[0] = netstat_ipv6[0].split()
            netstat_ipv6[1] = netstat_ipv6[1].split()

            # add data
            ret[dev] = {}
            for i in range(len(netstat_ipv4[0])-1):
                if netstat_ipv4[0][i] == 'Name':
                    continue
                if netstat_ipv4[0][i] in ['Address', 'Net/Dest']:
                    ret[dev]['IPv4 {field}'.format(field=netstat_ipv4[0][i])] = netstat_ipv4[1][i]
                else:
                    ret[dev][netstat_ipv4[0][i]] = _number(netstat_ipv4[1][i])
            for i in range(len(netstat_ipv6[0])-1):
                if netstat_ipv6[0][i] == 'Name':
                    continue
                if netstat_ipv6[0][i] in ['Address', 'Net/Dest']:
                    ret[dev]['IPv6 {field}'.format(field=netstat_ipv6[0][i])] = netstat_ipv6[1][i]
                else:
                    ret[dev][netstat_ipv6[0][i]] = _number(netstat_ipv6[1][i])

        return ret

    def aix_netdev():
        '''
        AIX specific implementation of netdev
        '''
        ret = {}
        fields = []
        procn = None
        for dev in __grains__['ip4_interfaces'].keys() + __grains__['ip6_interfaces'].keys():
            # fetch device info
            #root@la68pp002_pub:/opt/salt/lib/python2.7/site-packages/salt/modules# netstat -i -n -I en0 -f inet6
            #Name  Mtu   Network     Address            Ipkts Ierrs    Opkts Oerrs  Coll
            #en0   1500  link#3      e2.eb.32.42.84.c 10029668     0   446490     0     0
            #en0   1500  172.29.128  172.29.149.95    10029668     0   446490     0     0
            #root@la68pp002_pub:/opt/salt/lib/python2.7/site-packages/salt/modules# netstat -i -n -I en0 -f inet6
            #Name  Mtu   Network     Address            Ipkts Ierrs    Opkts Oerrs  Coll
            #en0   1500  link#3      e2.eb.32.42.84.c 10029731     0   446499     0     0

            netstat_ipv4 = __salt__['cmd.run']('netstat -i -n -I {dev} -f inet'.format(dev=dev)).splitlines()
            netstat_ipv6 = __salt__['cmd.run']('netstat -i -n -I {dev} -f inet6'.format(dev=dev)).splitlines()

            # add data
            ret[dev] = []

            for line in netstat_ipv4:
                if line.startswith('Name'):
                    fields = line.split()
                    continue

                comps = line.split()
                if len(comps) < 3:
                    raise CommandExecutionError('Insufficent data returned by command to process \'{0}\''.format(line))

                if comps[2].startswith('link'):
                    continue

                procn = len(ret[dev])
                ret[dev].append({})
                ret[dev][procn]['ipv4'] = {}
                for i in range(1, len(fields)):
                    if len(comps) > i:
                        ret[dev][procn]['ipv4'][fields[i]] = comps[i]

            for line in netstat_ipv6:
                if line.startswith('Name'):
                    fields = line.split()
                    continue

                comps = line.split()
                if len(comps) < 3:
                    raise CommandExecutionError('Insufficent data returned by command to process \'{0}\''.format(line))

                if comps[2].startswith('link'):
                    continue

                procn = len(ret[dev])
                ret[dev].append({})
                ret[dev][procn]['ipv6'] = {}
                for i in range(1, len(fields)):
                    if len(comps) > i:
                        ret[dev][procn]['ipv6'][fields[i]] = comps[i]

        return ret

    # dict that returns a function that does the right thing per platform
    get_version = {
        'Linux': linux_netdev,
        'FreeBSD': freebsd_netdev,
        'SunOS': sunos_netdev,
        'AIX': aix_netdev,
    }

    errmsg = 'This method is unsupported on the current operating system!'
    return get_version.get(__grains__['kernel'], lambda: errmsg)()