2015-03-31 31 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)的等效剪輯buildin函數是什麼?一般來說,如果一個變量被綁定在LHS中,那麼是否有任何buildin函數檢查RHS?剪輯規則中的變量綁定檢查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) 
    ) 

你需要實現這個作爲這樣的RHS每個可以在兩個單獨的規則有所不同:

(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並沒有幫助。我覺得var邊界檢查有助於在RHS中檢查LHS中的哪個子/子條款。可能有其他用途,這有助於。再次感謝。 – Ramachandran 2015-04-01 04:25:55