blob: 9c5877ed812a1333b296393c9039a69facab264a [file] [log] [blame]
Chip Boling6e27b352020-02-14 09:10:01 -06001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
Andrea Campanella7167ebb2020-02-24 09:56:38 +01003 * Copyright 2020-present Open Networking Foundation
4
Chip Boling6e27b352020-02-14 09:10:01 -06005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Andrea Campanella7167ebb2020-02-24 09:56:38 +01008
Chip Boling6e27b352020-02-14 09:10:01 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Andrea Campanella7167ebb2020-02-24 09:56:38 +010010
Chip Boling6e27b352020-02-14 09:10:01 -060011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Chip Boling6e27b352020-02-14 09:10:01 -060016 */
17package omci_test
18
19import (
Andrea Campanella7167ebb2020-02-24 09:56:38 +010020 . "github.com/opencord/omci-lib-go"
21 me "github.com/opencord/omci-lib-go/generated"
Chip Boling6e27b352020-02-14 09:10:01 -060022 mapset "github.com/deckarep/golang-set"
23 "github.com/google/gopacket"
24 "github.com/stretchr/testify/assert"
25 "math/rand"
26 "testing"
27 "time"
28)
29
30var messageTypeTestFuncs map[MessageType]func(*testing.T, *me.ManagedEntity)
31
32func init() {
33 messageTypeTestFuncs = make(map[MessageType]func(*testing.T, *me.ManagedEntity), 0)
34
35 messageTypeTestFuncs[CreateRequestType] = testCreateRequestTypeMeFrame
36 messageTypeTestFuncs[CreateResponseType] = testCreateResponseTypeMeFrame
37 messageTypeTestFuncs[DeleteRequestType] = testDeleteRequestTypeMeFrame
38 messageTypeTestFuncs[DeleteResponseType] = testDeleteResponseTypeMeFrame
39 messageTypeTestFuncs[SetRequestType] = testSetRequestTypeMeFrame
40 messageTypeTestFuncs[SetResponseType] = testSetResponseTypeMeFrame
41 messageTypeTestFuncs[GetRequestType] = testGetRequestTypeMeFrame
42 messageTypeTestFuncs[GetResponseType] = testGetResponseTypeMeFrame
43 messageTypeTestFuncs[GetAllAlarmsRequestType] = testGetAllAlarmsRequestTypeMeFrame
44 messageTypeTestFuncs[GetAllAlarmsResponseType] = testGetAllAlarmsResponseTypeMeFrame
45 messageTypeTestFuncs[GetAllAlarmsNextRequestType] = testGetAllAlarmsNextRequestTypeMeFrame
46 messageTypeTestFuncs[GetAllAlarmsNextResponseType] = testGetAllAlarmsNextResponseTypeMeFrame
47 messageTypeTestFuncs[MibUploadRequestType] = testMibUploadRequestTypeMeFrame
48 messageTypeTestFuncs[MibUploadResponseType] = testMibUploadResponseTypeMeFrame
49 messageTypeTestFuncs[MibUploadNextRequestType] = testMibUploadNextRequestTypeMeFrame
50 messageTypeTestFuncs[MibUploadNextResponseType] = testMibUploadNextResponseTypeMeFrame
51 messageTypeTestFuncs[MibResetRequestType] = testMibResetRequestTypeMeFrame
52 messageTypeTestFuncs[MibResetResponseType] = testMibResetResponseTypeMeFrame
53 messageTypeTestFuncs[TestRequestType] = testTestRequestTypeMeFrame
54 messageTypeTestFuncs[TestResponseType] = testTestResponseTypeMeFrame
55 messageTypeTestFuncs[StartSoftwareDownloadRequestType] = testStartSoftwareDownloadRequestTypeMeFrame
56 messageTypeTestFuncs[StartSoftwareDownloadResponseType] = testStartSoftwareDownloadResponseTypeMeFrame
57 messageTypeTestFuncs[DownloadSectionRequestType] = testDownloadSectionRequestTypeMeFrame
58 messageTypeTestFuncs[DownloadSectionResponseType] = testDownloadSectionResponseTypeMeFrame
59 messageTypeTestFuncs[EndSoftwareDownloadRequestType] = testEndSoftwareDownloadRequestTypeMeFrame
60 messageTypeTestFuncs[EndSoftwareDownloadResponseType] = testEndSoftwareDownloadResponseTypeMeFrame
61 messageTypeTestFuncs[ActivateSoftwareRequestType] = testActivateSoftwareRequestTypeMeFrame
62 messageTypeTestFuncs[ActivateSoftwareResponseType] = testActivateSoftwareResponseTypeMeFrame
63 messageTypeTestFuncs[CommitSoftwareRequestType] = testCommitSoftwareRequestTypeMeFrame
64 messageTypeTestFuncs[CommitSoftwareResponseType] = testCommitSoftwareResponseTypeMeFrame
65 messageTypeTestFuncs[SynchronizeTimeRequestType] = testSynchronizeTimeRequestTypeMeFrame
66 messageTypeTestFuncs[SynchronizeTimeResponseType] = testSynchronizeTimeResponseTypeMeFrame
67 messageTypeTestFuncs[RebootRequestType] = testRebootRequestTypeMeFrame
68 messageTypeTestFuncs[RebootResponseType] = testRebootResponseTypeMeFrame
69 messageTypeTestFuncs[GetNextRequestType] = testGetNextRequestTypeMeFrame
70 messageTypeTestFuncs[GetNextResponseType] = testGetNextResponseTypeMeFrame
71 messageTypeTestFuncs[GetCurrentDataRequestType] = testGetCurrentDataRequestTypeMeFrame
72 messageTypeTestFuncs[GetCurrentDataResponseType] = testGetCurrentDataResponseTypeMeFrame
73 messageTypeTestFuncs[SetTableRequestType] = testSetTableRequestTypeMeFrame
74 messageTypeTestFuncs[SetTableResponseType] = testSetTableResponseTypeMeFrame
75 messageTypeTestFuncs[AlarmNotificationType] = testAlarmNotificationTypeMeFrame
76 messageTypeTestFuncs[AttributeValueChangeType] = testAttributeValueChangeTypeMeFrame
77 messageTypeTestFuncs[TestResultType] = testTestResultTypeMeFrame
78}
79
80func getMEsThatSupportAMessageType(messageType MessageType) []*me.ManagedEntity {
81 msgType := me.MsgType(byte(messageType) & me.MsgTypeMask)
82
83 entities := make([]*me.ManagedEntity, 0)
84 for _, classID := range me.GetSupportedClassIDs() {
85 if managedEntity, err := me.LoadManagedEntityDefinition(classID); err.StatusCode() == me.Success {
86 supportedTypes := managedEntity.GetManagedEntityDefinition().GetMessageTypes()
87 if supportedTypes.Contains(msgType) {
88 entities = append(entities, managedEntity)
89 }
90 }
91 }
92 return entities
93}
94
95func TestFrameFormatNotYetSupported(t *testing.T) {
96 // We do not yet support extended frame formats. Once we do, add a bunch of tests
97 // to cover it
98
99 params := me.ParamData{
100 Attributes: me.AttributeValueMap{"MibDataSync": 0},
101 }
102 managedEntity, omciErr := me.NewOnuData(params)
103 assert.NotNil(t, omciErr)
104 assert.Equal(t, omciErr.StatusCode(), me.Success)
105
106 buffer, err := GenFrame(managedEntity, GetRequestType, FrameFormat(ExtendedIdent), TransactionID(1))
107 assert.Nil(t, buffer)
108 assert.NotNil(t, err)
109}
110
111// TODO: Add more specific get next response tests as we have had issues
112
113func TestGetNextResponseOneFrameOnly(t *testing.T) {
114 // OMCI ME GetRequest for MsgTypes often needs only a single frame and
115 // it is a table of one octet values. Make sure we decode it correctly
116
117 response1 := []uint8{
118 0, 250, 58, 10, 1, 31, 0, 0, 0, 64, 0,
119 4, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 40,
121 }
122 // getNextSize is the size returned by the original Get request. Normally you would
123 // do many OMCI requests and append all the results (while decreasing size), but
124 // this is all in on packet.
125 //
126 // Do the buffer loop anyway
127 getNextSize := 23
128 remaining := getNextSize
129
130 dataBuffer := make([]byte, 0)
131 packets := []gopacket.Packet{
132 gopacket.NewPacket(response1, LayerTypeOMCI, gopacket.NoCopy),
133 }
134 for _, packet := range packets {
135 omciLayer := packet.Layer(LayerTypeOMCI)
136 assert.NotNil(t, omciLayer)
137
138 omciObj, omciOk := omciLayer.(*OMCI)
139 assert.True(t, omciOk)
140 assert.NotNil(t, omciObj)
141 assert.Equal(t, uint16(250), omciObj.TransactionID)
142 assert.Equal(t, GetNextResponseType, omciObj.MessageType)
143 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
144 assert.Equal(t, uint32(0), omciObj.MIC)
145 assert.Equal(t, uint16(40), omciObj.Length)
146
147 msgLayer := packet.Layer(LayerTypeGetNextResponse)
148 msgObj, msgOk := msgLayer.(*GetNextResponse)
149 assert.True(t, msgOk)
150 assert.NotNil(t, msgObj)
151 assert.Equal(t, me.Success, msgObj.Result)
152 assert.Equal(t, uint16(0x4000), msgObj.AttributeMask)
153 assert.Equal(t, 2, len(msgObj.Attributes))
154
155 for attrName, value := range msgObj.Attributes {
156 // Skip Entity ID attribute always stored in attribute list
157 if attrName == "ManagedEntityId" {
158 assert.Equal(t, uint16(0), value.(uint16))
159 continue
160 }
161 assert.Equal(t, "MessageTypeTable", attrName)
162 tmpBuffer, ok := value.([]byte)
163 assert.True(t, ok)
164
165 validOctets := len(tmpBuffer)
166 assert.NotZero(t, validOctets)
167 if validOctets > remaining {
168 validOctets = remaining
169 }
170 remaining -= validOctets
171 dataBuffer = append(dataBuffer, tmpBuffer[:validOctets]...)
172
173 assert.True(t, remaining >= 0)
174 if remaining == 0 {
175 break
176 }
177 }
178 }
179 bufSize := len(dataBuffer)
180 assert.Equal(t, getNextSize, bufSize)
181}
182
183func aTestFailingGetNextResponseTypeMeFrame(t *testing.T) {
184 //params := me.ParamData{
185 // EntityID: 0,
186 // Attributes: me.AttributeValueMap{
187 // "Rmep5DatabaseTable": []uint8{
188 // 0,1,2,3,4,5,6,7,8,9,
189 // 10,11,12,13,14,15,16,17,18,19,
190 // 20,21,22,23,24,25,26,27,28,29,
191 // 30,
192 // },
193 // },
194 //}
195 //meInstance, err := me.NewDot1AgMepCcmDatabase(params)
196 //bitmask := uint16(2048)
197 //assert.NotNil(t, meInstance)
198 //assert.Nil(t, err)
199 //
200 //tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
201 //
202 //frame, omciErr := GenFrame(meInstance, GetNextResponseType, TransactionID(tid), Result(me.Success),
203 // AttributeMask(bitmask))
204 //assert.NotNil(t, frame)
205 //assert.NotZero(t, len(frame))
206 //assert.Nil(t, omciErr)
207 //
208 /////////////////////////////////////////////////////////////////////
209 //// Now decode and compare
210 //cid := meInstance.GetClassID()
211 //assert.NotEqual(t, cid, 0)
212 //packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
213 //assert.NotNil(t, packet)
214 //
215 //omciLayer := packet.Layer(LayerTypeOMCI)
216 //assert.NotNil(t, omciLayer)
217 //
218 //omciObj, omciOk := omciLayer.(*OMCI)
219 //assert.NotNil(t, omciObj)
220 //assert.True(t, omciOk)
221 //assert.Equal(t, tid, omciObj.TransactionID)
222 //assert.Equal(t, GetNextResponseType, omciObj.MessageType)
223 //assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
224 //
225 //msgLayer := packet.Layer(LayerTypeGetNextResponse)
226 //assert.NotNil(t, msgLayer)
227 //
228 //msgObj, msgOk := msgLayer.(*GetNextResponse)
229 //assert.NotNil(t, msgObj)
230 //assert.True(t, msgOk)
231 //
232 //assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
233 //assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
234 //assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask)
235
236}
237
238func TestAllMessageTypes(t *testing.T) {
239 // Loop over all message types
240 for _, messageType := range allMessageTypes {
241 //typeTested := false
242 if testRoutine, ok := messageTypeTestFuncs[messageType]; ok {
243 // Loop over all Managed Entities that support that type
244 for _, managedEntity := range getMEsThatSupportAMessageType(messageType) {
245 // Call the test routine
246 testRoutine(t, managedEntity)
247 //typeTested = true
248 }
249 }
250 // Verify at least one test ran for this message type
251 // TODO: Enable once all tests are working -> assert.True(t, typeTested)
252 }
253}
254
255//func TestAllThatSupportAlarms(t *testing.T) { TODO: Future
256// // Loop over all Managed Entities and test those with Attributes that support
257//
258// for _, managedEntity := range getMEsThatSupportAMessageType(messageType) {
259// // Call the test routine
260// testRoutine(t, managedEntity)
261// //typeTested = true
262// }
263//}
264
265func getAttributeNameSet(attributes me.AttributeValueMap) mapset.Set {
266 // TODO: For Classes with attribute masks that can set/get/... more than just
267 // a single attribute, test a set/get of just a single attribute to verify
268 // all encoding/decoding methods are working as expected.
269 names := mapset.NewSet()
270 for name, _ := range attributes {
271 names.Add(name)
272 }
273 return names
274}
275
276func pickAValue(attrDef me.AttributeDefinition) interface{} {
277 constraint := attrDef.Constraint
278 defaultVal := attrDef.DefValue
279 size := attrDef.GetSize()
280 _, isOctetString := defaultVal.([]byte)
281
282 if attrDef.IsTableAttribute() || isOctetString {
283 // Table attributes treated as a string of octets. If size is zero, it is
284 // most likely an attribute with variable size. Pick a random size that will
285 // fit into a simple frame (1-33 octets)
286 if size == 0 {
287 size = rand.Intn(32) + 1
288 }
289 value := make([]byte, size)
290 for octet := 0; octet < size; octet++ {
291 value[octet] = byte(octet & 0xff)
292 }
293 return value
294 }
295 switch size {
296 case 1:
297 // Try the default + 1 as a value. Since some defaults are zero
298 // and we want example frames without zeros in them.
299 if value, ok := defaultVal.(uint8); ok {
300 if constraint == nil {
301 return value + 1
302 }
303 if err := constraint(value + 1); err == nil {
304 return value + 1
305 }
306 }
307 return defaultVal.(uint8)
308
309 case 2:
310 // Try the default + 1 as a value. Since some defaults are zero
311 // and we want example frames without zeros in them.
312 if value, ok := defaultVal.(uint16); ok {
313 if constraint == nil {
314 return value + 1
315 }
316 if err := constraint(value + 1); err == nil {
317 return value + 1
318 }
319 }
320 return defaultVal.(uint16)
321
322 case 4:
323 // Try the default + 1 as a value. Since some defaults are zero
324 // and we want example frames without zeros in them.
325 if value, ok := defaultVal.(uint32); ok {
326 if constraint == nil {
327 return value + 1
328 }
329 if err := constraint(value + 1); err == nil {
330 return value + 1
331 }
332 }
333 return defaultVal.(uint32)
334
335 case 8:
336 // Try the default + 1 as a value. Since some defaults are zero
337 // and we want example frames without zeros in them.
338 if value, ok := defaultVal.(uint64); ok {
339 if constraint == nil {
340 return value + 1
341 }
342 if err := constraint(value + 1); err == nil {
343 return value + 1
344 }
345 }
346 return defaultVal.(uint64)
347
348 default:
349 size := attrDef.GetSize()
350 value := make([]uint8, size)
351 for index := 0; index < size; index++ {
352 value[index] = uint8(index & 0xFF)
353 }
354 return value
355 }
356}
357
358func testCreateRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
359 // Generate the frame. Use a default Entity ID of zero, but for the
360 // OMCI library, we need to specify all supported Set-By-Create
361 params := me.ParamData{
362 EntityID: uint16(0),
363 Attributes: make(me.AttributeValueMap, 0),
364 }
365 for _, attrDef := range managedEntity.GetAttributeDefinitions() {
366 if attrDef.Index == 0 {
367 continue // Skip entity ID, already specified
368
369 } else if attrDef.GetAccess().Contains(me.SetByCreate) {
370 params.Attributes[attrDef.GetName()] = pickAValue(attrDef)
371 }
372 }
373 // Create the managed instance
374 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
375 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
376 assert.NotNil(t, err)
377 assert.Equal(t, err.StatusCode(), me.Success)
378
379 frame, omciErr := GenFrame(meInstance, CreateRequestType, TransactionID(tid))
380 assert.NotNil(t, frame)
381 assert.NotZero(t, len(frame))
382 assert.Nil(t, omciErr)
383
384 ///////////////////////////////////////////////////////////////////
385 // Now decode and compare
386 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
387 assert.NotNil(t, packet)
388
389 omciLayer := packet.Layer(LayerTypeOMCI)
390 assert.NotNil(t, omciLayer)
391
392 omciObj, omciOk := omciLayer.(*OMCI)
393 assert.NotNil(t, omciObj)
394 assert.True(t, omciOk)
395 assert.Equal(t, tid, omciObj.TransactionID)
396 assert.Equal(t, CreateRequestType, omciObj.MessageType)
397 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
398
399 msgLayer := packet.Layer(LayerTypeCreateRequest)
400 assert.NotNil(t, msgLayer)
401
402 msgObj, msgOk := msgLayer.(*CreateRequest)
403 assert.NotNil(t, msgObj)
404 assert.True(t, msgOk)
405
406 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
407 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
408 assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes)
409}
410
411func testCreateResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
412 params := me.ParamData{
413 EntityID: uint16(0),
414 }
415 // Create the managed instance
416 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
417 assert.NotNil(t, err)
418 assert.Equal(t, err.StatusCode(), me.Success)
419
420 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
421 result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested
422
423 // Always pass a failure mask, but should only get encoded if result == ParameterError
424 var mask uint16
425 for _, attrDef := range managedEntity.GetAttributeDefinitions() {
426 if attrDef.Index == 0 {
427 continue // Skip entity ID, already specified
428
429 } else if attrDef.GetAccess().Contains(me.SetByCreate) {
430 // Random 20% chance this parameter was bad
431 if rand.Int31n(5) == 0 {
432 mask |= attrDef.Mask
433 }
434 }
435 }
436 frame, omciErr := GenFrame(meInstance, CreateResponseType,
437 TransactionID(tid), Result(result), AttributeExecutionMask(mask))
438 assert.NotNil(t, frame)
439 assert.NotZero(t, len(frame))
440 assert.Nil(t, omciErr)
441
442 ///////////////////////////////////////////////////////////////////
443 // Now decode and compare
444 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
445 assert.NotNil(t, packet)
446
447 omciLayer := packet.Layer(LayerTypeOMCI)
448 assert.NotNil(t, omciLayer)
449
450 omciObj, omciOk := omciLayer.(*OMCI)
451 assert.NotNil(t, omciObj)
452 assert.True(t, omciOk)
453 assert.Equal(t, tid, omciObj.TransactionID)
454 assert.Equal(t, CreateResponseType, omciObj.MessageType)
455 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
456
457 msgLayer := packet.Layer(LayerTypeCreateResponse)
458 assert.NotNil(t, msgLayer)
459
460 msgObj, msgOk := msgLayer.(*CreateResponse)
461 assert.NotNil(t, msgObj)
462 assert.True(t, msgOk)
463
464 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
465 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
466 assert.Equal(t, result, msgObj.Result)
467
468 if result == me.ParameterError {
469 assert.Equal(t, mask, msgObj.AttributeExecutionMask)
470 } else {
471 assert.Zero(t, msgObj.AttributeExecutionMask)
472 }
473}
474
475func testDeleteRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
476 // Generate the frame. Use a default Entity ID of zero, but for the
477 // OMCI library, we need to specify all supported Set-By-Create
478 params := me.ParamData{
479 EntityID: uint16(0),
480 }
481 // Create the managed instance
482 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
483 assert.NotNil(t, err)
484 assert.Equal(t, err.StatusCode(), me.Success)
485
486 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
487
488 frame, omciErr := GenFrame(meInstance, DeleteRequestType, TransactionID(tid))
489 assert.NotNil(t, frame)
490 assert.NotZero(t, len(frame))
491 assert.Nil(t, omciErr)
492
493 ///////////////////////////////////////////////////////////////////
494 // Now decode and compare
495 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
496 assert.NotNil(t, packet)
497
498 omciLayer := packet.Layer(LayerTypeOMCI)
499 assert.NotNil(t, omciLayer)
500
501 omciObj, omciOk := omciLayer.(*OMCI)
502 assert.NotNil(t, omciObj)
503 assert.True(t, omciOk)
504 assert.Equal(t, tid, omciObj.TransactionID)
505 assert.Equal(t, DeleteRequestType, omciObj.MessageType)
506 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
507
508 msgLayer := packet.Layer(LayerTypeDeleteRequest)
509 assert.NotNil(t, msgLayer)
510
511 msgObj, msgOk := msgLayer.(*DeleteRequest)
512 assert.NotNil(t, msgObj)
513 assert.True(t, msgOk)
514
515 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
516 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
517}
518
519func testDeleteResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
520 params := me.ParamData{
521 EntityID: uint16(0),
522 }
523 // Create the managed instance
524 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
525 assert.NotNil(t, err)
526 assert.Equal(t, err.StatusCode(), me.Success)
527
528 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
529 result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested
530
531 frame, omciErr := GenFrame(meInstance, DeleteResponseType, TransactionID(tid), Result(result))
532 assert.NotNil(t, frame)
533 assert.NotZero(t, len(frame))
534 assert.Nil(t, omciErr)
535
536 ///////////////////////////////////////////////////////////////////
537 // Now decode and compare
538 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
539 assert.NotNil(t, packet)
540
541 omciLayer := packet.Layer(LayerTypeOMCI)
542 assert.NotNil(t, omciLayer)
543
544 omciObj, omciOk := omciLayer.(*OMCI)
545 assert.NotNil(t, omciObj)
546 assert.True(t, omciOk)
547 assert.Equal(t, tid, omciObj.TransactionID)
548 assert.Equal(t, DeleteResponseType, omciObj.MessageType)
549 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
550
551 msgLayer := packet.Layer(LayerTypeDeleteResponse)
552 assert.NotNil(t, msgLayer)
553
554 msgObj, msgOk := msgLayer.(*DeleteResponse)
555 assert.NotNil(t, msgObj)
556 assert.True(t, msgOk)
557
558 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
559 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
560 assert.Equal(t, result, msgObj.Result)
561}
562
563func testSetRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
564 params := me.ParamData{
565 EntityID: uint16(0),
566 Attributes: make(me.AttributeValueMap, 0),
567 }
568 attrDefs := managedEntity.GetAttributeDefinitions()
569 tableAttrFound := false
570 for _, attrDef := range attrDefs {
571 if attrDef.Index == 0 {
572 continue // Skip entity ID, already specified
573 } else if attrDef.IsTableAttribute() {
574 tableAttrFound = true
575 continue // TODO: Skip table attributes for now
576 } else if attrDef.GetAccess().Contains(me.Write) {
577 params.Attributes[attrDef.GetName()] = pickAValue(attrDef)
578 }
579 }
580 if tableAttrFound && len(params.Attributes) == 0 {
581 // The only set attribute may have been a table and we do not have
582 // a test for that right now.
583 return
584 }
585 assert.NotEmpty(t, params.Attributes) // Need a parameter that is a table attribute
586 bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes))
587 assert.Nil(t, attrErr)
588
589 // Create the managed instance
590 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
591 assert.NotNil(t, err)
592 assert.Equal(t, err.StatusCode(), me.Success)
593 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
594
595 frame, omciErr := GenFrame(meInstance, SetRequestType, TransactionID(tid), AttributeMask(bitmask))
596 // some frames cannot fit all the attributes
597 if omciErr != nil {
598 if _, ok := omciErr.(*me.MessageTruncatedError); ok {
599 return
600 }
601 }
602 assert.NotNil(t, frame)
603 assert.NotZero(t, len(frame))
604
605 ///////////////////////////////////////////////////////////////////
606 // Now decode and compare
607 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
608 assert.NotNil(t, packet)
609
610 omciLayer := packet.Layer(LayerTypeOMCI)
611 assert.NotNil(t, omciLayer)
612
613 omciObj, omciOk := omciLayer.(*OMCI)
614 assert.NotNil(t, omciObj)
615 assert.True(t, omciOk)
616 assert.Equal(t, tid, omciObj.TransactionID)
617 assert.Equal(t, SetRequestType, omciObj.MessageType)
618 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
619
620 msgLayer := packet.Layer(LayerTypeSetRequest)
621 assert.NotNil(t, msgLayer)
622
623 msgObj, msgOk := msgLayer.(*SetRequest)
624 assert.NotNil(t, msgObj)
625 assert.True(t, msgOk)
626
627 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
628 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
629 assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes)
630}
631
632func testSetResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
633 params := me.ParamData{
634 EntityID: uint16(0),
635 }
636 // Create the managed instance
637 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
638 assert.NotNil(t, err)
639 assert.Equal(t, err.StatusCode(), me.Success)
640
641 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
642 result := me.Results(rand.Int31n(10)) // [0, 9] Not all types will be tested
643
644 // Always pass a failure mask, but should only get encoded if result == ParameterError
645 var unsupportedMask uint16
646 var failedMask uint16
647 attrDefs := managedEntity.GetAttributeDefinitions()
648 for _, attrDef := range attrDefs {
649 if attrDef.Index == 0 {
650 continue // Skip entity ID, already specified
651
652 } else if attrDef.GetAccess().Contains(me.Write) {
653 // Random 10% chance this parameter unsupported and
654 // 10% it failed
655 switch rand.Int31n(5) {
656 case 0:
657 unsupportedMask |= attrDef.Mask
658 case 1:
659 failedMask |= attrDef.Mask
660 }
661 }
662 }
663 bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes))
664 assert.Nil(t, attrErr)
665
666 frame, omciErr := GenFrame(meInstance, SetResponseType,
667 TransactionID(tid), Result(result),
668 AttributeMask(bitmask),
669 AttributeExecutionMask(failedMask),
670 UnsupportedAttributeMask(unsupportedMask))
671 assert.NotNil(t, frame)
672 assert.NotZero(t, len(frame))
673 assert.Nil(t, omciErr)
674
675 ///////////////////////////////////////////////////////////////////
676 // Now decode and compare
677 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
678 assert.NotNil(t, packet)
679
680 omciLayer := packet.Layer(LayerTypeOMCI)
681 assert.NotNil(t, omciLayer)
682
683 omciObj, omciOk := omciLayer.(*OMCI)
684 assert.NotNil(t, omciObj)
685 assert.True(t, omciOk)
686 assert.Equal(t, tid, omciObj.TransactionID)
687 assert.Equal(t, SetResponseType, omciObj.MessageType)
688 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
689
690 msgLayer := packet.Layer(LayerTypeSetResponse)
691 assert.NotNil(t, msgLayer)
692
693 msgObj, msgOk := msgLayer.(*SetResponse)
694 assert.NotNil(t, msgObj)
695 assert.True(t, msgOk)
696
697 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
698 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
699 assert.Equal(t, result, msgObj.Result)
700
701 if result == me.AttributeFailure {
702 assert.Equal(t, failedMask, msgObj.FailedAttributeMask)
703 assert.Equal(t, unsupportedMask, msgObj.UnsupportedAttributeMask)
704 } else {
705 assert.Zero(t, msgObj.FailedAttributeMask)
706 assert.Zero(t, msgObj.UnsupportedAttributeMask)
707 }
708}
709
710func testGetRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
711 params := me.ParamData{
712 EntityID: uint16(0),
713 Attributes: make(me.AttributeValueMap, 0),
714 }
715 attrDefs := managedEntity.GetAttributeDefinitions()
716 for _, attrDef := range attrDefs {
717 if attrDef.Index == 0 {
718 continue // Skip entity ID, already specified
719 } else if attrDef.GetAccess().Contains(me.Read) {
720 // Allow 'nil' as parameter value for GetRequests since we only need names
721 params.Attributes[attrDef.GetName()] = nil
722 }
723 }
724 assert.NotEmpty(t, params.Attributes) // Need a parameter that is a table attribute
725 bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes))
726 assert.Nil(t, attrErr)
727
728 // Create the managed instance
729 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
730 assert.NotNil(t, err)
731 assert.Equal(t, err.StatusCode(), me.Success)
732
733 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
734
735 frame, omciErr := GenFrame(meInstance, GetRequestType, TransactionID(tid), AttributeMask(bitmask))
736 assert.NotNil(t, frame)
737 assert.NotZero(t, len(frame))
738 assert.Nil(t, omciErr)
739
740 ///////////////////////////////////////////////////////////////////
741 // Now decode and compare
742 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
743 assert.NotNil(t, packet)
744
745 omciLayer := packet.Layer(LayerTypeOMCI)
746 assert.NotNil(t, omciLayer)
747
748 omciObj, omciOk := omciLayer.(*OMCI)
749 assert.NotNil(t, omciObj)
750 assert.True(t, omciOk)
751 assert.Equal(t, tid, omciObj.TransactionID)
752 assert.Equal(t, GetRequestType, omciObj.MessageType)
753 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
754
755 msgLayer := packet.Layer(LayerTypeGetRequest)
756 assert.NotNil(t, msgLayer)
757
758 msgObj, msgOk := msgLayer.(*GetRequest)
759 assert.NotNil(t, msgObj)
760 assert.True(t, msgOk)
761
762 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
763 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
764 assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask)
765}
766
767func testGetResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
768 params := me.ParamData{
769 EntityID: uint16(0),
770 Attributes: make(me.AttributeValueMap),
771 }
772 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
773 result := me.Results(rand.Int31n(10)) // [0, 9]
774
775 // If success Results selected, set FailIfTruncated 50% of time to test
776 // overflow detection and failures periodically.
777 failIfTruncated := false
778 if result == me.Success && rand.Int31n(2) == 1 {
779 failIfTruncated = true
780 }
781 // Always pass a failure mask, but should only get encoded if result == ParameterError
782 var unsupportedMask uint16
783 var failedMask uint16
784 attrDefs := managedEntity.GetAttributeDefinitions()
785 for _, attrDef := range attrDefs {
786 if attrDef.Index == 0 {
787 continue // Skip entity ID, already specified
788
789 } else if attrDef.GetAccess().Contains(me.Read) {
790 // Random 10% chance this parameter unsupported and
791 // 10% it failed
792 switch rand.Int31n(5) {
793 default:
794 // TODO: Table attributes not yet supported. For Table Attributes, figure out a
795 // good way to unit test this and see if that can be extended to a more
796 // general operation that provides the 'get-next' frames to the caller who
797 // wishes to serialize a table attribute.
798 if !attrDef.IsTableAttribute() {
799 params.Attributes[attrDef.GetName()] = pickAValue(attrDef)
800 }
801 case 0:
802 unsupportedMask |= attrDef.Mask
803 case 1:
804 failedMask |= attrDef.Mask
805 }
806 }
807 }
808 bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes))
809 assert.Nil(t, attrErr)
810
811 // Create the managed instance
812 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
813
814 frame, omciErr := GenFrame(meInstance, GetResponseType,
815 TransactionID(tid), Result(result),
816 AttributeMask(bitmask),
817 AttributeExecutionMask(failedMask),
818 UnsupportedAttributeMask(unsupportedMask),
819 FailIfTruncated(failIfTruncated))
820
821 // TODO: Need to test if err is MessageTruncatedError. Sometimes reported as
822 // a proessing error
823 if omciErr != nil {
824 if _, ok := omciErr.(*me.MessageTruncatedError); ok {
825 return
826 }
827 }
828 assert.NotNil(t, frame)
829 assert.NotZero(t, len(frame))
830 assert.NotNil(t, err)
831 assert.Equal(t, err.StatusCode(), me.Success)
832
833 ///////////////////////////////////////////////////////////////////
834 // Now decode and compare
835 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
836 assert.NotNil(t, packet)
837
838 omciLayer := packet.Layer(LayerTypeOMCI)
839 assert.NotNil(t, omciLayer)
840
841 omciObj, omciOk := omciLayer.(*OMCI)
842 assert.NotNil(t, omciObj)
843 assert.True(t, omciOk)
844 assert.Equal(t, tid, omciObj.TransactionID)
845 assert.Equal(t, GetResponseType, omciObj.MessageType)
846 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
847
848 msgLayer := packet.Layer(LayerTypeGetResponse)
849 // If requested Result was Success and FailIfTruncated is true, then we may
850 // fail (get nil layer) if too many attributes to fit in a frame
851 if result == me.Success && msgLayer == nil {
852 return // was expected
853 }
854 assert.NotNil(t, msgLayer)
855
856 msgObj, msgOk := msgLayer.(*GetResponse)
857 assert.NotNil(t, msgObj)
858 assert.True(t, msgOk)
859
860 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
861 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
862
863 switch msgObj.Result {
864 default:
865 assert.Equal(t, result, msgObj.Result)
866 assert.Zero(t, msgObj.FailedAttributeMask)
867 assert.Zero(t, msgObj.UnsupportedAttributeMask)
868
869 case me.Success:
870 assert.Equal(t, result, msgObj.Result)
871 assert.Zero(t, msgObj.FailedAttributeMask)
872 assert.Zero(t, msgObj.UnsupportedAttributeMask)
873 assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes)
874
875 case me.AttributeFailure:
876 // Should have been Success or AttributeFailure to start with
877 assert.True(t, result == me.Success || result == me.AttributeFailure)
878 if result == me.AttributeFailure {
879 assert.Equal(t, unsupportedMask, msgObj.UnsupportedAttributeMask)
880 }
881 // Returned may have more bits set in failed mask and less attributes
882 // since failIfTruncated is false and we may add more fail attributes
883 // since they do not fit. May also set only lower value (lower bits)
884 // if it turns out that the upper bits are already pre-assigned to the
885 // failure bits.
886 //
887 // Make sure any successful attributes were requested
888 meMap := meInstance.GetAttributeValueMap()
889 for name := range msgObj.Attributes {
890 getValue, ok := meMap[name]
891 assert.True(t, ok)
892 assert.NotNil(t, getValue)
893 }
894 }
895}
896
897func testGetAllAlarmsRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
898 params := me.ParamData{
899 EntityID: uint16(0),
900 }
901 // Create the managed instance
902 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
903 assert.NotNil(t, err)
904 assert.Equal(t, err.StatusCode(), me.Success)
905
906 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
907 mode := uint8(rand.Int31n(2)) // [0, 1]
908
909 frame, omciErr := GenFrame(meInstance, GetAllAlarmsRequestType, TransactionID(tid), RetrievalMode(mode))
910 assert.NotNil(t, frame)
911 assert.NotZero(t, len(frame))
912 assert.Nil(t, omciErr)
913
914 ///////////////////////////////////////////////////////////////////
915 // Now decode and compare
916 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
917 assert.NotNil(t, packet)
918
919 omciLayer := packet.Layer(LayerTypeOMCI)
920 assert.NotNil(t, omciLayer)
921
922 omciObj, omciOk := omciLayer.(*OMCI)
923 assert.NotNil(t, omciObj)
924 assert.True(t, omciOk)
925 assert.Equal(t, tid, omciObj.TransactionID)
926 assert.Equal(t, GetAllAlarmsRequestType, omciObj.MessageType)
927 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
928
929 msgLayer := packet.Layer(LayerTypeGetAllAlarmsRequest)
930 assert.NotNil(t, msgLayer)
931
932 msgObj, msgOk := msgLayer.(*GetAllAlarmsRequest)
933 assert.NotNil(t, msgObj)
934 assert.True(t, msgOk)
935
936 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
937 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
938 assert.Equal(t, mode, msgObj.AlarmRetrievalMode)
939}
940
941func testGetAllAlarmsResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
942 params := me.ParamData{
943 EntityID: uint16(0),
944 }
945 // Create the managed instance
946 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
947 assert.NotNil(t, err)
948 assert.Equal(t, err.StatusCode(), me.Success)
949
950 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
951 numOfCommands := uint16(rand.Int31n(5)) // [0, 5)
952
953 frame, omciErr := GenFrame(meInstance, GetAllAlarmsResponseType, TransactionID(tid),
954 SequenceNumberCountOrSize(numOfCommands))
955 assert.NotNil(t, frame)
956 assert.NotZero(t, len(frame))
957 assert.Nil(t, omciErr)
958
959 ///////////////////////////////////////////////////////////////////
960 // Now decode and compare
961 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
962 assert.NotNil(t, packet)
963
964 omciLayer := packet.Layer(LayerTypeOMCI)
965 assert.NotNil(t, omciLayer)
966
967 omciObj, omciOk := omciLayer.(*OMCI)
968 assert.NotNil(t, omciObj)
969 assert.True(t, omciOk)
970 assert.Equal(t, tid, omciObj.TransactionID)
971 assert.Equal(t, GetAllAlarmsResponseType, omciObj.MessageType)
972 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
973
974 msgLayer := packet.Layer(LayerTypeGetAllAlarmsResponse)
975 assert.NotNil(t, msgLayer)
976
977 msgObj, msgOk := msgLayer.(*GetAllAlarmsResponse)
978 assert.NotNil(t, msgObj)
979 assert.True(t, msgOk)
980
981 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
982 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
983 assert.Equal(t, numOfCommands, msgObj.NumberOfCommands)
984}
985
986func testGetAllAlarmsNextRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
987 params := me.ParamData{
988 EntityID: uint16(0),
989 }
990 // Create the managed instance
991 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
992 assert.NotNil(t, err)
993 assert.Equal(t, err.StatusCode(), me.Success)
994
995 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
996 sequenceNumber := uint16(rand.Int31n(5)) // [0, 5)
997
998 frame, omciErr := GenFrame(meInstance, GetAllAlarmsNextRequestType, TransactionID(tid),
999 SequenceNumberCountOrSize(sequenceNumber))
1000 assert.NotNil(t, frame)
1001 assert.NotZero(t, len(frame))
1002 assert.Nil(t, omciErr)
1003
1004 ///////////////////////////////////////////////////////////////////
1005 // Now decode and compare
1006 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1007 assert.NotNil(t, packet)
1008
1009 omciLayer := packet.Layer(LayerTypeOMCI)
1010 assert.NotNil(t, omciLayer)
1011
1012 omciObj, omciOk := omciLayer.(*OMCI)
1013 assert.NotNil(t, omciObj)
1014 assert.True(t, omciOk)
1015 assert.Equal(t, tid, omciObj.TransactionID)
1016 assert.Equal(t, GetAllAlarmsNextRequestType, omciObj.MessageType)
1017 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1018
1019 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextRequest)
1020 assert.NotNil(t, msgLayer)
1021
1022 msgObj, msgOk := msgLayer.(*GetAllAlarmsNextRequest)
1023 assert.NotNil(t, msgObj)
1024 assert.True(t, msgOk)
1025
1026 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1027 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1028 assert.Equal(t, sequenceNumber, msgObj.CommandSequenceNumber)
1029}
1030
1031func testGetAllAlarmsNextResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1032 params := me.ParamData{
1033 EntityID: uint16(0),
1034 }
1035 // Create the managed instance
1036 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1037 assert.NotNil(t, err)
1038 assert.Equal(t, err.StatusCode(), me.Success)
1039
1040 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1041
1042 alarmInfo := AlarmOptions{
1043 AlarmClassID: 123, // TODO: Real class here?
1044 AlarmInstance: 456,
1045 AlarmBitmap: make([]byte, 28),
1046 }
1047 // TODO: Allow a 1 to 28 octet array to be used and zero fill any remainder...
1048 for octet := 0; octet < 28; octet++ {
1049 alarmInfo.AlarmBitmap[octet] = uint8(rand.Intn(256))
1050 }
1051 frame, omciErr := GenFrame(meInstance, GetAllAlarmsNextResponseType, TransactionID(tid),
1052 Alarm(alarmInfo))
1053 assert.NotNil(t, frame)
1054 assert.NotZero(t, len(frame))
1055 assert.Nil(t, omciErr)
1056
1057 ///////////////////////////////////////////////////////////////////
1058 // Now decode and compare
1059 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1060 assert.NotNil(t, packet)
1061
1062 omciLayer := packet.Layer(LayerTypeOMCI)
1063 assert.NotNil(t, omciLayer)
1064
1065 omciObj, omciOk := omciLayer.(*OMCI)
1066 assert.NotNil(t, omciObj)
1067 assert.True(t, omciOk)
1068 assert.Equal(t, tid, omciObj.TransactionID)
1069 assert.Equal(t, GetAllAlarmsNextResponseType, omciObj.MessageType)
1070 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1071
1072 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse)
1073 assert.NotNil(t, msgLayer)
1074
1075 msgObj, msgOk := msgLayer.(*GetAllAlarmsNextResponse)
1076 assert.NotNil(t, msgObj)
1077 assert.True(t, msgOk)
1078
1079 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1080 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1081 assert.Equal(t, alarmInfo.AlarmClassID, msgObj.AlarmEntityClass)
1082 assert.Equal(t, alarmInfo.AlarmInstance, msgObj.AlarmEntityInstance)
1083 for octet := 0; octet < len(alarmInfo.AlarmBitmap); octet++ {
1084 assert.Equal(t, alarmInfo.AlarmBitmap[octet], msgObj.AlarmBitMap[octet])
1085 }
1086}
1087
1088func testMibUploadRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1089 params := me.ParamData{
1090 EntityID: uint16(0),
1091 }
1092 // Create the managed instance
1093 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1094 assert.NotNil(t, err)
1095 assert.Equal(t, err.StatusCode(), me.Success)
1096
1097 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1098
1099 frame, omciErr := GenFrame(meInstance, MibUploadRequestType, TransactionID(tid))
1100 assert.NotNil(t, frame)
1101 assert.NotZero(t, len(frame))
1102 assert.Nil(t, omciErr)
1103
1104 ///////////////////////////////////////////////////////////////////
1105 // Now decode and compare
1106 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1107 assert.NotNil(t, packet)
1108
1109 omciLayer := packet.Layer(LayerTypeOMCI)
1110 assert.NotNil(t, omciLayer)
1111
1112 omciObj, omciOk := omciLayer.(*OMCI)
1113 assert.NotNil(t, omciObj)
1114 assert.True(t, omciOk)
1115 assert.Equal(t, tid, omciObj.TransactionID)
1116 assert.Equal(t, MibUploadRequestType, omciObj.MessageType)
1117 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1118
1119 msgLayer := packet.Layer(LayerTypeMibUploadRequest)
1120 assert.NotNil(t, msgLayer)
1121
1122 msgObj, msgOk := msgLayer.(*MibUploadRequest)
1123 assert.NotNil(t, msgObj)
1124 assert.True(t, msgOk)
1125
1126 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1127 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1128}
1129
1130func testMibUploadResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1131 params := me.ParamData{
1132 EntityID: uint16(0),
1133 }
1134 // Create the managed instance
1135 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1136 assert.NotNil(t, err)
1137 assert.Equal(t, err.StatusCode(), me.Success)
1138
1139 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1140 numOfCommands := uint16(rand.Int31n(5)) // [0, 5)
1141
1142 frame, omciErr := GenFrame(meInstance, MibUploadResponseType, TransactionID(tid),
1143 SequenceNumberCountOrSize(numOfCommands))
1144 assert.NotNil(t, frame)
1145 assert.NotZero(t, len(frame))
1146 assert.Nil(t, omciErr)
1147
1148 ///////////////////////////////////////////////////////////////////
1149 // Now decode and compare
1150 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1151 assert.NotNil(t, packet)
1152
1153 omciLayer := packet.Layer(LayerTypeOMCI)
1154 assert.NotNil(t, omciLayer)
1155
1156 omciObj, omciOk := omciLayer.(*OMCI)
1157 assert.NotNil(t, omciObj)
1158 assert.True(t, omciOk)
1159 assert.Equal(t, tid, omciObj.TransactionID)
1160 assert.Equal(t, MibUploadResponseType, omciObj.MessageType)
1161 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1162
1163 msgLayer := packet.Layer(LayerTypeMibUploadResponse)
1164 assert.NotNil(t, msgLayer)
1165
1166 msgObj, msgOk := msgLayer.(*MibUploadResponse)
1167 assert.NotNil(t, msgObj)
1168 assert.True(t, msgOk)
1169
1170 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1171 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1172 assert.Equal(t, numOfCommands, msgObj.NumberOfCommands)
1173}
1174
1175func testMibUploadNextRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1176 params := me.ParamData{
1177 EntityID: uint16(0),
1178 }
1179 // Create the managed instance
1180 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1181 assert.NotNil(t, err)
1182 assert.Equal(t, err.StatusCode(), me.Success)
1183
1184 seqNumber := uint16(rand.Int31n(0xFFFF)) // [0, 0xFFFE]
1185 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1186
1187 var frame []byte
1188 frame, omciErr := GenFrame(meInstance, MibUploadNextRequestType, TransactionID(tid),
1189 SequenceNumberCountOrSize(seqNumber))
1190 assert.NotNil(t, frame)
1191 assert.NotZero(t, len(frame))
1192 assert.Nil(t, omciErr)
1193
1194 ///////////////////////////////////////////////////////////////////
1195 // Now decode and compare
1196 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1197 assert.NotNil(t, packet)
1198
1199 omciLayer := packet.Layer(LayerTypeOMCI)
1200 assert.NotNil(t, omciLayer)
1201
1202 omciObj, omciOk := omciLayer.(*OMCI)
1203 assert.NotNil(t, omciObj)
1204 assert.True(t, omciOk)
1205 assert.Equal(t, tid, omciObj.TransactionID)
1206 assert.Equal(t, MibUploadNextRequestType, omciObj.MessageType)
1207 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1208
1209 msgLayer := packet.Layer(LayerTypeMibUploadNextRequest)
1210 assert.NotNil(t, msgLayer)
1211
1212 msgObj, msgOk := msgLayer.(*MibUploadNextRequest)
1213 assert.NotNil(t, msgObj)
1214 assert.True(t, msgOk)
1215
1216 assert.Equal(t, seqNumber, msgObj.CommandSequenceNumber)
1217 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1218 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1219}
1220
1221func testMibUploadNextResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1222 params := me.ParamData{
1223 EntityID: uint16(0),
1224 }
1225 // Create the managed instance
1226 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1227 assert.NotNil(t, err)
1228 assert.Equal(t, err.StatusCode(), me.Success)
1229
1230 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1231
1232 // TODO: Since only baseline messages supported, send only one ME
1233 uploadMe := meInstance
1234
1235 frame, omciErr := GenFrame(meInstance, MibUploadNextResponseType, TransactionID(tid), Payload(uploadMe))
1236 assert.NotNil(t, frame)
1237 assert.NotZero(t, len(frame))
1238 assert.Nil(t, omciErr)
1239
1240 ///////////////////////////////////////////////////////////////////
1241 // Now decode and compare
1242 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1243 assert.NotNil(t, packet)
1244
1245 omciLayer := packet.Layer(LayerTypeOMCI)
1246 assert.NotNil(t, omciLayer)
1247
1248 omciObj, omciOk := omciLayer.(*OMCI)
1249 assert.NotNil(t, omciObj)
1250 assert.True(t, omciOk)
1251 assert.Equal(t, tid, omciObj.TransactionID)
1252 assert.Equal(t, MibUploadNextResponseType, omciObj.MessageType)
1253 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1254
1255 msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
1256 assert.NotNil(t, msgLayer)
1257
1258 msgObj, msgOk := msgLayer.(*MibUploadNextResponse)
1259 assert.NotNil(t, msgObj)
1260 assert.True(t, msgOk)
1261
1262 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1263 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1264 assert.Equal(t, uploadMe.GetClassID(), msgObj.ReportedME.GetClassID())
1265 assert.Equal(t, uploadMe.GetEntityID(), msgObj.ReportedME.GetEntityID())
1266}
1267
1268func testMibResetRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1269 params := me.ParamData{
1270 EntityID: uint16(0),
1271 }
1272 // Create the managed instance
1273 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1274 assert.NotNil(t, err)
1275 assert.Equal(t, err.StatusCode(), me.Success)
1276
1277 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1278
1279 frame, omciErr := GenFrame(meInstance, MibResetRequestType, TransactionID(tid))
1280 assert.NotNil(t, frame)
1281 assert.NotZero(t, len(frame))
1282 assert.Nil(t, omciErr)
1283
1284 ///////////////////////////////////////////////////////////////////
1285 // Now decode and compare
1286 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1287 assert.NotNil(t, packet)
1288
1289 omciLayer := packet.Layer(LayerTypeOMCI)
1290 assert.NotNil(t, omciLayer)
1291
1292 omciObj, omciOk := omciLayer.(*OMCI)
1293 assert.NotNil(t, omciObj)
1294 assert.True(t, omciOk)
1295 assert.Equal(t, tid, omciObj.TransactionID)
1296 assert.Equal(t, MibResetRequestType, omciObj.MessageType)
1297 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1298
1299 msgLayer := packet.Layer(LayerTypeMibResetRequest)
1300 assert.NotNil(t, msgLayer)
1301
1302 msgObj, msgOk := msgLayer.(*MibResetRequest)
1303 assert.NotNil(t, msgObj)
1304 assert.True(t, msgOk)
1305
1306 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1307 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1308}
1309
1310func testMibResetResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1311 params := me.ParamData{
1312 EntityID: uint16(0),
1313 }
1314 // Create the managed instance
1315 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1316 assert.NotNil(t, err)
1317 assert.Equal(t, err.StatusCode(), me.Success)
1318
1319 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1320 result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested
1321
1322 frame, omciErr := GenFrame(meInstance, MibResetResponseType, TransactionID(tid), Result(result))
1323 assert.NotNil(t, frame)
1324 assert.NotZero(t, len(frame))
1325 assert.Nil(t, omciErr)
1326
1327 ///////////////////////////////////////////////////////////////////
1328 // Now decode and compare
1329 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1330 assert.NotNil(t, packet)
1331
1332 omciLayer := packet.Layer(LayerTypeOMCI)
1333 assert.NotNil(t, omciLayer)
1334
1335 omciObj, omciOk := omciLayer.(*OMCI)
1336 assert.NotNil(t, omciObj)
1337 assert.True(t, omciOk)
1338 assert.Equal(t, tid, omciObj.TransactionID)
1339 assert.Equal(t, MibResetResponseType, omciObj.MessageType)
1340 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1341
1342 msgLayer := packet.Layer(LayerTypeMibResetResponse)
1343 assert.NotNil(t, msgLayer)
1344
1345 msgObj, msgOk := msgLayer.(*MibResetResponse)
1346 assert.NotNil(t, msgObj)
1347 assert.True(t, msgOk)
1348
1349 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1350 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1351 assert.Equal(t, result, msgObj.Result)
1352}
1353
1354func testTestRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1355 // TODO: Implement
1356}
1357
1358func testTestResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1359 // TODO: Implement
1360}
1361
1362func testStartSoftwareDownloadRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1363 instance := uint16(0) // ONU-G
1364 image := uint16(1)
1365 params := me.ParamData{
1366 EntityID: uint16((instance << 8) + image),
1367 }
1368 // Create the managed instance
1369 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1370 assert.NotNil(t, err)
1371 assert.Equal(t, err.StatusCode(), me.Success)
1372
1373 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1374 options := SoftwareOptions{
1375 WindowSize: uint8(rand.Int31n(255)), // [0, 255]
1376 ImageSize: uint32(rand.Int31n(0x100000) + 0x100000), // [1 Meg, 2M-1]
1377 CircuitPacks: []uint16{0}, // [1 Meg, 2M-1]
1378 }
1379 frame, omciErr := GenFrame(meInstance, StartSoftwareDownloadRequestType, TransactionID(tid), Software(options))
1380 assert.NotNil(t, frame)
1381 assert.NotZero(t, len(frame))
1382 assert.Nil(t, omciErr)
1383
1384 ///////////////////////////////////////////////////////////////////
1385 // Now decode and compare
1386 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1387 assert.NotNil(t, packet)
1388
1389 omciLayer := packet.Layer(LayerTypeOMCI)
1390 assert.NotNil(t, omciLayer)
1391
1392 omciObj, omciOk := omciLayer.(*OMCI)
1393 assert.NotNil(t, omciObj)
1394 assert.True(t, omciOk)
1395 assert.Equal(t, tid, omciObj.TransactionID)
1396 assert.Equal(t, StartSoftwareDownloadRequestType, omciObj.MessageType)
1397 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1398
1399 msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest)
1400 assert.NotNil(t, msgLayer)
1401
1402 msgObj, msgOk := msgLayer.(*StartSoftwareDownloadRequest)
1403 assert.NotNil(t, msgObj)
1404 assert.True(t, msgOk)
1405
1406 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1407 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1408 assert.Equal(t, options.ImageSize, msgObj.ImageSize)
1409 assert.Equal(t, len(options.CircuitPacks), int(msgObj.NumberOfCircuitPacks))
1410
1411 for index, circuitPack := range options.CircuitPacks {
1412 assert.Equal(t, circuitPack, msgObj.CircuitPacks[index])
1413 }
1414}
1415
1416func testStartSoftwareDownloadResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1417 // TODO: Implement
1418}
1419
1420func testDownloadSectionRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1421 // TODO: Implement
1422}
1423
1424func testDownloadSectionResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1425 // TODO: Implement
1426}
1427
1428func testEndSoftwareDownloadRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1429 // TODO: Implement
1430}
1431
1432func testEndSoftwareDownloadResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1433 // TODO: Implement
1434}
1435
1436func testActivateSoftwareRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1437 // TODO: Implement
1438}
1439
1440func testActivateSoftwareResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1441 // TODO: Implement
1442}
1443
1444func testCommitSoftwareRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1445 // TODO: Implement
1446}
1447
1448func testCommitSoftwareResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1449 // TODO: Implement
1450}
1451
1452func testSynchronizeTimeRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1453 params := me.ParamData{
1454 EntityID: uint16(0),
1455 }
1456 // Create the managed instance
1457 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1458 assert.NotNil(t, err)
1459 assert.Equal(t, err.StatusCode(), me.Success)
1460
1461 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1462 tm := time.Now().UTC()
1463 tmUnix := tm.Unix()
1464
1465 frame, omciErr := GenFrame(meInstance, SynchronizeTimeRequestType, TransactionID(tid), Payload(tmUnix))
1466 assert.NotNil(t, frame)
1467 assert.NotZero(t, len(frame))
1468 assert.Nil(t, omciErr)
1469
1470 ///////////////////////////////////////////////////////////////////
1471 // Now decode and compare
1472 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1473 assert.NotNil(t, packet)
1474
1475 omciLayer := packet.Layer(LayerTypeOMCI)
1476 assert.NotNil(t, omciLayer)
1477
1478 omciObj, omciOk := omciLayer.(*OMCI)
1479 assert.NotNil(t, omciObj)
1480 assert.True(t, omciOk)
1481 assert.Equal(t, tid, omciObj.TransactionID)
1482 assert.Equal(t, SynchronizeTimeRequestType, omciObj.MessageType)
1483 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1484
1485 msgLayer := packet.Layer(LayerTypeSynchronizeTimeRequest)
1486 assert.NotNil(t, msgLayer)
1487
1488 msgObj, msgOk := msgLayer.(*SynchronizeTimeRequest)
1489 assert.NotNil(t, msgObj)
1490 assert.True(t, msgOk)
1491
1492 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1493 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1494
1495 assert.Equal(t, uint16(tm.Year()), msgObj.Year)
1496 assert.Equal(t, uint8(tm.Month()), msgObj.Month)
1497 assert.Equal(t, uint8(tm.Day()), msgObj.Day)
1498 assert.Equal(t, uint8(tm.Hour()), msgObj.Hour)
1499 assert.Equal(t, uint8(tm.Minute()), msgObj.Minute)
1500 assert.Equal(t, uint8(tm.Second()), msgObj.Second)
1501}
1502
1503func testSynchronizeTimeResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1504 params := me.ParamData{
1505 EntityID: uint16(0),
1506 }
1507 // Create the managed instance
1508 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1509 assert.NotNil(t, err)
1510 assert.Equal(t, err.StatusCode(), me.Success)
1511
1512 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1513 result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested
1514 successResult := uint8(rand.Int31n(2)) // [0, 1]
1515
1516 var frame []byte
1517 frame, omciErr := GenFrame(meInstance, SynchronizeTimeResponseType, TransactionID(tid),
1518 Result(result), SuccessResult(successResult))
1519 assert.NotNil(t, frame)
1520 assert.NotZero(t, len(frame))
1521 assert.Nil(t, omciErr)
1522
1523 ///////////////////////////////////////////////////////////////////
1524 // Now decode and compare
1525 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1526 assert.NotNil(t, packet)
1527
1528 omciLayer := packet.Layer(LayerTypeOMCI)
1529 assert.NotNil(t, omciLayer)
1530
1531 omciObj, omciOk := omciLayer.(*OMCI)
1532 assert.NotNil(t, omciObj)
1533 assert.True(t, omciOk)
1534 assert.Equal(t, tid, omciObj.TransactionID)
1535 assert.Equal(t, SynchronizeTimeResponseType, omciObj.MessageType)
1536 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1537
1538 msgLayer := packet.Layer(LayerTypeSynchronizeTimeResponse)
1539 assert.NotNil(t, msgLayer)
1540
1541 msgObj, msgOk := msgLayer.(*SynchronizeTimeResponse)
1542 assert.NotNil(t, msgObj)
1543 assert.True(t, msgOk)
1544
1545 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1546 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1547 assert.Equal(t, result, msgObj.Result)
1548 if result == me.Success {
1549 assert.Equal(t, successResult, msgObj.SuccessResults)
1550 } else {
1551 assert.Zero(t, msgObj.SuccessResults)
1552 }
1553}
1554
1555func testRebootRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1556 params := me.ParamData{
1557 EntityID: uint16(0),
1558 }
1559 // Create the managed instance
1560 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1561 assert.NotNil(t, err)
1562 assert.Equal(t, err.StatusCode(), me.Success)
1563
1564 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1565 condition := uint8(rand.Int31n(3)) // [0, 3]
1566
1567 frame, omciErr := GenFrame(meInstance, RebootRequestType, TransactionID(tid), RebootCondition(condition))
1568 assert.NotNil(t, frame)
1569 assert.NotZero(t, len(frame))
1570 assert.Nil(t, omciErr)
1571
1572 ///////////////////////////////////////////////////////////////////
1573 // Now decode and compare
1574 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1575 assert.NotNil(t, packet)
1576
1577 omciLayer := packet.Layer(LayerTypeOMCI)
1578 assert.NotNil(t, omciLayer)
1579
1580 omciObj, omciOk := omciLayer.(*OMCI)
1581 assert.NotNil(t, omciObj)
1582 assert.True(t, omciOk)
1583 assert.Equal(t, tid, omciObj.TransactionID)
1584 assert.Equal(t, RebootRequestType, omciObj.MessageType)
1585 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1586
1587 msgLayer := packet.Layer(LayerTypeRebootRequest)
1588 assert.NotNil(t, msgLayer)
1589
1590 msgObj, msgOk := msgLayer.(*RebootRequest)
1591 assert.NotNil(t, msgObj)
1592 assert.True(t, msgOk)
1593
1594 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1595 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1596 assert.Equal(t, condition, msgObj.RebootCondition)
1597}
1598
1599func testRebootResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1600 params := me.ParamData{
1601 EntityID: uint16(0),
1602 }
1603 // Create the managed instance
1604 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1605 assert.NotNil(t, err)
1606 assert.Equal(t, err.StatusCode(), me.Success)
1607
1608 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1609 result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested
1610
1611 frame, omciErr := GenFrame(meInstance, RebootResponseType, TransactionID(tid), Result(result))
1612 assert.NotNil(t, frame)
1613 assert.NotZero(t, len(frame))
1614 assert.Nil(t, omciErr)
1615
1616 ///////////////////////////////////////////////////////////////////
1617 // Now decode and compare
1618 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1619 assert.NotNil(t, packet)
1620
1621 omciLayer := packet.Layer(LayerTypeOMCI)
1622 assert.NotNil(t, omciLayer)
1623
1624 omciObj, omciOk := omciLayer.(*OMCI)
1625 assert.NotNil(t, omciObj)
1626 assert.True(t, omciOk)
1627 assert.Equal(t, tid, omciObj.TransactionID)
1628 assert.Equal(t, RebootResponseType, omciObj.MessageType)
1629 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1630
1631 msgLayer := packet.Layer(LayerTypeRebootResponse)
1632 assert.NotNil(t, msgLayer)
1633
1634 msgObj, msgOk := msgLayer.(*RebootResponse)
1635 assert.NotNil(t, msgObj)
1636 assert.True(t, msgOk)
1637
1638 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1639 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1640 assert.Equal(t, result, msgObj.Result)
1641}
1642
1643func testGetNextRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1644 params := me.ParamData{
1645 EntityID: uint16(0),
1646 Attributes: make(me.AttributeValueMap, 0),
1647 }
1648 // TODO: Loop over all table attributes for this class ID
1649 // Find first attribute that is a table definition
1650 // TODO: Test request of more than 1 attribute. G.988 specifies that a status
1651 // code of (3) should be returned. Raise error during encode instead of
1652 // waiting for compliant ONU. May want to have an 'ignore' to allow it.
1653 attrDefs := managedEntity.GetAttributeDefinitions()
1654 for _, attrDef := range attrDefs {
1655 if attrDef.Index == 0 {
1656 continue // Skip entity ID, already specified
1657 } else if attrDef.IsTableAttribute() {
1658 // TODO: Tables without a size are not supported. At least needs to be one octet
1659 if attrDef.Size == 0 {
1660 continue
1661 }
1662 // Allow 'nil' as parameter value for GetNextRequests since we only need names
1663 params.Attributes[attrDef.GetName()] = nil
1664 break
1665 }
1666 }
1667 if len(params.Attributes) == 0 {
1668 return
1669 }
1670 bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes))
1671 assert.Nil(t, attrErr)
1672
1673 // Create the managed instance
1674 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1675 assert.NotNil(t, err)
1676 assert.Equal(t, err.StatusCode(), me.Success)
1677
1678 seqNumber := uint16(rand.Int31n(0xFFFF)) // [0, 0xFFFE]
1679 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1680
1681 frame, omciErr := GenFrame(meInstance, GetNextRequestType, TransactionID(tid), SequenceNumberCountOrSize(seqNumber),
1682 AttributeMask(bitmask))
1683 assert.NotNil(t, frame)
1684 assert.NotZero(t, len(frame))
1685 assert.Nil(t, omciErr)
1686
1687 ///////////////////////////////////////////////////////////////////
1688 // Now decode and compare
1689 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1690 assert.NotNil(t, packet)
1691
1692 omciLayer := packet.Layer(LayerTypeOMCI)
1693 assert.NotNil(t, omciLayer)
1694
1695 omciObj, omciOk := omciLayer.(*OMCI)
1696 assert.NotNil(t, omciObj)
1697 assert.True(t, omciOk)
1698 assert.Equal(t, tid, omciObj.TransactionID)
1699 assert.Equal(t, GetNextRequestType, omciObj.MessageType)
1700 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1701
1702 msgLayer := packet.Layer(LayerTypeGetNextRequest)
1703 assert.NotNil(t, msgLayer)
1704
1705 msgObj, msgOk := msgLayer.(*GetNextRequest)
1706 assert.NotNil(t, msgObj)
1707 assert.True(t, msgOk)
1708
1709 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1710 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1711 assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask)
1712 assert.Equal(t, seqNumber, msgObj.SequenceNumber)
1713}
1714
1715func testGetNextResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1716 params := me.ParamData{
1717 EntityID: uint16(0),
1718 Attributes: make(me.AttributeValueMap, 0),
1719 }
1720 // TODO: Loop over result types (here and other responses with results)
1721 result := me.Success // me.Results(rand.Int31n(7)) // [0, 6]
1722 bitmask := uint16(0)
1723 attrDefs := managedEntity.GetAttributeDefinitions()
1724
1725 // TODO: Loop over all table attributes for this class ID
1726 if result == me.Success {
1727 // Find first attribute that is a table definition
1728 // TODO: Test request of more than 1 attribute. G.988 specifies that a status
1729 // code of (3) should be returned. Raise error during encode instead of
1730 // waiting for compliant ONU. May want to have an 'ignore' to allow it.
1731 for _, attrDef := range attrDefs {
1732 if attrDef.Index == 0 {
1733 continue // Skip entity ID, already specified
1734 } else if attrDef.IsTableAttribute() {
1735 if len(params.Attributes) == 0 {
1736 // Need a parameter that is a table attribute
1737 return
1738 }
1739 params.Attributes[attrDef.GetName()] = pickAValue(attrDef)
1740 break
1741 }
1742 }
1743 if len(params.Attributes) == 0 {
1744 return
1745 }
1746 assert.NotEmpty(t, params.Attributes) // Need a parameter that is a table attribute
1747 var attrErr error
1748 bitmask, attrErr = me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes))
1749 assert.Nil(t, attrErr)
1750 }
1751 // Create the managed instance
1752 meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params)
1753 assert.NotNil(t, err)
1754 assert.Equal(t, err.StatusCode(), me.Success)
1755
1756 tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF]
1757
1758 frame, omciErr := GenFrame(meInstance, GetNextResponseType, TransactionID(tid), Result(result),
1759 AttributeMask(bitmask))
1760 assert.NotNil(t, frame)
1761 assert.NotZero(t, len(frame))
1762 assert.Nil(t, omciErr)
1763
1764 ///////////////////////////////////////////////////////////////////
1765 // Now decode and compare
1766 cid := meInstance.GetClassID()
1767 assert.NotEqual(t, cid, 0)
1768 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1769 assert.NotNil(t, packet)
1770
1771 omciLayer := packet.Layer(LayerTypeOMCI)
1772 assert.NotNil(t, omciLayer)
1773
1774 omciObj, omciOk := omciLayer.(*OMCI)
1775 assert.NotNil(t, omciObj)
1776 assert.True(t, omciOk)
1777 assert.Equal(t, tid, omciObj.TransactionID)
1778 assert.Equal(t, GetNextResponseType, omciObj.MessageType)
1779 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1780
1781 msgLayer := packet.Layer(LayerTypeGetNextResponse)
1782 assert.NotNil(t, msgLayer)
1783
1784 msgObj, msgOk := msgLayer.(*GetNextResponse)
1785 assert.NotNil(t, msgObj)
1786 assert.True(t, msgOk)
1787
1788 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1789 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1790 assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask)
1791
1792 switch msgObj.Result {
1793 default:
1794 assert.Equal(t, result, msgObj.Result)
1795
1796 case me.Success:
1797 assert.Equal(t, result, msgObj.Result)
1798 // The attributes should be equal but for variable length table attribute (size = 0 in structure)
1799 // we will have the frame padding returned as well.
1800 for attrName, value := range meInstance.GetAttributeValueMap() {
1801 attr, err := me.GetAttributeDefinitionByName(attrDefs, attrName)
1802 assert.Nil(t, err)
1803 assert.NotNil(t, attr)
1804 assert.Equal(t, attrName, attr.GetName())
1805 if attr.IsTableAttribute() {
1806 instValue := value.([]byte)
1807 msgValue := msgObj.Attributes[attrName].([]byte)
1808 assert.True(t, len(instValue) <= len(msgValue))
1809 assert.Equal(t, msgValue[:len(instValue)], instValue)
1810 } else {
1811 assert.Equal(t, value, msgObj.Attributes[attrName])
1812 }
1813 }
1814 }
1815}
1816
1817func testGetCurrentDataRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1818 // TODO: Implement
1819}
1820
1821func testGetCurrentDataResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1822 // TODO: Implement
1823}
1824
1825func testSetTableRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1826 // TODO: Implement
1827}
1828
1829func testSetTableResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1830 // TODO: Implement
1831}
1832
1833func testAlarmNotificationTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1834 // TODO: Implement
1835}
1836
1837func testAttributeValueChangeTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1838 // TODO: Implement
1839}
1840
1841func testTestResultTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity) {
1842 // TODO: Implement
1843}