blob: b3838817d50363e1299c4f2170e0898f967c47fd [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 */
17
18package omci_test
19
20import (
21 "encoding/hex"
22 "fmt"
Chip Bolingff6bf172020-12-01 10:38:12 -060023 "github.com/google/gopacket"
Andrea Campanella7167ebb2020-02-24 09:56:38 +010024 . "github.com/opencord/omci-lib-go"
25 . "github.com/opencord/omci-lib-go/generated"
Chip Boling6e27b352020-02-14 09:10:01 -060026 "github.com/stretchr/testify/assert"
27 "strings"
28 "testing"
29)
30
31func stringToPacket(input string) ([]byte, error) {
32 var p []byte
33
34 p, err := hex.DecodeString(input)
35 if err != nil {
36 fmt.Println(err)
37 return nil, err
38 }
39 return p, nil
40}
41
42func packetToString(input []byte) string {
43 return strings.ToLower(hex.EncodeToString(input))
44}
45
46func getSbcMask(meDefinition IManagedEntityDefinition) uint16 {
47 var sbcMask uint16
48
49 for index, attr := range meDefinition.GetAttributeDefinitions() {
50 if SupportsAttributeAccess(attr, SetByCreate) {
51 if index == 0 {
52 continue // Skip Entity ID
53 }
54 sbcMask |= attr.Mask
55 }
56 }
57 return sbcMask
58}
59
60func TestDeviceIdents(t *testing.T) {
61
62 baselineString := BaselineIdent.String()
63 assert.NotZero(t, len(baselineString))
64
65 extendedString := ExtendedIdent.String()
66 assert.NotZero(t, len(extendedString))
67
68 assert.NotEqual(t, baselineString, extendedString)
69
70 unknownString := DeviceIdent(0xff).String()
71 assert.NotZero(t, len(unknownString))
72 assert.NotEqual(t, unknownString, baselineString)
73 assert.NotEqual(t, unknownString, extendedString)
74}
75
76// MibResetRequestTest tests decode/encode of a MIB Reset Request
77func TestMibResetRequestMessage(t *testing.T) {
78 mibResetRequest := "00014F0A000200000000000000000000" +
79 "00000000000000000000000000000000" +
80 "000000000000000000000028"
81
82 data, err := stringToPacket(mibResetRequest)
83 assert.NoError(t, err)
84
85 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
86
87 omciLayer := packet.Layer(LayerTypeOMCI)
88 assert.NotNil(t, packet)
89
90 omciMsg, ok := omciLayer.(*OMCI)
91 assert.True(t, ok)
92 assert.Equal(t, omciMsg.TransactionID, uint16(1))
93 assert.Equal(t, omciMsg.MessageType, MibResetRequestType)
94 assert.Equal(t, omciMsg.Length, uint16(40))
95
96 msgLayer := packet.Layer(LayerTypeMibResetRequest)
97 assert.NotNil(t, msgLayer)
98
99 omciMsg2, ok2 := msgLayer.(*MibResetRequest)
100 assert.True(t, ok2)
101 assert.Equal(t, omciMsg2.EntityClass, OnuDataClassID)
102 assert.Equal(t, omciMsg2.EntityInstance, uint16(0))
103
104 // Test serialization back to former string
105 var options gopacket.SerializeOptions
106 options.FixLengths = true
107
108 buffer := gopacket.NewSerializeBuffer()
109 err = gopacket.SerializeLayers(buffer, options, omciMsg, omciMsg2)
110 assert.NoError(t, err)
111
112 outgoingPacket := buffer.Bytes()
113 reconstituted := packetToString(outgoingPacket)
114 assert.Equal(t, strings.ToLower(mibResetRequest), reconstituted)
115}
116
117func TestCreateGalEthernetProfile(t *testing.T) {
118 createGalEthernetProfile := "0002440A011000010030000000000000" +
119 "00000000000000000000000000000000" +
120 "000000000000000000000028"
121
122 data, err := stringToPacket(createGalEthernetProfile)
123 assert.NoError(t, err)
124
125 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
126 assert.NotNil(t, packet)
127
128 omciLayer := packet.Layer(LayerTypeOMCI)
129 assert.NotNil(t, packet)
130
131 omciMsg, ok := omciLayer.(*OMCI)
132 assert.True(t, ok)
133 assert.Equal(t, omciMsg.TransactionID, uint16(2))
134 assert.Equal(t, omciMsg.MessageType, CreateRequestType)
135 assert.Equal(t, omciMsg.Length, uint16(40))
136
137 msgLayer := packet.Layer(LayerTypeCreateRequest)
138 assert.NotNil(t, msgLayer)
139
140 omciMsg2, ok2 := msgLayer.(*CreateRequest)
141 assert.True(t, ok2)
142 assert.Equal(t, omciMsg2.EntityClass, GalEthernetProfileClassID)
143 assert.Equal(t, omciMsg2.EntityInstance, uint16(1))
144
145 // Test serialization back to former string
146 var options gopacket.SerializeOptions
147 options.FixLengths = true
148
149 buffer := gopacket.NewSerializeBuffer()
150 err = gopacket.SerializeLayers(buffer, options, omciMsg, omciMsg2)
151 assert.NoError(t, err)
152
153 outgoingPacket := buffer.Bytes()
154 reconstituted := packetToString(outgoingPacket)
155 assert.Equal(t, strings.ToLower(createGalEthernetProfile), reconstituted)
156}
157
158func TestSetTCont(t *testing.T) {
159 setTCont := "0003480A010680008000040000000000" +
160 "00000000000000000000000000000000" +
161 "000000000000000000000028"
162
163 data, err := stringToPacket(setTCont)
164 assert.NoError(t, err)
165
166 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
167 assert.NotNil(t, packet)
168
169 omciLayer := packet.Layer(LayerTypeOMCI)
170 assert.NotNil(t, packet)
171
172 omciMsg, ok := omciLayer.(*OMCI)
173 assert.True(t, ok)
174 assert.Equal(t, omciMsg.TransactionID, uint16(3))
175 assert.Equal(t, omciMsg.MessageType, SetRequestType)
176 assert.Equal(t, omciMsg.Length, uint16(40))
177
178 msgLayer := packet.Layer(LayerTypeSetRequest)
179 assert.NotNil(t, msgLayer)
180
181 omciMsg2, ok2 := msgLayer.(*SetRequest)
182 assert.True(t, ok2)
183 assert.Equal(t, omciMsg2.EntityClass, TContClassID)
184 assert.Equal(t, omciMsg2.EntityInstance, uint16(0x8000))
185
186 attributes := omciMsg2.Attributes
187 assert.Equal(t, len(attributes), 2)
188
189 // TODO: Create generic test to look up the name from definition
190 // Here 1 is the index in the attribute definition map of a TCONT that points
191 // to the AllocID attribute.
192 value, ok3 := attributes["AllocId"]
193 assert.True(t, ok3)
194 assert.Equal(t, value, uint16(1024))
195
196 // Test serialization back to former string
197 var options gopacket.SerializeOptions
198 options.FixLengths = true
199
200 buffer := gopacket.NewSerializeBuffer()
201 err = gopacket.SerializeLayers(buffer, options, omciMsg, omciMsg2)
202 assert.NoError(t, err)
203
204 outgoingPacket := buffer.Bytes()
205 reconstituted := packetToString(outgoingPacket)
206 assert.Equal(t, strings.ToLower(setTCont), reconstituted)
207}
208
209func TestCreate8021pMapperService_profile(t *testing.T) {
210 create8021pMapperServiceProfile := "0007440A00828000ffffffffffffffff" +
211 "ffffffffffffffffffff000000000000" +
212 "000000000000000000000028"
213
214 data, err := stringToPacket(create8021pMapperServiceProfile)
215 assert.NoError(t, err)
216
217 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
218 assert.NotNil(t, packet)
219
220 omciLayer := packet.Layer(LayerTypeOMCI)
221 assert.NotNil(t, packet)
222
223 omciMsg, ok := omciLayer.(*OMCI)
224 assert.True(t, ok)
225 assert.Equal(t, omciMsg.TransactionID, uint16(7))
226 assert.Equal(t, omciMsg.MessageType, CreateRequestType)
227 assert.Equal(t, omciMsg.Length, uint16(40))
228
229 msgLayer := packet.Layer(LayerTypeCreateRequest)
230 assert.NotNil(t, msgLayer)
231
232 createRequest, ok2 := msgLayer.(*CreateRequest)
233 assert.True(t, ok2)
234 assert.Equal(t, createRequest.EntityClass, Ieee8021PMapperServiceProfileClassID)
235 assert.Equal(t, createRequest.EntityInstance, uint16(0x8000))
236
237 attributes := createRequest.Attributes
238 assert.NotNil(t, attributes)
239 assert.Equal(t, len(attributes), 13)
240
241 // As this is a create request, gather up all set-by-create attributes
242 // make sure we got them all, and nothing else
243 meDefinition, omciErr := LoadManagedEntityDefinition(createRequest.EntityClass)
244 assert.NotNil(t, omciErr)
245 assert.Equal(t, omciErr.StatusCode(), Success)
246
247 attrDefs := meDefinition.GetAttributeDefinitions()
248
249 for index := uint(1); index <= uint(9); index++ {
250 attrName := attrDefs[index].GetName()
251 value, ok := attributes[attrName]
252 assert.True(t, ok)
253
254 value16, ok3 := value.(uint16)
255 assert.True(t, ok3)
256 assert.Equal(t, value16, uint16(0xffff))
257 }
258
259 sbcMask := getSbcMask(meDefinition)
260 for index := uint(1); index < uint(len(attrDefs)); index++ {
261 attrName := attrDefs[index].GetName()
262
263 if sbcMask&uint16(1<<(uint)(16-index)) != 0 {
264 _, ok3 := attributes[attrName]
265 assert.True(t, ok3)
266 } else {
267 _, ok3 := attributes[attrName]
268 assert.False(t, ok3)
269 }
270 }
271 // TODO: Individual attribute tests here if needed
272 // Test serialization back to former string
273 var options gopacket.SerializeOptions
274 options.FixLengths = true
275
276 buffer := gopacket.NewSerializeBuffer()
277 err = gopacket.SerializeLayers(buffer, options, omciMsg, createRequest)
278 assert.NoError(t, err)
279
280 outgoingPacket := buffer.Bytes()
281 reconstituted := packetToString(outgoingPacket)
282 assert.Equal(t, strings.ToLower(create8021pMapperServiceProfile), reconstituted)
283}
284
285func TestCreate_macBridgeService_profile(t *testing.T) {
286 var createMacBridgeServiceProfile = "000B440A002D02010001008000140002" +
287 "000f0001000000000000000000000000" +
288 "000000000000000000000028"
289
290 data, err := stringToPacket(createMacBridgeServiceProfile)
291 assert.NoError(t, err)
292
293 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
294 assert.NotNil(t, packet)
295
296 omciLayer := packet.Layer(LayerTypeOMCI)
297 assert.NotNil(t, packet)
298
299 omciMsg, ok := omciLayer.(*OMCI)
300 assert.True(t, ok)
301 assert.Equal(t, omciMsg.TransactionID, uint16(0xb))
302 assert.Equal(t, omciMsg.MessageType, CreateRequestType)
303 assert.Equal(t, omciMsg.Length, uint16(40))
304
305 msgLayer := packet.Layer(LayerTypeCreateRequest)
306 assert.NotNil(t, msgLayer)
307
308 createRequest, ok2 := msgLayer.(*CreateRequest)
309 assert.True(t, ok2)
310 assert.Equal(t, createRequest.EntityClass, MacBridgeServiceProfileClassID)
311 assert.Equal(t, createRequest.EntityInstance, uint16(0x201))
312
313 attributes := createRequest.Attributes
314 assert.NotNil(t, attributes)
315
316 // As this is a create request, gather up all set-by-create attributes
317 // make sure we got them all, and nothing else
318 meDefinition, omciErr := LoadManagedEntityDefinition(createRequest.EntityClass)
319 assert.NotNil(t, omciErr)
320 assert.Equal(t, omciErr.StatusCode(), Success)
321
322 attrDefs := meDefinition.GetAttributeDefinitions()
323
324 sbcMask := getSbcMask(meDefinition)
325 for index := uint(1); index < uint(len(attrDefs)); index++ {
326 attrName := attrDefs[index].GetName()
327
328 if sbcMask&uint16(1<<(uint)(16-index)) != 0 {
329 _, ok3 := attributes[attrName]
330 assert.True(t, ok3)
331 } else {
332 _, ok3 := attributes[attrName]
333 assert.False(t, ok3)
334 }
335 }
336 // Test serialization back to former string
337 var options gopacket.SerializeOptions
338 options.FixLengths = true
339
340 buffer := gopacket.NewSerializeBuffer()
341 err = gopacket.SerializeLayers(buffer, options, omciMsg, createRequest)
342 assert.NoError(t, err)
343
344 outgoingPacket := buffer.Bytes()
345 reconstituted := packetToString(outgoingPacket)
346 assert.Equal(t, strings.ToLower(createMacBridgeServiceProfile), reconstituted)
347}
348
349func TestCreateGemPortNetworkCtp(t *testing.T) {
350 createGemPortNetworkCtp := "000C440A010C01000400800003010000" +
351 "00000000000000000000000000000000" +
352 "000000000000000000000028"
353
354 data, err := stringToPacket(createGemPortNetworkCtp)
355 assert.NoError(t, err)
356
357 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
358 assert.NotNil(t, packet)
359
360 omciLayer := packet.Layer(LayerTypeOMCI)
361 assert.NotNil(t, packet)
362
363 omciMsg, ok := omciLayer.(*OMCI)
364 assert.True(t, ok)
365 assert.Equal(t, omciMsg.TransactionID, uint16(0xc))
366 assert.Equal(t, omciMsg.MessageType, CreateRequestType)
367 assert.Equal(t, omciMsg.Length, uint16(40))
368
369 msgLayer := packet.Layer(LayerTypeCreateRequest)
370 assert.NotNil(t, msgLayer)
371
372 createRequest, ok2 := msgLayer.(*CreateRequest)
373 assert.True(t, ok2)
374 assert.Equal(t, createRequest.EntityClass, GemPortNetworkCtpClassID)
375 assert.Equal(t, createRequest.EntityInstance, uint16(0x100))
376
377 attributes := createRequest.Attributes
378 assert.NotNil(t, attributes)
379
380 // As this is a create request, gather up all set-by-create attributes
381 // make sure we got them all, and nothing else
382 meDefinition, omciErr := LoadManagedEntityDefinition(createRequest.EntityClass)
383 assert.NotNil(t, omciErr)
384 assert.Equal(t, omciErr.StatusCode(), Success)
385
386 attrDefs := meDefinition.GetAttributeDefinitions()
387
388 sbcMask := getSbcMask(meDefinition)
389 for index := uint(1); index < uint(len(attrDefs)); index++ {
390 attrName := attrDefs[index].GetName()
391
392 if sbcMask&uint16(1<<(uint)(16-index)) != 0 {
393 _, ok3 := attributes[attrName]
394 assert.True(t, ok3)
395 } else {
396 _, ok3 := attributes[attrName]
397 assert.False(t, ok3)
398 }
399 }
400 // Test serialization back to former string
401 var options gopacket.SerializeOptions
402 options.FixLengths = true
403
404 buffer := gopacket.NewSerializeBuffer()
405 err = gopacket.SerializeLayers(buffer, options, omciMsg, createRequest)
406 assert.NoError(t, err)
407
408 outgoingPacket := buffer.Bytes()
409 reconstituted := packetToString(outgoingPacket)
410 assert.Equal(t, strings.ToLower(createGemPortNetworkCtp), reconstituted)
411}
412
413// TODO: Uncomment as encode/decode supported
414//func TestMulticastGemInterworkingTp(t *testing.T) {
415//
416// multicastGemInterworkingTp := "0011440A011900060104000001000000" +
417// "00000000000000000000000000000000" +
418// "000000000000000000000028"
419//
420// data, err := stringToPacket(multicastGemInterworkingTp)
421// assert.NoError(t, err)
422//
423// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
424// fmt.Println(packet)
425//
426// customLayer := packet.Layer(LayerTypeOMCI)
427// assert.NotNil(t, customLayer)
428//}
429//
430//func TestCreateGemInteworkingTp(t *testing.T) {
431//
432// createGemInteworkingTp := "0012440A010A80010100058000000000" +
433// "01000000000000000000000000000000" +
434// "000000000000000000000028"
435//
436// data, err := stringToPacket(createGemInteworkingTp)
437// assert.NoError(t, err)
438//
439// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
440// fmt.Println(packet)
441//
442// customLayer := packet.Layer(LayerTypeOMCI)
443// assert.NotNil(t, customLayer)
444//}
445
446func TestSet8021pMapperServiceProfile(t *testing.T) {
447 set8021pMapperServiceProfile := "0016480A008280004000800100000000" +
448 "00000000000000000000000000000000" +
449 "000000000000000000000028"
450
451 data, err := stringToPacket(set8021pMapperServiceProfile)
452 assert.NoError(t, err)
453
454 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
455 assert.NotNil(t, packet)
456
457 omciLayer := packet.Layer(LayerTypeOMCI)
458 assert.NotNil(t, packet)
459
460 omciMsg, ok := omciLayer.(*OMCI)
461 assert.True(t, ok)
462 assert.Equal(t, omciMsg.TransactionID, uint16(0x16))
463 assert.Equal(t, omciMsg.MessageType, SetRequestType)
464 assert.Equal(t, omciMsg.Length, uint16(40))
465
466 msgLayer := packet.Layer(LayerTypeSetRequest)
467 assert.NotNil(t, msgLayer)
468
469 setRequest, ok2 := msgLayer.(*SetRequest)
470 assert.True(t, ok2)
471 assert.Equal(t, setRequest.EntityClass, Ieee8021PMapperServiceProfileClassID)
472 assert.Equal(t, setRequest.EntityInstance, uint16(0x8000))
473
474 attributes := setRequest.Attributes
475 assert.NotNil(t, attributes)
476 assert.Equal(t, len(attributes), 2)
477
478 // Test serialization back to former string
479 var options gopacket.SerializeOptions
480 options.FixLengths = true
481
482 buffer := gopacket.NewSerializeBuffer()
483 err = gopacket.SerializeLayers(buffer, options, omciMsg, setRequest)
484 assert.NoError(t, err)
485
486 outgoingPacket := buffer.Bytes()
487 reconstituted := packetToString(outgoingPacket)
488 assert.Equal(t, strings.ToLower(set8021pMapperServiceProfile), reconstituted)
489}
490
491// TODO: Uncomment as encode/decode supported
492//func TestCreateMacBridgePortConfigurationData(t *testing.T) {
493//
494// createMacBridgePortConfigurationData := "001A440A002F21010201020380000000" +
495// "00000000000000000000000000000000" +
496// "000000000000000000000028"
497//
498// data, err := stringToPacket(createMacBridgePortConfigurationData)
499// assert.NoError(t, err)
500//
501// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
502// fmt.Println(packet)
503//
504// customLayer := packet.Layer(LayerTypeOMCI)
505// assert.NotNil(t, customLayer)
506//}
507//
508//func TestCreateVlanTaggingFilterData(t *testing.T) {
509//
510// createVlanTaggingFilterData := "001F440A005421010400000000000000" +
511// "00000000000000000000000000000000" +
512// "100100000000000000000028"
513//
514// data, err := stringToPacket(createVlanTaggingFilterData)
515// assert.NoError(t, err)
516//
517// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
518// fmt.Println(packet)
519//
520// customLayer := packet.Layer(LayerTypeOMCI)
521// assert.NotNil(t, customLayer)
522//}
523//
524//func TestCreateExtendedVlanTaggingOperationConfigurationData(t *testing.T) {
525//
526// createExtendedVlanTaggingOperationConfigurationData := "0023440A00AB02020A04010000000000" +
527// "00000000000000000000000000000000" +
528// "000000000000000000000028"
529//
530// data, err := stringToPacket(createExtendedVlanTaggingOperationConfigurationData)
531// assert.NoError(t, err)
532//
533// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
534// fmt.Println(packet)
535//}
536//
537//func TestSetExtendedVlanTagging_operationConfigurationData(t *testing.T) {
538//
539// setExtendedVlanTaggingOperationConfigurationData := "0024480A00AB02023800810081000000" +
540// "00000000000000000000000000000000" +
541// "000000000000000000000028"
542//
543// data, err := stringToPacket(setExtendedVlanTaggingOperationConfigurationData)
544// assert.NoError(t, err)
545//
546// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
547// fmt.Println(packet)
548//
549// customLayer := packet.Layer(LayerTypeOMCI)
550// assert.NotNil(t, customLayer)
551//}
552//
553//func TestSetExtendedVlanTagging1(t *testing.T) {
554//
555// setExtendedVlanTagging1 := "0025480A00AB02020400f00000008200" +
556// "5000402f000000082004000000000000" +
557// "000000000000000000000028"
558//
559// data, err := stringToPacket(setExtendedVlanTagging1)
560// assert.NoError(t, err)
561//
562// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
563// fmt.Println(packet)
564//
565// customLayer := packet.Layer(LayerTypeOMCI)
566// assert.NotNil(t, customLayer)
567//}
568//
569//func TestSetExtendedVlanTagging2(t *testing.T) {
570//
571// setExtendedVlanTagging2 := "0026480A00AB02020400F00000008200" +
572// "d000402f00000008200c000000000000" +
573// "000000000000000000000028"
574//
575// data, err := stringToPacket(setExtendedVlanTagging2)
576// assert.NoError(t, err)
577//
578// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
579// fmt.Println(packet)
580//
581// customLayer := packet.Layer(LayerTypeOMCI)
582// assert.NotNil(t, customLayer)
583//}
584//
585//func TestCreateMacBridgePortConfigurationData2(t *testing.T) {
586//
587// createMacBridgePortConfigurationData2 := "0029440A002F02010201010b04010000" +
588// "00000000000000000000000000000000" +
589// "000000000000000000000028"
590//
591// data, err := stringToPacket(createMacBridgePortConfigurationData2)
592// assert.NoError(t, err)
593//
594// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
595// fmt.Println(packet)
596//
597// customLayer := packet.Layer(LayerTypeOMCI)
598// assert.NotNil(t, customLayer)
599//}
600
601func TestMibUpload(t *testing.T) {
602 mibUpload := "00304D0A000200000000000000000000" +
603 "00000000000000000000000000000000" +
604 "000000000000000000000028"
605
606 data, err := stringToPacket(mibUpload)
607 assert.NoError(t, err)
608
609 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
610 assert.NotNil(t, packet)
611
612 omciLayer := packet.Layer(LayerTypeOMCI)
613 assert.NotNil(t, packet)
614
615 omciMsg, ok := omciLayer.(*OMCI)
616 assert.True(t, ok)
617 assert.Equal(t, omciMsg.TransactionID, uint16(0x30))
618 assert.Equal(t, omciMsg.MessageType, MibUploadRequestType)
619 assert.Equal(t, omciMsg.Length, uint16(40))
620
621 msgLayer := packet.Layer(LayerTypeMibUploadRequest)
622 assert.NotNil(t, msgLayer)
623
624 uploadRequest, ok2 := msgLayer.(*MibUploadRequest)
625 assert.True(t, ok2)
626 assert.Equal(t, uploadRequest.EntityClass, OnuDataClassID)
627 assert.Equal(t, uploadRequest.EntityInstance, uint16(0))
628
629 // Test serialization back to former string
630 var options gopacket.SerializeOptions
631 options.FixLengths = true
632
633 buffer := gopacket.NewSerializeBuffer()
634 err = gopacket.SerializeLayers(buffer, options, omciMsg, uploadRequest)
635 assert.NoError(t, err)
636
637 outgoingPacket := buffer.Bytes()
638 reconstituted := packetToString(outgoingPacket)
639 assert.Equal(t, strings.ToLower(mibUpload), reconstituted)
640}
641
642// TODO: Uncomment as encode/decode supported
643//func TestEnhSecurityAvc(t *testing.T) {
644//
645// enhSecurityAvc := "0000110a014c0000008000202020202020202020202020202020202020202020" +
646// "2020202020202020000000280be43cf4"
647//
648// data, err := stringToPacket(enhSecurityAvc)
649// assert.NoError(t, err)
650//
651// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
652// fmt.Println(packet)
653//
654// customLayer := packet.Layer(LayerTypeOMCI)
655// assert.NotNil(t, customLayer)
656//}
657
658//func TestAlarmMessage(t *testing.T) {
659// alarmMessage := "0000100a00050101000000000000000000000000000000000000000000000000" +
660// "0000000220000000000000280be43cf4"
661//
662// data, err := stringToPacket(alarmMessage)
663// assert.NoError(t, err)
664//
665// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
666// assert.NotNil(t, packet)
667//
668// omciLayer := packet.Layer(LayerTypeOMCI)
669// assert.NotNil(t, packet)
670//
671// omciMsg, ok := omciLayer.(*OMCI)
672// assert.True(t, ok)
673// assert.Equal(t, omciMsg.TransactionID, uint16(0))
674// assert.Equal(t, omciMsg.MessageType, byte(AlarmNotification))
675// assert.Equal(t, omciMsg.Length, uint16(40))
676//
677// msgLayer := packet.Layer(LayerTypeAlarmNotification)
678// assert.Nil(t, msgLayer) // TODO: Fix decode
679//
680// //assert.NotNil(t, msgLayer)
681// //
682// //alarmNotification, ok2 := msgLayer.(*AlarmNotificationMsg)
683// //assert.True(t, ok2)
684// //// TODO: Repace with actual entity class
685// //assert.Equal(t, alarmNotification.EntityClass, uint16(0x0005))
686// //assert.Equal(t, alarmNotification.EntityInstance, uint16(0x101))
687// // TODO: Decode alarm bits
688//
689// // TODO: Serialize frame and test with original
690//}
691
692func TestOnuRebootRequest(t *testing.T) {
693 onuRebootRequest := "0016590a01000000000000000000000000000" +
694 "0000000000000000000000000000000000000" +
695 "00000000000028"
696
697 data, err := stringToPacket(onuRebootRequest)
698 assert.NoError(t, err)
699
700 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
701 assert.NotNil(t, packet)
702
703 omciLayer := packet.Layer(LayerTypeOMCI)
704 assert.NotNil(t, packet)
705
706 omciMsg, ok := omciLayer.(*OMCI)
707 assert.True(t, ok)
708 assert.Equal(t, omciMsg.TransactionID, uint16(0x16))
709 assert.Equal(t, omciMsg.MessageType, RebootRequestType)
710 assert.Equal(t, omciMsg.Length, uint16(40))
711
712 msgLayer := packet.Layer(LayerTypeRebootRequest)
713 assert.NotNil(t, msgLayer) // TODO: Fix decode
714
715 //assert.NotNil(t, msgLayer)
716 //
717 //rebootRequest, ok2 := msgLayer.(*RebootRequest)
718 //assert.True(t, ok2)
719 //assert.Equal(t, rebootRequest.EntityClass, OnuDataClassID)
720 //assert.Equal(t, rebootRequest.EntityInstance, uint16(0x8000))
721
722 // TODO: Test Decoded flags
723
724 // TODO: Serialize frame and test with original
725}
726
727func TestMibUploadNextSequence(t *testing.T) {
728 mibUploadNextSequence := [...]string{
729 "00032e0a00020000000200008000000000000000000000000000000000000000000000000000000000000028",
730 "00042e0a0002000000050101f0002f2f05202020202020202020202020202020202020202000000000000028",
731 "00052e0a00020000000501010f80202020202020202020202020202020202020202000000000000000000028",
732 "00062e0a0002000000050104f000303001202020202020202020202020202020202020202000000000000028",
733 "00072e0a00020000000501040f80202020202020202020202020202020202020202000000000000000000028",
734 "00082e0a0002000000050180f000f8f801202020202020202020202020202020202020202000000000000028",
735 "00092e0a00020000000501800f80202020202020202020202020202020202020202000000000000000000028",
736 "000a2e0a0002000000060101f0002f054252434d12345678000000000000000000000000000c000000000028",
737 "000b2e0a00020000000601010f004252434d0000000000000000000000000000000000000000000000000028",
738 "000c2e0a000200000006010100f8202020202020202020202020202020202020202000000000000000000028",
739 "000d2e0a00020000000601010004000000000000000000000000000000000000000000000000000000000028",
740 "000e2e0a0002000000060104f00030014252434d12345678000000000000000000000000000c000000000028",
741 "000f2e0a00020000000601040f004252434d0000000000000000000000000000000000000000000000000028",
742 "00102e0a000200000006010400f8202020202020202020202020202020202020202000000800000000000028",
743 "00112e0a00020000000601040004000000000000000000000000000000000000000000000000000000000028",
744 "00122e0a0002000000060180f000f8014252434d12345678000000000000000000000000000c000000000028",
745 "00132e0a00020000000601800f004252434d0000000000000000000000000000000000000000000000000028",
746 "00142e0a000200000006018000f8202020202020202020202020202020202020202000084040000000000028",
747 "00152e0a00020000000601800004000000000000000000000000000000000000000000000000000000000028",
748 "00162e0a0002000000070000f0003530323247574f3236363230303301010100000000000000000000000028",
749 "00172e0a0002000000070001f0003530323247574f3236363230303300000100000000000000000000000028",
750 "00182e0a0002000000830000c000202020202020202020202020202020202020202020202020000000000028",
751 "00192e0a00020000008300002000202020202020202020202020202000000000000000000000000000000028",
752 "001a2e0a00020000008300001000000000000000000000000000000000000000000000000000000000000028",
753 "001b2e0a0002000000850000ffe0000000000000000000000000000000000000000000000000000000000028",
754 "001c2e0a0002000000860001c00000001018aaaa000000000000000000000000000000000000000000000028",
755 "001d2e0a00020000008600012000000000000000000000000000000000000000000000000000000000000028",
756 "001e2e0a00020000008600011f80000000000000000000000000000000000000000000000000000000000028",
757 "001f2e0a00020000008600010078000000000000000000000000000000000000000000000000000000000028",
758 "00202e0a00020000008600010004000000000000000000000000000000000000000000000000000000000028",
759 "00212e0a00020000008600010002000000000000000000000000000000000000000000000000000000000028",
760 "00222e0a0002000001000000e0004252434d00000000000000000000000000004252434d1234567800000028",
761 "00232e0a00020000010000001f80000000000000000000000000000000000000000000000000000000000028",
762 "00242e0a00020000010000000040000000000000000000000000000000000000000000000000000000000028",
763 "00252e0a00020000010000000038000000000000000000000000000003000000000000000000000000000028",
764 "00262e0a0002000001010000f80042564d344b3030425241303931352d3030383300b3000001010000000028",
765 "00272e0a000200000101000007f8000000010020027c85630016000030000000000000000000000000000028",
766 "00282e0a0002000001068000e00000ff01010000000000000000000000000000000000000000000000000028",
767 "00292e0a0002000001068001e00000ff01010000000000000000000000000000000000000000000000000028",
768 "002a2e0a0002000001068002e00000ff01010000000000000000000000000000000000000000000000000028",
769 "002b2e0a0002000001068003e00000ff01010000000000000000000000000000000000000000000000000028",
770 "002c2e0a0002000001068004e00000ff01010000000000000000000000000000000000000000000000000028",
771 "002d2e0a0002000001068005e00000ff01010000000000000000000000000000000000000000000000000028",
772 "002e2e0a0002000001068006e00000ff01010000000000000000000000000000000000000000000000000028",
773 "002f2e0a0002000001068007e00000ff01010000000000000000000000000000000000000000000000000028",
774 "00302e0a0002000001078001ffff01000800300000050900000000ffff000000008181000000000000000028",
775 "00312e0a0002000001080401f000000000000401000000000000000000000000000000000000000000000028",
776 "00322e0a0002000001150401fff0000080008000000000040100000000010000000000000000000000000028",
777 "00332e0a0002000001150401000f0200020002000200ffff0900000000000000000000000000000000000028",
778 "00342e0a0002000001150402fff0000080008000000000040100010000010000000000000000000000000028",
779 "00352e0a0002000001150402000f0200020002000200ffff0900000000000000000000000000000000000028",
780 "00362e0a0002000001150403fff0000080008000000000040100020000010000000000000000000000000028",
781 "00372e0a0002000001150403000f0200020002000200ffff0900000000000000000000000000000000000028",
782 "00382e0a0002000001150404fff0000080008000000000040100030000010000000000000000000000000028",
783 "00392e0a0002000001150404000f0200020002000200ffff0900000000000000000000000000000000000028",
784 "003a2e0a0002000001150405fff0000080008000000000040100040000010000000000000000000000000028",
785 "003b2e0a0002000001150405000f0200020002000200ffff0900000000000000000000000000000000000028",
786 "003c2e0a0002000001150406fff0000080008000000000040100050000010000000000000000000000000028",
787 "003d2e0a0002000001150406000f0200020002000200ffff0900000000000000000000000000000000000028",
788 "003e2e0a0002000001150407fff0000080008000000000040100060000010000000000000000000000000028",
789 "003f2e0a0002000001150407000f0200020002000200ffff0900000000000000000000000000000000000028",
790 "00402e0a0002000001150408fff0000080008000000000040100070000010000000000000000000000000028",
791 "00412e0a0002000001150408000f0200020002000200ffff0900000000000000000000000000000000000028",
792 "00422e0a0002000001158000fff0000100010000000000800000000000010000000000000000000000000028",
793 "00432e0a0002000001158000000f0200020002000200ffff0900000000000000000000000000000000000028",
794 "00442e0a0002000001158001fff0000100010000000000800000010000010000000000000000000000000028",
795 "00452e0a0002000001158001000f0200020002000200ffff0900000000000000000000000000000000000028",
796 "00462e0a0002000001158002fff0000100010000000000800000020000010000000000000000000000000028",
797 "00472e0a0002000001158002000f0200020002000200ffff0900000000000000000000000000000000000028",
798 "00482e0a0002000001158003fff0000100010000000000800000030000010000000000000000000000000028",
799 "00492e0a0002000001158003000f0200020002000200ffff0900000000000000000000000000000000000028",
800 "004a2e0a0002000001158004fff0000100010000000000800000040000010000000000000000000000000028",
801 "004b2e0a0002000001158004000f0200020002000200ffff0900000000000000000000000000000000000028",
802 "004c2e0a0002000001158005fff0000100010000000000800000050000010000000000000000000000000028",
803 "004d2e0a0002000001158005000f0200020002000200ffff0900000000000000000000000000000000000028",
804 "004e2e0a0002000001158006fff0000100010000000000800000060000010000000000000000000000000028",
805 "004f2e0a0002000001158006000f0200020002000200ffff0900000000000000000000000000000000000028",
806 "00502e0a0002000001158007fff0000100010000000000800000070000010000000000000000000000000028",
807 "00512e0a0002000001158007000f0200020002000200ffff0900000000000000000000000000000000000028",
808 "00522e0a0002000001158008fff0000100010000000000800100000000010000000000000000000000000028",
809 "00532e0a0002000001158008000f0200020002000200ffff0900000000000000000000000000000000000028",
810 "00542e0a0002000001158009fff0000100010000000000800100010000010000000000000000000000000028",
811 "00552e0a0002000001158009000f0200020002000200ffff0900000000000000000000000000000000000028",
812 "00562e0a000200000115800afff0000100010000000000800100020000010000000000000000000000000028",
813 "00572e0a000200000115800a000f0200020002000200ffff0900000000000000000000000000000000000028",
814 "00582e0a000200000115800bfff0000100010000000000800100030000010000000000000000000000000028",
815 "00592e0a000200000115800b000f0200020002000200ffff0900000000000000000000000000000000000028",
816 "005a2e0a000200000115800cfff0000100010000000000800100040000010000000000000000000000000028",
817 "005b2e0a000200000115800c000f0200020002000200ffff0900000000000000000000000000000000000028",
818 "005c2e0a000200000115800dfff0000100010000000000800100050000010000000000000000000000000028",
819 "005d2e0a000200000115800d000f0200020002000200ffff0900000000000000000000000000000000000028",
820 "005e2e0a000200000115800efff0000100010000000000800100060000010000000000000000000000000028",
821 "005f2e0a000200000115800e000f0200020002000200ffff0900000000000000000000000000000000000028",
822 "00602e0a000200000115800ffff0000100010000000000800100070000010000000000000000000000000028",
823 "00612e0a000200000115800f000f0200020002000200ffff0900000000000000000000000000000000000028",
824 "00622e0a0002000001158010fff0000100010000000000800200000000010000000000000000000000000028",
825 "00632e0a0002000001158010000f0200020002000200ffff0900000000000000000000000000000000000028",
826 "00642e0a0002000001158011fff0000100010000000000800200010000010000000000000000000000000028",
827 "00652e0a0002000001158011000f0200020002000200ffff0900000000000000000000000000000000000028",
828 "00662e0a0002000001158012fff0000100010000000000800200020000010000000000000000000000000028",
829 "00672e0a0002000001158012000f0200020002000200ffff0900000000000000000000000000000000000028",
830 "00682e0a0002000001158013fff0000100010000000000800200030000010000000000000000000000000028",
831 "00692e0a0002000001158013000f0200020002000200ffff0900000000000000000000000000000000000028",
832 "006a2e0a0002000001158014fff0000100010000000000800200040000010000000000000000000000000028",
833 "006b2e0a0002000001158014000f0200020002000200ffff0900000000000000000000000000000000000028",
834 "006c2e0a0002000001158015fff0000100010000000000800200050000010000000000000000000000000028",
835 "006d2e0a0002000001158015000f0200020002000200ffff0900000000000000000000000000000000000028",
836 "006e2e0a0002000001158016fff0000100010000000000800200060000010000000000000000000000000028",
837 "006f2e0a0002000001158016000f0200020002000200ffff0900000000000000000000000000000000000028",
838 "00702e0a0002000001158017fff0000100010000000000800200070000010000000000000000000000000028",
839 "00712e0a0002000001158017000f0200020002000200ffff0900000000000000000000000000000000000028",
840 "00722e0a0002000001158018fff0000100010000000000800300000000010000000000000000000000000028",
841 "00732e0a0002000001158018000f0200020002000200ffff0900000000000000000000000000000000000028",
842 "00742e0a0002000001158019fff0000100010000000000800300010000010000000000000000000000000028",
843 "00752e0a0002000001158019000f0200020002000200ffff0900000000000000000000000000000000000028",
844 "00762e0a000200000115801afff0000100010000000000800300020000010000000000000000000000000028",
845 "00772e0a000200000115801a000f0200020002000200ffff0900000000000000000000000000000000000028",
846 "00782e0a000200000115801bfff0000100010000000000800300030000010000000000000000000000000028",
847 "00792e0a000200000115801b000f0200020002000200ffff0900000000000000000000000000000000000028",
848 "007a2e0a000200000115801cfff0000100010000000000800300040000010000000000000000000000000028",
849 "007b2e0a000200000115801c000f0200020002000200ffff0900000000000000000000000000000000000028",
850 "007c2e0a000200000115801dfff0000100010000000000800300050000010000000000000000000000000028",
851 "007d2e0a000200000115801d000f0200020002000200ffff0900000000000000000000000000000000000028",
852 "007e2e0a000200000115801efff0000100010000000000800300060000010000000000000000000000000028",
853 "007f2e0a000200000115801e000f0200020002000200ffff0900000000000000000000000000000000000028",
854 "00802e0a000200000115801ffff0000100010000000000800300070000010000000000000000000000000028",
855 "00812e0a000200000115801f000f0200020002000200ffff0900000000000000000000000000000000000028",
856 "00822e0a0002000001158020fff0000100010000000000800400000000010000000000000000000000000028",
857 "00832e0a0002000001158020000f0200020002000200ffff0900000000000000000000000000000000000028",
858 "00842e0a0002000001158021fff0000100010000000000800400010000010000000000000000000000000028",
859 "00852e0a0002000001158021000f0200020002000200ffff0900000000000000000000000000000000000028",
860 "00862e0a0002000001158022fff0000100010000000000800400020000010000000000000000000000000028",
861 "00872e0a0002000001158022000f0200020002000200ffff0900000000000000000000000000000000000028",
862 "00882e0a0002000001158023fff0000100010000000000800400030000010000000000000000000000000028",
863 "00892e0a0002000001158023000f0200020002000200ffff0900000000000000000000000000000000000028",
864 "008a2e0a0002000001158024fff0000100010000000000800400040000010000000000000000000000000028",
865 "008b2e0a0002000001158024000f0200020002000200ffff0900000000000000000000000000000000000028",
866 "008c2e0a0002000001158025fff0000100010000000000800400050000010000000000000000000000000028",
867 "008d2e0a0002000001158025000f0200020002000200ffff0900000000000000000000000000000000000028",
868 "008e2e0a0002000001158026fff0000100010000000000800400060000010000000000000000000000000028",
869 "008f2e0a0002000001158026000f0200020002000200ffff0900000000000000000000000000000000000028",
870 "00902e0a0002000001158027fff0000100010000000000800400070000010000000000000000000000000028",
871 "00912e0a0002000001158027000f0200020002000200ffff0900000000000000000000000000000000000028",
872 "00922e0a0002000001158028fff0000100010000000000800500000000010000000000000000000000000028",
873 "00932e0a0002000001158028000f0200020002000200ffff0900000000000000000000000000000000000028",
874 "00942e0a0002000001158029fff0000100010000000000800500010000010000000000000000000000000028",
875 "00952e0a0002000001158029000f0200020002000200ffff0900000000000000000000000000000000000028",
876 "00962e0a000200000115802afff0000100010000000000800500020000010000000000000000000000000028",
877 "00972e0a000200000115802a000f0200020002000200ffff0900000000000000000000000000000000000028",
878 "00982e0a000200000115802bfff0000100010000000000800500030000010000000000000000000000000028",
879 "00992e0a000200000115802b000f0200020002000200ffff0900000000000000000000000000000000000028",
880 "009a2e0a000200000115802cfff0000100010000000000800500040000010000000000000000000000000028",
881 "009b2e0a000200000115802c000f0200020002000200ffff0900000000000000000000000000000000000028",
882 "009c2e0a000200000115802dfff0000100010000000000800500050000010000000000000000000000000028",
883 "009d2e0a000200000115802d000f0200020002000200ffff0900000000000000000000000000000000000028",
884 "009e2e0a000200000115802efff0000100010000000000800500060000010000000000000000000000000028",
885 "009f2e0a000200000115802e000f0200020002000200ffff0900000000000000000000000000000000000028",
886 "00a02e0a000200000115802ffff0000100010000000000800500070000010000000000000000000000000028",
887 "00a12e0a000200000115802f000f0200020002000200ffff0900000000000000000000000000000000000028",
888 "00a22e0a0002000001158030fff0000100010000000000800600000000010000000000000000000000000028",
889 "00a32e0a0002000001158030000f0200020002000200ffff0900000000000000000000000000000000000028",
890 "00a42e0a0002000001158031fff0000100010000000000800600010000010000000000000000000000000028",
891 "00a52e0a0002000001158031000f0200020002000200ffff0900000000000000000000000000000000000028",
892 "00a62e0a0002000001158032fff0000100010000000000800600020000010000000000000000000000000028",
893 "00a72e0a0002000001158032000f0200020002000200ffff0900000000000000000000000000000000000028",
894 "00a82e0a0002000001158033fff0000100010000000000800600030000010000000000000000000000000028",
895 "00a92e0a0002000001158033000f0200020002000200ffff0900000000000000000000000000000000000028",
896 "00aa2e0a0002000001158034fff0000100010000000000800600040000010000000000000000000000000028",
897 "00ab2e0a0002000001158034000f0200020002000200ffff0900000000000000000000000000000000000028",
898 "00ac2e0a0002000001158035fff0000100010000000000800600050000010000000000000000000000000028",
899 "00ad2e0a0002000001158035000f0200020002000200ffff0900000000000000000000000000000000000028",
900 "00ae2e0a0002000001158036fff0000100010000000000800600060000010000000000000000000000000028",
901 "00af2e0a0002000001158036000f0200020002000200ffff0900000000000000000000000000000000000028",
902 "00b02e0a0002000001158037fff0000100010000000000800600070000010000000000000000000000000028",
903 "00b12e0a0002000001158037000f0200020002000200ffff0900000000000000000000000000000000000028",
904 "00b22e0a0002000001158038fff0000100010000000000800700000000010000000000000000000000000028",
905 "00b32e0a0002000001158038000f0200020002000200ffff0900000000000000000000000000000000000028",
906 "00b42e0a0002000001158039fff0000100010000000000800700010000010000000000000000000000000028",
907 "00b52e0a0002000001158039000f0200020002000200ffff0900000000000000000000000000000000000028",
908 "00b62e0a000200000115803afff0000100010000000000800700020000010000000000000000000000000028",
909 "00b72e0a000200000115803a000f0200020002000200ffff0900000000000000000000000000000000000028",
910 "00b82e0a000200000115803bfff0000100010000000000800700030000010000000000000000000000000028",
911 "00b92e0a000200000115803b000f0200020002000200ffff0900000000000000000000000000000000000028",
912 "00ba2e0a000200000115803cfff0000100010000000000800700040000010000000000000000000000000028",
913 "00bb2e0a000200000115803c000f0200020002000200ffff0900000000000000000000000000000000000028",
914 "00bc2e0a000200000115803dfff0000100010000000000800700050000010000000000000000000000000028",
915 "00bd2e0a000200000115803d000f0200020002000200ffff0900000000000000000000000000000000000028",
916 "00be2e0a000200000115803efff0000100010000000000800700060000010000000000000000000000000028",
917 "00bf2e0a000200000115803e000f0200020002000200ffff0900000000000000000000000000000000000028",
918 "00c02e0a000200000115803ffff0000100010000000000800700070000010000000000000000000000000028",
919 "00c12e0a000200000115803f000f0200020002000200ffff0900000000000000000000000000000000000028",
920 "00c22e0a0002000001168000f000800000000200000000000000000000000000000000000000000000000028",
921 "00c32e0a0002000001168001f000800000000200000000000000000000000000000000000000000000000028",
922 "00c42e0a0002000001168002f000800000000200000000000000000000000000000000000000000000000028",
923 "00c52e0a0002000001168003f000800000000200000000000000000000000000000000000000000000000028",
924 "00c62e0a0002000001168004f000800000000200000000000000000000000000000000000000000000000028",
925 "00c72e0a0002000001168005f000800000000200000000000000000000000000000000000000000000000028",
926 "00c82e0a0002000001168006f000800000000200000000000000000000000000000000000000000000000028",
927 "00c92e0a0002000001168007f000800000000200000000000000000000000000000000000000000000000028",
928 "00ca2e0a0002000001168008f000800100000200000000000000000000000000000000000000000000000028",
929 "00cb2e0a0002000001168009f000800100000200000000000000000000000000000000000000000000000028",
930 "00cc2e0a000200000116800af000800100000200000000000000000000000000000000000000000000000028",
931 "00cd2e0a000200000116800bf000800100000200000000000000000000000000000000000000000000000028",
932 "00ce2e0a000200000116800cf000800100000200000000000000000000000000000000000000000000000028",
933 "00cf2e0a000200000116800df000800100000200000000000000000000000000000000000000000000000028",
934 "00d02e0a000200000116800ef000800100000200000000000000000000000000000000000000000000000028",
935 "00d12e0a000200000116800ff000800100000200000000000000000000000000000000000000000000000028",
936 "00d22e0a0002000001168010f000800200000200000000000000000000000000000000000000000000000028",
937 "00d32e0a0002000001168011f000800200000200000000000000000000000000000000000000000000000028",
938 "00d42e0a0002000001168012f000800200000200000000000000000000000000000000000000000000000028",
939 "00d52e0a0002000001168013f000800200000200000000000000000000000000000000000000000000000028",
940 "00d62e0a0002000001168014f000800200000200000000000000000000000000000000000000000000000028",
941 "00d72e0a0002000001168015f000800200000200000000000000000000000000000000000000000000000028",
942 "00d82e0a0002000001168016f000800200000200000000000000000000000000000000000000000000000028",
943 "00d92e0a0002000001168017f000800200000200000000000000000000000000000000000000000000000028",
944 "00da2e0a0002000001168018f000800300000200000000000000000000000000000000000000000000000028",
945 "00db2e0a0002000001168019f000800300000200000000000000000000000000000000000000000000000028",
946 "00dc2e0a000200000116801af000800300000200000000000000000000000000000000000000000000000028",
947 "00dd2e0a000200000116801bf000800300000200000000000000000000000000000000000000000000000028",
948 "00de2e0a000200000116801cf000800300000200000000000000000000000000000000000000000000000028",
949 "00df2e0a000200000116801df000800300000200000000000000000000000000000000000000000000000028",
950 "00e02e0a000200000116801ef000800300000200000000000000000000000000000000000000000000000028",
951 "00e12e0a000200000116801ff000800300000200000000000000000000000000000000000000000000000028",
952 "00e22e0a0002000001168020f000800400000200000000000000000000000000000000000000000000000028",
953 "00e32e0a0002000001168021f000800400000200000000000000000000000000000000000000000000000028",
954 "00e42e0a0002000001168022f000800400000200000000000000000000000000000000000000000000000028",
955 "00e52e0a0002000001168023f000800400000200000000000000000000000000000000000000000000000028",
956 "00e62e0a0002000001168024f000800400000200000000000000000000000000000000000000000000000028",
957 "00e72e0a0002000001168025f000800400000200000000000000000000000000000000000000000000000028",
958 "00e82e0a0002000001168026f000800400000200000000000000000000000000000000000000000000000028",
959 "00e92e0a0002000001168027f000800400000200000000000000000000000000000000000000000000000028",
960 "00ea2e0a0002000001168028f000800500000200000000000000000000000000000000000000000000000028",
961 "00eb2e0a0002000001168029f000800500000200000000000000000000000000000000000000000000000028",
962 "00ec2e0a000200000116802af000800500000200000000000000000000000000000000000000000000000028",
963 "00ed2e0a000200000116802bf000800500000200000000000000000000000000000000000000000000000028",
964 "00ee2e0a000200000116802cf000800500000200000000000000000000000000000000000000000000000028",
965 "00ef2e0a000200000116802df000800500000200000000000000000000000000000000000000000000000028",
966 "00f02e0a000200000116802ef000800500000200000000000000000000000000000000000000000000000028",
967 "00f12e0a000200000116802ff000800500000200000000000000000000000000000000000000000000000028",
968 "00f22e0a0002000001168030f000800600000200000000000000000000000000000000000000000000000028",
969 "00f32e0a0002000001168031f000800600000200000000000000000000000000000000000000000000000028",
970 "00f42e0a0002000001168032f000800600000200000000000000000000000000000000000000000000000028",
971 "00f52e0a0002000001168033f000800600000200000000000000000000000000000000000000000000000028",
972 "00f62e0a0002000001168034f000800600000200000000000000000000000000000000000000000000000028",
973 "00f72e0a0002000001168035f000800600000200000000000000000000000000000000000000000000000028",
974 "00f82e0a0002000001168036f000800600000200000000000000000000000000000000000000000000000028",
975 "00f92e0a0002000001168037f000800600000200000000000000000000000000000000000000000000000028",
976 "00fa2e0a0002000001168038f000800700000200000000000000000000000000000000000000000000000028",
977 "00fb2e0a0002000001168039f000800700000200000000000000000000000000000000000000000000000028",
978 "00fc2e0a000200000116803af000800700000200000000000000000000000000000000000000000000000028",
979 "00fd2e0a000200000116803bf000800700000200000000000000000000000000000000000000000000000028",
980 "00fe2e0a000200000116803cf000800700000200000000000000000000000000000000000000000000000028",
981 "00ff2e0a000200000116803df000800700000200000000000000000000000000000000000000000000000028",
982 "01002e0a000200000116803ef000800700000200000000000000000000000000000000000000000000000028",
983 "01012e0a000200000116803ff000800700000200000000000000000000000000000000000000000000000028",
984 "01022e0a0002000001490401c000000000000000000000000000000000000000000000000000000000000028",
985 "01032e0a00020000014904012000000000000000000000000000000000000000000000000000000000000028",
986 "01042e0a00020000014904011800ffffffff0000000000000000000000000000000000000000000000000028",
987 }
988 firstTid := uint16(3)
989
990 for _, packetString := range mibUploadNextSequence {
991 data, err := stringToPacket(packetString)
992 assert.NoError(t, err)
993
994 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
995 assert.NotNil(t, packet)
996
997 omciLayer := packet.Layer(LayerTypeOMCI)
998 assert.NotNil(t, omciLayer)
999
1000 omciMsg, ok := omciLayer.(*OMCI)
1001 assert.True(t, ok)
1002 assert.Equal(t, omciMsg.TransactionID, firstTid)
1003 assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
1004 assert.Equal(t, omciMsg.Length, uint16(40))
1005
1006 msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
1007 assert.NotNil(t, msgLayer)
1008
1009 uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
1010 assert.True(t, ok2)
1011 assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
1012 assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
1013
1014 // Test serialization back to former string
1015 var options gopacket.SerializeOptions
1016 options.FixLengths = true
1017
1018 buffer := gopacket.NewSerializeBuffer()
1019 err = gopacket.SerializeLayers(buffer, options, omciMsg, uploadResponse)
1020 assert.NoError(t, err)
1021
1022 outgoingPacket := buffer.Bytes()
1023 reconstituted := packetToString(outgoingPacket)
1024 assert.Equal(t, strings.ToLower(packetString), reconstituted)
1025
1026 // Advance TID
1027 firstTid += 1
1028 }
1029}
1030
1031//func TestMibUploadNextWithMIC(t *testing.T) {
1032// // Similar to previous, but with the MIC available for testing
1033// mibUploadNextSequence := [...]string{
1034// "00032e0a0002000000020000800000000000000000000000000000000000000000000000000000000000002828ce00e2",
1035// "00042e0a0002000000050101f0002f2f05202020202020202020202020202020202020202000000000000028d4eb4bdf",
1036// "00052e0a00020000000501010f802020202020202020202020202020202020202020000000000000000000282dbe4b44",
1037// "00062e0a0002000000050104f000303001202020202020202020202020202020202020202000000000000028ef1b035b",
1038// }
1039// firstTid := uint16(3)
1040//
1041// for pktNumber, packetString := range mibUploadNextSequence {
1042// data, err := stringToPacket(packetString)
1043// assert.NoError(t, err)
1044//
1045// packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1046// fmt.Printf("Packet: %v: %v", pktNumber, packet)
1047// assert.NotNil(t, packet)
1048//
1049// omciLayer := packet.Layer(LayerTypeOMCI)
1050// assert.NotNil(t, omciLayer)
1051//
1052// omciMsg, ok := omciLayer.(*OMCI)
1053// assert.True(t, ok)
1054// assert.Equal(t, omciMsg.TransactionID, firstTid)
1055// assert.Equal(t, omciMsg.MessageType, byte(MibUploadNext))
1056// assert.Equal(t, omciMsg.Length, uint16(40))
1057//
1058// msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
1059// assert.NotNil(t, msgLayer)
1060//
1061// uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
1062// assert.True(t, ok2)
1063// assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
1064// assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
1065//
1066// // Test serialization back to former string
1067// var options gopacket.SerializeOptions
1068// options.FixLengths = true
1069//
1070// buffer := gopacket.NewSerializeBuffer()
1071// err = gopacket.SerializeLayers(buffer, options, omciMsg, uploadResponse)
1072// assert.NoError(t, err)
1073//
1074// outgoingPacket := buffer.Bytes()
1075// reconstituted := packetToString(outgoingPacket)
1076// assert.Equal(t, strings.ToLower(packetString), reconstituted)
1077//
1078// // Advance TID
1079// firstTid += 1
1080// }
1081//}
Chip Boling8a5379a2020-11-17 12:59:40 -06001082
1083// TestUnsupportedG988ClassIDMibUploadNextResponse tests decoding of an Unknown class ID that is
1084// in the range of IDs assigned for G.988 use
1085func TestUnsupportedG988ClassIDMibUploadNextResponse(t *testing.T) {
1086 // The unsupported G.988 class ID below is 37 (0x0025), which is marked in the G.988
1087 // (11/2017) as 'Intentionally left blank). The encoded frame is a Get-Next
1088 // response with a single attribute 1 & 16 (0x8001) encoded.
1089 //
1090 tid := 3
1091 cid := 0x25
1092 eid := 1
1093 mask := 0x8000
Chip Bolingd8543b22021-03-08 08:34:26 -06001094 omci_hdr := "00032e0a"
David K. Bainbridgeadf422d2021-04-09 16:06:41 +00001095 msg_hdr := "00020000002500018000"
1096 attr := "0102030405060708090A0B0C0D0E0F101112131415161718191A"
1097 trailer := "0000002828ce00e2"
Chip Bolingd8543b22021-03-08 08:34:26 -06001098 msg := omci_hdr + msg_hdr + attr + trailer
Chip Boling8a5379a2020-11-17 12:59:40 -06001099 data, err := stringToPacket(msg)
1100 assert.NoError(t, err)
1101
Chip Bolingd8543b22021-03-08 08:34:26 -06001102 // Decode packet (lazy this time)
1103 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.Lazy)
Chip Boling8a5379a2020-11-17 12:59:40 -06001104 assert.NotNil(t, packet)
1105
Chip Bolingd8543b22021-03-08 08:34:26 -06001106 // OMCI Layer Contents are the
1107 // - TCI (2 bytes)
1108 // - Msg Type (1 byte)
1109 // - Device Ident (1 byte)
1110 //
1111 // payload is remaining layers (less optional length and MIC)
1112
Chip Boling8a5379a2020-11-17 12:59:40 -06001113 omciLayer := packet.Layer(LayerTypeOMCI)
1114 assert.NotNil(t, packet)
1115
Chip Bolingd8543b22021-03-08 08:34:26 -06001116 contents := omciLayer.LayerContents()
1117 payload := omciLayer.LayerPayload()
1118 assert.NotNil(t, contents)
1119 assert.NotNil(t, payload)
David K. Bainbridgeadf422d2021-04-09 16:06:41 +00001120 assert.Equal(t, len(omci_hdr)/2, len(contents))
1121 assert.Equal(t, (len(msg_hdr)+len(attr))/2, len(payload))
Chip Bolingd8543b22021-03-08 08:34:26 -06001122
Chip Boling8a5379a2020-11-17 12:59:40 -06001123 omciMsg, ok := omciLayer.(*OMCI)
1124 assert.True(t, ok)
1125 assert.Equal(t, omciMsg.TransactionID, uint16(tid))
1126 assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
1127 assert.Equal(t, omciMsg.Length, uint16(40))
1128
Chip Bolingd8543b22021-03-08 08:34:26 -06001129 // Message Layer contents for a MIB upload next response are the
1130 // - ONU Data Class/Instance (4 bytes)
1131 // - Reported Managed Entity Class/Instance (4 bytes)
1132 // - Attribute Mask (2 bytes)
1133 //
1134 // Message Layer payload for a MIB upload next response are the attributes
1135 // and zero-padding (but not length & MIC)
1136
Chip Boling8a5379a2020-11-17 12:59:40 -06001137 msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
1138 assert.NotNil(t, msgLayer)
1139
Chip Bolingd8543b22021-03-08 08:34:26 -06001140 contents = msgLayer.LayerContents()
1141 payload = msgLayer.LayerPayload()
1142 assert.NotNil(t, contents)
1143 assert.NotNil(t, payload)
David K. Bainbridgeadf422d2021-04-09 16:06:41 +00001144 assert.Equal(t, len(msg_hdr)/2, len(contents))
1145 assert.Equal(t, len(attr)/2, len(payload))
Chip Bolingd8543b22021-03-08 08:34:26 -06001146
Chip Boling8a5379a2020-11-17 12:59:40 -06001147 uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
1148 assert.True(t, ok2)
1149 assert.NotNil(t, uploadResponse)
1150 assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
1151 assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
1152 assert.Equal(t, uploadResponse.ReportedME.GetClassID(), ClassID(cid))
1153 assert.Equal(t, uploadResponse.ReportedME.GetEntityID(), uint16(eid))
1154 assert.Equal(t, uploadResponse.ReportedME.GetAttributeMask(), uint16(mask))
1155
1156 name := "UnknownAttr_1"
1157 blobAttribute, err := uploadResponse.ReportedME.GetAttribute(name)
1158
1159 assert.Nil(t, err)
1160 assert.NotNil(t, blobAttribute)
1161
1162 byteValue, ok3 := blobAttribute.([]uint8)
1163 assert.True(t, ok3)
1164 assert.NotNil(t, byteValue)
1165}
1166
Chip Boling8a5379a2020-11-17 12:59:40 -06001167func TestUnsupportedG988ClassIDMibUploadNextResponseAttributes(t *testing.T) {
1168 // Same as previous, but try different attribute mask combinations
1169 tid := 3
1170 cid := 0x25
1171 eid := 1
1172
1173 // There are a number of ranges for vendor ID use. List below picks one from
1174 // each of those ranges
1175 masks := []uint16{0x8001, 0x0000, 0x0001, 0x8000}
1176
1177 trailer := "0000002828ce00e2"
1178 attr := "0102030405060708090A0B0C0D0E0F101112131415161718191A"
1179
1180 for _, mask := range masks {
1181 hdr := fmt.Sprintf("00032e0a0002000000250001%04x", mask)
1182
1183 msg := hdr + attr + trailer
1184 data, err := stringToPacket(msg)
1185 assert.NoError(t, err)
1186
1187 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1188 assert.NotNil(t, packet)
1189
1190 omciLayer := packet.Layer(LayerTypeOMCI)
1191 assert.NotNil(t, packet)
1192
1193 omciMsg, ok := omciLayer.(*OMCI)
1194 assert.True(t, ok)
1195 assert.Equal(t, omciMsg.TransactionID, uint16(tid))
1196 assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
1197 assert.Equal(t, omciMsg.Length, uint16(40))
1198
1199 msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
1200 assert.NotNil(t, msgLayer)
1201
1202 uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
1203 assert.True(t, ok2)
1204 assert.NotNil(t, uploadResponse)
1205 assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
1206 assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
1207 assert.Equal(t, uploadResponse.ReportedME.GetClassID(), ClassID(cid))
1208 assert.Equal(t, uploadResponse.ReportedME.GetEntityID(), uint16(eid))
1209 assert.Equal(t, uploadResponse.ReportedME.GetAttributeMask(), uint16(mask))
1210
1211 //name := "UnknownAttr_1"
1212 //blobAttribute, err := uploadResponse.ReportedME.GetAttribute(name)
1213 //
1214 //assert.Nil(t, err)
1215 //assert.NotNil(t, blobAttribute)
1216 //
1217 //byteValue, ok3 := blobAttribute.([]uint8)
1218 //assert.True(t, ok3)
1219 //assert.NotNil(t, byteValue)
1220 }
1221}
1222
1223// TestUnsupportedVendorClassIDMibUploadNextResponse tests decoding of an Unknown class ID that is
1224// in the range of IDs assigned for vendor assignment
1225func TestUnsupportedVendorClassIDMibUploadNextResponse(t *testing.T) {
1226 tid := 3
1227 eid := 0
1228 mask := 0x8000
1229
1230 // There are a number of ranges for vendor ID use. List below picks one from
1231 // each of those ranges
1232 classIDs := []uint16{250, 355, 65500}
1233
1234 hdr := "00032e0a00020000"
1235 attr := "0102030405060708090A0B0C0D0E0F101112131415161718191A"
1236 trailer := "0000002828ce00e2"
1237
1238 for _, cid := range classIDs {
1239 cidToMask := fmt.Sprintf("%04x%04x%04x", cid, eid, mask)
1240 msg := hdr + cidToMask + attr + trailer
1241 data, err := stringToPacket(msg)
1242 assert.NoError(t, err)
1243
1244 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1245 assert.NotNil(t, packet)
1246
1247 omciLayer := packet.Layer(LayerTypeOMCI)
1248 assert.NotNil(t, packet)
1249
1250 omciMsg, ok := omciLayer.(*OMCI)
1251 assert.True(t, ok)
1252 assert.Equal(t, omciMsg.TransactionID, uint16(tid))
1253 assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
1254 assert.Equal(t, omciMsg.Length, uint16(40))
1255
1256 msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
1257 assert.NotNil(t, msgLayer)
1258
1259 uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
1260 assert.True(t, ok2)
1261 assert.NotNil(t, uploadResponse)
1262 assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
1263 assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
1264 assert.Equal(t, uploadResponse.ReportedME.GetClassID(), ClassID(cid))
1265 assert.Equal(t, uploadResponse.ReportedME.GetEntityID(), uint16(eid))
1266 assert.Equal(t, uploadResponse.ReportedME.GetAttributeMask(), uint16(mask))
1267
1268 name := "UnknownAttr_1"
1269 blobAttribute, err := uploadResponse.ReportedME.GetAttribute(name)
1270
1271 assert.Nil(t, err)
1272 assert.NotNil(t, blobAttribute)
1273
1274 byteValue, ok3 := blobAttribute.([]uint8)
1275 assert.True(t, ok3)
1276 assert.NotNil(t, byteValue)
1277 }
Chip Bolingff6bf172020-12-01 10:38:12 -06001278}
1279
1280func TestCreateMulticastOperationsProfileMe(t *testing.T) {
1281 // Test various create request for this ME
1282 meParams := ParamData{
1283 EntityID: uint16(0x501),
1284 Attributes: AttributeValueMap{
1285 "IgmpVersion": 2,
1286 "IgmpFunction": 0,
1287 "ImmediateLeave": 0,
1288 "USIgmpTci": 0,
1289 "Robustness": 2,
1290 "QuerierIp": 0,
1291 "QueryInterval": 125,
1292 "QuerierMaxResponseTime": 100,
1293 "LastMemberResponseTime": 10,
1294 "UnauthorizedJoinBehaviour": 0,
1295 "USIgmpRate": 0,
1296 "USIgmpTagCtrl": 0,
1297 "DSIgmpMcastTci": []byte{0, 0, 0},
1298 },
1299 }
1300 meInstance, newErr := NewMulticastOperationsProfile(meParams)
1301 assert.NotNil(t, meInstance)
1302 assert.Equal(t, newErr.StatusCode(), Success)
1303
1304 tid := uint16(123)
1305 frame, omciErr := GenFrame(meInstance, CreateRequestType, TransactionID(tid))
1306 assert.NotNil(t, frame)
1307 assert.NotZero(t, len(frame))
1308 assert.Nil(t, omciErr)
1309
1310 ///////////////////////////////////////////////////////////////////
1311 // Now decode
1312 packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy)
1313 assert.NotNil(t, packet)
1314
1315 omciLayer := packet.Layer(LayerTypeOMCI)
1316 assert.NotNil(t, omciLayer)
1317
1318 omciObj, omciOk := omciLayer.(*OMCI)
1319 assert.NotNil(t, omciObj)
1320 assert.True(t, omciOk)
1321 assert.Equal(t, tid, omciObj.TransactionID)
1322 assert.Equal(t, CreateRequestType, omciObj.MessageType)
1323 assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier)
1324
1325 msgLayer := packet.Layer(LayerTypeCreateRequest)
1326 assert.NotNil(t, msgLayer)
1327
1328 msgObj, msgOk := msgLayer.(*CreateRequest)
1329 assert.NotNil(t, msgObj)
1330 assert.True(t, msgOk)
1331
1332 assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass)
1333 assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance)
1334 //assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes)
1335}