-
Notifications
You must be signed in to change notification settings - Fork 0
/
sswitch_CLI.py
88 lines (70 loc) · 2.91 KB
/
sswitch_CLI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python2
# Copyright 2013-present Barefoot Networks, Inc.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Antonin Bas ([email protected])
#
#
import runtime_CLI
import sys
import os
from sswitch_runtime import SimpleSwitch
class SimpleSwitchAPI(runtime_CLI.RuntimeAPI):
@staticmethod
def get_thrift_services():
return [("simple_switch", SimpleSwitch.Client)]
def __init__(self, pre_type, standard_client, mc_client, sswitch_client):
runtime_CLI.RuntimeAPI.__init__(self, pre_type,
standard_client, mc_client)
self.sswitch_client = sswitch_client
def do_set_queue_depth(self, line):
"Set depth of one / all egress queue(s): set_queue_depth <nb_pkts> [<egress_port>]"
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)
def do_set_queue_rate(self, line):
"Set rate of one / all egress queue(s): set_queue_rate <rate_pps> [<egress_port>]"
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)
def do_mirroring_add(self, line):
"Add mirroring mapping: mirroring_add <mirror_id> <egress_port>"
args = line.split()
mirror_id, egress_port = int(args[0]), int(args[1])
self.sswitch_client.mirroring_mapping_add(mirror_id, egress_port)
def do_mirroring_delete(self, line):
"Delete mirroring mapping: mirroring_delete <mirror_id>"
mirror_id = int(line)
self.sswitch_client.mirroring_mapping_delete(mirror_id)
def main():
args = runtime_CLI.get_parser().parse_args()
args.pre = runtime_CLI.PreType.SimplePreLAG
services = runtime_CLI.RuntimeAPI.get_thrift_services(args.pre)
services.extend(SimpleSwitchAPI.get_thrift_services())
standard_client, mc_client, sswitch_client = runtime_CLI.thrift_connect(
args.thrift_ip, args.thrift_port, services
)
runtime_CLI.load_json_config(standard_client, args.json)
SimpleSwitchAPI(args.pre, standard_client, mc_client, sswitch_client).cmdloop()
if __name__ == '__main__':
main()