- ...note:: First set all required parameters.
- """
- node = self._node
-
- # create policer
- color_aware = 'color-aware' if self._color_aware else ''
-
- # pylint: disable=no-member
- conform_action = self._conform_action.value
-
- if PolicerAction.MARK_AND_TRANSMIT == self._conform_action:
- conform_action += ' {0}'.format(self._conform_dscp.string)
-
- exceed_action = self._exceed_action.value
- if PolicerAction.MARK_AND_TRANSMIT == self._exceed_action:
- exceed_action += ' {0}'.format(self._exceed_dscp.string)
-
- violate_action = self._violate_action.value
- if PolicerAction.MARK_AND_TRANSMIT == self._violate_action:
- violate_action += ' {0}'.format(self._violate_dscp.string)
-
- out = VatExecutor.cmd_from_template(node,
- "policer/policer_add_3c.vat",
- name=self._policer_name,
- cir=self._cir,
- eir=self._eir,
- cb=self._cb,
- eb=self._eb,
- rate_type=self._rate_type.value,
- round_type=self._round_type.value,
- p_type=self._policer_type.value,
- conform_action=conform_action,
- exceed_action=exceed_action,
- violate_action=violate_action,
- color_aware=color_aware)
-
- VatJsonUtil.verify_vat_retval(
- out[0],
- err_msg='Add policer {0} failed on {1}'.format(self._policer_name,
- node['host']))
-
- policer_index = out[0].get('policer_index')
-
- # create classify table
- direction = 'src' if self._classify_match_is_src else 'dst'
-
- if ip_address(unicode(self._classify_match_ip)).version == 6:
- ip_version = 'ip6'
- table_type = PolicerClassifyTableType.IP6_TABLE
- else:
- ip_version = 'ip4'
- table_type = PolicerClassifyTableType.IP4_TABLE
-
- out = VatExecutor.cmd_from_template(node,
- "classify_add_table.vat",
- ip_version=ip_version,
- direction=direction)
-
- VatJsonUtil.verify_vat_retval(
- out[0],
- err_msg='Add classify table failed on {0}'.format(node['host']))
-
- new_table_index = out[0].get('new_table_index')
- skip_n_vectors = out[0].get('skip_n_vectors')
- match_n_vectors = out[0].get('match_n_vectors')
-
- # create classify session
- match = 'l3 {0} {1} {2}'.format(ip_version,
- direction,
- self._classify_match_ip)
-
- out = VatExecutor.cmd_from_template(
- node,
- "policer/policer_classify_add_session.vat",
- policer_index=policer_index,
- pre_color=self._classify_precolor.value, # pylint: disable=no-member
- table_index=new_table_index,
- skip_n=skip_n_vectors,
- match_n=match_n_vectors,
- match=match)
-
- VatJsonUtil.verify_vat_retval(
- out[0],
- err_msg='Add classify session failed on {0}'.format(node['host']))
-
- # set classify interface
- out = VatExecutor.cmd_from_template(
- node,
- "policer/policer_classify_set_interface.vat",
- sw_if_index=self._sw_if_index,
- table_type=table_type.value, # pylint: disable=no-member
- table_index=new_table_index)
-
- VatJsonUtil.verify_vat_retval(
- out[0],
- err_msg='Set classify interface failed on {0}'.format(node['host']))
-
- def policer_clear_settings(self):
- """Clear policer settings."""
- self._cir = 0
- self._eir = 0
- self._cb = 0
- self._eb = 0
- self._rate_type = None
- self._round_type = None
- self._policer_type = None
- self._conform_action = None
- self._conform_dscp = None
- self._exceed_action = None
- self._exceed_dscp = None
- self._violate_action = None
- self._violate_dscp = None
- self._color_aware = False
- self._classify_match_ip = ''
- self._classify_match_is_src = True
- self._classify_precolor = None
- self._sw_if_index = 0
- self._node = None
- self._policer_name = ''
-
- def policer_set_name(self, name):
- """Set policer name.
-
- :param name: Policer name.
- :type name: str
- """
- self._policer_name = name
-
- def policer_set_node(self, node):
- """Set node to setup policer on.
-