def in_group(group, ptype): if isinstance(ptype, basestring): ptype = ptype.upper() if not PNAMES.has_key(ptype): log_and_raise( 'in_group predicate expects a SEPL atomic type string as the second argument.', ptype) ptype = PNAMES[ptype] pinfo = __valid_principal__(ptype) if pinfo is None: log_and_raise( 'in_group predicate expects a SEPL atomic type as the second argument.', ptype) if pinfo[compile.GROUPABLE_IDX]: if not (isinstance(group, list) or isinstance(group, tuple)): d = compile.group_check(group, pinfo[compile.TYPE_IDX]) d.addCallback(in_group2, ptype, pinfo, group) return AsyncPred(d) elif pinfo[compile.TYPE_IDX] == SW_T: log_and_raise( 'in_group cannot be declared over an unregistered switch group.' ) tinfo = compile.pred_type_info(pinfo[compile.TYPE_IDX]) d = __check_list__(tinfo[compile.CHECK_IDX], group) d.addCallback(in_group_exp, ptype) return AsyncPred(d)
def conn_role(role): if isinstance(role, basestring): role = role.upper() if not ROLES.has_key(role): log_and_raise('conn_role predicate expects a role.', role) role = ROLES[role] d = compile.role_check(role) d.addCallback(conn_role2, role) return AsyncPred(d)
def protocol(*proto): if len(proto) == 1: proto = proto[0] d = compile.proto_check(proto) d.addCallback(protocol2, proto) return AsyncPred(d)
def isConnResponse(): async = AsyncPred(defer.Deferred()) async .d.callback( PyComplexPred(PyLiteral(Flow_expr.CONN_ROLE, [Flow_expr.RESPONSE]))) return async
def isConnRequest(): async = AsyncPred(defer.Deferred()) async .d.callback( PyComplexPred(PyLiteral(Flow_expr.CONN_ROLE, [Flow_expr.REQUEST]))) return async
def udst(user): d = compile.user_check(user) d.addCallback(udst2, user) return AsyncPred(d)
def hdst(host): d = compile.host_check(host) d.addCallback(hdst2, host) return AsyncPred(d)
def dldst(dladdr): d = compile.dladdr_check(dladdr) d.addCallback(dldst2, dladdr) return AsyncPred(d)
def locdst(loc): d = compile.loc_check(loc) d.addCallback(locdst2, loc) return AsyncPred(d)
def subnetdst(subnet): d = compile.subnet_check(subnet) d.addCallback(subnetdst2, subnet) return AsyncPred(d)
def tpdst(tport): d = compile.tport_check(tport) d.addCallback(tpdst2, tport) return AsyncPred(d)
def nwproto(proto): d = compile.nwproto_check(proto) d.addCallback(nwproto2, proto) return AsyncPred(d)
def nwdst(nwaddr): d = compile.nwaddr_check(nwaddr) d.addCallback(nwdst2, nwaddr) return AsyncPred(d)
def dltype(dlt): d = compile.dltype_check(dlt) d.addCallback(dltype2, dlt) return AsyncPred(d)
def hsrc(host): d = compile.host_check(host) d.addCallback(hsrc2, host) return AsyncPred(d)
def func(fn): d = compile.func_check(fn) d.addCallback(func2, fn) return AsyncPred(d)
def dlvlan(vlan): d = compile.dlvlan_check(vlan) d.addCallback(dlvlan2, vlan) return AsyncPred(d)