本文整理汇总了C++中PolicyRule::getLabel方法的典型用法代码示例。如果您正苦于以下问题:C++ PolicyRule::getLabel方法的具体用法?C++ PolicyRule::getLabel怎么用?C++ PolicyRule::getLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PolicyRule
的用法示例。
在下文中一共展示了PolicyRule::getLabel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::deque<Rule*>::iterator
PolicyCompiler::findMoreGeneralRule::find_more_general_rule(
PolicyRule *rule,
bool check_interface,
const std::deque<Rule*>::iterator &start_here,
const std::deque<Rule*>::iterator &stop_here,
bool reverse)
{
PolicyCompiler *pcomp=dynamic_cast<PolicyCompiler*>(compiler);
if (compiler->debug>=9)
{
cerr << "********* searching for more general rule: -------------\n";
cerr << compiler->debugPrintRule(rule);
cerr << endl;
}
std::deque<Rule*>::iterator j;
for (j=start_here ; j!=stop_here; j++)
{
PolicyRule *r = PolicyRule::cast( *j );
bool intf_cr = false;
if (reverse)
intf_cr = pcomp->checkInterfacesForShadowing( *r , *rule );
else
intf_cr = pcomp->checkInterfacesForShadowing( *rule , *r );
if (! check_interface || intf_cr)
{
bool cr = false;
if (reverse)
cr = pcomp->checkForShadowing( *r , *rule );
else
cr = pcomp->checkForShadowing( *rule , *r );
if ( cr && pcomp->checkForShadowingPlatformSpecific(rule, r))
{
if (compiler->debug>=9)
{
cerr << r->getLabel()
<< ": FOUND more general rule:\n";
cerr << compiler->debugPrintRule(r);
cerr << endl;
}
return j;
} else
{
if (compiler->debug>=9)
cerr << r->getLabel()
<< ": rules do not intersect \n";
continue;
}
}
}
return j;
}
示例2: if
bool PolicyCompiler::DetectShadowingForNonTerminatingRules::processNext()
{
PolicyRule *rule;
rule=getNext(); if (rule==NULL) return false;
tmp_queue.push_back(rule); // to pass it to the next processor, if any
if (rule->isFallback()) return true; // do not check fallback ..
if (rule->isHidden()) return true; // ... and hidden rules
std::deque<Rule*>::iterator i =
find_more_general_rule(rule,
true,
rules_seen_so_far.begin(),
rules_seen_so_far.end(),
true); // <<<<<<< NB!
if (i!=rules_seen_so_far.end())
{
Rule *r = *i;
/*
* find_more_general finds more general _or_ equivalent rule
*/
if (r && r->getAbsRuleNumber() != rule->getAbsRuleNumber() &&
! (*r == *rule) )
{
compiler->abort(
rule,
"Non-terminating rule '" + rule->getLabel() +
"' shadows rule '" + r->getLabel() + "' above it");
}
}
rules_seen_so_far.push_back(rule);
return true;
}
示例3: cmpRules
bool PolicyCompiler::cmpRules(PolicyRule &r1, PolicyRule &r2)
{
if (r1.getSrc()->getNeg()!=r2.getSrc()->getNeg()) return false;
if (r1.getDst()->getNeg()!=r2.getDst()->getNeg()) return false;
if (r1.getSrv()->getNeg()!=r2.getSrv()->getNeg()) return false;
if (r2.getSrc()->getNeg()!=r2.getSrc()->getNeg()) return false;
if (r2.getDst()->getNeg()!=r2.getDst()->getNeg()) return false;
if (r2.getSrv()->getNeg()!=r2.getSrv()->getNeg()) return false;
Address *src1=getFirstSrc(&r1);
Address *dst1=getFirstDst(&r1);
Service *srv1=getFirstSrv(&r1);
Address *src2=getFirstSrc(&r2);
Address *dst2=getFirstDst(&r2);
Service *srv2=getFirstSrv(&r2);
if (src1==NULL || dst1==NULL || srv1==NULL)
throw FWException("Can not compare rules because rule " +
r1.getLabel() +
" has a group in one of its elements. Aborting.");
if (src2==NULL || dst2==NULL || srv2==NULL)
throw FWException("Can not compare rules because rule " +
r2.getLabel() +
" has a group in one of its elements. Aborting.");
PolicyRule::Direction dir1=r1.getDirection();
PolicyRule::Direction dir2=r2.getDirection();
if (dir1==PolicyRule::Both) dir1=dir2;
if (dir2==PolicyRule::Both) dir2=dir1;
if (dir1!=dir2) return false;
return ( (*src1 == *src2) && (*dst1 == *dst2) && (*srv1 == *srv2) );
}
示例4: slurp
bool PolicyCompiler_ipf::calculateSkip::processNext()
{
// PolicyRule *rule;
slurp();
if (tmp_queue.size()==0) return false;
/*
* first, we scan all rules and build a hash that maps attribute
* "skip_label" to rule number. Attribute "skip_label" is set in
* optimize1, after which we could have split some rules, so this
* attrbiute may not be unique. We want to skip to the first rule
* marked with the same skip label if there are few with the same
* label. The simplest way to find the first one with the same label
* is to scan rules in reverse order, that is from the bottom up.
*/
int N=tmp_queue.size()-1; // The last rule number is N
for (deque<Rule*>::reverse_iterator k=tmp_queue.rbegin(); k!=tmp_queue.rend(); ++k)
{
PolicyRule *r = PolicyRule::cast( *k );
if (!r->getStr("skip_label").empty()) allrules[r->getStr("skip_label")]=N;
r->setInt("rule_num",N);
N--;
}
for (deque<Rule*>::iterator k=tmp_queue.begin(); k!=tmp_queue.end(); ++k)
{
PolicyRule *r = PolicyRule::cast( *k );
string rl=r->getLabel();
int current_position=r->getPosition();
if (r->getAction()==PolicyRule::Skip)
{
assert(!r->getStr("skip_to").empty());
int to=allrules[r->getStr("skip_to")];
int n =r->getInt("rule_num");
r->setInt("no_to_skip",to-n-1);
}
/* Action 'Continue' means we need to jump to the next rule in the
* GUI. We scan rules down from the current one, looking for the first
* rule that corresponds to the next rule in the GUI.
*/
if (r->getAction()==PolicyRule::Continue)
{
r->setAction(PolicyRule::Skip);
r->setBool("quick",false);
deque<Rule*>::iterator j=k;
++j;
int n=0;
for ( ; j!=tmp_queue.end(); ++j)
{
PolicyRule *r2 = PolicyRule::cast( *j );
if (r2->getPosition()!=current_position) break;
/* 'skip' only skips rules with the same setting of 'in' or 'out',
* that is the same direction
*/
if (r2->getDirection()==r->getDirection()) ++n;
}
r->setInt("no_to_skip",n);
}
}
return true;
}
示例5: prolog
int PolicyCompiler::prolog()
{
Compiler::prolog();
Policy *policy = Policy::cast(fw->getFirstByType(Policy::TYPENAME));
assert(policy);
if (source_ruleset == NULL) source_ruleset = policy;
source_ruleset->renumberRules();
temp_ruleset = new Policy(); // working copy of the policy
fw->add( temp_ruleset );
temp_ruleset->setName(source_ruleset->getName());
int global_num = 0;
string label_prefix = "";
if (source_ruleset->getName() != "Policy") label_prefix = source_ruleset->getName();
int rule_counter = 0;
for (FWObject::iterator i=source_ruleset->begin(); i!=source_ruleset->end(); i++)
{
PolicyRule *r = PolicyRule::cast(*i);
if (r == NULL) continue; // skip RuleSetOptions object
/*
* do not remove disabled rules just yet because some
* compilers might use RuleSet::insertRuleAtTop() and other
* similar methods from prolog() or
* addPredefinedPolicyRules()() and these methods renumber
* rules (labels stop matching rule positions when this is
* done because labels are configured in prolog() method of
* the base class. See fwbuilder ticket 1173)
*/
//if (r->isDisabled()) continue;
if (r->getLabel().empty())
{
RuleElementItf *itfre = r->getItf();
assert(itfre);
if (itfre->isAny())
{
r->setLabel( createRuleLabel(label_prefix,
"global", r->getPosition()) );
} else
{
string interfaces = "";
for (FWObject::iterator i=itfre->begin(); i!=itfre->end(); ++i)
{
FWObject *o = FWReference::getObject(*i);
if (interfaces!="") interfaces += ",";
interfaces += o->getName();
}
r->setLabel( createRuleLabel(label_prefix,
interfaces, r->getPosition()) );
}
}
r->setAbsRuleNumber(global_num);
global_num++;
rule_counter++;
}
initialized = true;
return rule_counter;
}
示例6: checkForShadowing
//.........这里部分代码省略.........
* r2 has action != Return and r1 has action Return, we ignore r1.
*/
if (r1_action==PolicyRule::Return ||
r2_action==PolicyRule::Return ) return false;
/*
* the problem with branching rules is that it is combination of
* the head rule and rules in the branch rather than a single rule
* that can shadow other rules below them. Our current mechanism for
* shadowing detection does not support this so all we can do is
* skip rules with action Branch.
*/
if (r1_action==PolicyRule::Branch ||
r2_action==PolicyRule::Branch ) return false;
/*
* rules with action continue do not make final decision and
* therefore can not shadow other rules (but can be shadowed)
*/
if (/* r1_action==PolicyRule::Continue || */
r2_action==PolicyRule::Continue ) return false;
Address *src1;
Address *dst1;
Service *srv1;
Address *src2;
Address *dst2;
Service *srv2;
map<int, threeTuple*>::iterator it = rule_elements_cache.find(r1.getId());
if (it!=rule_elements_cache.end())
{
threeTuple *tt = it->second;
src1 = tt->src;
dst1 = tt->dst;
srv1 = tt->srv;
} else
{
src1 = Address::cast(FWReference::cast(srcrel1->front())->getPointer());
dst1 = Address::cast(FWReference::cast(dstrel1->front())->getPointer());
srv1 = Service::cast(FWReference::cast(srvrel1->front())->getPointer());
threeTuple *tt = new struct threeTuple;
tt->src = src1;
tt->dst = dst1;
tt->srv = srv1;
rule_elements_cache[r1.getId()] = tt;
}
it = rule_elements_cache.find(r2.getId());
if (it!=rule_elements_cache.end())
{
threeTuple *tt = it->second;
src2 = tt->src;
dst2 = tt->dst;
srv2 = tt->srv;
} else
{
src2 = Address::cast(FWReference::cast(srcrel2->front())->getPointer());
dst2 = Address::cast(FWReference::cast(dstrel2->front())->getPointer());
srv2 = Service::cast(FWReference::cast(srvrel2->front())->getPointer());
threeTuple *tt = new struct threeTuple;
tt->src = src2;
tt->dst = dst2;
tt->srv = srv2;
rule_elements_cache[r2.getId()] = tt;
}
if (src1==NULL || dst1==NULL || srv1==NULL)
throw FWException("Can not compare rules because rule " +
r1.getLabel()
+ " has a group in one of its elements. Aborting.");
if (src2==NULL || dst2==NULL || srv2==NULL)
throw FWException("Can not compare rules because rule " +
r2.getLabel() +
" has a group in one of its elements. Aborting.");
if (MultiAddressRunTime::isA(src1) || MultiAddressRunTime::isA(dst1) ||
MultiAddressRunTime::isA(src2) || MultiAddressRunTime::isA(dst2))
return false;
PolicyRule::Direction dir1 = r1.getDirection();
PolicyRule::Direction dir2 = r2.getDirection();
if (dir1 == PolicyRule::Both) dir1 = dir2;
if (dir2 == PolicyRule::Both) dir2 = dir1;
if (dir1 != dir2) return false;
return (
Compiler::checkForShadowing(*src1, *src2) &&
Compiler::checkForShadowing(*dst1, *dst2) &&
Compiler::checkForShadowing(*srv1, *srv2)
);
// complete: 3'5"
return false;
}