p4utils.utils.sswitch_thrift_API module

This module provides the Simple Switch Thrift API. It builds on the generic Thrift API. It is a modified version of sswitch_CLI.py from behavioral model.

class p4utils.utils.sswitch_thrift_API.SimpleSwitchThriftAPI(thrift_port, thrift_ip='localhost', json_path=None)[source]

Bases: p4utils.utils.thrift_API.ThriftAPI

Simple Switch Thrift control plane API.

Parameters:
  • thrift_port (int) – port to connect to
  • thrift_ip (str) – IP the Thrift server is listening on
  • json_path (str) – optional JSON compiled P4 file to push to the switch
sswitch_client[source]

Thrift client instance to communicate with the switch

static get_thrift_services()[source]

Get available Thrift services.

get_time_elapsed()[source]

Prints time elapsed (in microseconds) since the switch started.

get_time_since_epoch()[source]

Prints time elapsed (in microseconds) since the switch clock’s epoch.

mirroring_add(mirror_id, egress_port)[source]

Adds mirroring mapping.

Parameters:
  • mirror_id (int) – mirror id to use
  • egress_port (int) – egress port to associate with the mirror
mirroring_add_mc(mirror_id, mgrp)[source]

Adds mirroring session to multicast group.

Parameters:
  • mirror_id (int) – mirror id to associate
  • mgrp (int) – multicast group
mirroring_add_port_and_mgrp(mirror_id, egress_port, mgrp)[source]

Adds mirroring session to multicast group.

Parameters:
  • mirror_id (int) – mirror id to use
  • egress_port (int) – egress port to associate with the mirror
  • mgrp (int) – multicast group
mirroring_delete(mirror_id)[source]

Deletes mirroring mapping.

Parameters:mirror_id (int) – id of the mirror to delete
mirroring_get(mirror_id)[source]

Prints mirroring session information

Parameters:mirror_id (int) – id of the mirror to display
parse_int(arg, name)[source]

Tries to convert the argument to int.

Parameters:
  • arg – argument that can be converted to int
  • name (str) – name of the argument
Returns:

integer value of the argument

Return type:

int

Raises:

p4utils.utils.thrift_API.UIn_Error – if the argument cannot be transformed in an integer.

set_queue_depth(queue_depth, egress_port=None, priority=None)[source]

Sets depth of one / all egress queue(s).

Parameters:
  • queue_depth (int) – number of packets
  • egress_port (int) – optional egress port, otherwise all ports are considered
  • priority (int) – optional priority. Setting the depth of a specific priority queue if enabled
set_queue_rate(rate, egress_port=None, priority=None)[source]

Sets rate of one / all egress queue(s).

Parameters:
  • rate (int) – rate (packets per seconds)
  • egress_port (int) – optional egress port, otherwise all ports are considered
  • priority (int) – optional priority. Setting the depth of a specific priority queue if enabled
p4utils.utils.sswitch_thrift_API.handle_bad_input(f)[source]

Handles bad input.

Parameters:f (types.FunctionType) – function or method to handle