Skip to content

Commit c515890

Browse files
author
Capirca Team
committed
Allow generation of empty match condition term with counter action.
PiperOrigin-RevId: 745559392
1 parent 150dc56 commit c515890

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

capirca/lib/arista_tp.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,17 @@ def __str__(self):
233233
self.term.hop_limit or self.term.port or self.term.protocol or
234234
self.term.protocol_except or self.term.source_address or
235235
self.term.source_address_exclude or self.term.source_port or
236-
self.term.source_prefix or self.term.ttl)
236+
self.term.source_prefix or self.term.ttl )
237237

238238
# if the term name is default-* we will render this into the
239239
# appropriate default term name to be used in this filter.
240240
is_default_term = re.match(r"^ipv(4|6)\-default\-.*", self.term.name,
241241
re.IGNORECASE)
242242

243-
if (not has_match_criteria and not is_default_term):
243+
# if the term doesn't match on anything and isn't a default-term and
244+
# isn't a counter term, then we don't render it.
245+
if (not has_match_criteria and not is_default_term
246+
and not self.term.counter):
244247
# this term doesn't match on anything and isn't a default-term
245248
logging.warning(
246249
"WARNING: term %s has no valid match criteria and "

tests/lib/arista_tp_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@
359359
action:: deny
360360
}
361361
"""
362+
NO_MATCH_TERM_COUNTER = """
363+
term deny-and-count {
364+
counter:: deny-counter
365+
action:: deny
366+
}
367+
"""
362368
LONG_COMMENT_TERM_1 = """
363369
term long-comment-term-1 {
364370
comment:: "this is very very very very very very very very very very very
@@ -801,6 +807,13 @@ def testDefaultDeny(self):
801807
self.assertIn("match ipv4-default-all ipv4", output, output)
802808
self.assertIn("match ipv6-default-all ipv6", output, output)
803809

810+
def testEmptyMatchDenyCounter(self):
811+
atp = arista_tp.AristaTrafficPolicy(
812+
policy.ParsePolicy(GOOD_HEADER + NO_MATCH_TERM_COUNTER, self.naming),
813+
EXP_INFO)
814+
output = str(atp)
815+
self.assertIn("count deny-counter", output, output)
816+
804817
def testIcmpType(self):
805818
atp = arista_tp.AristaTrafficPolicy(
806819
policy.ParsePolicy(GOOD_HEADER + GOOD_TERM_3, self.naming), EXP_INFO)

0 commit comments

Comments
 (0)