Exemplo n.º 1
0
def get(key):
    """
    API:

    GET:

    Retrun: {
        arr: [
            tbl_interface
            ]
            },
            ...
            ...
        ],
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',  # err_code: 0
        'interface is not exist',  # err_code: 1
    ]

    obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''}
    if key == '' or key == 'all':
        arr = vcmd.get_arr('cdbctl read/cdb/interface')

        if arr:
            for item in arr:
                item['sort_name'] = portMap.Mapping(item['key'])
                item['full_name'] = portMap.Mapping(item['key'], is_sort=False)
            obj['arr'] = arr
        else:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = _err_reason[1]
    else:
        arr = vcmd.get_lines('cdbctl read/cdb/interface/%s' % key)
        if arr[0].find('%') >= 0:
            for item in arr:
                item['sort_name'] = portMap.Mapping(item['key'])
                item['full_name'] = portMap.Mapping(item['key'], is_sort=False)
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = arr
        else:
            arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key)
            if arr:
                for item in arr:
                    item['sort_name'] = portMap.Mapping(item['key'])
                    item['full_name'] = portMap.Mapping(item['key'],
                                                        is_sort=False)
                obj['arr'] = arr
            else:
                obj['error'] = True
                obj['err_code'] = 1
                obj['err_reason'] = _err_reason[1]

    return obj
Exemplo n.º 2
0
def dot1x_load_dot1x_port_get(key):
    """
    API:

    GET:

    Retrun: {
        arr: [
            tbl_interface
            ]
            },
            ...
            ...
        ],
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',                    # err_code: 0
        'interface is not exist',         # err_code: 1
    ]

    obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''}

    if key == '' or key == 'all':
        arr = vcmd.get_arr('cdbctl read/cdb/l2/dot1x_port/')

        if arr:
            # pre-process for front-web easy display
            for entry in arr:
                if entry['guest_vlan'] == '0':
                    entry['guest_vlan'] = 'none'

                if entry['max_user'] == '0':
                    entry['max_user'] = '******'
            obj['arr'] = arr
#        else:
#            obj['error'] = True
#            obj['err_code'] = 1
#            obj['err_reason'] = _err_reason[1]
    else:
        arr = vcmd.get_lines('cdbctl read/cdb/l2/dot1x_port/%s' % key)
        if arr[0].find('%') >= 0:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = arr
        else:
            arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key)
            if arr:
                obj['arr'] = arr
            else:
                obj['error'] = True
                obj['err_code'] = 1
                obj['err_reason'] = _err_reason[1]

    return obj
Exemplo n.º 3
0
def get():
    """
    API:

    GET:

    Retrun: {
        arr: {[
            ddos_prevent
            ]
            },
            ...
            ...
        ],
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',                    # err_code: 0
        'iptables prevent is not exist',         # err_code: 1
    ]

    obj = {'arr': {}, 'error': False, 'err_code': 0, 'err_reason': ''}

    vcmd.execute('cdbctl update/cdb/sys/iptables_prevent/pkt_statistic_update/1')
    tmp = vcmd.get_lines('cdbctl read/cdb/sys/iptables_prevent')
    if tmp:
        prevent_info = tmp[0]
        obj['arr'] = vcmd._line_to_obj_simple(prevent_info)
        #print obj['arr']
    else:
        obj['error'] = True
        obj['err_code'] = 1
        obj['err_reason'] = _err_reason[1]
    return obj
Exemplo n.º 4
0
def get(key):
    """
    API:

    GET:

    Retrun: {
        if_statistic_arr: [
            {
                ifidx: int,
                octets_rcv_rate: int,
                pkts_rcv_rate: int,
                octets_send_rate: int,
                pkts_send_rate: int,
                octets_rcv: int,
                pkts_rcv: int,
                uc_pkts_rcv: int,
                brdc_pkts_rcv: int,
                mc_pkts_rcv: int,
                oam_pkts_rcv: int,
                undersize_pkts: int,
                oversize_pkts: int,
                mac_rcv_error: int,
                bad_crc: int,
                frame_error: int,
                drop_events: int,
                pause_rcv: int,
                octets_send: int,
                pkts_send: int,
                uc_pkts_send: int,
                brdc_pkts_send: int,
                mc_pkts_send: int,
                oam_pkts_send: int,
                underruns: int,
                mac_transmit_err: int,
                pause_send: int,
                fcs_pkts_rcv: int,
                fcs_octets_rcv: int,
                fcs_pkts_send: int,
                fcs_octets_send: int,
                fragments_pkts: int,
                bad_pkts_rcv: int,
                bad_octets_rcv: int,
                ifname: string
            },
            ...
            ...
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',  # err_code: 0
        'interface statistic is not exist',  # err_code: 1
    ]

    obj = {
        'if_statistic_arr': [],
        'error': False,
        'err_code': 0,
        'err_reason': ''
    }

    arr_if = vcmd.get_arr('cdbctl read/cdb/interface')

    if key == '' or key == 'all':
        arr = vcmd.get_arr('cdbctl read/cdb/sys/port_stats')
        if arr:
            for i in arr:
                tmp = {}
                tmp['ifidx'] = i.get('key')
                if arr_if:
                    for j in arr_if:
                        if j.get('ifindex') == i.get('key'):
                            tmp['ifname'] = j.get('key')
                            tmp['sort_name'] = portMap.Mapping(tmp['ifname'])
                            tmp['full_name'] = portMap.Mapping(tmp['ifname'],
                                                               is_sort=False)
                            break
                else:
                    tmp['ifname'] = ''

                if j.get('ifg_stats_en') == "1":
                    octets_rcv = str(
                        int(i.get('octets_rcv')) + int(i.get('pkts_rcv')) * 20)
                    tmp['octets_rcv'] = octets_rcv
                else:
                    tmp['octets_rcv'] = i.get('octets_rcv')

                tmp['pkts_rcv'] = i.get('pkts_rcv')
                tmp['uc_pkts_rcv'] = i.get('uc_pkts_rcv')
                tmp['brdc_pkts_rcv'] = i.get('brdc_pkts_rcv')
                tmp['mc_pkts_rcv'] = i.get('mc_pkts_rcv')
                tmp['oam_pkts_rcv'] = i.get('oam_pkts_rcv')
                tmp['undersize_pkts'] = i.get('undersize_pkts')
                tmp['oversize_pkts'] = i.get('oversize_pkts')
                tmp['mac_rcv_error'] = i.get('mac_rcv_error')
                tmp['bad_crc'] = i.get('bad_crc')
                tmp['frame_error'] = i.get('frame_error')
                tmp['drop_events'] = i.get('drop_events')
                tmp['pause_rcv'] = i.get('pause_rcv')

                if j.get('ifg_stats_en') == "1":
                    octets_send = str(
                        int(i.get('octets_send')) +
                        int(i.get('pkts_send')) * 20)
                    tmp['octets_send'] = octets_send
                else:
                    tmp['octets_send'] = i.get('octets_send')

                tmp['pkts_send'] = i.get('pkts_send')
                tmp['uc_pkts_send'] = i.get('uc_pkts_send')
                tmp['brdc_pkts_send'] = i.get('brdc_pkts_send')
                tmp['mc_pkts_send'] = i.get('mc_pkts_send')
                tmp['oam_pkts_send'] = i.get('oam_pkts_send')
                tmp['underruns'] = i.get('underruns')
                tmp['mac_transmit_err'] = i.get('mac_transmit_err')
                tmp['pause_send'] = i.get('pause_send')
                tmp['fcs_pkts_rcv'] = i.get('fcs_pkts_rcv')
                tmp['fcs_octets_rcv'] = i.get('fcs_octets_rcv')
                tmp['fcs_pkts_send'] = i.get('fcs_pkts_send')
                tmp['fcs_octets_send'] = i.get('fcs_octets_send')
                tmp['fragments_pkts'] = i.get('fragments_pkts')
                tmp['bad_pkts_rcv'] = i.get('bad_pkts_rcv')
                tmp['bad_octets_rcv'] = i.get('bad_octets_rcv')
                if arr_if:
                    for j in arr_if:
                        if j.get('ifindex') == i.get('key'):
                            tmp['ifname'] = j.get('key')
                            tmp['sort_name'] = portMap.Mapping(tmp['ifname'])
                            tmp['full_name'] = portMap.Mapping(tmp['ifname'],
                                                               is_sort=False)
                            break
                else:
                    tmp['ifname'] = ''

                arr_rate = vcmd.get_arr('cdbctl read/cdb/sys/port_stats_rate')
                if arr_rate:
                    for j in arr_rate:
                        if j.get('key') == i.get('key'):
                            tmp['octets_rcv_rate'] = j.get('octets_rcv_rate')
                            tmp['pkts_rcv_rate'] = j.get('pkts_rcv_rate')
                            tmp['octets_send_rate'] = j.get('octets_send_rate')
                            tmp['pkts_send_rate'] = j.get('pkts_send_rate')
                        break
                else:
                    tmp['octets_rcv_rate'] = 0
                    tmp['pkts_rcv_rate'] = 0
                    tmp['octets_send_rate'] = 0
                    tmp['pkts_send_rate'] = 0

                obj['if_statistic_arr'].append(tmp)

        else:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = _err_reason[1]
    else:
        arr = vcmd.get_lines('cdbctl read/cdb/sys/port_stats/%s' % key)
        status, lines = vcmd.get_status_lines()
        if arr[0].find('%') >= 0:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = arr
        else:
            arr = vcmd.get_arr('cdbctl read/cdb/sys/port_stats/%s' % key)

            if arr:
                for i in arr:
                    tmp = {}
                    tmp['ifidx'] = i.get('key')
                    #tmp['octets_rcv_rate'] = i.get('octets_rcv_rate')
                    #tmp['pkts_rcv_rate'] = i.get('pkts_rcv_rate')
                    #tmp['octets_send_rate'] = i.get('octets_send_rate')
                    #tmp['pkts_send_rate'] = i.get('pkts_send_rate')
                    tmp['octets_rcv'] = i.get('octets_rcv')
                    tmp['pkts_rcv'] = i.get('pkts_rcv')
                    tmp['uc_pkts_rcv'] = i.get('uc_pkts_rcv')
                    tmp['brdc_pkts_rcv'] = i.get('brdc_pkts_rcv')
                    tmp['mc_pkts_rcv'] = i.get('mc_pkts_rcv')
                    tmp['oam_pkts_rcv'] = i.get('oam_pkts_rcv')
                    tmp['undersize_pkts'] = i.get('undersize_pkts')
                    tmp['oversize_pkts'] = i.get('oversize_pkts')
                    tmp['mac_rcv_error'] = i.get('mac_rcv_error')
                    tmp['bad_crc'] = i.get('bad_crc')
                    tmp['frame_error'] = i.get('frame_error')
                    tmp['drop_events'] = i.get('drop_events')
                    tmp['pause_rcv'] = i.get('pause_rcv')
                    tmp['octets_send'] = i.get('octets_send')
                    tmp['pkts_send'] = i.get('pkts_send')
                    tmp['uc_pkts_send'] = i.get('uc_pkts_send')
                    tmp['brdc_pkts_send'] = i.get('brdc_pkts_send')
                    tmp['mc_pkts_send'] = i.get('mc_pkts_send')
                    tmp['oam_pkts_send'] = i.get('oam_pkts_send')
                    tmp['underruns'] = i.get('underruns')
                    tmp['mac_transmit_err'] = i.get('mac_transmit_err')
                    tmp['pause_send'] = i.get('pause_send')
                    tmp['fcs_pkts_rcv'] = i.get('fcs_pkts_rcv')
                    tmp['fcs_octets_rcv'] = i.get('fcs_octets_rcv')
                    tmp['fcs_pkts_send'] = i.get('fcs_pkts_send')
                    tmp['fcs_octets_send'] = i.get('fcs_octets_send')
                    tmp['fragments_pkts'] = i.get('fragments_pkts')
                    tmp['bad_pkts_rcv'] = i.get('bad_pkts_rcv')
                    tmp['bad_octets_rcv'] = i.get('bad_octets_rcv')
                    if arr_if:
                        for j in arr_if:
                            if j.get('ifindex') == i.get('key'):
                                tmp['ifname'] = j.get('key')
                                tmp['sort_name'] = portMap.Mapping(
                                    tmp['ifname'])
                                tmp['full_name'] = portMap.Mapping(
                                    tmp['ifname'], is_sort=False)
                                break
                        else:
                            tmp['ifname'] = ''

                    arr_rate = vcmd.get_arr(
                        'cdbctl read/cdb/sys/port_stats_rate/%s' % key)
                    if arr_rate:
                        for j in arr_rate:
                            if j.get('key') == j.get('key'):
                                tmp['octets_rcv_rate'] = j.get(
                                    'octets_rcv_rate')
                                tmp['pkts_rcv_rate'] = j.get('pkts_rcv_rate')
                                tmp['octets_send_rate'] = j.get(
                                    'octets_send_rate')
                                tmp['pkts_send_rate'] = j.get('pkts_send_rate')
                            break
                    else:
                        tmp['octets_rcv_rate'] = 0
                        tmp['pkts_rcv_rate'] = 0
                        tmp['octets_send_rate'] = 0
                        tmp['pkts_send_rate'] = 0
                    obj['if_statistic_arr'].append(tmp)
            else:
                obj['error'] = True
                obj['err_code'] = 1
                obj['err_reason'] = _err_reason[1]

    return obj
Exemplo n.º 5
0
def get(key):
    """
    API:

    GET:

    Retrun: {
        arr: [
            tbl_interface
            ]
            },
            ...
            ...
        ],
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',  # err_code: 0
        'interface is not exist',  # err_code: 1
    ]

    obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''}

    if key == '' or key == 'all':
        arr = vcmd.get_arr('cdbctl read/cdb/interface')
        if arr:
            # process split port, assert a 'split_type' field
            for item in arr:

                if item['key'].startswith('eth-'):
                    item['split_type'] = 'splited' if (
                        item['key'].find('_') != -1) else 'not_split'
                else:
                    item['split_type'] = 'not_support'

                if item['brgif'] and item['brgif']['allowed_vlan']:

                    # change "all5-10" to 'ALL', if exist keyword 'all', we ignore other when display
                    item['brgif']['allowed_vlan'] = 'ALL' if (
                        item['brgif']['allowed_vlan'].find('all')
                        == 0) else item['brgif']['allowed_vlan']

                item['sort_name'] = portMap.Mapping(item['key'])
                item['full_name'] = portMap.Mapping(item['key'], is_sort=False)
                item['svlan_tpid_mode'] = '0x%x' % int(item['svlan_tpid'])
            # process split port end

            obj['arr'] = arr
        else:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = _err_reason[1]
    else:
        arr = vcmd.get_lines('cdbctl read/cdb/interface/%s' % key)
        if arr[0].find('%') >= 0:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = arr
        else:
            arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key)
            if arr:
                obj['arr'] = arr
            else:
                obj['error'] = True
                obj['err_code'] = 1
                obj['err_reason'] = _err_reason[1]

    return obj
Exemplo n.º 6
0
def ipv4_port_load_l3_port_get(key):
    """
    API:

    GET:

    Retrun: {
        arr: [
            tbl_interface
            ]
            },
            ...
            ...
        ],
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',  # err_code: 0
        'interface is not exist',  # err_code: 1
    ]

    obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''}
    entry = []

    if key == '' or key == 'all':
        arr = vcmd.get_arr('cdbctl read/cdb/l3/route_if/')

        if arr:
            for i in range(len(arr)):
                ipv4 = arr[i].get('ifc_ipv4')

                if (isinstance(ipv4, list)):

                    for item in ipv4:
                        # Add option web need
                        item['name'] = arr[i].get('key')
                        item['ip_redirects_en'] = arr[i].get('ip_redirects_en')
                        item['unicast_rpf_en'] = arr[i].get('unicast_rpf_en')

                        # ',/key' --> 'key'
                        if item.has_key(',/key'):

                            item['ip'] = item[',/key'].split('#')[0]
                            item['mask'] = item[',/key'].split('#')[1]

                            del item[',/key']

                        if item.has_key('key'):

                            item['ip'] = item['key'].split('#')[0]
                            item['mask'] = item['key'].split('#')[1]

                            del item['key']

                        # append to entry
                        entry.append(item)

                if (isinstance(ipv4, dict)):
                    ipv4['name'] = arr[i].get('key')
                    ipv4['ip_redirects_en'] = arr[i].get('ip_redirects_en')
                    ipv4['unicast_rpf_en'] = arr[i].get('unicast_rpf_en')
                    if (ipv4.has_key('key')):
                        item = ipv4['key'].split('#')
                        ipv4['ip'] = item[0]
                        ipv4['mask'] = item[1]
                    else:
                        ipv4['ip'] = 'N/A'
                        ipv4['mask'] = 'N/A'
                    entry.append(ipv4)

            obj['arr'] = entry

    else:
        arr = vcmd.get_lines('cdbctl read/cdb/l2/dot1x_port/%s' % key)
        if arr[0].find('%') >= 0:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = arr
        else:
            arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key)
            if arr:
                obj['arr'] = arr
            else:
                obj['error'] = True
                obj['err_code'] = 1
                obj['err_reason'] = _err_reason[1]

    return obj
Exemplo n.º 7
0
def get(key):
    """
    API:

    GET:

    Retrun: {
        arr: [
            tbl_interface
            ]
            },
            ...
            ...
        ],
        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',  # err_code: 0
        'interface is not exist',  # err_code: 1
    ]

    obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''}
    if key == '' or key == 'all':
        arr = vcmd.get_arr('cdbctl read/cdb/sys/fiber/')
        if arr:
            newArr = []
            for map in arr:
                m = {}
                for key, value in map.items():
                    if key == 'interface_name':
                        m['interface_name'] = str(value)
                        m['sort_name'] = portMap.Mapping(m['interface_name'])
                        m['full_name'] = portMap.Mapping(m['interface_name'],
                                                         is_sort=False)

                    if key == 'fiber_type_name':
                        m['fiber_type_name'] = str(value)

                    if key == 'name':
                        m['name'] = str(value)

                    if key == 'pn':
                        m['pn'] = str(value)

                    if key == 'sn':
                        m['sn'] = str(value)

                newArr.append(m)
            obj['arr'] = newArr
        else:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = _err_reason[1]
    else:
        arr = vcmd.get_lines('cdbctl read/cdb/sys/fiber/%s' % key)
        if arr[0].find('%') >= 0:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = arr
        else:
            arr = vcmd.get_arr('cdbctl read/cdb/sys/fiber/%s' % key)
            if arr:
                obj['arr'] = arr
            else:
                obj['error'] = True
                obj['err_code'] = 1
                obj['err_reason'] = _err_reason[1]

    return obj
Exemplo n.º 8
0
def ipv4_routing_get(key):
    """
    API:

    GET:

    Retrun: {
        static: [
            route_entry,
            ...
            ],

        connect: [
            route_entry,
            ...
            ],

        ospf: [
            route_entry,
            ...
            ],

        error: bool,
        err_code: int,
        err_reason: string
    }
    """
    _err_reason = [
        '',  # err_code: 0
        'interface is not exist',  # err_code: 1
    ]

    obj = {
        'static': [],
        'connect': [],
        'ospf': [],
        'error': False,
        'err_code': 0,
        'err_reason': ''
    }
    if key == '' or key == 'all':
        arr = vcmd.get_lines('vtysh -c "show ip route"')

        if len(arr) <= 3:
            return obj

        lines = arr[4:]

        if len(arr[0]) > 1:
            lasttmp = {}
            lasttype = ''
            for line in lines:
                tmp = {}
                item = line.split()

                # static routing
                if item and (item[0].find('S') != -1):
                    # For example:  ['S>*', '1.1.1.0/24', '[11/0]', 'via', '2.1.1.1', 'inactive']

                    tmp['selected'] = "Yes" if (
                        item[0].find('>') != -1) else "No"
                    tmp['fib'] = "Yes" if (item[0].find('*') != -1) else "No"

                    tmp['type'] = 'S'
                    tmp['ip'] = item[1]

                    # distance/metric
                    tmp['distance'] = item[2]

                    if len(item) == 7:
                        # black-hole-route
                        tmp['nexthop'] = item[5].strip(',')
                        tmp['active'] = item[6].strip(',')
                    else:
                        # static route
                        tmp['nexthop'] = item[4].strip(',')
                        tmp['active'] = item[5].strip(',')

                    lasttmp = tmp
                    lasttype = 'static'
                    obj['static'].append(copy.deepcopy(tmp))

                    ## just simple handler, may be exist bug
                    # For example:
                    [
                        'S>*', '1.1.1.0/24', '[11/0]', 'via', '2.1.1.1',
                        'inactive'
                    ]
                    ['via', '2.1.1.2', 'inactive']
                # FixME
                #if item and (item[0].find('via') != -1):
                #
                #    #tmp = obj['arr'][-1].copy()
                #    tmp['nexthop'] = item[1].strip(',')
                #    tmp['active'] = item[2]

                #    obj['static'].append(tmp)

                # connect routing
                if item and (item[0].find('C') != -1):
                    # For example:  ['C>*', '2.1.1.0/24', 'is', 'directly', 'connected,', 'eth-0-2']

                    tmp['type'] = 'C'
                    tmp['selected'] = "Yes" if (
                        item[0].find('>') != -1) else "No"
                    tmp['fib'] = "Yes" if (item[0].find('*') != -1) else "No"

                    tmp['ip'] = item[1]
                    tmp['ifname'] = item[5]

                    lasttmp = tmp
                    lasttype = 'connect'
                    obj['connect'].append(copy.deepcopy(tmp))
                # OSPF routing
                if item and (item[0].find('O') != -1):
                    if 'directly' in item:
                        # For example:  "O   1.1.1.0/24 [110/10] is directly connected, eth-0-49/1, 00:03:14"
                        tmp['type'] = 'O'
                        tmp['selected'] = "Yes"
                        tmp['fib'] = "Yes" if (
                            item[0].find('*') != -1) else "No"

                        tmp['ip'] = item[1]

                        tmp['ifname'] = item[6].strip(',')

                        tmp['uptime'] = item[7]

                    else:
                        # For example:  "O>* 2.1.1.0/24 [110/20] via 1.1.1.2, eth-0-49/1, 00:03:0"
                        #                O   109.109.109.109/32 [110/100] via 0.0.0.0, loopback0 onlink, 07:01:19
                        tmp['type'] = 'O'
                        tmp['selected'] = "No"
                        tmp['fib'] = "Yes" if (
                            item[0].find('*') != -1) else "No"
                        tmp['ip'] = item[1]
                        tmp['ifname'] = item[5].strip(',')
                        if item[5].find('loopback') != -1:
                            tmp['uptime'] = item[7]
                        else:
                            tmp['uptime'] = item[6]

                    lasttmp = tmp
                    lasttype = 'ospf'
                    obj['ospf'].append(copy.deepcopy(tmp))

                if item and (item[0].find('via') != -1):
                    tmp = lasttmp
                    tmp['nexthop'] = item[1].strip(',')
                    tmp['active'] = item[2]
                    obj[lasttype].append(copy.deepcopy(tmp))

                if item and (item[1].find('via') != -1):
                    tmp = lasttmp
                    tmp['nexthop'] = item[2].strip(',')
                    tmp['active'] = item[3]
                    obj[lasttype].append(copy.deepcopy(tmp))

        else:
            obj['error'] = True
            obj['err_code'] = 1
            obj['err_reason'] = _err_reason[1]

    return obj