-
Notifications
You must be signed in to change notification settings - Fork 0
/
ekinops_module_reader.go
253 lines (236 loc) · 9.49 KB
/
ekinops_module_reader.go
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
package codecommunicator
import (
"context"
"github.com/RincewindsHat/thola/internal/device"
"github.com/RincewindsHat/thola/internal/network"
"github.com/pkg/errors"
"math"
)
// ekinopsModuleReader is an interface with one function that receives an array of device.Interface and
// adds the module specific metrics to it. It returns a new
type ekinopsModuleReader interface {
readModuleMetrics(context.Context, []device.Interface) ([]device.Interface, error)
getSlotIdentifier() string
getModuleName() string
}
func ekinopsGetModuleReader(slotIdentifier, module string) (ekinopsModuleReader, error) {
moduleData := ekinopsModuleData{slotIdentifier, module}
switch module {
case "PM_OAIL-HCS", "PM_OAIL-HCS-17", "PM-OABP-HC", "PM-OAIL-HC":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderAmplifier{
ekinopsModuleData: moduleData,
boosterPorts: ekinopsAmplifierOIDs{
identifierOID: ".1.3.6.1.4.1.20044.62.7.7.1.2",
labelOID: ".1.3.6.1.4.1.20044.62.9.4.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.62.3.3.49.0",
rxPowerOID: ".1.3.6.1.4.1.20044.62.3.3.50.0",
gainOID: ".1.3.6.1.4.1.20044.62.3.3.51.0",
powerTransformFunc: ekinopsPowerTransformMinus32768MultiplyByPoint005,
},
preAmpPorts: ekinopsAmplifierOIDs{
identifierOID: ".1.3.6.1.4.1.20044.62.7.8.1.2",
labelOID: ".1.3.6.1.4.1.20044.62.9.4.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.62.3.2.33.0",
rxPowerOID: ".1.3.6.1.4.1.20044.62.3.2.34.0",
gainOID: ".1.3.6.1.4.1.20044.62.3.2.35.0",
powerTransformFunc: ekinopsPowerTransformMinus32768MultiplyByPoint005,
},
}}, nil
case "PM_100G-AGG":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderTransponder{
ekinopsModuleData: moduleData,
networkLinePortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.91.7.1.2.1.2",
labelOID: ".1.3.6.1.4.1.20044.91.9.3.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.91.3.3.160.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.91.3.3.192.1.2",
correctedFEC: ".1.3.6.1.4.1.20044.91.4.3.193.1.2",
uncorrectedFEC: ".1.3.6.1.4.1.20044.91.4.3.197.1.2",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
clientPortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.91.7.1.1.1.2",
labelOID: ".1.3.6.1.4.1.20044.91.9.3.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.91.3.2.80.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.91.3.2.112.1.2",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
}}, nil
case "PM_1604":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderTransponder{
ekinopsModuleData: moduleData,
networkLinePortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.77.7.1.2.1.2",
labelOID: ".1.3.6.1.4.1.20044.77.9.3.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.77.3.3.44.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.77.3.3.52.1.2",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
clientPortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.77.7.1.1.1.2",
labelOID: ".1.3.6.1.4.1.20044.77.9.3.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.77.3.2.40.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.77.3.2.48.1.2",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
}}, nil
case "PM_200FRS02":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderTransponder{
ekinopsModuleData: moduleData,
networkLinePortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.90.7.1.2.1.2",
labelOID: ".1.3.6.1.4.1.20044.90.9.3.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.90.3.3.144.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.90.3.3.156.1.2",
correctedFEC: "",
uncorrectedFEC: ".1.3.6.1.4.1.20044.90.4.3.197.1.2",
powerTransformFunc: ekionopsPowerTransformShiftDivideBy100,
},
clientPortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.90.7.1.1.1.2",
labelOID: ".1.3.6.1.4.1.20044.90.9.3.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.90.3.2.256.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.90.3.2.288.1.2",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
}}, nil
case "PM_400FRS04-SF":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderTransponder{
ekinopsModuleData: moduleData,
networkLinePortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.100.7.1.2.1.2",
labelOID: ".1.3.6.1.4.1.20044.100.9.3.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.100.3.3.144.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.100.3.3.156.1.2",
correctedFEC: "",
uncorrectedFEC: ".1.3.6.1.4.1.20044.100.4.3.197.1.2",
powerTransformFunc: ekionopsPowerTransformShiftDivideBy100,
},
clientPortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.100.7.1.1.1.2",
labelOID: ".1.3.6.1.4.1.20044.100.9.3.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.100.3.2.256.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.100.3.2.288.1.2",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
}}, nil
case "PM_O6006MP":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderTransponder{
ekinopsModuleData: moduleData,
networkLinePortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.70.7.1.2.1.2",
labelOID: ".1.3.6.1.4.1.20044.70.9.2.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.70.3.3.80.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.70.3.3.128.1.2",
correctedFEC: ".1.3.6.1.4.1.20044.70.4.3.200.1.2",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XDivideBy10000,
},
clientPortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.70.7.1.1.1.2",
labelOID: ".1.3.6.1.4.1.20044.70.9.2.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.70.3.2.48.1.2",
rxPowerOID: ".1.3.6.1.4.1.20044.70.3.2.64.1.2",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XDivideBy10000,
},
}}, nil
case "PM_1001RR":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderTransponder{
ekinopsModuleData: moduleData,
networkLinePortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.8.7.7",
labelOID: ".1.3.6.1.4.1.20044.8.9.3.2.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.8.3.3.27",
rxPowerOID: ".1.3.6.1.4.1.20044.8.3.3.28",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
clientPortsOIDs: ekinopsTransponderOIDs{
identifierOID: ".1.3.6.1.4.1.20044.8.7.6",
labelOID: ".1.3.6.1.4.1.20044.8.9.3.1.1.3",
txPowerOID: ".1.3.6.1.4.1.20044.8.3.2.19",
rxPowerOID: ".1.3.6.1.4.1.20044.8.3.2.20",
correctedFEC: "",
uncorrectedFEC: "",
powerTransformFunc: ekinopsPowerTransform10Log10XMinus40,
},
}}, nil
case "PM_OPM8":
return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderOPM8{
ekinopsModuleData: moduleData,
ports: ekinopsOPMOIDs{
identifierOID: ".1.3.6.1.4.1.20044.66.7.1.1.1.2",
labelOID: ".1.3.6.1.4.1.20044.66.9.2.7.1.3",
rxPowerOID: ".1.3.6.1.4.1.20044.66.3.2.784.1.2",
channelsOid: ".1.3.6.1.4.1.20044.66.3.2",
powerTransformFunc: ekinopsPowerTransformOPM8,
},
}}, nil
}
return nil, errors.New("no module reader available")
}
type ekinopsModuleData struct {
slotIdentifier string
moduleName string
}
func (e *ekinopsModuleData) getSlotIdentifier() string {
return e.slotIdentifier
}
func (e *ekinopsModuleData) getModuleName() string {
return e.moduleName
}
type ekinopsModuleReaderWrapper struct {
ekinopsModuleReader
}
func (m *ekinopsModuleReaderWrapper) readModuleMetrics(ctx context.Context, interfaces []device.Interface) ([]device.Interface, error) {
// switch snmp community
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("no device connection available")
}
community := con.SNMP.SnmpClient.GetCommunity()
con.SNMP.SnmpClient.SetCommunity(community + m.getSlotIdentifier())
defer con.SNMP.SnmpClient.SetCommunity(community)
return m.ekinopsModuleReader.readModuleMetrics(ctx, interfaces)
}
type ekinopsPowerTransformFunc func(float64) float64
func ekinopsPowerTransform10Log10XMinus40(f float64) float64 {
return ekinopsPowerTransformCheckInfinity(10*math.Log10(f) - 40)
}
func ekinopsPowerTransform10Log10XDivideBy10000(f float64) float64 {
return ekinopsPowerTransformCheckInfinity(10 * math.Log10(f/10000))
}
func ekionopsPowerTransformShiftDivideBy100(f float64) float64 {
if f < 32768 {
return f / 100
}
return (f - 65536) / 100
}
func ekinopsPowerTransformMinus32768MultiplyByPoint005(f float64) float64 {
return (f - 32768) * 0.005
}
func ekinopsPowerTransformOPM8(f float64) float64 {
if f < 32768 {
return f / 256
}
return f/256 - 256
}
func ekinopsPowerTransformCheckInfinity(f float64) float64 {
if math.IsInf(f, -1) || math.IsNaN(f) {
f = -99999
}
return f
}