-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTribTraffic.py
295 lines (250 loc) · 9.71 KB
/
TribTraffic.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env python
# $Header: /usr/local/cvsroot/stratex/rats/Traffic/TribTraffic.py,
"""
Interface to tributary traffic functions
Traffic checking available for all terminals that have defined BER tester connections.
"""
__docformat__ = 'epytext en' #Formatted for use with Epydoc tool (http://epydoc.sourceforge.net/)
from BerManager import BerManager
from Snmp import SnmpManager
from Modules import Timer
import time
class TribTraffic(object):
"""
"""
def __init__(self):
"""
"""
#self.stats = {}
#self.stats["ErrorCount"] = 0
self._manager = BerManager()
mgr = SnmpManager.SnmpManager()
self._context = "terminal"
self._terminalId = 0
def _getDacContext(self, slot=0, trib=0):
if self._context == "terminal":
#use ber connection information to decide trib
pass
if self._context.startswith("slot"):
#use ber connection information to decide trib
pass
if slot:
pass
if trib:
pass
return (slot, trib)
def start(self, terminal, slot, trib):
self._manager.ber_function("start", terminal, slot, trib)
def stop(self, terminal, slot, trib):
self._manager.ber_function("stop", terminal, slot, trib)
def set_type(self, terminal, slot, trib, traffic_type):
"""
Sets the traffic type for the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("set_type", terminal, slot, trib, traffic_type)
result = self._manager.ber_function("reset", terminal, slot, trib)
if result < 0:
result = 0
return result
def reset(self, terminal, slot, trib):
"""
Resets traffic generation for the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("reset", terminal, slot, trib)
return result
def on(self, terminal, slot, trib):
"""
Enables traffic generation INTO the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("on", terminal, slot, trib)
if result < 0:
result = 0
return result
def off(self, terminal, slot, trib):
"""
Disables traffic generation INTO the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("off", terminal, slot, trib)
if result < 0:
result = 0
return result
def los_on(self, terminal, slot, trib):
"""
Disables the channel connected to the terminal specified causing LOS to be
generated
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("los_on", terminal, slot, trib)
if result < 0:
result = 0
return result
def los_off(self, terminal, slot, trib):
"""
Enable the channel connected to the terminal specified
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("los_off", terminal, slot, trib)
if result < 0:
result = 0
return result
def ais_on(self, terminal, slot, trib):
"""
Enables AIS generation INTO the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("ais_on", terminal, slot, trib)
if result < 0:
result = 0
return result
def ais_off(self, terminal, slot, trib):
"""
Disables AIS generation INTO the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
"""
result = self._manager.ber_function("ais_off", terminal, slot, trib)
if result < 0:
result = 0
return result
def errors(self, terminal, slot, trib):
"""
Returns the number of errors for the specified terminal, slot and tributary.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@rtype: int
@return: Zero if the requested operation was successful. Non-zero otherwise.
Stats dictionary updated. ErrorCount entry reports number of detected errors.
"""
result = self._manager.ber_function("check", terminal, slot, trib)
#result = self.traffic_on(terminal, slot, trib)
#self.traffic_errors(terminal, slot, trib)
#self.stats["ErrorCount"] = result
return result
def check(self, terminal, slot, trib, duration=10):
"""
Checks that traffic remains error-free for a duration.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@type duration: int
@param duration: The duration in seconds to verify traffic for.
@rtype: int
@return: Zero if the traffic was error-free. Number of detected errors otherwise.
Stats dictionary updated. ErrorCount entry reports number of detected errors.
"""
self.reset(terminal, slot, trib)
Timer.Wait("Checking traffic: "+terminal, duration)
result = self.errors(terminal, slot, trib)
return result
def check_poll(self, terminal, slot, trib, retry=1, duration=10):
while retry > 0:
self.reset(terminal, slot, trib)
Timer.Wait("Checking traffic: "+terminal, duration)
result = self.errors(terminal, slot, trib)
if result == 0:
break
retry -= 1
return result
def check_ais(self, terminal, slot, trib, duration=5):
"""
Checks for AIS for a duration.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@type duration: int
@param duration: The duration in seconds to verify AIS for.
@rtype: int
@return: Zero if AIS is not active, -1 otherwise
"""
self.reset(terminal, slot, trib)
Timer.Wait("Checking for AIS: "+terminal, duration)
return self._manager.ber_function("check_ais", terminal, slot, trib)
def check_los(self, terminal, slot, trib, duration=5):
"""
Checks for LOS for a duration.
@type terminal: session
@param terminal: The terminal
@type slot: int
@param slot: The slot
@type trib: int
@param trib: The trib
@type duration: int
@param duration: The duration in seconds to verify LOS for.
@rtype: int
@return: Zero if AIS is not active, -1 otherwise
"""
self.reset(terminal, slot, trib)
Timer.Wait("Checking for LOS: "+terminal, duration)
return self._manager.ber_function("check_los", terminal, slot, trib)
if __name__ == "__main__":
print "RATS system support module: Cannot be run independently"
#