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