簡體   English   中英

剪輯規則RHS中的變量邊界檢查

[英]variable bound check in a clips rule RHS

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中綁定?

沒有確定變量是否已綁定的功能。 通過為or包含的每個條件元素創建規則來實現or條件元素,因此您現有的規則將轉換為以下內容:

 (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)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM