diff --git a/targets/simple_switch/simple_switch.cpp b/targets/simple_switch/simple_switch.cpp index 08e7f99fb..5d5504c9e 100644 --- a/targets/simple_switch/simple_switch.cpp +++ b/targets/simple_switch/simple_switch.cpp @@ -182,6 +182,12 @@ SimpleSwitch::set_egress_queue_depth(int port, const size_t depth_pkts) { return 0; } +int +SimpleSwitch::set_egress_priority_queue_depth(int port, size_t priority, const size_t depth_pkts) { + egress_buffers.set_capacity(port, priority, depth_pkts); + return 0; +} + int SimpleSwitch::set_all_egress_queue_depths(const size_t depth_pkts) { for (int i = 0; i < max_port; i++) { @@ -196,6 +202,12 @@ SimpleSwitch::set_egress_queue_rate(int port, const uint64_t rate_pps) { return 0; } +int +SimpleSwitch::set_egress_priority_queue_rate(int port, size_t priority, const uint64_t rate_pps) { + egress_buffers.set_rate(port, priority, rate_pps); + return 0; +} + int SimpleSwitch::set_all_egress_queue_rates(const uint64_t rate_pps) { for (int i = 0; i < max_port; i++) { diff --git a/targets/simple_switch/simple_switch.h b/targets/simple_switch/simple_switch.h index afbc5d47c..90a54223b 100644 --- a/targets/simple_switch/simple_switch.h +++ b/targets/simple_switch/simple_switch.h @@ -100,9 +100,11 @@ class SimpleSwitch : public Switch { } int set_egress_queue_depth(int port, const size_t depth_pkts); + int set_egress_priority_queue_depth(int port, size_t priority, const size_t depth_pkts); int set_all_egress_queue_depths(const size_t depth_pkts); int set_egress_queue_rate(int port, const uint64_t rate_pps); + int set_egress_priority_queue_rate(int port, size_t priority, const uint64_t rate_pps); int set_all_egress_queue_rates(const uint64_t rate_pps); // returns the number of microseconds elapsed since the switch started diff --git a/targets/simple_switch/sswitch_CLI.py b/targets/simple_switch/sswitch_CLI.py index c0965804e..ec04b40f9 100644 --- a/targets/simple_switch/sswitch_CLI.py +++ b/targets/simple_switch/sswitch_CLI.py @@ -37,41 +37,69 @@ def __init__(self, pre_type, standard_client, mc_client, sswitch_client): standard_client, mc_client) self.sswitch_client = sswitch_client + @runtime_CLI.handle_bad_input def do_set_queue_depth(self, line): - "Set depth of one / all egress queue(s): set_queue_depth []" + "Set depth of one / all egress queue(s): set_queue_depth [] []" args = line.split() - depth = int(args[0]) - if len(args) > 1: - port = int(args[1]) - self.sswitch_client.set_egress_queue_depth(port, depth) - else: - self.sswitch_client.set_all_egress_queue_depths(depth) + self.at_least_n_args(args, 1) + + try: + depth = int(args[0]) + if len(args) > 2: + port = int(args[1]) + priority = int(args[2]) + self.sswitch_client.set_egress_priority_queue_depth(port, priority, depth) + elif len(args) > 1: + port = int(args[1]) + self.sswitch_client.set_egress_queue_depth(port, rate) + else: + self.sswitch_client.set_all_egress_queue_depths(depth) + + except ValueError: + print "Invalid depth, port or priority value" + + @runtime_CLI.handle_bad_input def do_set_queue_rate(self, line): - "Set rate of one / all egress queue(s): set_queue_rate []" + "Set rate of one / all egress queue(s): set_queue_rate [] []" args = line.split() - rate = int(args[0]) - if len(args) > 1: - port = int(args[1]) - self.sswitch_client.set_egress_queue_rate(port, rate) - else: - self.sswitch_client.set_all_egress_queue_rates(rate) - + + self.at_least_n_args(args,1) + + try: + rate = int(args[0]) + if len(args) > 2: + port = int(args[1]) + priority = int(args[2]) + self.sswitch_client.set_egress_priority_queue_rate(port, priority, rate) + elif len(args) > 1: + port = int(args[1]) + self.sswitch_client.set_egress_queue_rate(port, rate) + else: + self.sswitch_client.set_all_egress_queue_rates(rate) + except ValueError: + print "Invalid rate, port or priority value" + + @runtime_CLI.handle_bad_input def do_mirroring_add(self, line): "Add mirroring mapping: mirroring_add " args = line.split() + self.at_least_n_args(args,2) mirror_id, egress_port = int(args[0]), int(args[1]) self.sswitch_client.mirroring_mapping_add(mirror_id, egress_port) + @runtime_CLI.handle_bad_input def do_mirroring_delete(self, line): "Delete mirroring mapping: mirroring_delete " mirror_id = int(line) self.sswitch_client.mirroring_mapping_delete(mirror_id) + @runtime_CLI.handle_bad_input def do_get_time_elapsed(self, line): "Get time elapsed (in microseconds) since the switch started: get_time_elapsed" print self.sswitch_client.get_time_elapsed_us() + @runtime_CLI.handle_bad_input def do_get_time_since_epoch(self, line): "Get time elapsed (in microseconds) since the switch clock's epoch: get_time_since_epoch" print self.sswitch_client.get_time_since_epoch_us() diff --git a/targets/simple_switch/thrift/simple_switch.thrift b/targets/simple_switch/thrift/simple_switch.thrift index 1242b7a85..aadd41a43 100644 --- a/targets/simple_switch/thrift/simple_switch.thrift +++ b/targets/simple_switch/thrift/simple_switch.thrift @@ -28,8 +28,10 @@ service SimpleSwitch { i32 mirroring_mapping_get_egress_port(1:i32 mirror_id); i32 set_egress_queue_depth(1:i32 port_num, 2:i32 depth_pkts); + i32 set_egress_priority_queue_depth(1:i32 port_num, 2:i32 priority, 3:i32 depth_pkts); i32 set_all_egress_queue_depths(1:i32 depth_pkts); i32 set_egress_queue_rate(1:i32 port_num, 2:i64 rate_pps); + i32 set_egress_priority_queue_rate(1:i32 port_num, 2:i32 priority, 3:i64 rate_pps); i32 set_all_egress_queue_rates(1:i64 rate_pps); // these methods are here as an experiment, prefer get_time_elapsed_us() when diff --git a/targets/simple_switch/thrift/src/SimpleSwitch_server.cpp b/targets/simple_switch/thrift/src/SimpleSwitch_server.cpp index a3be4649d..b6253aa7d 100644 --- a/targets/simple_switch/thrift/src/SimpleSwitch_server.cpp +++ b/targets/simple_switch/thrift/src/SimpleSwitch_server.cpp @@ -71,6 +71,15 @@ class SimpleSwitchHandler : virtual public SimpleSwitchIf { static_cast(depth_pkts)); } + int32_t set_egress_priority_queue_depth(const int32_t port_num, + const int32_t priority, + const int32_t depth_pkts) { + bm::Logger::get()->trace("set_egress_priority_queue_depth"); + return switch_->set_egress_priority_queue_depth(port_num, + priority, + static_cast(depth_pkts)); + } + int32_t set_all_egress_queue_depths(const int32_t depth_pkts) { bm::Logger::get()->trace("set_all_egress_queue_depths"); return switch_->set_all_egress_queue_depths( @@ -84,6 +93,15 @@ class SimpleSwitchHandler : virtual public SimpleSwitchIf { static_cast(rate_pps)); } + int32_t set_egress_priority_queue_rate(const int32_t port_num, + const int32_t priority, + const int64_t rate_pps) { + bm::Logger::get()->trace("set_egress_priority_queue_rate"); + return switch_->set_egress_priority_queue_rate(port_num, + priority, + static_cast(rate_pps)); + } + int32_t set_all_egress_queue_rates(const int64_t rate_pps) { bm::Logger::get()->trace("set_all_egress_queue_rates"); return switch_->set_all_egress_queue_rates(static_cast(rate_pps));