blob: eefb7a6ac9dc83e8da065f4e5c4ad43e655cdb68 [file] [log] [blame]
Chip Boling610117d2021-09-09 11:24:34 -05001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
3 * Copyright 2020-present Open Networking Foundation
4
5 * 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
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * 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.
16 */
17
18package omci_test
19
20import (
21 "github.com/google/gopacket"
Andrea Campanellae0cd8232021-10-15 15:10:23 +020022 . "github.com/opencord/omci-lib-go/v2"
23 me "github.com/opencord/omci-lib-go/v2/generated"
Chip Boling610117d2021-09-09 11:24:34 -050024 "github.com/stretchr/testify/assert"
25 "strings"
26 "testing"
27)
28
29func TestGetAllAlarmsRequestDecode(t *testing.T) {
30 goodMessage := "04454b0a00020000000000000000000000000000000000000000000000000000000000000000000000000028"
31 data, err := stringToPacket(goodMessage)
32 assert.NoError(t, err)
33
34 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
35 assert.NotNil(t, packet)
36
37 omciLayer := packet.Layer(LayerTypeOMCI)
38 assert.NotNil(t, omciLayer)
39
40 omciMsg, ok := omciLayer.(*OMCI)
41 assert.True(t, ok)
42 assert.NotNil(t, omciMsg)
43 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
44 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
45 assert.Equal(t, LayerTypeGetAllAlarmsRequest, omciMsg.NextLayerType())
46 assert.Equal(t, uint16(0x0445), omciMsg.TransactionID)
47 assert.Equal(t, GetAllAlarmsRequestType, omciMsg.MessageType)
48 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
49 assert.Equal(t, uint16(40), omciMsg.Length)
50
51 msgLayer := packet.Layer(LayerTypeGetAllAlarmsRequest)
52 assert.NotNil(t, msgLayer)
53
54 request, ok2 := msgLayer.(*GetAllAlarmsRequest)
55 assert.True(t, ok2)
56 assert.NotNil(t, request)
57 assert.Equal(t, LayerTypeGetAllAlarmsRequest, request.LayerType())
58 assert.Equal(t, LayerTypeGetAllAlarmsRequest, request.CanDecode())
59 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
60 assert.Equal(t, byte(0), request.AlarmRetrievalMode)
61
62 // Verify string output for message
63 packetString := packet.String()
64 assert.NotZero(t, len(packetString))
65}
66
67func TestGetAllAlarmsRequestDecodeExtended(t *testing.T) {
68 goodMessage := "04454b0b00020000000101"
69 data, err := stringToPacket(goodMessage)
70 assert.NoError(t, err)
71
72 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
73 assert.NotNil(t, packet)
74
75 omciLayer := packet.Layer(LayerTypeOMCI)
76 assert.NotNil(t, omciLayer)
77
78 omciMsg, ok := omciLayer.(*OMCI)
79 assert.True(t, ok)
80 assert.NotNil(t, omciMsg)
81 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
82 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
83 assert.Equal(t, LayerTypeGetAllAlarmsRequest, omciMsg.NextLayerType())
84 assert.Equal(t, uint16(0x0445), omciMsg.TransactionID)
85 assert.Equal(t, GetAllAlarmsRequestType, omciMsg.MessageType)
86 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
87 assert.Equal(t, uint16(1), omciMsg.Length)
88
89 msgLayer := packet.Layer(LayerTypeGetAllAlarmsRequest)
90 assert.NotNil(t, msgLayer)
91
92 request, ok2 := msgLayer.(*GetAllAlarmsRequest)
93 assert.True(t, ok2)
94 assert.NotNil(t, request)
95 assert.Equal(t, LayerTypeGetAllAlarmsRequest, request.LayerType())
96 assert.Equal(t, LayerTypeGetAllAlarmsRequest, request.CanDecode())
97 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
98 assert.Equal(t, byte(1), request.AlarmRetrievalMode)
99
100 // Verify string output for message
101 packetString := packet.String()
102 assert.NotZero(t, len(packetString))
103}
104
105func TestGetAllAlarmsRequestSerialize(t *testing.T) {
106 goodMessage := "04454b0a00020000010000000000000000000000000000000000000000000000000000000000000000000028"
107
108 omciLayer := &OMCI{
109 TransactionID: 0x0445,
110 MessageType: GetAllAlarmsRequestType,
111 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
112 // Length: 0x28, // Optional, defaults to 40 octets
113 }
114 request := &GetAllAlarmsRequest{
115 MeBasePacket: MeBasePacket{
116 EntityClass: me.OnuDataClassID,
117 EntityInstance: uint16(0),
118 },
119 AlarmRetrievalMode: byte(1),
120 }
121 // Test serialization back to former string
122 var options gopacket.SerializeOptions
123 options.FixLengths = true
124
125 buffer := gopacket.NewSerializeBuffer()
126 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
127 assert.NoError(t, err)
128
129 outgoingPacket := buffer.Bytes()
130 reconstituted := packetToString(outgoingPacket)
131 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
132}
133
134func TestGetAllAlarmsRequestSerializeExtended(t *testing.T) {
135 goodMessage := "04454b0b00020000000101"
136
137 omciLayer := &OMCI{
138 TransactionID: 0x0445,
139 MessageType: GetAllAlarmsRequestType,
140 DeviceIdentifier: ExtendedIdent,
141 }
142 request := &GetAllAlarmsRequest{
143 MeBasePacket: MeBasePacket{
144 EntityClass: me.OnuDataClassID,
145 EntityInstance: uint16(0),
146 Extended: true,
147 },
148 AlarmRetrievalMode: byte(1),
149 }
150 // Test serialization back to former string
151 var options gopacket.SerializeOptions
152 options.FixLengths = true
153
154 buffer := gopacket.NewSerializeBuffer()
155 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
156 assert.NoError(t, err)
157
158 outgoingPacket := buffer.Bytes()
159 reconstituted := packetToString(outgoingPacket)
160 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
161}
162
163func TestGetAllAlarmsResponseDecode(t *testing.T) {
164 goodMessage := "04452b0a00020000000300000000000000000000000000000000000000000000000000000000000000000028"
165 data, err := stringToPacket(goodMessage)
166 assert.NoError(t, err)
167
168 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
169 assert.NotNil(t, packet)
170
171 omciLayer := packet.Layer(LayerTypeOMCI)
172 assert.NotNil(t, omciLayer)
173
174 omciMsg, ok := omciLayer.(*OMCI)
175 assert.True(t, ok)
176 assert.NotNil(t, omciMsg)
177 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
178 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
179 assert.Equal(t, LayerTypeGetAllAlarmsResponse, omciMsg.NextLayerType())
180 assert.Equal(t, uint16(0x0445), omciMsg.TransactionID)
181 assert.Equal(t, GetAllAlarmsResponseType, omciMsg.MessageType)
182 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
183 assert.Equal(t, uint16(40), omciMsg.Length)
184
185 msgLayer := packet.Layer(LayerTypeGetAllAlarmsResponse)
186 assert.NotNil(t, msgLayer)
187
188 response, ok2 := msgLayer.(*GetAllAlarmsResponse)
189 assert.True(t, ok2)
190 assert.NotNil(t, response)
191 assert.Equal(t, LayerTypeGetAllAlarmsResponse, response.LayerType())
192 assert.Equal(t, LayerTypeGetAllAlarmsResponse, response.CanDecode())
193 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
194 assert.Equal(t, uint16(3), response.NumberOfCommands)
195
196 // Verify string output for message
197 packetString := packet.String()
198 assert.NotZero(t, len(packetString))
199}
200
201func TestGetAllAlarmsResponseDecodeExtended(t *testing.T) {
202 goodMessage := "04452b0b0002000000020003"
203 data, err := stringToPacket(goodMessage)
204 assert.NoError(t, err)
205
206 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
207 assert.NotNil(t, packet)
208
209 omciLayer := packet.Layer(LayerTypeOMCI)
210 assert.NotNil(t, omciLayer)
211
212 omciMsg, ok := omciLayer.(*OMCI)
213 assert.True(t, ok)
214 assert.NotNil(t, omciMsg)
215 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
216 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
217 assert.Equal(t, LayerTypeGetAllAlarmsResponse, omciMsg.NextLayerType())
218 assert.Equal(t, uint16(0x0445), omciMsg.TransactionID)
219 assert.Equal(t, GetAllAlarmsResponseType, omciMsg.MessageType)
220 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
221 assert.Equal(t, uint16(2), omciMsg.Length)
222
223 msgLayer := packet.Layer(LayerTypeGetAllAlarmsResponse)
224 assert.NotNil(t, msgLayer)
225
226 response, ok2 := msgLayer.(*GetAllAlarmsResponse)
227 assert.True(t, ok2)
228 assert.NotNil(t, response)
229 assert.Equal(t, LayerTypeGetAllAlarmsResponse, response.LayerType())
230 assert.Equal(t, LayerTypeGetAllAlarmsResponse, response.CanDecode())
231 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
232 assert.Equal(t, uint16(3), response.NumberOfCommands)
233
234 // Verify string output for message
235 packetString := packet.String()
236 assert.NotZero(t, len(packetString))
237}
238
239func TestGetAllAlarmsResponseSerialize(t *testing.T) {
240 goodMessage := "04452b0a00020000000300000000000000000000000000000000000000000000000000000000000000000028"
241
242 omciLayer := &OMCI{
243 TransactionID: 0x0445,
244 MessageType: GetAllAlarmsResponseType,
245 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
246 // Length: 0x28, // Optional, defaults to 40 octets
247 }
248 request := &GetAllAlarmsResponse{
249 MeBasePacket: MeBasePacket{
250 EntityClass: me.OnuDataClassID,
251 EntityInstance: uint16(0),
252 },
253 NumberOfCommands: uint16(3),
254 }
255 // Test serialization back to former string
256 var options gopacket.SerializeOptions
257 options.FixLengths = true
258
259 buffer := gopacket.NewSerializeBuffer()
260 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
261 assert.NoError(t, err)
262
263 outgoingPacket := buffer.Bytes()
264 reconstituted := packetToString(outgoingPacket)
265 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
266}
267
268func TestGetAllAlarmsResponseSerializeExtended(t *testing.T) {
269 goodMessage := "04452b0b0002000000020003"
270
271 omciLayer := &OMCI{
272 TransactionID: 0x0445,
273 MessageType: GetAllAlarmsResponseType,
274 DeviceIdentifier: ExtendedIdent,
275 }
276 request := &GetAllAlarmsResponse{
277 MeBasePacket: MeBasePacket{
278 EntityClass: me.OnuDataClassID,
279 EntityInstance: uint16(0),
280 Extended: true,
281 },
282 NumberOfCommands: uint16(3),
283 }
284 // Test serialization back to former string
285 var options gopacket.SerializeOptions
286 options.FixLengths = true
287
288 buffer := gopacket.NewSerializeBuffer()
289 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
290 assert.NoError(t, err)
291
292 outgoingPacket := buffer.Bytes()
293 reconstituted := packetToString(outgoingPacket)
294 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
295}
296
297func TestGetAllAlarmsNextRequestDecode(t *testing.T) {
298 goodMessage := "02344c0a00020000000300000000000000000000000000000000000000000000000000000000000000000028"
299
300 data, err := stringToPacket(goodMessage)
301 assert.NoError(t, err)
302
303 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
304 assert.NotNil(t, packet)
305
306 omciLayer := packet.Layer(LayerTypeOMCI)
307 assert.NotNil(t, omciLayer)
308
309 omciMsg, ok := omciLayer.(*OMCI)
310 assert.True(t, ok)
311 assert.NotNil(t, omciMsg)
312 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
313 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
314 assert.Equal(t, LayerTypeGetAllAlarmsNextRequest, omciMsg.NextLayerType())
315 assert.Equal(t, uint16(0x0234), omciMsg.TransactionID)
316 assert.Equal(t, GetAllAlarmsNextRequestType, omciMsg.MessageType)
317 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
318 assert.Equal(t, uint16(40), omciMsg.Length)
319
320 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextRequest)
321 assert.NotNil(t, msgLayer)
322
323 request, ok2 := msgLayer.(*GetAllAlarmsNextRequest)
324 assert.True(t, ok2)
325 assert.NotNil(t, request)
326 assert.Equal(t, LayerTypeGetAllAlarmsNextRequest, request.LayerType())
327 assert.Equal(t, LayerTypeGetAllAlarmsNextRequest, request.CanDecode())
328 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
329 assert.Equal(t, uint16(3), request.CommandSequenceNumber)
330
331 // Verify string output for message
332 packetString := packet.String()
333 assert.NotZero(t, len(packetString))
334}
335
336func TestGetAllAlarmsNextRequestDecodeExtended(t *testing.T) {
337 goodMessage := "02344c0b0002000000020003"
338
339 data, err := stringToPacket(goodMessage)
340 assert.NoError(t, err)
341
342 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
343 assert.NotNil(t, packet)
344
345 omciLayer := packet.Layer(LayerTypeOMCI)
346 assert.NotNil(t, omciLayer)
347
348 omciMsg, ok := omciLayer.(*OMCI)
349 assert.True(t, ok)
350 assert.NotNil(t, omciMsg)
351 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
352 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
353 assert.Equal(t, LayerTypeGetAllAlarmsNextRequest, omciMsg.NextLayerType())
354 assert.Equal(t, uint16(0x0234), omciMsg.TransactionID)
355 assert.Equal(t, GetAllAlarmsNextRequestType, omciMsg.MessageType)
356 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
357 assert.Equal(t, uint16(2), omciMsg.Length)
358
359 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextRequest)
360 assert.NotNil(t, msgLayer)
361
362 request, ok2 := msgLayer.(*GetAllAlarmsNextRequest)
363 assert.True(t, ok2)
364 assert.NotNil(t, request)
365 assert.Equal(t, LayerTypeGetAllAlarmsNextRequest, request.LayerType())
366 assert.Equal(t, LayerTypeGetAllAlarmsNextRequest, request.CanDecode())
367 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
368 assert.Equal(t, uint16(3), request.CommandSequenceNumber)
369
370 // Verify string output for message
371 packetString := packet.String()
372 assert.NotZero(t, len(packetString))
373}
374
375func TestGetAllAlarmsNextRequestSerialize(t *testing.T) {
376 goodMessage := "02344c0a00020000000300000000000000000000000000000000000000000000000000000000000000000028"
377
378 omciLayer := &OMCI{
379 TransactionID: 0x0234,
380 MessageType: GetAllAlarmsNextRequestType,
381 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
382 // Length: 0x28, // Optional, defaults to 40 octets
383 }
384 request := &GetAllAlarmsNextRequest{
385 MeBasePacket: MeBasePacket{
386 EntityClass: me.OnuDataClassID,
387 EntityInstance: uint16(0),
388 },
389 CommandSequenceNumber: uint16(3),
390 }
391 // Test serialization back to former string
392 var options gopacket.SerializeOptions
393 options.FixLengths = true
394
395 buffer := gopacket.NewSerializeBuffer()
396 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
397 assert.NoError(t, err)
398
399 outgoingPacket := buffer.Bytes()
400 reconstituted := packetToString(outgoingPacket)
401 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
402}
403
404func TestGetAllAlarmsNextRequestSerializeExtended(t *testing.T) {
405 goodMessage := "02344c0b0002000000020004"
406
407 omciLayer := &OMCI{
408 TransactionID: 0x0234,
409 MessageType: GetAllAlarmsNextRequestType,
410 DeviceIdentifier: ExtendedIdent,
411 }
412 request := &GetAllAlarmsNextRequest{
413 MeBasePacket: MeBasePacket{
414 EntityClass: me.OnuDataClassID,
415 EntityInstance: uint16(0),
416 Extended: true,
417 },
418 CommandSequenceNumber: uint16(4),
419 }
420 // Test serialization back to former string
421 var options gopacket.SerializeOptions
422 options.FixLengths = true
423
424 buffer := gopacket.NewSerializeBuffer()
425 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
426 assert.NoError(t, err)
427
428 outgoingPacket := buffer.Bytes()
429 reconstituted := packetToString(outgoingPacket)
430 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
431}
432
433func TestGetAllAlarmsNextResponseDecode(t *testing.T) {
434 goodMessage := "02342c0a00020000000b01028000000000000000000000000000000000000000000000000000000000000028f040fc87"
435 data, err := stringToPacket(goodMessage)
436 assert.NoError(t, err)
437
438 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
439 assert.NotNil(t, packet)
440
441 omciLayer := packet.Layer(LayerTypeOMCI)
442 assert.NotNil(t, omciLayer)
443
444 omciMsg, ok := omciLayer.(*OMCI)
445 assert.True(t, ok)
446 assert.NotNil(t, omciMsg)
447 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
448 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
449 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, omciMsg.NextLayerType())
450 assert.Equal(t, uint16(0x0234), omciMsg.TransactionID)
451 assert.Equal(t, GetAllAlarmsNextResponseType, omciMsg.MessageType)
452 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
453 assert.Equal(t, uint16(40), omciMsg.Length)
454
455 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse)
456 assert.NotNil(t, msgLayer)
457
458 response, ok2 := msgLayer.(*GetAllAlarmsNextResponse)
459 assert.True(t, ok2)
460 assert.NotNil(t, response)
461 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, response.LayerType())
462 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, response.CanDecode())
463 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
464
465 var alarms [224 / 8]byte
466 alarms[0] = 0x80
467 assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, response.AlarmEntityClass)
468 assert.Equal(t, uint16(0x102), response.AlarmEntityInstance)
469 assert.Equal(t, alarms, response.AlarmBitMap)
470 assert.Nil(t, response.AdditionalAlarms)
471
472 // Verify string output for message
473 packetString := packet.String()
474 assert.NotZero(t, len(packetString))
475}
476
477func TestGetAllAlarmsNextResponseDecodeExtended(t *testing.T) {
478 goodMessage := "02342c0b000200000020000b010280000000000000000000000000000000000000000000000000000000"
479 data, err := stringToPacket(goodMessage)
480 assert.NoError(t, err)
481
482 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
483 assert.NotNil(t, packet)
484
485 omciLayer := packet.Layer(LayerTypeOMCI)
486 assert.NotNil(t, omciLayer)
487
488 omciMsg, ok := omciLayer.(*OMCI)
489 assert.True(t, ok)
490 assert.NotNil(t, omciMsg)
491 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
492 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
493 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, omciMsg.NextLayerType())
494 assert.Equal(t, uint16(0x0234), omciMsg.TransactionID)
495 assert.Equal(t, GetAllAlarmsNextResponseType, omciMsg.MessageType)
496 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
497 assert.Equal(t, uint16(32), omciMsg.Length)
498
499 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse)
500 assert.NotNil(t, msgLayer)
501
502 response, ok2 := msgLayer.(*GetAllAlarmsNextResponse)
503 assert.True(t, ok2)
504 assert.NotNil(t, response)
505 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, response.LayerType())
506 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, response.CanDecode())
507 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
508
509 var alarms [224 / 8]byte
510 alarms[0] = 0x80
511 assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, response.AlarmEntityClass)
512 assert.Equal(t, uint16(0x102), response.AlarmEntityInstance)
513 assert.Equal(t, alarms, response.AlarmBitMap)
514 assert.Nil(t, response.AdditionalAlarms)
515
516 // Verify string output for message
517 packetString := packet.String()
518 assert.NotZero(t, len(packetString))
519}
520
521func TestGetAllAlarmsNextResponseDecodeExtendedTwoBitmaps(t *testing.T) {
522 alarm1 := "000b010280000000000000000000000000000000000000000000000000000000"
523 alarm2 := "000b010380000000000000000000000000000000000000000000000000000000"
524 goodMessage := "02342c0b000200000040" + alarm1 + alarm2
525 data, err := stringToPacket(goodMessage)
526 assert.NoError(t, err)
527
528 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
529 assert.NotNil(t, packet)
530
531 omciLayer := packet.Layer(LayerTypeOMCI)
532 assert.NotNil(t, omciLayer)
533
534 omciMsg, ok := omciLayer.(*OMCI)
535 assert.True(t, ok)
536 assert.NotNil(t, omciMsg)
537 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
538 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
539 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, omciMsg.NextLayerType())
540 assert.Equal(t, uint16(0x0234), omciMsg.TransactionID)
541 assert.Equal(t, GetAllAlarmsNextResponseType, omciMsg.MessageType)
542 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
543 assert.Equal(t, uint16(64), omciMsg.Length)
544
545 msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse)
546 assert.NotNil(t, msgLayer)
547
548 response, ok2 := msgLayer.(*GetAllAlarmsNextResponse)
549 assert.True(t, ok2)
550 assert.NotNil(t, response)
551 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, response.LayerType())
552 assert.Equal(t, LayerTypeGetAllAlarmsNextResponse, response.CanDecode())
553 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
554
555 var alarms [224 / 8]byte
556 alarms[0] = 0x80
557 assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, response.AlarmEntityClass)
558 assert.Equal(t, uint16(0x102), response.AlarmEntityInstance)
559 assert.Equal(t, alarms, response.AlarmBitMap)
560
561 assert.NotNil(t, response.AdditionalAlarms)
562 assert.Equal(t, 1, len(response.AdditionalAlarms))
563 assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, response.AdditionalAlarms[0].AlarmEntityClass)
564 assert.Equal(t, uint16(0x103), response.AdditionalAlarms[0].AlarmEntityInstance)
565 assert.Equal(t, alarms, response.AdditionalAlarms[0].AlarmBitMap)
566
567 // Verify string output for message
568 packetString := packet.String()
569 assert.NotZero(t, len(packetString))
570}
571
572func TestGetAllAlarmsNextResponseSerialize(t *testing.T) {
573 goodMessage := "02342c0a00020000000b01028000000000000000000000000000000000000000000000000000000000000028"
574
575 omciLayer := &OMCI{
576 TransactionID: 0x0234,
577 MessageType: GetAllAlarmsNextResponseType,
578 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
579 // Length: 0x28, // Optional, defaults to 40 octets
580 }
581 var alarms [224 / 8]byte
582 alarms[0] = 0x80
583
584 request := &GetAllAlarmsNextResponse{
585 MeBasePacket: MeBasePacket{
586 EntityClass: me.OnuDataClassID,
587 EntityInstance: uint16(0),
588 },
589 AlarmEntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
590 AlarmEntityInstance: uint16(0x102),
591 AlarmBitMap: alarms,
592 }
593 // Test serialization back to former string
594 var options gopacket.SerializeOptions
595 options.FixLengths = true
596
597 buffer := gopacket.NewSerializeBuffer()
598 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
599 assert.NoError(t, err)
600
601 outgoingPacket := buffer.Bytes()
602 reconstituted := packetToString(outgoingPacket)
603 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
604}
605
606func TestGetAllAlarmsNextResponseSerializeExtended(t *testing.T) {
607 goodMessage := "02342c0b000200000020000b010280000000000000000000000000000000000000000000000000000000"
608
609 omciLayer := &OMCI{
610 TransactionID: 0x0234,
611 MessageType: GetAllAlarmsNextResponseType,
612 DeviceIdentifier: ExtendedIdent,
613 }
614 var alarms [224 / 8]byte
615 alarms[0] = 0x80
616
617 request := &GetAllAlarmsNextResponse{
618 MeBasePacket: MeBasePacket{
619 EntityClass: me.OnuDataClassID,
620 EntityInstance: uint16(0),
621 Extended: true,
622 },
623 AlarmEntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
624 AlarmEntityInstance: uint16(0x102),
625 AlarmBitMap: alarms,
626 }
627 // Test serialization back to former string
628 var options gopacket.SerializeOptions
629 options.FixLengths = true
630
631 buffer := gopacket.NewSerializeBuffer()
632 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
633 assert.NoError(t, err)
634
635 outgoingPacket := buffer.Bytes()
636 reconstituted := packetToString(outgoingPacket)
637 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
638}
639
640func TestGetAllAlarmsNextResponseSerializeExtendedTwoBitmaps(t *testing.T) {
641 alarm1 := "000b010280000000000000000000000000000000000000000000000000000000"
642 alarm2 := "000b010380000000000000000000000000000000000000000000000000000000"
643 goodMessage := "02342c0b000200000040" + alarm1 + alarm2
644
645 omciLayer := &OMCI{
646 TransactionID: 0x0234,
647 MessageType: GetAllAlarmsNextResponseType,
648 DeviceIdentifier: ExtendedIdent,
649 }
650 var alarms [224 / 8]byte
651 alarms[0] = 0x80
652
653 secondAlarm := AdditionalAlarmsData{
654 AlarmEntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
655 AlarmEntityInstance: uint16(0x103),
656 AlarmBitMap: alarms,
657 }
658 request := &GetAllAlarmsNextResponse{
659 MeBasePacket: MeBasePacket{
660 EntityClass: me.OnuDataClassID,
661 EntityInstance: uint16(0),
662 Extended: true,
663 },
664 AlarmEntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
665 AlarmEntityInstance: uint16(0x102),
666 AlarmBitMap: alarms,
667 AdditionalAlarms: []AdditionalAlarmsData{secondAlarm},
668 }
669 // Test serialization back to former string
670 var options gopacket.SerializeOptions
671 options.FixLengths = true
672
673 buffer := gopacket.NewSerializeBuffer()
674 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
675 assert.NoError(t, err)
676
677 outgoingPacket := buffer.Bytes()
678 reconstituted := packetToString(outgoingPacket)
679 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
680}
681
682func TestGetAllAlarmsNextResponseBadCommandNumberDecode(t *testing.T) {
683 // Test of a GetNext Response that results when an invalid command number
684 // is requested. In the case where the ONU receives a get all alarms next
685 // request message in which the command sequence number is out of range,
686 // the ONU should respond with a message in which bytes 9 to 40 are all
687 // set to 0. This corresponds to a response with entity class 0, entity
688 // instance 0, and bit map all 0s.
689 //TODO: Implement
690}
691
692func TestGetAllAlarmsNextResponseBadCommandNumberSerialize(t *testing.T) {
693 // Test of a GetNext Response that results when an invalid command number
694 // is requested.
695 //TODO: Implement
696}
697
698func TestAlarmNotificationDecode(t *testing.T) {
699 goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028"
700 data, err := stringToPacket(goodMessage)
701 assert.NoError(t, err)
702
703 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
704 assert.NotNil(t, packet)
705
706 omciLayer := packet.Layer(LayerTypeOMCI)
707 assert.NotNil(t, omciLayer)
708
709 omciMsg, ok := omciLayer.(*OMCI)
710 assert.True(t, ok)
711 assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
712 assert.Equal(t, AlarmNotificationType, omciMsg.MessageType)
713 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
714 assert.Equal(t, uint16(40), omciMsg.Length)
715
716 msgLayer := packet.Layer(LayerTypeAlarmNotification)
717 assert.NotNil(t, msgLayer)
718
719 request, ok2 := msgLayer.(*AlarmNotificationMsg)
720 assert.True(t, ok2)
721 assert.NotNil(t, request)
722 assert.Equal(t, LayerTypeAlarmNotification, request.LayerType())
723 assert.Equal(t, LayerTypeAlarmNotification, request.CanDecode())
724 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
725 assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, request.EntityClass)
726 assert.Equal(t, uint16(0x104), request.EntityInstance)
727 assert.Equal(t, [28]byte{
728 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
729 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
730 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
731 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
732 }, request.AlarmBitmap)
733 assert.Equal(t, byte(5), request.AlarmSequenceNumber)
734
735 // Active/Clear tests
736 active, err2 := request.IsAlarmActive(0)
737 clear, err3 := request.IsAlarmClear(0)
738 assert.Nil(t, err2)
739 assert.Nil(t, err3)
740 assert.True(t, active)
741 assert.False(t, clear)
742
743 // Active/Clear for undefined alarm bits
744 active, err2 = request.IsAlarmActive(1)
745 clear, err3 = request.IsAlarmClear(1)
746 assert.NotNil(t, err2)
747 assert.NotNil(t, err3)
748
749 // Verify string output for message
750 packetString := packet.String()
751 assert.NotZero(t, len(packetString))
752}
753
754func TestInvalidClassAlarmNotificationDecode(t *testing.T) {
755 // Choosing GalEthernetProfile (272) since it does not support alarms, show we should
756 // file the decode
757 badMessage := "0000100a01100104800000000000000000000000000000000000000000000000000000000000000500000028"
758 data, err := stringToPacket(badMessage)
759 assert.NoError(t, err)
760
761 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
762 assert.NotNil(t, packet)
763
764 omciLayer := packet.Layer(LayerTypeOMCI)
765 assert.NotNil(t, omciLayer)
766
767 omciMsg, ok := omciLayer.(*OMCI)
768 assert.True(t, ok)
769 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
770 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
771 assert.Equal(t, LayerTypeAlarmNotification, omciMsg.NextLayerType())
772 assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
773 assert.Equal(t, AlarmNotificationType, omciMsg.MessageType)
774 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
775 assert.Equal(t, uint16(40), omciMsg.Length)
776
777 msgLayer := packet.Layer(LayerTypeAlarmNotification)
778 assert.Nil(t, msgLayer)
779
780 request, ok2 := msgLayer.(*AlarmNotificationMsg)
781 assert.False(t, ok2)
782 assert.Nil(t, request)
783 assert.Equal(t, LayerTypeAlarmNotification, request.LayerType())
784 assert.Equal(t, LayerTypeAlarmNotification, request.CanDecode())
785 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
786}
787
788func TestUnknownsMeAlarmNotificationDecode(t *testing.T) {
789 // Choosing class ID 22 since it is in the G.988 class ID space and is reserved
790 goodMessage := "0000100a00160104800000000000000000000000000000000000000000000000000000000000000500000028"
791 data, err := stringToPacket(goodMessage)
792 assert.NoError(t, err)
793
794 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
795 assert.NotNil(t, packet)
796
797 omciLayer := packet.Layer(LayerTypeOMCI)
798 assert.NotNil(t, omciLayer)
799
800 omciMsg, ok := omciLayer.(*OMCI)
801 assert.True(t, ok)
802 assert.NotNil(t, omciMsg)
803 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
804 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
805 assert.Equal(t, LayerTypeAlarmNotification, omciMsg.NextLayerType())
806 assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
807 assert.Equal(t, AlarmNotificationType, omciMsg.MessageType)
808 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
809 assert.Equal(t, uint16(40), omciMsg.Length)
810
811 msgLayer := packet.Layer(LayerTypeAlarmNotification)
812 assert.NotNil(t, msgLayer)
813
814 request, ok2 := msgLayer.(*AlarmNotificationMsg)
815 assert.True(t, ok2)
816 assert.NotNil(t, request)
817 assert.Equal(t, LayerTypeAlarmNotification, request.LayerType())
818 assert.Equal(t, LayerTypeAlarmNotification, request.CanDecode())
819 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
820 assert.Equal(t, me.ClassID(22), request.EntityClass)
821 assert.Equal(t, uint16(0x104), request.EntityInstance)
822 assert.Equal(t, [28]byte{
823 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 }, request.AlarmBitmap)
828 assert.Equal(t, byte(5), request.AlarmSequenceNumber)
829}
830
831func TestVendorSpecificAlarmNotificationDecode(t *testing.T) {
832 // Choosing class ID 255 since it is in the first vendor specific class ID space
833 goodMessage := "0000100a00FF0104800000000000000000000000000000000000000000000000000000000000000500000028"
834 data, err := stringToPacket(goodMessage)
835 assert.NoError(t, err)
836
837 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
838 assert.NotNil(t, packet)
839
840 omciLayer := packet.Layer(LayerTypeOMCI)
841 assert.NotNil(t, omciLayer)
842
843 omciMsg, ok := omciLayer.(*OMCI)
844 assert.True(t, ok)
845 assert.NotNil(t, omciMsg)
846 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
847 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
848 assert.Equal(t, LayerTypeAlarmNotification, omciMsg.NextLayerType())
849 assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
850 assert.Equal(t, AlarmNotificationType, omciMsg.MessageType)
851 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
852 assert.Equal(t, uint16(40), omciMsg.Length)
853
854 msgLayer := packet.Layer(LayerTypeAlarmNotification)
855 assert.NotNil(t, msgLayer)
856
857 request, ok2 := msgLayer.(*AlarmNotificationMsg)
858 assert.True(t, ok2)
859 assert.NotNil(t, request)
860 assert.Equal(t, LayerTypeAlarmNotification, request.LayerType())
861 assert.Equal(t, LayerTypeAlarmNotification, request.CanDecode())
862 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
863 assert.Equal(t, me.ClassID(255), request.EntityClass)
864 assert.Equal(t, uint16(0x104), request.EntityInstance)
865 assert.Equal(t, [28]byte{
866 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
867 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
868 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
869 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
870 }, request.AlarmBitmap)
871 assert.Equal(t, byte(5), request.AlarmSequenceNumber)
872}
873
874func TestAlarmNotificationSerialize(t *testing.T) {
875 goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028"
876
877 omciLayer := &OMCI{
878 TransactionID: 0,
879 MessageType: AlarmNotificationType,
880 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
881 // Length: 0x28, // Optional, defaults to 40 octets
882 }
883 request := &AlarmNotificationMsg{
884 MeBasePacket: MeBasePacket{
885 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
886 EntityInstance: uint16(0x104),
887 },
888 AlarmBitmap: [28]byte{
889 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
890 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
891 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
892 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
893 },
894 AlarmSequenceNumber: byte(5),
895 }
896 // Test serialization back to former string
897 var options gopacket.SerializeOptions
898 options.FixLengths = true
899
900 buffer := gopacket.NewSerializeBuffer()
901 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
902 assert.NoError(t, err)
903
904 outgoingPacket := buffer.Bytes()
905 reconstituted := packetToString(outgoingPacket)
906 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
907}
908
909func TestAlarmNotificationSerializeNonZeroTIC(t *testing.T) {
910 omciLayer := &OMCI{
911 TransactionID: 1,
912 MessageType: AlarmNotificationType,
913 }
914 request := &AlarmNotificationMsg{
915 MeBasePacket: MeBasePacket{
916 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
917 EntityInstance: uint16(0x104),
918 },
919 AlarmBitmap: [28]byte{
920 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
921 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
922 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
924 },
925 AlarmSequenceNumber: byte(5),
926 }
927 // Test serialization back to former string
928 var options gopacket.SerializeOptions
929 options.FixLengths = true
930
931 buffer := gopacket.NewSerializeBuffer()
932 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
933 assert.Error(t, err)
934}
935
936func TestExtendedAlarmNotificationDecode(t *testing.T) {
937 // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
938 goodMessage := "0000100b000b0104001d8000000000000000000000000000000000000000000000000000000005"
939 data, err := stringToPacket(goodMessage)
940 assert.NoError(t, err)
941
942 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
943 assert.NotNil(t, packet)
944
945 omciLayer := packet.Layer(LayerTypeOMCI)
946 assert.NotNil(t, omciLayer)
947
948 omciMsg, ok := omciLayer.(*OMCI)
949 assert.True(t, ok)
950 assert.NotNil(t, omciMsg)
951 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
952 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
953 assert.Equal(t, LayerTypeAlarmNotification, omciMsg.NextLayerType())
954 assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
955 assert.Equal(t, AlarmNotificationType, omciMsg.MessageType)
956 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
957 assert.Equal(t, uint16(29), omciMsg.Length)
958
959 msgLayer := packet.Layer(LayerTypeAlarmNotification)
960 assert.NotNil(t, msgLayer)
961
962 request, ok2 := msgLayer.(*AlarmNotificationMsg)
963 assert.True(t, ok2)
964 assert.NotNil(t, request)
965 assert.Equal(t, LayerTypeAlarmNotification, request.LayerType())
966 assert.Equal(t, LayerTypeAlarmNotification, request.CanDecode())
967 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
968 assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, request.EntityClass)
969 assert.Equal(t, uint16(0x104), request.EntityInstance)
970 assert.Equal(t, [28]byte{
971 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
972 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
973 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
974 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
975 }, request.AlarmBitmap)
976 assert.Equal(t, byte(5), request.AlarmSequenceNumber)
977
978 // Active/Clear tests
979 active, err2 := request.IsAlarmActive(0)
980 clear, err3 := request.IsAlarmClear(0)
981 assert.Nil(t, err2)
982 assert.Nil(t, err3)
983 assert.True(t, active)
984 assert.False(t, clear)
985
986 // Active/Clear for undefined alarm bits
987 active, err2 = request.IsAlarmActive(1)
988 clear, err3 = request.IsAlarmClear(1)
989 assert.NotNil(t, err2)
990 assert.NotNil(t, err3)
991
992 // Verify string output for message
993 packetString := packet.String()
994 assert.NotZero(t, len(packetString))
995}
996
997func TestExtendedAlarmNotificationSerialize(t *testing.T) {
998 // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
999 goodMessage := "0000100b000b0104001d8000000000000000000000000000000000000000000000000000000005"
1000
1001 omciLayer := &OMCI{
1002 TransactionID: 0,
1003 MessageType: AlarmNotificationType,
1004 DeviceIdentifier: ExtendedIdent,
1005 // Length parameter is optional for Extended message format serialization
1006 // and if present it will be overwritten during the serialization with the
1007 // actual value.
1008 }
1009 request := &AlarmNotificationMsg{
1010 MeBasePacket: MeBasePacket{
1011 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
1012 EntityInstance: uint16(0x104),
1013 Extended: true,
1014 },
1015 AlarmBitmap: [28]byte{
1016 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1017 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1018 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1019 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1020 },
1021 AlarmSequenceNumber: byte(5),
1022 }
1023 // Test serialization back to former string
1024 var options gopacket.SerializeOptions
1025 options.FixLengths = true
1026
1027 buffer := gopacket.NewSerializeBuffer()
1028 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
1029 assert.NoError(t, err)
1030
1031 outgoingPacket := buffer.Bytes()
1032 reconstituted := packetToString(outgoingPacket)
1033 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
1034}
1035
1036func TestAlarmDecodesOmciLayerHeaderTooSmall(t *testing.T) {
1037 // Baseline is always checked for < 40 octets and that test is in mebase_test.go. And
1038 // that test also handles Extended message set where the length field is short. This
1039 // test for a valid length field but no message content past that.
1040 getAllAlarmsRequestExt := "04454b0b000200000000"
1041 getAllAlarmsResponseExt := "04452b0b000200000000"
1042 getAllAlarmsNextRequestExt := "02344c0b000200000000"
1043 alarmNotificationExt := "0000100b000b01040000"
1044
1045 frames := []string{
1046 getAllAlarmsRequestExt,
1047 getAllAlarmsResponseExt,
1048 getAllAlarmsNextRequestExt,
1049 alarmNotificationExt,
1050 }
1051 for _, frame := range frames {
1052 data, err := stringToPacket(frame)
1053 assert.NoError(t, err)
1054
1055 // Should get packet but with error layer
1056 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1057 assert.NotNil(t, packet)
1058
1059 // OMCI layer should be present (but not message type specific layer)
1060 omciLayer := packet.Layer(LayerTypeOMCI)
1061 assert.NotNil(t, omciLayer)
1062
1063 // And there is an error layer. Since OMCI, we only have two OMCI and
1064 // the message type layer (which should be the failed one)
1065 assert.Equal(t, 2, len(packet.Layers()))
1066 errLayer := packet.ErrorLayer()
1067 assert.NotNil(t, errLayer)
1068 metaData := packet.Metadata()
1069 assert.NotNil(t, metaData)
1070 assert.True(t, metaData.Truncated)
1071 }
1072}