forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabric.py
More file actions
247 lines (196 loc) · 7.83 KB
/
Copy pathfabric.py
File metadata and controls
247 lines (196 loc) · 7.83 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import click
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util
from sonic_py_common import multi_asic
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
#
# 'config fabric ...'
#
@click.group(cls=clicommon.AbbreviationGroup)
def fabric():
"""FABRIC-related configuration tasks"""
pass
#
# 'config fabric port ...'
#
@fabric.group(cls=clicommon.AbbreviationGroup)
def port():
"""FABRIC PORT configuration tasks"""
pass
#
# 'config fabric port isolate <portid> [ -n <asic> ]'
#
@port.command()
@click.argument('portid', metavar='<portid>', required=True)
@multi_asic_util.multi_asic_click_option_namespace
def isolate(portid, namespace):
"""FABRIC PORT isolate <portid>"""
ctx = click.get_current_context()
if not portid.isdigit():
ctx.fail("Invalid portid")
n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')
# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)
# check if the port is actually in use
portName = f'PORT{portid}'
portStateData = state_db.get_all(state_db.STATE_DB, "FABRIC_PORT_TABLE|" + portName)
if "REMOTE_PORT" not in portStateData:
ctx.fail(f"Port {portid} is not in use")
# Make sure configuration data exists
portName = f'Fabric{portid}'
portConfigData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_PORT|" + portName)
if not bool(portConfigData):
ctx.fail("Fabric monitor configuration data not present")
# Update entry
config_db.mod_entry("FABRIC_PORT", portName, {'isolateStatus': True})
#
# 'config fabric port unisolate <portid> [ -n <asic> ]'
#
@port.command()
@click.argument('portid', metavar='<portid>', required=True)
@multi_asic_util.multi_asic_click_option_namespace
def unisolate(portid, namespace):
"""FABRIC PORT unisolate <portid>"""
ctx = click.get_current_context()
if not portid.isdigit():
ctx.fail("Invalid portid")
n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')
# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)
# check if the port is actually in use
portName = f'PORT{portid}'
portStateData = state_db.get_all(state_db.STATE_DB, "FABRIC_PORT_TABLE|" + portName)
if "REMOTE_PORT" not in portStateData:
ctx.fail(f"Port {portid} is not in use")
# Make sure configuration data exists
portName = f'Fabric{portid}'
portConfigData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_PORT|" + portName)
if not bool(portConfigData):
ctx.fail("Fabric monitor configuration data not present")
# Update entry
config_db.mod_entry("FABRIC_PORT", portName, {'isolateStatus': False})
#
# 'config fabric port monitor ...'
#
@port.group(cls=clicommon.AbbreviationGroup)
def monitor():
"""FABRIC PORT MONITOR configuration tasks"""
pass
#
# 'config fabric port monitor error ...'
#
@monitor.group(cls=clicommon.AbbreviationGroup)
def error():
"""FABRIC PORT MONITOR ERROR configuration tasks"""
pass
#
# 'config fabric port monitor error threshold <crcCells> <rxCells>'
#
@error.command('threshold')
@click.argument('crcCells', metavar='<crcCells>', required=True, type=int)
@click.argument('rxcells', metavar='<rxCells>', required=True, type=int)
@multi_asic_util.multi_asic_click_option_namespace
def error_threshold(crccells, rxcells, namespace):
"""FABRIC PORT MONITOR ERROR THRESHOLD configuration tasks"""
ctx = click.get_current_context()
n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')
# Check the values
if crccells < 1 or crccells > 1000:
ctx.fail("crcCells must be in range 1...1000")
if rxcells < 10000 or rxcells > 100000000:
ctx.fail("rxCells must be in range 10000...100000000")
# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)
# Make sure configuration data exists
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
if not bool(monitorData):
ctx.fail("Fabric monitor configuration data not present")
# Update entry
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
{'monErrThreshCrcCells': crccells, 'monErrThreshRxCells': rxcells})
#
# 'config fabric port monitor poll ...'
#
@monitor.group(cls=clicommon.AbbreviationGroup)
def poll():
"""FABRIC PORT MONITOR POLL configuration tasks"""
pass
#
# 'config fabric port monitor poll threshold ...'
#
@poll.group(cls=clicommon.AbbreviationGroup, name='threshold')
def poll_threshold():
"""FABRIC PORT MONITOR POLL THRESHOLD configuration tasks"""
pass
#
# 'config fabric port monitor poll threshold isolation <pollCount>'
#
@poll_threshold.command()
@click.argument('pollcount', metavar='<pollCount>', required=True, type=int)
@multi_asic_util.multi_asic_click_option_namespace
def isolation(pollcount, namespace):
"""FABRIC PORT MONITOR POLL THRESHOLD configuration tasks"""
ctx = click.get_current_context()
n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')
if pollcount < 1 or pollcount > 10:
ctx.fail("pollCount must be in range 1...10")
# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)
# Make sure configuration data exists
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
if not bool(monitorData):
ctx.fail("Fabric monitor configuration data not present")
# Update entry
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
{"monPollThreshIsolation": pollcount})
#
# 'config fabric port monitor poll threshold recovery <pollCount>'
#
@poll_threshold.command()
@click.argument('pollcount', metavar='<pollCount>', required=True, type=int)
@multi_asic_util.multi_asic_click_option_namespace
def recovery(pollcount, namespace):
"""FABRIC PORT MONITOR POLL THRESHOLD configuration tasks"""
ctx = click.get_current_context()
n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')
if pollcount < 1 or pollcount > 10:
ctx.fail("pollCount must be in range 1...10")
# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)
# Make sure configuration data exists
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
if not bool(monitorData):
ctx.fail("Fabric monitor configuration data not present")
# Update entry
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
{"monPollThreshRecovery": pollcount})