2015-03-31 2 views
0
checkIntfIntVlanMemberConfigRule = """ 
    (defrule checkSubIntfIntVlanMemberConfigRule 
    (checkIntf (intf ?intf)) 
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan   ?intVlan)) 
    (or (not (VlanStatus (vlan ?intVlan) (intf ?intf))) 
    ?f <- (VlanStatus (vlan ?intVlan) (intf ?intf))) 
    => 
    (if (isbound ?f) then (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) (return 0)) 
    (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf) 
    )""" 

В приведенном выше правиле клипов, какова эквивалентная функция сборки клипов для (isbound? F)? В общем, есть ли какая-либо функция построения для проверки в RHS, если переменная была связана с LHS?переменная связанная проверка в правиле клипов RHS

ответ

0

Нет никакой функции для определения того, была ли привязана переменная. Или условный элемент реализуется путем создания правил для каждого условного элемента, содержащегося с или, поэтому ваше существующее правило преобразуется в следующее:

(defrule checkSubIntfIntVlanMemberConfigRule-1 
    (checkIntf (intf ?intf)) 
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan)) 
    (not (VlanStatus (vlan ?intVlan) (intf ?intf)) 
    => 
    (if (isbound ?f) then (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) (return 0)) 
    (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf) 
    ) 

(defrule checkSubIntfIntVlanMemberConfigRule-2 
    (checkIntf (intf ?intf)) 
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan)) 
    ?f <- (VlanStatus (vlan ?intVlan) (intf ?intf)) 
    => 
    (if (isbound ?f) then (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) (return 0)) 
    (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf) 
    ) 

Вы должны реализовать это как два отдельных правила так РИТ для каждого может быть разными:

(defrule checkSubIntfIntVlanMemberConfigRule-1 
    (checkIntf (intf ?intf)) 
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan)) 
    (not (VlanStatus (vlan ?intVlan) (intf ?intf))) 
    => 
    (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf) 
    ) 

(defrule checkSubIntfIntVlanMemberConfigRule-2 
    (checkIntf (intf ?intf)) 
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan)) 
    ?f <- (VlanStatus (vlan ?intVlan) (intf ?intf)) 
    => 
    (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) 
    ) 

в качестве альтернативы вы можете проверить существование факта из RHS правила с помощью функций запроса фактов:

(defrule checkSubIntfIntVlanMemberConfigRule 
    (checkIntf (intf ?intf)) 
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan)) 
    (VlanStatus (vlan ?intVlan) (intf ?intf)) 
    => 
    (if (any-factp ((?f VlanStatus)) (and (eq ?f:vlan ?intVlan) (eq ?f:intf ?intf))) 
     then 
     (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) 
     else 
    (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf))) 
+0

Спасибо! последнее решение работает для меня. Я пытался сократить количество правил, поэтому разделение RHS не помогает. Я чувствую, что api для проверки на соответствие var помогает проверять в RHS, какой субфакт/подкласс или CE был поражен в LHS. Там могут быть и другие случаи, когда это помогает. Еще раз спасибо. – Ramachandran

Смежные вопросы