X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FPolicer.py;h=af2321bae962c850edf1dabbaba46437a6e5accf;hb=e08706e85b412b1307df3789fdbe747b43c2bd95;hp=d5500e1d89220ca841925f5ed18f596efa06447a;hpb=063abf35e81deaf749ebbcfee339fbd1d9e89412;p=csit.git diff --git a/resources/libraries/python/Policer.py b/resources/libraries/python/Policer.py index d5500e1d89..af2321bae9 100644 --- a/resources/libraries/python/Policer.py +++ b/resources/libraries/python/Policer.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2020 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -32,7 +32,7 @@ class PolicerRoundType(IntEnum): ROUND_TO_CLOSEST = 0 ROUND_TO_UP = 1 ROUND_TO_DOWN = 2 - ROUND_TO_INVALID = 3 + ROUND_INVALID = 3 class PolicerType(IntEnum): @@ -132,10 +132,29 @@ class Policer: :type exceed_dscp: str :type violate_dscp: str """ + conform_action = dict( + type=getattr(PolicerAction, conform_action_type.upper()).value, + dscp=Policer.get_dscp_num_value(conform_dscp) if + conform_action_type.upper() == PolicerAction.MARK_AND_TRANSMIT.name + else 0 + ) + exceed_action = dict( + type=getattr(PolicerAction, exceed_action_type.upper()).value, + dscp=Policer.get_dscp_num_value(exceed_dscp) if + exceed_action_type.upper() == PolicerAction.MARK_AND_TRANSMIT.name + else 0 + ) + violate_action = dict( + type=getattr(PolicerAction, violate_action_type.upper()).value, + dscp=Policer.get_dscp_num_value(violate_dscp) if + violate_action_type.upper() == PolicerAction.MARK_AND_TRANSMIT.name + else 0 + ) + cmd = u"policer_add_del" args = dict( - is_add=int(is_add), - name=str(policer_name).encode(encoding=u"utf-8"), + is_add=is_add, + name=str(policer_name), cir=int(cir), eir=int(eir), cb=int(cbs), @@ -145,28 +164,10 @@ class Policer: PolicerRoundType, f"ROUND_TO_{round_type.upper()}" ).value, type=getattr(PolicerType, f"TYPE_{policer_type.upper()}").value, - conform_action_type=getattr( - PolicerAction, conform_action_type.upper() - ).value, - conform_dscp=getattr(DSCP, f"D_{conform_dscp.upper()}").value - if - conform_action_type.upper() == PolicerAction.MARK_AND_TRANSMIT.name - else 0, - exceed_action_type=getattr( - PolicerAction, exceed_action_type.upper() - ).value, - exceed_dscp=getattr(DSCP, f"D_{exceed_dscp.upper()}").value - if - exceed_action_type.upper() == PolicerAction.MARK_AND_TRANSMIT.name - else 0, - violate_action_type=getattr( - PolicerAction, violate_action_type.upper() - ).value, - violate_dscp=getattr(DSCP, f"D_{violate_dscp.upper()}").value - if - violate_action_type.upper() == PolicerAction.MARK_AND_TRANSMIT.name - else 0, - color_aware=1 if color_aware == u"'ca'" else 0 + conform_action=conform_action, + exceed_action=exceed_action, + violate_action=violate_action, + color_aware=bool(color_aware == u"'ca'") ) err_msg = f"Failed to configure policer {policer_name} " \ f"on host {node['host']}" @@ -180,7 +181,7 @@ class Policer: def policer_classify_set_interface( node, interface, ip4_table_index=Constants.BITWISE_NON_ZERO, ip6_table_index=Constants.BITWISE_NON_ZERO, - l2_table_index=Constants.BITWISE_NON_ZERO, is_add=1): + l2_table_index=Constants.BITWISE_NON_ZERO, is_add=True): """Set/unset policer classify interface. :param node: VPP node. @@ -192,12 +193,13 @@ class Policer: (Default value = ~0) :param l2_table_index: L2 classify table index (~0 to skip). (Default value = ~0) - :param is_add: Set if non-zero, else unset. + :param is_add: Set if True, else unset. :type node: dict :type interface: str or int :type ip4_table_index: int :type ip6_table_index: int :type l2_table_index: int + :type is_add: bool """ if isinstance(interface, str): sw_if_index = Topology.get_interface_sw_index(node, interface) @@ -206,8 +208,8 @@ class Policer: cmd = u"policer_classify_set_interface" args = dict( - is_add=int(is_add), - sw_if_index=sw_if_index, + is_add=is_add, + sw_if_index=int(sw_if_index), ip4_table_index=int(ip4_table_index), ip6_table_index=int(ip6_table_index), l2_table_index=int(l2_table_index)