blob: e9fabede4496be8df1f08e1c5b2c6c3dabe36a43 [file] [log] [blame]
Matteo Scandoloef4e8f82021-05-17 11:20:49 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package omci
18
19import (
Matteo Scandolo8a574812021-05-20 15:18:53 -070020 "bytes"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070021 "encoding/binary"
22 "encoding/hex"
Elia Battistonac63b112022-01-12 18:40:49 +010023
Andrea Campanella10426e22021-10-15 17:58:04 +020024 me "github.com/opencord/omci-lib-go/v2/generated"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070025)
26
27type MibDbEntry struct {
28 classId me.ClassID
29 entityId EntityID
30 params me.AttributeValueMap
31}
32
33type MibDb struct {
34 NumberOfCommands uint16
35 items []MibDbEntry
36}
37
38type EntityID []byte
39
40func (e EntityID) ToString() string {
41 return hex.EncodeToString(e)
42}
43
44func (e EntityID) ToUint16() uint16 {
45 return binary.BigEndian.Uint16(e)
46}
47
48func (e EntityID) ToUint32() uint32 {
49 return binary.BigEndian.Uint32(e)
50}
51
Matteo Scandolo8a574812021-05-20 15:18:53 -070052func (e EntityID) FromUint16(id uint16) EntityID {
53 buff := new(bytes.Buffer)
54 err := binary.Write(buff, binary.BigEndian, id)
55 if err != nil {
56 panic(err)
57 }
58
59 return buff.Bytes()
60}
61
62func (e EntityID) Equals(i EntityID) bool {
63 if res := bytes.Compare(e, i); res == 0 {
64 return true
65 }
66 return false
67}
68
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070069const (
70 cardHolderOnuType byte = 0x01 // ONU is a single piece of integrated equipment
71 ethernetUnitType byte = 0x2f // Ethernet BASE-T
72 xgsPonUnitType byte = 0xee // XG-PON10G10
Elia Battistonac63b112022-01-12 18:40:49 +010073 potsUnitType byte = 0x20 // POTS
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070074 cardHolderSlotID byte = 0x01
75 tcontSlotId byte = 0x80 // why is this not the same as the cardHolderSlotID, it does not point to anything
76 aniGId byte = 0x01
77
78 upstreamPriorityQueues = 8 // Number of queues for each T-CONT
79 downstreamPriorityQueues = 16 // Number of queues for each PPTP
80 tconts = 8 // NOTE will we ever need to configure this?
81 // trafficSchedulers = 8 // NOTE will we ever need to configure this?
82)
83
84var (
85 cardHolderEntityID = EntityID{cardHolderOnuType, cardHolderSlotID}
86 circuitPackEntityID = cardHolderEntityID // is the same as that of the cardholder ME containing this circuit pack instance
87)
88
89func GenerateUniPortEntityId(id uint32) EntityID {
90 return EntityID{cardHolderSlotID, byte(id)}
91}
92
93// creates a MIB database for a ONU
94// CircuitPack and CardHolder are static, everything else can be configured
Elia Battistonac63b112022-01-12 18:40:49 +010095func GenerateMibDatabase(ethUniPortCount int, potsUniPortCount int) (*MibDb, error) {
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070096
97 mibDb := MibDb{
98 items: []MibDbEntry{},
99 }
100
101 // the first element to return is the ONU-Data
102 mibDb.items = append(mibDb.items, MibDbEntry{
103 me.OnuDataClassID,
104 EntityID{0x00, 0x00},
Elia Battiston9bfe1102022-02-03 10:38:03 +0100105 me.AttributeValueMap{me.OnuData_MibDataSync: 0}, // FIXME this needs to be parametrized before sending the response
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700106 })
107
108 // then we report the CardHolder
109 // NOTE we have not report it till now, so leave it commented out
110 //mibDb.items = append(mibDb.items, MibDbEntry{
111 // me.CardholderClassID,
112 // cardHolderEntityID,
113 // me.AttributeValueMap{
114 // "ActualPlugInUnitType": cardHolderOnuType,
115 // "ExpectedPlugInUnitType": ethernetUnitType,
116 // },
117 //})
118
119 // circuitPack XG-PON10G10
120 mibDb.items = append(mibDb.items, MibDbEntry{
121 me.CircuitPackClassID,
122 circuitPackEntityID,
123 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100124 me.CircuitPack_Type: xgsPonUnitType,
125 me.CircuitPack_NumberOfPorts: 1, // NOTE is this the ANI port? must be
126 me.CircuitPack_SerialNumber: ToOctets("BBSM-Circuit-Pack-ani", 20),
127 me.CircuitPack_Version: ToOctets("v0.0.1", 20),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700128 },
129 })
130 mibDb.items = append(mibDb.items, MibDbEntry{
131 me.CircuitPackClassID,
132 circuitPackEntityID,
133 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100134 me.CircuitPack_VendorId: ToOctets("ONF", 4),
135 me.CircuitPack_AdministrativeState: 0,
136 me.CircuitPack_OperationalState: 0,
137 me.CircuitPack_BridgedOrIpInd: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700138 },
139 })
140 mibDb.items = append(mibDb.items, MibDbEntry{
141 me.CircuitPackClassID,
142 circuitPackEntityID,
143 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100144 me.CircuitPack_EquipmentId: ToOctets("BBSM-Circuit-Pack", 20),
145 me.CircuitPack_CardConfiguration: 0,
146 me.CircuitPack_TotalTContBufferNumber: 8,
147 me.CircuitPack_TotalPriorityQueueNumber: 8,
148 me.CircuitPack_TotalTrafficSchedulerNumber: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700149 },
150 })
151 mibDb.items = append(mibDb.items, MibDbEntry{
152 me.CircuitPackClassID,
153 circuitPackEntityID,
154 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100155 me.CircuitPack_PowerShedOverride: uint32(0),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700156 },
157 })
158
159 // ANI-G
160 mibDb.items = append(mibDb.items, MibDbEntry{
161 me.AniGClassID,
162 EntityID{tcontSlotId, aniGId},
163 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100164 me.AniG_Arc: 0,
165 me.AniG_ArcInterval: 0,
166 me.AniG_Deprecated: 0,
167 me.AniG_GemBlockLength: 48,
168 me.AniG_LowerOpticalThreshold: 255,
169 me.AniG_LowerTransmitPowerThreshold: 129,
170 me.AniG_OnuResponseTime: 0,
171 me.AniG_OpticalSignalLevel: 57428,
172 me.AniG_PiggybackDbaReporting: 0,
173 me.AniG_SignalDegradeThreshold: 9,
174 me.AniG_SignalFailThreshold: 5,
175 me.AniG_SrIndication: 1,
176 me.AniG_TotalTcontNumber: 8,
177 me.AniG_TransmitOpticalLevel: 3171,
178 me.AniG_UpperOpticalThreshold: 255,
179 me.AniG_UpperTransmitPowerThreshold: 129,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700180 },
181 })
182
183 // circuitPack Ethernet
184 // NOTE the circuit pack is divided in multiple messages as too big to fit in a single one
185 mibDb.items = append(mibDb.items, MibDbEntry{
186 me.CircuitPackClassID,
187 circuitPackEntityID,
188 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100189 me.CircuitPack_Type: ethernetUnitType,
190 me.CircuitPack_NumberOfPorts: ethUniPortCount,
191 me.CircuitPack_SerialNumber: ToOctets("BBSM-Circuit-Pack", 20),
192 me.CircuitPack_Version: ToOctets("v0.0.1", 20),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700193 },
194 })
195 mibDb.items = append(mibDb.items, MibDbEntry{
196 me.CircuitPackClassID,
197 circuitPackEntityID,
198 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100199 me.CircuitPack_VendorId: ToOctets("ONF", 4),
200 me.CircuitPack_AdministrativeState: 0,
201 me.CircuitPack_OperationalState: 0,
202 me.CircuitPack_BridgedOrIpInd: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700203 },
204 })
205 mibDb.items = append(mibDb.items, MibDbEntry{
206 me.CircuitPackClassID,
207 circuitPackEntityID,
208 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100209 me.CircuitPack_EquipmentId: ToOctets("BBSM-Circuit-Pack", 20),
210 me.CircuitPack_CardConfiguration: 0,
211 me.CircuitPack_TotalTContBufferNumber: 8,
212 me.CircuitPack_TotalPriorityQueueNumber: 8,
213 me.CircuitPack_TotalTrafficSchedulerNumber: 16,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700214 },
215 })
216 mibDb.items = append(mibDb.items, MibDbEntry{
217 me.CircuitPackClassID,
218 circuitPackEntityID,
219 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100220 me.CircuitPack_PowerShedOverride: uint32(0),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700221 },
222 })
223
Elia Battistonac63b112022-01-12 18:40:49 +0100224 if potsUniPortCount > 0 {
225 // circuitPack POTS
226 // NOTE the circuit pack is divided in multiple messages as too big to fit in a single one
227 mibDb.items = append(mibDb.items, MibDbEntry{
228 me.CircuitPackClassID,
229 circuitPackEntityID,
230 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100231 me.CircuitPack_Type: potsUnitType,
232 me.CircuitPack_NumberOfPorts: potsUniPortCount,
233 me.CircuitPack_SerialNumber: ToOctets("BBSM-Circuit-Pack", 20),
234 me.CircuitPack_Version: ToOctets("v0.0.1", 20),
Elia Battistonac63b112022-01-12 18:40:49 +0100235 },
236 })
237 mibDb.items = append(mibDb.items, MibDbEntry{
238 me.CircuitPackClassID,
239 circuitPackEntityID,
240 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100241 me.CircuitPack_VendorId: ToOctets("ONF", 4),
242 me.CircuitPack_AdministrativeState: 0,
243 me.CircuitPack_OperationalState: 0,
244 me.CircuitPack_BridgedOrIpInd: 0,
Elia Battistonac63b112022-01-12 18:40:49 +0100245 },
246 })
247 mibDb.items = append(mibDb.items, MibDbEntry{
248 me.CircuitPackClassID,
249 circuitPackEntityID,
250 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100251 me.CircuitPack_EquipmentId: ToOctets("BBSM-Circuit-Pack", 20),
252 me.CircuitPack_CardConfiguration: 0,
253 me.CircuitPack_TotalTContBufferNumber: 8,
254 me.CircuitPack_TotalPriorityQueueNumber: 8,
255 me.CircuitPack_TotalTrafficSchedulerNumber: 16,
Elia Battistonac63b112022-01-12 18:40:49 +0100256 },
257 })
258 mibDb.items = append(mibDb.items, MibDbEntry{
259 me.CircuitPackClassID,
260 circuitPackEntityID,
261 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100262 me.CircuitPack_PowerShedOverride: uint32(0),
Elia Battistonac63b112022-01-12 18:40:49 +0100263 },
264 })
265 }
266
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700267 // PPTP and UNI-Gs
268 // NOTE this are dependent on the number of UNI this ONU supports
269 // Through an identical ID, the UNI-G ME is implicitly linked to an instance of a PPTP
Elia Battistonac63b112022-01-12 18:40:49 +0100270 totalPortsCount := ethUniPortCount + potsUniPortCount
271 for i := 1; i <= totalPortsCount; i++ {
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700272 uniEntityId := GenerateUniPortEntityId(uint32(i))
273
Elia Battistonac63b112022-01-12 18:40:49 +0100274 if i <= ethUniPortCount {
275 // first, create the correct amount of ethernet UNIs, the same is done in onu.go
276 mibDb.items = append(mibDb.items, MibDbEntry{
277 me.PhysicalPathTerminationPointEthernetUniClassID,
278 uniEntityId,
279 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100280 me.PhysicalPathTerminationPointEthernetUni_ExpectedType: 0,
281 me.PhysicalPathTerminationPointEthernetUni_SensedType: ethernetUnitType,
282 me.PhysicalPathTerminationPointEthernetUni_AutoDetectionConfiguration: 0,
283 me.PhysicalPathTerminationPointEthernetUni_EthernetLoopbackConfiguration: 0,
284 me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: 0,
285 me.PhysicalPathTerminationPointEthernetUni_OperationalState: 0,
286 me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd: 3,
287 me.PhysicalPathTerminationPointEthernetUni_MaxFrameSize: 1518,
288 me.PhysicalPathTerminationPointEthernetUni_DteOrDceInd: 0,
289 me.PhysicalPathTerminationPointEthernetUni_PauseTime: 0,
290 me.PhysicalPathTerminationPointEthernetUni_BridgedOrIpInd: 2,
291 me.PhysicalPathTerminationPointEthernetUni_Arc: 0,
292 me.PhysicalPathTerminationPointEthernetUni_ArcInterval: 0,
293 me.PhysicalPathTerminationPointEthernetUni_PppoeFilter: 0,
294 me.PhysicalPathTerminationPointEthernetUni_PowerControl: 0,
Elia Battistonac63b112022-01-12 18:40:49 +0100295 },
296 })
297 } else {
298 // the remaining ones are pots UNIs, the same is done in onu.go
299 mibDb.items = append(mibDb.items, MibDbEntry{
300 me.PhysicalPathTerminationPointPotsUniClassID,
301 uniEntityId,
302 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100303 me.PhysicalPathTerminationPointPotsUni_AdministrativeState: 0,
304 me.PhysicalPathTerminationPointPotsUni_Deprecated: 0,
305 me.PhysicalPathTerminationPointPotsUni_Arc: 0,
306 me.PhysicalPathTerminationPointPotsUni_ArcInterval: 0,
307 me.PhysicalPathTerminationPointPotsUni_Impedance: 0,
308 me.PhysicalPathTerminationPointPotsUni_TransmissionPath: 0,
309 me.PhysicalPathTerminationPointPotsUni_RxGain: 0,
310 me.PhysicalPathTerminationPointPotsUni_TxGain: 0,
311 me.PhysicalPathTerminationPointPotsUni_OperationalState: 0,
312 me.PhysicalPathTerminationPointPotsUni_HookState: 0,
313 me.PhysicalPathTerminationPointPotsUni_PotsHoldoverTime: 0,
314 me.PhysicalPathTerminationPointPotsUni_NominalFeedVoltage: 0,
315 me.PhysicalPathTerminationPointPotsUni_LossOfSoftswitch: 0,
Elia Battistonac63b112022-01-12 18:40:49 +0100316 },
317 })
318 }
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700319
320 mibDb.items = append(mibDb.items, MibDbEntry{
321 me.UniGClassID,
322 uniEntityId,
323 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100324 me.UniG_AdministrativeState: 0,
325 me.UniG_Deprecated: 0,
326 me.UniG_ManagementCapability: 0,
327 me.UniG_NonOmciManagementIdentifier: 0,
328 me.UniG_RelayAgentOptions: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700329 },
330 })
331
332 // Downstream Queues (related to PPTP)
333 // 16 priorities queues for each UNI Ports
334 // EntityID = cardHolderSlotID + Uni EntityID (0101)
335 for j := 1; j <= downstreamPriorityQueues; j++ {
336 queueEntityId := EntityID{cardHolderSlotID, byte(j)}
337
338 // we first report the PriorityQueue without any attribute
339 mibDb.items = append(mibDb.items, MibDbEntry{
340 me.PriorityQueueClassID,
341 queueEntityId, //was not reported in the original implementation
342 me.AttributeValueMap{},
343 })
344
345 // then we report it with the required attributes
346 // In the downstream direction, the first byte is the slot number and the second byte is the port number of the queue's destination port.
347 relatedPort := append(uniEntityId, 0x00, byte(j))
348 mibDb.items = append(mibDb.items, MibDbEntry{
349 me.PriorityQueueClassID,
350 queueEntityId, //was not reported in the original implementation
351 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100352 me.PriorityQueue_QueueConfigurationOption: 0,
353 me.PriorityQueue_MaximumQueueSize: 100,
354 me.PriorityQueue_AllocatedQueueSize: 100,
355 me.PriorityQueue_DiscardBlockCounterResetInterval: 0,
356 me.PriorityQueue_ThresholdValueForDiscardedBlocksDueToBufferOverflow: 0,
357 me.PriorityQueue_RelatedPort: relatedPort.ToUint32(),
358 me.PriorityQueue_TrafficSchedulerPointer: 0, //it was hardcoded to 0x0108 in the current implementation
359 me.PriorityQueue_Weight: 1,
360 me.PriorityQueue_BackPressureOperation: 1,
361 me.PriorityQueue_BackPressureTime: 0,
362 me.PriorityQueue_BackPressureOccurQueueThreshold: 0,
363 me.PriorityQueue_BackPressureClearQueueThreshold: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700364 },
365 })
366 }
367 }
368
369 // T-CONTS and Traffic Schedulers
370 for i := 1; i <= tconts; i++ {
371 tcontEntityId := EntityID{tcontSlotId, byte(i)}
372
373 mibDb.items = append(mibDb.items, MibDbEntry{
374 me.TContClassID,
375 tcontEntityId,
376 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100377 me.TCont_AllocId: 65535,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700378 },
379 })
380
381 tsEntityId := EntityID{cardHolderSlotID, byte(i)}
382 mibDb.items = append(mibDb.items, MibDbEntry{
383 me.TrafficSchedulerClassID,
384 tsEntityId, //was not reported in the original implementation
385 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100386 me.TrafficScheduler_TContPointer: tcontEntityId.ToUint16(), // was hardcoded to a non-existing t-cont
387 me.TrafficScheduler_TrafficSchedulerPointer: 0,
388 me.TrafficScheduler_Policy: 02,
389 me.TrafficScheduler_PriorityWeight: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700390 },
391 })
392
393 for j := 1; j <= upstreamPriorityQueues; j++ {
394 queueEntityId := EntityID{tcontSlotId, byte(j)}
395 // Upstream Queues (related to traffic schedulers)
396 // 8 priorities queues per TCONT
397 // EntityID = tcontSlotId + Uni EntityID (8001)
398
399 // we first report the PriorityQueue without any attribute
400 mibDb.items = append(mibDb.items, MibDbEntry{
401 me.PriorityQueueClassID,
402 queueEntityId, //was not reported in the original implementation
403 me.AttributeValueMap{},
404 })
405
406 // then we report it with the required attributes
407 // In the upstream direction, the first 2 bytes are the ME ID of the associated T- CONT, the first byte of which is a slot number, the second byte a T-CONT number.
408 relatedPort := append(tcontEntityId, 0x00, byte(j))
409 mibDb.items = append(mibDb.items, MibDbEntry{
410 me.PriorityQueueClassID,
411 queueEntityId, //was not reported in the original implementation
412 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100413 me.PriorityQueue_QueueConfigurationOption: 0,
414 me.PriorityQueue_MaximumQueueSize: 100,
415 me.PriorityQueue_AllocatedQueueSize: 100,
416 me.PriorityQueue_DiscardBlockCounterResetInterval: 0,
417 me.PriorityQueue_ThresholdValueForDiscardedBlocksDueToBufferOverflow: 0,
418 me.PriorityQueue_RelatedPort: relatedPort.ToUint32(),
419 me.PriorityQueue_TrafficSchedulerPointer: tsEntityId.ToUint16(), //it was hardcoded to 0x0108 in the current implementation
420 me.PriorityQueue_Weight: 1,
421 me.PriorityQueue_BackPressureOperation: 1,
422 me.PriorityQueue_BackPressureTime: 0,
423 me.PriorityQueue_BackPressureOccurQueueThreshold: 0,
424 me.PriorityQueue_BackPressureClearQueueThreshold: 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700425 },
426 })
427 }
428 }
429
430 // ONU-2g
431 mibDb.items = append(mibDb.items, MibDbEntry{
432 me.Onu2GClassID,
433 EntityID{0x00, 0x00},
434 me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100435 me.Onu2G_ConnectivityCapability: 127,
436 me.Onu2G_CurrentConnectivityMode: 0,
437 me.Onu2G_Deprecated: 1,
438 me.Onu2G_PriorityQueueScaleFactor: 1,
439 me.Onu2G_QualityOfServiceQosConfigurationFlexibility: 63,
440 me.Onu2G_Sysuptime: 0,
441 me.Onu2G_TotalGemPortIdNumber: 8,
442 me.Onu2G_TotalPriorityQueueNumber: 64,
443 me.Onu2G_TotalTrafficSchedulerNumber: 8,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700444 },
445 })
446
447 mibDb.NumberOfCommands = uint16(len(mibDb.items))
448
449 return &mibDb, nil
450}