剪辑规则RHS中的变量绑定检查

时间:2015-03-31 07:12:19

标签: clips

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?

1 个答案:

答案 0 :(得分:0)

没有确定变量是否已绑定的功能。或条件元素是通过为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)))