{
    "name"  : "多链路负载均衡配置",
    "problems" : {
        "close" : {
            "desc"      : "【问题】mllb未开启",
            "advice"    : "【建议】当前多出口环境，建议开启多链路负载均衡"
        },
        "notBandwidth" : {
            "desc"      : "【问题】mllb开启了，但不是bandwidth模式",
            "advice"    : "【建议】mllb多链路负载均衡，基于负载的方式可能会导致游戏与网银的掉线，建议采用带宽的策略"
        },
        "mllbError" : {
            "desc"      : "【问题】mllb负载均衡选路流量比值不是很均衡",
            "advice"    : "【建议】当前均衡效果是在保证良好网络体验下进行均衡，如果当前网络体验较好，建议保持现状，否则请联系客服进行调整"
        }
    }
}

---------------------------code-------------------------------
result = get_share_value('result')
if result == 'break' || result == 'needless' :
    return 'skip'
end

reg = /multi-link\sload\sbalance\sstate.\senable/
response = cli('show mllb configure')
isOpen = reg.test(response)
if isOpen == false :
    add_problem('close')
    return 'warn'
end

reg = /multi-link\sload\sbalance\spolicy.\sbandwidth/
isBandwidth = reg.test(response)
if isBandwidth == false :
    add_problem('notBandwidth')
    return 'warn'
end

intf_mllb_info = []
wan_int_info = get_share_value('wan_int_info')
rep = /[\r\n]+[a-zA-Z]+\s[\d\/]+\s{2,}.+?\s{2,}\d+/g
response = cli('show mllb statistics')
mllbStatisticLine = response.match(rep)
if !mllbStatisticLine || mllbStatisticLine.length < 2 :
    return 'success'
else :
    foreach mllbStatistic in mllbStatisticLine :
        rep = /([a-zA-Z]+\s[\d\/]+)\s{2,}.+?\s{2,}(\d+)/
        mllbInfo = mllbStatistic.match(rep)
        if mllbInfo != null :
            o = {}
            o['intf'] = mllbInfo[1]
            o['flow'] = mllbInfo[2]
            foreach wan in wan_int_info:
                if wan['intf'] == mllbInfo[1] :
                    o['bandWidth'] = wan['bandWidth']
                    break
                end
            end
            intf_mllb_info.push(o)
        end
    end
end

i = 0
isMllbError = false
length = intf_mllb_info.length
while i < length :
    intf_mllb_A = intf_mllb_info[i]
    bandWidth_A = intf_mllb_A['bandWidth']
    flow_A = intf_mllb_A['flow']
    j = i + 1
    while j < length :
        intf_mllb_B = intf_mllb_info[j]
        bandWidth_B = intf_mllb_B['bandWidth']
        flow_B = intf_mllb_B['flow']
        ratioBandWidth = bandWidth_A / bandWidth_B
        ratioFlow = flow_A / flow_B
        if ratioBandWidth > ratioFlow :
            gapBetween =  ratioBandWidth - ratioFlow
        else :
            gapBetween =  ratioFlow - ratioBandWidth
        end
#       print bandWidth_A
#       print bandWidth_B
#       print flow_A
#       print flow_B
#       print gapBetween
        ratio = gapBetween / ratioBandWidth * 100
#       print ratio
        if ratio > 30 :
            isMllbError = true
            break
        end
        j = j + 1
    end
    if isMllbError == true :
        break
    end
    i = i + 1
end

if isMllbError == true :
    add_problem('mllbError')
    return 'warn'
end

return 'success'



