blob: 0b73519f6d71b913763bbb3bac776af8de0865d6 [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"
23 me "github.com/opencord/omci-lib-go/generated"
24)
25
26type MibDbEntry struct {
27 classId me.ClassID
28 entityId EntityID
29 params me.AttributeValueMap
30}
31
32type MibDb struct {
33 NumberOfCommands uint16
34 items []MibDbEntry
35}
36
37type EntityID []byte
38
39func (e EntityID) ToString() string {
40 return hex.EncodeToString(e)
41}
42
43func (e EntityID) ToUint16() uint16 {
44 return binary.BigEndian.Uint16(e)
45}
46
47func (e EntityID) ToUint32() uint32 {
48 return binary.BigEndian.Uint32(e)
49}
50
Matteo Scandolo8a574812021-05-20 15:18:53 -070051func (e EntityID) FromUint16(id uint16) EntityID {
52 buff := new(bytes.Buffer)
53 err := binary.Write(buff, binary.BigEndian, id)
54 if err != nil {
55 panic(err)
56 }
57
58 return buff.Bytes()
59}
60
61func (e EntityID) Equals(i EntityID) bool {
62 if res := bytes.Compare(e, i); res == 0 {
63 return true
64 }
65 return false
66}
67
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070068const (
69 cardHolderOnuType byte = 0x01 // ONU is a single piece of integrated equipment
70 ethernetUnitType byte = 0x2f // Ethernet BASE-T
71 xgsPonUnitType byte = 0xee // XG-PON10G10
72 cardHolderSlotID byte = 0x01
73 tcontSlotId byte = 0x80 // why is this not the same as the cardHolderSlotID, it does not point to anything
74 aniGId byte = 0x01
75
76 upstreamPriorityQueues = 8 // Number of queues for each T-CONT
77 downstreamPriorityQueues = 16 // Number of queues for each PPTP
78 tconts = 8 // NOTE will we ever need to configure this?
79 // trafficSchedulers = 8 // NOTE will we ever need to configure this?
80)
81
82var (
83 cardHolderEntityID = EntityID{cardHolderOnuType, cardHolderSlotID}
84 circuitPackEntityID = cardHolderEntityID // is the same as that of the cardholder ME containing this circuit pack instance
85)
86
87func GenerateUniPortEntityId(id uint32) EntityID {
88 return EntityID{cardHolderSlotID, byte(id)}
89}
90
91// creates a MIB database for a ONU
92// CircuitPack and CardHolder are static, everything else can be configured
93func GenerateMibDatabase(uniPortCount int) (*MibDb, error) {
94
95 mibDb := MibDb{
96 items: []MibDbEntry{},
97 }
98
99 // the first element to return is the ONU-Data
100 mibDb.items = append(mibDb.items, MibDbEntry{
101 me.OnuDataClassID,
102 EntityID{0x00, 0x00},
103 me.AttributeValueMap{"MibDataSync": 0}, // FIXME this needs to be parametrized before sending the response
104 })
105
106 // then we report the CardHolder
107 // NOTE we have not report it till now, so leave it commented out
108 //mibDb.items = append(mibDb.items, MibDbEntry{
109 // me.CardholderClassID,
110 // cardHolderEntityID,
111 // me.AttributeValueMap{
112 // "ActualPlugInUnitType": cardHolderOnuType,
113 // "ExpectedPlugInUnitType": ethernetUnitType,
114 // },
115 //})
116
117 // circuitPack XG-PON10G10
118 mibDb.items = append(mibDb.items, MibDbEntry{
119 me.CircuitPackClassID,
120 circuitPackEntityID,
121 me.AttributeValueMap{
122 "Type": xgsPonUnitType,
123 "NumberOfPorts": 1, // NOTE is this the ANI port? must be
124 "SerialNumber": ToOctets("BBSM-Circuit-Pack-ani", 20),
125 "Version": ToOctets("v0.0.1", 20),
126 },
127 })
128 mibDb.items = append(mibDb.items, MibDbEntry{
129 me.CircuitPackClassID,
130 circuitPackEntityID,
131 me.AttributeValueMap{
132 "VendorId": "ONF",
133 "AdministrativeState": 0,
134 "OperationalState": 0,
135 "BridgedOrIpInd": 0,
136 },
137 })
138 mibDb.items = append(mibDb.items, MibDbEntry{
139 me.CircuitPackClassID,
140 circuitPackEntityID,
141 me.AttributeValueMap{
142 "EquipmentId": ToOctets("BBSM-Circuit-Pack", 20),
143 "CardConfiguration": 0,
144 "TotalTContBufferNumber": 8,
145 "TotalPriorityQueueNumber": 8,
146 "TotalTrafficSchedulerNumber": 0,
147 },
148 })
149 mibDb.items = append(mibDb.items, MibDbEntry{
150 me.CircuitPackClassID,
151 circuitPackEntityID,
152 me.AttributeValueMap{
153 "PowerShedOverride": uint32(0),
154 },
155 })
156
157 // ANI-G
158 mibDb.items = append(mibDb.items, MibDbEntry{
159 me.AniGClassID,
160 EntityID{tcontSlotId, aniGId},
161 me.AttributeValueMap{
162 "Arc": 0,
163 "ArcInterval": 0,
164 "Deprecated": 0,
165 "GemBlockLength": 48,
166 "LowerOpticalThreshold": 255,
167 "LowerTransmitPowerThreshold": 129,
168 "OnuResponseTime": 0,
169 "OpticalSignalLevel": 57428,
170 "PiggybackDbaReporting": 0,
171 "SignalDegradeThreshold": 9,
172 "SignalFailThreshold": 5,
173 "SrIndication": 1,
174 "TotalTcontNumber": 8,
175 "TransmitOpticalLevel": 3171,
176 "UpperOpticalThreshold": 255,
177 "UpperTransmitPowerThreshold": 129,
178 },
179 })
180
181 // circuitPack Ethernet
182 // NOTE the circuit pack is divided in multiple messages as too big to fit in a single one
183 mibDb.items = append(mibDb.items, MibDbEntry{
184 me.CircuitPackClassID,
185 circuitPackEntityID,
186 me.AttributeValueMap{
187 "Type": ethernetUnitType,
188 "NumberOfPorts": uniPortCount,
189 "SerialNumber": ToOctets("BBSM-Circuit-Pack", 20),
190 "Version": ToOctets("v0.0.1", 20),
191 },
192 })
193 mibDb.items = append(mibDb.items, MibDbEntry{
194 me.CircuitPackClassID,
195 circuitPackEntityID,
196 me.AttributeValueMap{
197 "VendorId": "ONF",
198 "AdministrativeState": 0,
199 "OperationalState": 0,
200 "BridgedOrIpInd": 0,
201 },
202 })
203 mibDb.items = append(mibDb.items, MibDbEntry{
204 me.CircuitPackClassID,
205 circuitPackEntityID,
206 me.AttributeValueMap{
207 "EquipmentId": ToOctets("BBSM-Circuit-Pack", 20),
208 "CardConfiguration": 0,
209 "TotalTContBufferNumber": 8,
210 "TotalPriorityQueueNumber": 8,
211 "TotalTrafficSchedulerNumber": 16,
212 },
213 })
214 mibDb.items = append(mibDb.items, MibDbEntry{
215 me.CircuitPackClassID,
216 circuitPackEntityID,
217 me.AttributeValueMap{
218 "PowerShedOverride": uint32(0),
219 },
220 })
221
222 // PPTP and UNI-Gs
223 // NOTE this are dependent on the number of UNI this ONU supports
224 // Through an identical ID, the UNI-G ME is implicitly linked to an instance of a PPTP
225 for i := 1; i <= uniPortCount; i++ {
226 uniEntityId := GenerateUniPortEntityId(uint32(i))
227
228 mibDb.items = append(mibDb.items, MibDbEntry{
229 me.PhysicalPathTerminationPointEthernetUniClassID,
230 uniEntityId,
231 me.AttributeValueMap{
232 "ExpectedType": 0,
233 "SensedType": ethernetUnitType,
234 "AutoDetectionConfiguration": 0,
235 "EthernetLoopbackConfiguration": 0,
236 "AdministrativeState": 0,
237 "OperationalState": 0,
238 "ConfigurationInd": 3,
239 "MaxFrameSize": 1518,
240 "DteOrDceInd": 0,
241 "PauseTime": 0,
242 "BridgedOrIpInd": 2,
243 "Arc": 0,
244 "ArcInterval": 0,
245 "PppoeFilter": 0,
246 "PowerControl": 0,
247 },
248 })
249
250 mibDb.items = append(mibDb.items, MibDbEntry{
251 me.UniGClassID,
252 uniEntityId,
253 me.AttributeValueMap{
254 "AdministrativeState": 0,
255 "Deprecated": 0,
256 "ManagementCapability": 0,
257 "NonOmciManagementIdentifier": 0,
258 "RelayAgentOptions": 0,
259 },
260 })
261
262 // Downstream Queues (related to PPTP)
263 // 16 priorities queues for each UNI Ports
264 // EntityID = cardHolderSlotID + Uni EntityID (0101)
265 for j := 1; j <= downstreamPriorityQueues; j++ {
266 queueEntityId := EntityID{cardHolderSlotID, byte(j)}
267
268 // we first report the PriorityQueue without any attribute
269 mibDb.items = append(mibDb.items, MibDbEntry{
270 me.PriorityQueueClassID,
271 queueEntityId, //was not reported in the original implementation
272 me.AttributeValueMap{},
273 })
274
275 // then we report it with the required attributes
276 // 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.
277 relatedPort := append(uniEntityId, 0x00, byte(j))
278 mibDb.items = append(mibDb.items, MibDbEntry{
279 me.PriorityQueueClassID,
280 queueEntityId, //was not reported in the original implementation
281 me.AttributeValueMap{
282 "QueueConfigurationOption": 0,
283 "MaximumQueueSize": 100,
284 "AllocatedQueueSize": 100,
285 "DiscardBlockCounterResetInterval": 0,
286 "ThresholdValueForDiscardedBlocksDueToBufferOverflow": 0,
287 "RelatedPort": relatedPort.ToUint32(),
288 "TrafficSchedulerPointer": 0, //it was hardcoded to 0x0108 in the current implementation
289 "Weight": 1,
290 "BackPressureOperation": 1,
291 "BackPressureTime": 0,
292 "BackPressureOccurQueueThreshold": 0,
293 "BackPressureClearQueueThreshold": 0,
294 },
295 })
296 }
297 }
298
299 // T-CONTS and Traffic Schedulers
300 for i := 1; i <= tconts; i++ {
301 tcontEntityId := EntityID{tcontSlotId, byte(i)}
302
303 mibDb.items = append(mibDb.items, MibDbEntry{
304 me.TContClassID,
305 tcontEntityId,
306 me.AttributeValueMap{
307 "AllocId": 65535,
308 },
309 })
310
311 tsEntityId := EntityID{cardHolderSlotID, byte(i)}
312 mibDb.items = append(mibDb.items, MibDbEntry{
313 me.TrafficSchedulerClassID,
314 tsEntityId, //was not reported in the original implementation
315 me.AttributeValueMap{
316 "TContPointer": tcontEntityId.ToUint16(), // was hardcoded to a non-existing t-cont
317 "TrafficSchedulerPointer": 0,
318 "Policy": 02,
319 "PriorityWeight": 0,
320 },
321 })
322
323 for j := 1; j <= upstreamPriorityQueues; j++ {
324 queueEntityId := EntityID{tcontSlotId, byte(j)}
325 // Upstream Queues (related to traffic schedulers)
326 // 8 priorities queues per TCONT
327 // EntityID = tcontSlotId + Uni EntityID (8001)
328
329 // we first report the PriorityQueue without any attribute
330 mibDb.items = append(mibDb.items, MibDbEntry{
331 me.PriorityQueueClassID,
332 queueEntityId, //was not reported in the original implementation
333 me.AttributeValueMap{},
334 })
335
336 // then we report it with the required attributes
337 // 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.
338 relatedPort := append(tcontEntityId, 0x00, byte(j))
339 mibDb.items = append(mibDb.items, MibDbEntry{
340 me.PriorityQueueClassID,
341 queueEntityId, //was not reported in the original implementation
342 me.AttributeValueMap{
343 "QueueConfigurationOption": 0,
344 "MaximumQueueSize": 100,
345 "AllocatedQueueSize": 100,
346 "DiscardBlockCounterResetInterval": 0,
347 "ThresholdValueForDiscardedBlocksDueToBufferOverflow": 0,
348 "RelatedPort": relatedPort.ToUint32(),
349 "TrafficSchedulerPointer": tsEntityId.ToUint16(), //it was hardcoded to 0x0108 in the current implementation
350 "Weight": 1,
351 "BackPressureOperation": 1,
352 "BackPressureTime": 0,
353 "BackPressureOccurQueueThreshold": 0,
354 "BackPressureClearQueueThreshold": 0,
355 },
356 })
357 }
358 }
359
360 // ONU-2g
361 mibDb.items = append(mibDb.items, MibDbEntry{
362 me.Onu2GClassID,
363 EntityID{0x00, 0x00},
364 me.AttributeValueMap{
365 "ConnectivityCapability": 127,
366 "CurrentConnectivityMode": 0,
367 "Deprecated": 1,
368 "PriorityQueueScaleFactor": 1,
369 "QualityOfServiceQosConfigurationFlexibility": 63,
370 "Sysuptime": 0,
371 "TotalGemPortIdNumber": 8,
372 "TotalPriorityQueueNumber": 64,
373 "TotalTrafficSchedulerNumber": 8,
374 },
375 })
376
377 mibDb.NumberOfCommands = uint16(len(mibDb.items))
378
379 return &mibDb, nil
380}