Skip to content

Commit

Permalink
Merge pull request #347 from sdatta09:versa_app_dev
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 559411926
  • Loading branch information
Capirca Team committed Aug 23, 2023
2 parents 0393eb2 + a92e4db commit d145ca4
Show file tree
Hide file tree
Showing 6 changed files with 1,744 additions and 0 deletions.
26 changes: 26 additions & 0 deletions capirca/lib/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ class Term:
source-service-accounts: VarType.SOURCE_SERVICE_ACCOUNTS
target-service-accounts: VarType.TARGET_SERVICE_ACCOUNTS
source-zone: VarType.SZONE
versa-application: VarType.VERSA_APPLICATION
vpn: VarType.VPN
""" # fmt: skip
ICMP_TYPE = {
Expand Down Expand Up @@ -457,6 +458,7 @@ def __init__(self, obj):
self.protocol_except = []
self.qos = None
self.pan_application = []
self.versa_application = []
self.routing_instance = None
self.source_address = []
self.source_address_exclude = []
Expand Down Expand Up @@ -827,6 +829,9 @@ def __str__(self):
ret_str.append(' qos: %s' % self.qos)
if self.pan_application:
ret_str.append(' pan_application: %s' % self.pan_application)
if self.versa_application:
# pylint: disable=consider-using-f-string
ret_str.append(' versa_application: %s' % self.versa_application)
if self.logging:
ret_str.append(' logging: %s' % self.logging)
if self.log_limit:
Expand Down Expand Up @@ -929,6 +934,10 @@ def __eq__(self, other):
if sorted(self.pan_application) != sorted(other.pan_application):
return False

# versa-application
if sorted(self.versa_application) != sorted(other.versa_application):
return False

# verbatim
if self.verbatim != other.verbatim:
return False
Expand Down Expand Up @@ -962,6 +971,8 @@ def __eq__(self, other):
return False
if sorted(self.pan_application) != sorted(other.pan_application):
return False
if sorted(self.versa_application) != sorted(other.versa_application):
return False
if self.packet_length != other.packet_length:
return False
if self.fragment_offset != other.fragment_offset:
Expand Down Expand Up @@ -1223,6 +1234,8 @@ def AddObject(self, obj):
self.forwarding_class_except.append(x.value)
elif x.var_type is VarType.PAN_APPLICATION:
self.pan_application.append(x.value)
elif x.var_type is VarType.VERSA_APPLICATION:
self.versa_application.append(x.value)
elif x.var_type is VarType.NEXT_IP:
self.next_ip = DEFINITIONS.GetNetAddr(x.value)
elif x.var_type is VarType.PLATFORM:
Expand Down Expand Up @@ -1276,6 +1289,8 @@ def AddObject(self, obj):
self.forwarding_class_except.append(obj.value)
elif obj.var_type is VarType.PAN_APPLICATION:
self.pan_application.append(obj.value)
elif obj.var_type is VarType.VERSA_APPLICATION:
self.versa_application.append(obj.value)
elif obj.var_type is VarType.NEXT_IP:
self.next_ip = DEFINITIONS.GetNetAddr(obj.value)
elif obj.var_type is VarType.VERBATIM:
Expand Down Expand Up @@ -1694,6 +1709,7 @@ class VarType:
DZONE = 66
DECAPSULATE = 67
SOURCE_SERVICE_ACCOUNTS = 68
VERSA_APPLICATION = 69

def __init__(self, var_type, value):
self.var_type = var_type
Expand Down Expand Up @@ -1931,6 +1947,7 @@ def __ne__(self, other):
'TRAFFIC_TYPE',
'TTL',
'VERBATIM',
'VERSA_APPLICATION',
'VPN',
)

Expand Down Expand Up @@ -2013,6 +2030,7 @@ def __ne__(self, other):
'traffic-type': 'TRAFFIC_TYPE',
'ttl': 'TTL',
'verbatim': 'VERBATIM',
'versa-application': 'VERSA_APPLICATION',
'vpn': 'VPN',
}

Expand Down Expand Up @@ -2194,6 +2212,7 @@ def p_term_spec(p):
| term_spec ttl_spec
| term_spec traffic_type_spec
| term_spec verbatim_spec
| term_spec versa_application_spec
| term_spec vpn_spec
|
"""
Expand Down Expand Up @@ -2607,6 +2626,13 @@ def p_vpn_spec(p):
p[0] = VarType(VarType.VPN, [p[4], ''])


def p_versa_application_spec(p):
"""versa_application_spec : VERSA_APPLICATION ':' ':' one_or_more_strings"""
p[0] = []
for apps in p[4]:
p[0].append(VarType(VarType.VERSA_APPLICATION, apps))


def p_qos_spec(p):
"""qos_spec : QOS ':' ':' STRING"""
p[0] = VarType(VarType.QOS, p[4])
Expand Down
3 changes: 3 additions & 0 deletions capirca/lib/policy_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ class TrafficClassCount(Field):
class Verbatim(Field):
"""A verbatim field."""

class VersaApplication(Field):
"""A VersaApplication field."""

class Vpn(Field):
"""A vpn field."""
Expand Down Expand Up @@ -385,6 +387,7 @@ class Vpn(Field):
'traffic-class-count': TrafficClassCount,
'traffic-type': TrafficType,
'verbatim': Verbatim,
'versa-application': VersaApplication,
'vpn': Vpn,
'encapsulate': Encapsulate,
'decapsulate': Decapsulate,
Expand Down
Loading

0 comments on commit d145ca4

Please sign in to comment.