p4utils.utils.thrift_API module¶
This module is a modified version of runtime_CLI that performs control plane operations by connecting to the Thrift server running on a capable switch. The main difference between this code and the original one is that this module is an API, whereas the other is a client.
-
class
p4utils.utils.thrift_API.
ThriftAPI
(thrift_port, thrift_ip, pre_type, json_path=None)[source]¶ Bases:
object
This class implements a client that connects to a P4 switch control plane and allows to configure it. It establishes a Thrift connection with the switch server that is then used to forward configuration information.
Parameters: Possible values for pre_type are the following:
simple_pre
simple_pre_lag
none
-
switch_info
[source]¶ object containing information about all the P4 structures present in the switch.
Type: SwitchInfo
-
table_entries_match_to_handle
[source]¶ dictionary used to associate table matches with the related handle.
Type: dict
-
act_prof_add_member_to_group
(act_prof_name, mbr_handle, grp_handle)[source]¶ Adds member to group in an action profile.
Parameters:
-
act_prof_create_group
(act_prof_name)[source]¶ Adds a group to an action pofile.
Parameters: act_prof_name (str) – name of the action profile Returns: group handle. Return type: int
-
act_prof_create_member
(act_prof_name, action_name, action_params=[])[source]¶ Adds a member to an action profile.
Parameters: Returns: member handle.
Return type: Note
In
action_params
, action parameters must bestr
.
-
act_prof_delete_group
(act_prof_name, grp_handle)[source]¶ Delete a group from an action profile.
Parameters:
-
act_prof_delete_member
(act_prof_name, mbr_handle)[source]¶ Deletes a member in an action profile.
Parameters:
-
act_prof_dump
(act_prof_name)[source]¶ Displays entries in an action profile.
Parameters: act_prof_name (str) – name of the action profile
-
act_prof_dump_group
(act_prof_name, grp_handle)[source]¶ Displays some information about a group.
Parameters:
-
act_prof_dump_member
(act_prof_name, mbr_handle)[source]¶ Displays some information about a member.
Parameters:
-
act_prof_modify_member
(act_prof_name, action_name, mbr_handle, action_params=[])[source]¶ Modifies member in an action profile.
Parameters: Returns: member handle.
Return type: Note
In
action_params
, action parameters must bestr
.
-
act_prof_remove_member_from_group
(act_prof_name, mbr_handle, grp_handle)[source]¶ Removes member from group in action profile.
Parameters:
-
counter_read
(counter_name, index)[source]¶ Reads counter value.
Parameters: Returns: (byte_count, packet_count)
where:byte_count
is the number of bytes counted;packet_count
is the number of bytes counted.
Return type:
-
counter_reset
(counter_name)[source]¶ Resets counter array.
Parameters: counter_name (str) – name of the counter
-
load_new_config_file
(filename)[source]¶ Loads new JSON config.
Parameters: filename (str) – path to the P4 compiled JSON file
-
mc_mgrp_create
(mgrp)[source]¶ Creates multicast group.
Parameters: mgrp (int) – multicast group id Returns: multicast group handle. Return type: int Note
The multicast group handle is equal to the multicast group id.
-
mc_node_create
(rid, ports, lags=[])[source]¶ Creates multicast node.
Parameters: Returns: node handle.
Return type:
-
mc_node_update
(l1_hdl, ports, lags=[])[source]¶ Updates multicast node.
Parameters: Returns: node handle.
Return type:
-
meter_array_set_rates
(meter_name, rates)[source]¶ Configures rates for an entire meter array.
Parameters: Note
cir
andpir
use units/second,cbursts
andpburst
use units where units is bytes or packets, depending on the meter type.
-
meter_get_rates
(meter_name, index)[source]¶ Retrieves rates for a meter.
Parameters: Returns: [(cir, cburst), (pir, pburst)]
.Return type: Note
cir
andpir
use units/second,cbursts
andpburst
use units where units is bytes or packets, depending on the meter type.
-
meter_set_rates
(meter_name, index, rates)[source]¶ Configures rates for a meter.
Parameters: Note
cir
andpir
use units/second,cbursts
andpburst
use units where units is bytes or packets, depending on the meter type.
-
port_add
(iface_name, port_num, pcap_path='')[source]¶ Adds a port to the switch (behavior depends on device manager used).
Parameters:
-
port_remove
(port_num)[source]¶ Removes a port from the switch (behavior depends on device manager used).
Parameters: port_num (int) – port number
-
pvs_add
(pvs_name, value)[source]¶ Adds a value to a parser value set.
Parameters: Warning
BMv2 will not report an error if the value already exists.
-
pvs_clear
(pvs_name)[source]¶ Removes all values from a parser value set.
Parameters: pvs_name (str) – name of the parser value set
-
pvs_get
(pvs_name)[source]¶ Retrieves all values from a parser value set.
Parameters: pvs_name (str) – name of the parser value set Returns: values of the parser value set Return type: list Note
Values are displayed in no particular order, one per line.
-
pvs_remove
(pvs_name, value)[source]¶ Removes a value from a parser value set.
Parameters: Warning
BMv2 will not report an error if the value does not exist.
-
register_read
(register_name, index=None, show=False)[source]¶ Reads register value.
Parameters: Returns: register value or list of values.
Return type:
-
register_reset
(register_name)[source]¶ Resets all the cells in the register array to
0
.Parameters: register_name (str) – name of the register
-
reset_state
()[source]¶ Resets all state in the switch (table entries, registers, …), but P4 config is preserved.
-
set_crc16_parameters
(name, polynomial, initial_remainder, final_xor_value, reflect_data, reflect_remainder)[source]¶ Changes the parameters for a custom
crc16
hash.Parameters:
-
set_crc32_parameters
(name, polynomial, initial_remainder, final_xor_value, reflect_data, reflect_remainder)[source]¶ Changes the parameters for a custom
crc32
hash.Parameters:
-
set_crc_parameters_common
(name, polynomial, initial_remainder, final_xor_value, reflect_data, reflect_remainder, crc_width=16)[source]¶
-
swap_configs
()[source]¶ Swap the 2 existing configs, need to have called
load_new_config_file()
before.
-
switch_info
()[source] Shows some basic info about the switch.
-
table_add
(table_name, action_name, match_keys, action_params=[], prio=0)[source]¶ Adds entry to a match table.
Parameters: Returns: entry handle.
Return type: Note
- In
action_params
andmatch_keys
, action parameters and match keys must bestr
. - A higher
prio
number indicates that the entry must be given higher priority when performing a table lookup.
- In
-
table_clear
(table_name)[source]¶ Clears all entries in a match table (direct or indirect), but not the default entry.
Parameters: table_name (str) – name of the table
-
table_delete
(table_name, entry_handle, quiet=False)[source]¶ Deletes entry from a match table.
Parameters:
-
table_delete_match
(table_name, match_keys)[source]¶ Deletes entry from a table using match keys.
Parameters: Note
In
match_keys
, match keys must bestr
.Warning
This may not work with ternary matches and priority entries.
-
table_dump
(table_name)[source]¶ Displays entries in a match-table.
Parameters: table_name (str) – name of the table
-
table_dump_entry
(table_name, entry_handle)[source]¶ Displays some information about a table entry.
Parameters:
-
table_dump_entry_from_key
(table_name, match_keys, prio=0)[source]¶ Displays some information about a table entry using match keys.
Parameters: Note
In
match_keys
, match keys must bestr
.
-
table_info
(table_name)[source]¶ Shows info about a table.
Parameters: table_name (str) – name of the table
-
table_modify
(table_name, action_name, entry_handle, action_params=[])[source]¶ Modifies entry of a match table.
Parameters: Returns: entry handle.
Return type: Note
In
action_params
, action parameters must bestr
.
-
table_modify_match
(table_name, action_name, match_keys, action_params=[])[source]¶ Modifies entry of a match table using match keys.
Parameters: Returns: entry handle.
Return type: Note
In
action_params
, action parameters must bestr
.
-
table_num_entries
(table_name)[source]¶ Returns the number of entries in a match table (direct or indirect).
Parameters: table_name (str) – name of the table Returns: the number of entries in a table. Return type: int
-
table_reset_default
(table_name)[source]¶ Resets default entry for a match table.
Parameters: table_name (str) – name of the table
-
table_set_default
(table_name, action_name, action_params=[])[source]¶ Sets default action for a match table.
Parameters: Note
In
action_params
, action parameters must bestr
.
-
table_set_timeout
(table_name, entry_handle, timeout_ms)[source]¶ Sets a timeout in ms for a given entry; the table has to support timeouts.
Parameters: