{
    "name"  : "AC不显示终端地址诊断",
    "problems" : {
        "terminal_offline" : {
            "desc"      : "【问题】终端不在线",
            "advice"    : "【建议】请指定一个在线的终端进行诊断"
        },
        "terminal_enter" : {
            "desc"      : "【问题】终端从其他AC漫入",
            "intr"      : "【说明】AC间漫游情况下，漫入终端的IP地址在其他AC上存在，不在漫入AC上显示，无问题",
            "advice"    : "【建议】正常现象，无需处理"
        },
        "ver_no_suport" : {
            "desc"      : "【问题】版本不支持本地转发静态IP",
            "advice"    : "【建议】该版本不能支持学习本地转发的静态IP地址，AC无法显示该终端的IP，若有需求可以升级到B80P3或B9之后版本"
        },
        "arp_agent" : {
            "desc"      : "【问题】ARP代理未学习到表项",
            "advice"    : "【建议】可能ARP代理表象老化或未生成，可尝试通过终端ping网关或通过AC ping终端，之后再查看是否有地址。若一直没有地址，建议升级到B80P3或B9之后版本，或改为动态IP",
            "fix"       : "【尝试修复】ping终端，再查看是否有地址，如果有地址则结束"
        },
        "arp_agent_invalid" : {
            "desc"      : "【问题】ARP代理表项未生效",
            "advice"    : "【建议】请联系锐捷工程师支持"
        },
        "no_address" : {
            "desc"      : "【问题】未从报文中学习到地址",
            "advice"    : "【建议】可尝试通过终端ping网关或通过AC ping终端，之后再查看是否有地址。若一直没有地址，建议改为动态IP，或联系锐捷工程师支持",
            "fix"       : "【尝试修复】ping终端，再查看是否有地址，如果有地址则结束"
        },
        "address_invalid" : {
            "desc"      : "【问题】报文中学习的地址未生效",
            "advice"    : "【建议】请联系锐捷工程师支持"
        },
        "transmit_config" : {
            "desc"      : "【问题】本地转发需配置DHCP-Snooping",
            "advice"    : "【建议】本地转发下需配置DHCP-Snooping才能学习到动态地址，请与售后人员确认"
        },
        "DHCP-Snooping_no_address" : {
            "desc"      : "【问题】DHCP-Snooping未学习到地址",
            "advice"    : "【建议】请联系锐捷工程师支持"
        },
        "DHCP-Snooping_no_VLAN" : {
            "desc"      : "【问题】DHCP-Snooping未学习到对应VLAN的表项",
            "advice"    : "【建议】请联系锐捷工程师支持"
        },
        "DHCP-Snooping_address_invalide" : {
            "desc"      : "【问题】DHCP-Snooping表项学习的地址未生效",
            "advice"    : "【建议】请联系锐捷工程师支持"
        }      
    }
}
---------------------------code-------------------------------
#step 1-------------------------
stamac = precondition('stamac')
staip = precondition('staip')
print(stamac+'stamac')
print(staip+'staip')
getIpMethed = precondition('getIpMethod')
cmd = 'show ac-config client | include ' + stamac
result = cli(cmd)
result = result.split(/\r?\n/)
result.splice(0,7)
if result.length == 2 :
    add_problem('terminal_offline')
    return 'warn'
else : 
    foreach item in result :
        item = item.split(/\s+/)
        displayip = item[1]
        wlanid = item[3]

        if displayip == staip :
            return 'success'
        end
    end
end

#step 2------------------------
result = cli('show stamg sta list')
result = result.split(/\r?\n/)
reg = /[0-9a-z]{4}.[0-9a-z]{4}.[0-9a-z]{4}/
if reg.test(result) :
    result.splice(0,5)
    foreach item in result :
        item = item.split('/s+')
        if item[8] == 2 :
            add_problem('terminal_enter')
            return 'warn'
        end
        vlanid = item[4]
        if displayid == '':
            #前往3.2
            break
        else if displayid != staip :
            #收集信息
            return 'skip'
        end
    end
end

#step 3---------------------
cmd = 'show stamg sta ' + stamac +' ip ipv4'
result = cli(cmd)
reg = /wvlan/
if reg.test(result) :
    ver = 'new'
else :
    ver = 'old'
end

#step 4---------------------
cmd = 'show run | begin wlan-config ' + wlanid
result = cli(cmd)
reg = /tunnel local/
if reg.test(result) :
    trans = 'local'
else :
    trans = 'focus'
end

if getIpMethed == 'static' : 
    if ver == 'old' && trans == 'local' :
        add_problem('ver_no_suport')
        return 'warn'
    else if ver == 'old' && trans == 'focus' :
        #前往5
        step5()
    else if ver == 'new' :
        #前往6
        step6()
    end
else :
    #前往7
    step7()
end

#step 5---------------------
def step5() :
    cmd = 'show proxy_arp | incl ' + stamac
    result = cli(cmd)
    result = result.split('\n+')
    result.splice(0,4)
    foreach item in result :
        item = item.split(/\s+/)
        if item[2] == '' :
            add_problem('arp_agent')
            return 'warn'
        else :
            #终止收集信息
            add_problem('arp_agent_invalid')
            return 'warn'
        end
    end
end

#step 6------------------------
def step6() :
    cmd = 'show wvlan mwlan | incl ' + stamac
    result = cli(cmd)
    result = result.split(/\n+/)
    reg = /[0-9a-z]{4}.[0-9a-z]{4}.[0-9a-z]{4}/
    if reg.test(result) :
        reg = /acwlanid\s+(\d)+/
        foreach item in result :
            match = result.match(reg)
            if wlanid != match[1] :
                #收集信息
                add_problem('no_address')
                return 'warn'
            else :
                add_problem('address_invalid')
                return 'warn'
            end 
        end
    else :
        #收集信息
        add_problem('no_address')
        return 'warn'
    end
end

#step 7------------------------
def step7() :
    result = cli('show run | incl dhcp snooping')
    reg = /ip dhcp snooping/
    if reg.test(result) :
        #前往6
        step6()
    else :
        if ver == 'old' && trans == 'local' :
            add_problem('transmit_config')
            return 'warn'
        else if trans == 'focus' :
            #前往5
            step5()
        else if ver == 'new' :
            #前往6
            step6()
        end
    end
end


#step 8----------------------
def step8() :
    result = cli('show ip dhcp snooping binding')
    reg = /[0-9a-z]{4}.[0-9a-z]{4}.[0-9a-z]{4}/
    if !reg.test(result) :
        #收集信息
        add_problem('DHCP-Snooping_no_address')
        return 'warn'
    end
    result = result.split(/\n+/)
    result.splice(0,4)
    foreach item in result :
        item = item.split(/\s+/)
        if item[5] != vlanid :
            #收集信息
            add_problem('DHCP-Snooping_no_VLAN')
            return 'warn'
        else :
            #收集信息
            add_problem('DHCP-Snooping_address_invalide')
            return 'warn'
        end
    end
end

return 'success'