Skip to content

Commit

Permalink
fix: update classifier object to account for 'class-default'.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouliez committed Jul 14, 2023
2 parents a34d8de + ce46e13 commit 2e25df8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 48 deletions.
77 changes: 38 additions & 39 deletions mdd/python/translation/openconfig_xe/xe_qos.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def xe_qos_program_service(self, nso_props) -> None:
Configure forwarding-groups
"""
for fg in nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group:
if device_cdb.ios__policy_map.exists(fg.name):
del device_cdb.ios__policy_map[fg.name]
device_cdb.ios__policy_map.create(fg.name)
if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0:
if device_cdb.ios__policy_map:
device_cdb.ios__policy_map.delete()

# Class-map
"""
Expand All @@ -31,41 +30,44 @@ def xe_qos_program_service(self, nso_props) -> None:
for c_map in nso_props.service.oc_qos__qos.classifiers.classifier:
pmap_cmap = {}
# Configure class-map
device_cdb.ios__class_map.create(c_map.name)
for t_map in c_map.terms.term:
pmap_cmap[t_map.actions.config.target_group] = c_map.name
# Configure "match ip dscp"
if t_map.conditions.ipv4.config.protocol == 4:
# Configure multiple dscp statements
if t_map.conditions.ipv4.config.dscp_set:
for new_ip_dscp in t_map.conditions.ipv4.config.dscp_set:
new_ip_dscp = modify_dscp(new_ip_dscp)
if device_cdb.ios__class_map.exists(c_map.name) and c_map.name != 'class-default':
del device_cdb.ios__class_map[c_map.name]
elif c_map.name == 'class-default':
for t_map in c_map.terms.term:
pmap_cmap[t_map.actions.config.target_group] = c_map.name
else:
device_cdb.ios__class_map.create(c_map.name)
for t_map in c_map.terms.term:
pmap_cmap[t_map.actions.config.target_group] = c_map.name
# Configure "match ip dscp"
if t_map.conditions.ipv4.config.protocol == 4:
# Configure multiple dscp statements
if t_map.conditions.ipv4.config.dscp_set:
for new_ip_dscp in t_map.conditions.ipv4.config.dscp_set:
new_ip_dscp = modify_dscp(new_ip_dscp)
device_cdb.ios__class_map[c_map.name].prematch = 'match-all'
device_cdb.ios__class_map[c_map.name].match.ip.dscp.create(new_ip_dscp)
# Configure single dscp statements
elif t_map.conditions.ipv4.config.dscp:
new_ip_dscp = modify_dscp(t_map.conditions.ipv4.config.dscp)
device_cdb.ios__class_map[c_map.name].prematch = 'match-all'
device_cdb.ios__class_map[c_map.name].match.ip.dscp.create(new_ip_dscp)
# Configure single dscp statements
elif t_map.conditions.ipv4.config.dscp:
new_ip_dscp = modify_dscp(t_map.conditions.ipv4.config.dscp)
device_cdb.ios__class_map[c_map.name].prematch = 'match-all'
device_cdb.ios__class_map[c_map.name].match.ip.dscp.create(
new_ip_dscp)
# Configure "match dscp"
else:
# Configure multiple dscp statements
if t_map.conditions.ipv4.config.dscp_set:
for new_dscp in t_map.conditions.ipv4.config.dscp_set:
new_dscp = modify_dscp(new_dscp)
device_cdb.ios__class_map[c_map.name].match.ip.dscp.create(
new_ip_dscp)
# Configure "match dscp"
else:
# Configure multiple dscp statements
if t_map.conditions.ipv4.config.dscp_set:
for new_dscp in t_map.conditions.ipv4.config.dscp_set:
new_dscp = modify_dscp(new_dscp)
device_cdb.ios__class_map[c_map.name].prematch = 'match-all'
device_cdb.ios__class_map[c_map.name].match.dscp.create(new_dscp)
# Configure single dscp statements
elif t_map.conditions.ipv4.config.dscp:
new_dscp = modify_dscp(t_map.conditions.ipv4.config.dscp)
device_cdb.ios__class_map[c_map.name].prematch = 'match-all'
device_cdb.ios__class_map[c_map.name].match.dscp.create(new_dscp)
# Configure single dscp statements
elif t_map.conditions.ipv4.config.dscp:
new_dscp = modify_dscp(t_map.conditions.ipv4.config.dscp)
device_cdb.ios__class_map[c_map.name].prematch = 'match-all'
device_cdb.ios__class_map[c_map.name].match.dscp.create(
new_dscp)
device_cdb.ios__class_map[c_map.name].match.dscp.create(
new_dscp)
list_cmap.append(pmap_cmap)
if len(nso_props.service.oc_qos__qos.classifiers.classifier) == 0:
if device_cdb.ios__class_map:
device_cdb.ios__class_map.delete()

# Schedulers
"""
Expand All @@ -92,9 +94,7 @@ def xe_qos_program_service(self, nso_props) -> None:
"""
Configure interfaces
"""
self.log.info(f'1*** sched_pol.name = {sched_pol.name}\n\n')
for interface in nso_props.service.oc_qos__qos.interfaces.interface:
self.log.info(f'2*** interface = {interface}\n\n')
if interface.output.scheduler_policy.config.name == sched_pol.name:
conf_out_service_policy(device_cdb, interface, sequence)
elif interface.input.scheduler_policy.config.name == sched_pol.name:
Expand Down Expand Up @@ -277,5 +277,4 @@ def conf_in_service_policy(device_cdb, interface, sequence):
def modify_dscp(dscp):
if (dscp % 2) != 0:
return dscp
if dscp in dscp_dict.keys():
return dscp_dict.get(dscp, 'default')
return dscp_dict.get(dscp, 'default')
6 changes: 3 additions & 3 deletions test/inventory_nx/nso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ all:
mdd_model_repos:
nso_installer_file: https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/nso-6.1.linux.x86_64.signed.bin
nso_ned_files:
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-ios-6.92.7.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1.2-cisco-ios-6.93.3.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-nx-5.23.13.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-iosxr-7.49.2.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.0.3-cisco-asa-6.18.3.signed.bin
nso_default_ned: cisco-ios-cli-6.92
nso_default_ned: cisco-ios-cli-6.93
nso_ned_dict:
ios: "cisco-ios-cli-6.92"
ios: "cisco-ios-cli-6.93"
children:
nso:
vars:
Expand Down
6 changes: 3 additions & 3 deletions test/inventory_xe/nso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ all:
mdd_model_repos:
nso_installer_file: https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/nso-6.1.linux.x86_64.signed.bin
nso_ned_files:
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-ios-6.92.7.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1.2-cisco-ios-6.93.3.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-nx-5.23.13.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-iosxr-7.49.2.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.0.3-cisco-asa-6.18.3.signed.bin
nso_default_ned: cisco-ios-cli-6.92
nso_default_ned: cisco-ios-cli-6.93
nso_ned_dict:
ios: "cisco-ios-cli-6.92"
ios: "cisco-ios-cli-6.93"
children:
nso:
vars:
Expand Down
6 changes: 3 additions & 3 deletions test/inventory_xr/nso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ all:
mdd_model_repos:
nso_installer_file: https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/nso-6.1.linux.x86_64.signed.bin
nso_ned_files:
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-ios-6.92.7.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1.2-cisco-ios-6.93.3.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-nx-5.23.13.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.1-cisco-iosxr-7.49.2.signed.bin
- https://colabucket.s3.amazonaws.com/sw/cisco/nso/6.1/ncs-6.0.3-cisco-asa-6.18.3.signed.bin
nso_default_ned: cisco-ios-cli-6.92
nso_default_ned: cisco-ios-cli-6.93
nso_ned_dict:
ios: "cisco-ios-cli-6.92"
ios: "cisco-ios-cli-6.93"
children:
nso:
vars:
Expand Down
6 changes: 6 additions & 0 deletions test/tests/xe/xe_qos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@
- "'+ match dscp 25:' in changes"
- "'+class-map match-all cm-dscp-31:' in changes"
- "'+ match dscp af41:' in changes"
- "'+policy-map pm-class-default-01:' in changes"
- "'+ class class-default:' in changes"
- "'+ priority percent 20:' in changes"
- "'+policy-map pm-class-default-02:' in changes"
- "'+ class class-default:' in changes"
- "'+ priority percent 30:' in changes"
- "'+policy-map pm-ip-dscp-11:' in changes"
- "'+ class cm-ip-dscp-11:' in changes"
- "'+ priority percent 10:' in changes"
Expand Down

0 comments on commit 2e25df8

Please sign in to comment.