blob: b387428f7b9098a6c5607d777c3a70b34f8e4bad [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 "fmt"
22 "github.com/google/gopacket"
23 . "github.com/opencord/omci-lib-go"
24 me "github.com/opencord/omci-lib-go/generated"
25 "github.com/stretchr/testify/assert"
26 "strings"
27 "testing"
28)
29
30func TestGenericTestResultDecode(t *testing.T) {
31 // ONU-G ME for this test with just made up data
32 payload := "1234567890123456789012345678901234567890123456789012345678901234"
33 goodMessage := "00001b0a01000000" + payload + "00000028"
34 data, err := stringToPacket(goodMessage)
35 assert.NoError(t, err)
36
37 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
38 assert.NotNil(t, packet)
39
40 omciLayer := packet.Layer(LayerTypeOMCI)
41 assert.NotNil(t, omciLayer)
42
43 omciMsg, ok := omciLayer.(*OMCI)
44 assert.True(t, ok)
45 assert.NotNil(t, omciMsg)
46 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
47 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
48 assert.Equal(t, LayerTypeTestResult, omciMsg.NextLayerType())
49 assert.Equal(t, uint16(0x0000), omciMsg.TransactionID)
50 assert.Equal(t, TestResultType, omciMsg.MessageType)
51 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
52 assert.Equal(t, uint16(40), omciMsg.Length)
53
54 msgLayer := packet.Layer(LayerTypeTestResult)
55 assert.NotNil(t, msgLayer)
56
57 // This is a generic struct since we do not do detailed decode
58 generic, ok2 := msgLayer.(*TestResultNotification)
59 assert.True(t, ok2)
60 assert.NotNil(t, generic)
61 assert.Equal(t, LayerTypeTestResult, generic.LayerType())
62 assert.Equal(t, LayerTypeTestResult, generic.CanDecode())
63 assert.Equal(t, gopacket.LayerTypePayload, generic.NextLayerType())
64 assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data
65 assert.NotNil(t, generic.Payload)
66 assert.NotNil(t, generic.TestResults())
67
68 base := generic.MeBasePacket
69 assert.Equal(t, me.OnuGClassID, base.EntityClass)
70 assert.Equal(t, uint16(0), base.EntityInstance)
71
72 // For the generic Test Result, get the payload data which is all the data in
73 // the test notification past the Entity Instance value.
74 payloadData, payloadErr := stringToPacket(payload)
75 assert.NotNil(t, payloadData)
76 assert.NoError(t, payloadErr)
77 assert.Equal(t, payloadData, base.Payload)
78 assert.Equal(t, payloadData, generic.Payload)
79
80 // Verify string output for message
81 packetString := packet.String()
82 assert.NotZero(t, len(packetString))
83}
84
85func TestOpticalLineSupervisionTestResultDecode(t *testing.T) {
86 // ANI-G ME for this test with just made up data
87 payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" + "000000000000000000000000000000"
88 goodMessage := "00001b0a01078001" + payload + "00000028"
89 data, err := stringToPacket(goodMessage)
90 assert.NoError(t, err)
91
92 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
93 assert.NotNil(t, packet)
94
95 omciLayer := packet.Layer(LayerTypeOMCI)
96 assert.NotNil(t, omciLayer)
97
98 omciMsg, ok := omciLayer.(*OMCI)
99 assert.True(t, ok)
100 assert.NotNil(t, omciMsg)
101 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
102 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
103 assert.Equal(t, LayerTypeTestResult, omciMsg.NextLayerType())
104 assert.Equal(t, uint16(0x0000), omciMsg.TransactionID)
105 assert.Equal(t, TestResultType, omciMsg.MessageType)
106 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
107 assert.Equal(t, uint16(40), omciMsg.Length)
108
109 msgLayer := packet.Layer(LayerTypeTestResult)
110 assert.NotNil(t, msgLayer)
111
112 // This is a optical line test results
113 optical, ok2 := msgLayer.(*OpticalLineSupervisionTestResult)
114 assert.True(t, ok2)
115 assert.NotNil(t, optical)
116 assert.Equal(t, LayerTypeTestResult, optical.LayerType())
117 assert.Equal(t, LayerTypeTestResult, optical.CanDecode())
118 assert.Equal(t, gopacket.LayerTypePayload, optical.NextLayerType())
119
120 // Get the Managed Entity class ID and instance ID from the base packet
121 base := optical.MeBasePacket
122 assert.Equal(t, me.AniGClassID, base.EntityClass)
123 assert.Equal(t, uint16(0x8001), base.EntityInstance)
124
125 assert.Equal(t, uint8(1), optical.PowerFeedVoltageType)
126 assert.Equal(t, uint16(0x34), optical.PowerFeedVoltage)
127
128 assert.Equal(t, uint8(3), optical.ReceivedOpticalPowerType)
129 assert.Equal(t, uint16(0x67), optical.ReceivedOpticalPower)
130
131 assert.Equal(t, uint8(5), optical.MeanOpticalLaunchType)
132 assert.Equal(t, uint16(0x91), optical.MeanOpticalLaunch)
133
134 assert.Equal(t, uint8(9), optical.LaserBiasCurrentType)
135 assert.Equal(t, uint16(0x34), optical.LaserBiasCurrent)
136
137 assert.Equal(t, uint8(12), optical.TemperatureType)
138 assert.Equal(t, uint16(0x67), optical.Temperature)
139
140 assert.Equal(t, uint16(0x8901), optical.GeneralPurposeBuffer)
141
142 // Verify string output for message
143 packetString := packet.String()
144 assert.NotZero(t, len(packetString))
145}
146
147func TestGenericTestResultSerialize(t *testing.T) {
148 payload := "1234567891234567890123456789012345678901234567890123456789012345"
149 goodMessage := "00001b0a01000000" + payload + "00000028"
150
151 omciLayer := &OMCI{
152 TransactionID: 0x0000, // Optional for notifications since TID always 0x0000
153 MessageType: TestResultType,
154 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
155 // Length: 0x28, // Optional, defaults to 40 octets
156 }
157 data, derr := stringToPacket(payload)
158 assert.NoError(t, derr)
159
160 request := &TestResultNotification{
161 MeBasePacket: MeBasePacket{
162 EntityClass: me.OnuGClassID,
163 EntityInstance: uint16(0),
164 },
165 Payload: data,
166 }
167 // Test serialization back to former string
168 var options gopacket.SerializeOptions
169 options.FixLengths = true
170
171 buffer := gopacket.NewSerializeBuffer()
172 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
173 assert.NoError(t, err)
174
175 outgoingPacket := buffer.Bytes()
176 reconstituted := packetToString(outgoingPacket)
177 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
178}
179
180func TestGenericTestResultNonZeroTICSerialize(t *testing.T) {
181 payload := "1234567891234567890123456789012345678901234567890123456789012345"
182 goodMessage := "12341b0a01000000" + payload + "00000028"
183
184 omciLayer := &OMCI{
185 TransactionID: 0x1234,
186 MessageType: TestResultType,
187 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
188 // Length: 0x28, // Optional, defaults to 40 octets
189 }
190 data, derr := stringToPacket(payload)
191 assert.NoError(t, derr)
192
193 request := &TestResultNotification{
194 MeBasePacket: MeBasePacket{
195 EntityClass: me.OnuGClassID,
196 EntityInstance: uint16(0),
197 },
198 Payload: data,
199 }
200 // Test serialization back to former string
201 var options gopacket.SerializeOptions
202 options.FixLengths = true
203
204 buffer := gopacket.NewSerializeBuffer()
205 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
206 assert.NoError(t, err)
207
208 outgoingPacket := buffer.Bytes()
209 reconstituted := packetToString(outgoingPacket)
210 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
211}
212
213func TestOpticalLineSupervisionTestResultSerialize(t *testing.T) {
214 // ANI-G ME for this test with just made up data
215 payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" + "000000000000000000000000000000"
216 goodMessage := "00001b0a01078001" + payload + "00000028"
217
218 omciLayer := &OMCI{
219 // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000
220 MessageType: TestResultType,
221 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
222 // Length: 0x28, // Optional, defaults to 40 octets
223 }
224 request := &OpticalLineSupervisionTestResult{
225 MeBasePacket: MeBasePacket{
226 EntityClass: me.AniGClassID,
227 EntityInstance: uint16(0x8001),
228 },
229 PowerFeedVoltageType: uint8(1),
230 PowerFeedVoltage: uint16(0x34),
231 ReceivedOpticalPowerType: uint8(3),
232 ReceivedOpticalPower: uint16(0x67),
233 MeanOpticalLaunchType: uint8(5),
234 MeanOpticalLaunch: uint16(0x91),
235 LaserBiasCurrentType: uint8(9),
236 LaserBiasCurrent: uint16(0x34),
237 TemperatureType: uint8(12),
238 Temperature: uint16(0x67),
239 GeneralPurposeBuffer: uint16(0x8901),
240 }
241 // Test serialization back to former string
242 var options gopacket.SerializeOptions
243 options.FixLengths = true
244
245 buffer := gopacket.NewSerializeBuffer()
246 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
247 assert.NoError(t, err)
248
249 outgoingPacket := buffer.Bytes()
250 reconstituted := packetToString(outgoingPacket)
251 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
252}
253
254func TestGenericTestRequestDecode(t *testing.T) {
255 // ONU-G ME for this test with just made up data
256 payload := "1234567890523456789012345678901234567890123456789012345678901234"
257 goodMessage := "0123520a01000000" + payload + "00000028"
258 data, err := stringToPacket(goodMessage)
259 assert.NoError(t, err)
260
261 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
262 assert.NotNil(t, packet)
263
264 omciLayer := packet.Layer(LayerTypeOMCI)
265 assert.NotNil(t, omciLayer)
266
267 omciMsg, ok := omciLayer.(*OMCI)
268 assert.True(t, ok)
269 assert.NotNil(t, omciMsg)
270 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
271 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
272 assert.Equal(t, LayerTypeTestRequest, omciMsg.NextLayerType())
273 assert.Equal(t, uint16(0x0123), omciMsg.TransactionID)
274 assert.Equal(t, TestRequestType, omciMsg.MessageType)
275 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
276 assert.Equal(t, uint16(40), omciMsg.Length)
277
278 msgLayer := packet.Layer(LayerTypeTestRequest)
279 assert.NotNil(t, msgLayer)
280
281 // This is a generic struct since we do not do detailed decode
282 generic, ok2 := msgLayer.(*TestRequest)
283 assert.True(t, ok2)
284 assert.NotNil(t, generic)
285 assert.Equal(t, LayerTypeTestRequest, generic.LayerType())
286 assert.Equal(t, LayerTypeTestRequest, generic.CanDecode())
287 assert.Equal(t, gopacket.LayerTypePayload, generic.NextLayerType())
288 assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data
289 assert.NotNil(t, generic.Payload)
290 assert.NotNil(t, generic.TestRequest())
291
292 base := generic.MeBasePacket
293 assert.Equal(t, me.OnuGClassID, base.EntityClass)
294 assert.Equal(t, uint16(0), base.EntityInstance)
295
296 // For the generic Test Result, get the payload data which is all the data in
297 // the test notification past the Entity Instance value.
298 payloadData, payloadErr := stringToPacket(payload)
299 assert.NotNil(t, payloadData)
300 assert.NoError(t, payloadErr)
301 assert.Equal(t, payloadData, base.Payload)
302 assert.Equal(t, payloadData, generic.Payload)
303
304 // Verify string output for message
305 packetString := packet.String()
306 assert.NotZero(t, len(packetString))
307}
308
309func TestOpticalLineSupervisionTestRequestDecode(t *testing.T) {
310 // ANI-G ME for this test with just made up data
311 payload := "01" + "1234" + "5678" + "000000000000000000000000000000000000000000000000000000"
312 goodMessage := "0ddd520a01078001" + payload + "00000028"
313 data, err := stringToPacket(goodMessage)
314 assert.NoError(t, err)
315
316 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
317 assert.NotNil(t, packet)
318
319 omciLayer := packet.Layer(LayerTypeOMCI)
320 assert.NotNil(t, omciLayer)
321
322 omciMsg, ok := omciLayer.(*OMCI)
323 assert.True(t, ok)
324 assert.NotNil(t, omciMsg)
325 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
326 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
327 assert.Equal(t, LayerTypeTestRequest, omciMsg.NextLayerType())
328 assert.Equal(t, uint16(0x0ddd), omciMsg.TransactionID)
329 assert.Equal(t, TestRequestType, omciMsg.MessageType)
330 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
331 assert.Equal(t, uint16(40), omciMsg.Length)
332
333 msgLayer := packet.Layer(LayerTypeTestRequest)
334 assert.NotNil(t, msgLayer)
335
336 // This is a optical line test results
337 optical, ok2 := msgLayer.(*OpticalLineSupervisionTestRequest)
338 assert.True(t, ok2)
339 assert.NotNil(t, optical)
340 assert.Equal(t, LayerTypeTestRequest, optical.LayerType())
341 assert.Equal(t, LayerTypeTestRequest, optical.CanDecode())
342 assert.Equal(t, gopacket.LayerTypePayload, optical.NextLayerType())
343
344 // Get the Managed Entity class ID and instance ID from the base packet
345 base := optical.MeBasePacket
346 assert.Equal(t, me.AniGClassID, base.EntityClass)
347 assert.Equal(t, uint16(0x8001), base.EntityInstance)
348
349 assert.Equal(t, uint8(1), optical.SelectTest)
350 assert.Equal(t, uint16(0x1234), optical.GeneralPurposeBuffer)
351 assert.Equal(t, uint16(0x5678), optical.VendorSpecificParameters)
352
353 // Verify string output for message
354 packetString := packet.String()
355 assert.NotZero(t, len(packetString))
356}
357
358func TestGenericTestRequestSerialize(t *testing.T) {
359 payload := "1234567891234567890123456789012345678901234567890123456789012345"
360 goodMessage := "eeee520a01000000" + payload + "00000028"
361
362 omciLayer := &OMCI{
363 TransactionID: 0xeeee,
364 MessageType: TestRequestType,
365 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
366 // Length: 0x28, // Optional, defaults to 40 octets
367 }
368 data, derr := stringToPacket(payload)
369 assert.NoError(t, derr)
370
371 request := &TestRequest{
372 MeBasePacket: MeBasePacket{
373 EntityClass: me.OnuGClassID,
374 EntityInstance: uint16(0),
375 },
376 Payload: data,
377 }
378 // Test serialization back to former string
379 var options gopacket.SerializeOptions
380 options.FixLengths = true
381
382 buffer := gopacket.NewSerializeBuffer()
383 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
384 assert.NoError(t, err)
385
386 outgoingPacket := buffer.Bytes()
387 reconstituted := packetToString(outgoingPacket)
388 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
389}
390
391func TestOpticalLineSupervisionTestRequestSerialize(t *testing.T) {
392 // ANI-G ME for this test with just made up data
393 payload := "01" + "1234" + "5678" + "000000000000000000000000000000000000000000000000000000"
394 goodMessage := "bbbb520a01078001" + payload + "00000028"
395
396 omciLayer := &OMCI{
397 TransactionID: 0xbbbb,
398 MessageType: TestRequestType,
399 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
400 // Length: 0x28, // Optional, defaults to 40 octets
401 }
402 request := &OpticalLineSupervisionTestRequest{
403 MeBasePacket: MeBasePacket{
404 EntityClass: me.AniGClassID,
405 EntityInstance: uint16(0x8001),
406 },
407 SelectTest: uint8(1),
408 GeneralPurposeBuffer: uint16(0x1234),
409 VendorSpecificParameters: uint16(0x5678),
410 }
411 // Test serialization back to former string
412 var options gopacket.SerializeOptions
413 options.FixLengths = true
414
415 buffer := gopacket.NewSerializeBuffer()
416 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
417 assert.NoError(t, err)
418
419 outgoingPacket := buffer.Bytes()
420 reconstituted := packetToString(outgoingPacket)
421 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
422}
423
424func TestTestResponseDecode(t *testing.T) {
425 goodMessage := "0001320A01000000000000000000000000000000000000000000000000000000000000000000000000000028"
426 data, err := stringToPacket(goodMessage)
427 assert.NoError(t, err)
428
429 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
430 assert.NotNil(t, packet)
431
432 omciLayer := packet.Layer(LayerTypeOMCI)
433 assert.NotNil(t, omciLayer)
434
435 omciMsg, ok := omciLayer.(*OMCI)
436 assert.True(t, ok)
437 assert.NotNil(t, omciMsg)
438 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
439 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
440 assert.Equal(t, LayerTypeTestResponse, omciMsg.NextLayerType())
441 assert.Equal(t, TestResponseType, omciMsg.MessageType)
442 assert.Equal(t, uint16(40), omciMsg.Length)
443
444 msgLayer := packet.Layer(LayerTypeTestResponse)
445
446 assert.NotNil(t, msgLayer)
447
448 response, ok2 := msgLayer.(*TestResponse)
449 assert.True(t, ok2)
450 assert.NotNil(t, response)
451 assert.Equal(t, LayerTypeTestResponse, response.LayerType())
452 assert.Equal(t, LayerTypeTestResponse, response.CanDecode())
453 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
454 assert.Equal(t, me.OnuGClassID, response.EntityClass)
455 assert.Equal(t, uint16(0), response.EntityInstance)
456 assert.Equal(t, me.Success, response.Result)
457
458 // Verify string output for message
459 packetString := packet.String()
460 assert.NotZero(t, len(packetString))
461}
462
463func TestTestResponseSerialize(t *testing.T) {
464 goodMessage := "0001320A01000000000000000000000000000000000000000000000000000000000000000000000000000028"
465
466 omciLayer := &OMCI{
467 TransactionID: 0x01,
468 MessageType: TestResponseType,
469 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
470 // Length: 0x28, // Optional, defaults to 40 octets
471 }
472 request := &TestResponse{
473 MeBasePacket: MeBasePacket{
474 EntityClass: me.OnuGClassID,
475 // Default Instance ID is 0
476 },
477 Result: me.Success,
478 }
479 // Test serialization back to former string
480 var options gopacket.SerializeOptions
481 options.FixLengths = true
482
483 buffer := gopacket.NewSerializeBuffer()
484 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
485 assert.NoError(t, err)
486
487 outgoingPacket := buffer.Bytes()
488 reconstituted := packetToString(outgoingPacket)
489 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
490}
491
492func TestExtendedGenericTestResultDecode(t *testing.T) {
493 // ONU-G ME for this test with just made up data
494 payload := "1234567890123456789012345678901234567890"
495 resultLen := len(payload) / 2
496 goodMessage := "00001b0b01000000" + fmt.Sprintf("%04x", resultLen) + payload
497 data, err := stringToPacket(goodMessage)
498 assert.NoError(t, err)
499
500 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
501 assert.NotNil(t, packet)
502
503 omciLayer := packet.Layer(LayerTypeOMCI)
504 assert.NotNil(t, omciLayer)
505
506 omciMsg, ok := omciLayer.(*OMCI)
507 assert.True(t, ok)
508 assert.NotNil(t, omciMsg)
509 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
510 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
511 assert.Equal(t, LayerTypeTestResult, omciMsg.NextLayerType())
512 assert.Equal(t, uint16(0x0000), omciMsg.TransactionID)
513 assert.Equal(t, TestResultType, omciMsg.MessageType)
514 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
515 assert.Equal(t, omciMsg.Length, uint16(resultLen))
516
517 msgLayer := packet.Layer(LayerTypeTestResult)
518 assert.NotNil(t, msgLayer)
519
520 // This is a generic struct since we do not do detailed decode
521 generic, ok2 := msgLayer.(*TestResultNotification)
522 assert.True(t, ok2)
523 assert.NotNil(t, generic)
524 assert.Equal(t, LayerTypeTestResult, generic.LayerType())
525 assert.Equal(t, LayerTypeTestResult, generic.CanDecode())
526 assert.Equal(t, gopacket.LayerTypePayload, generic.NextLayerType())
527 assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data
528 assert.NotNil(t, generic.Payload)
529 assert.NotNil(t, generic.TestResults())
530
531 base := generic.MeBasePacket
532 assert.Equal(t, me.OnuGClassID, base.EntityClass)
533 assert.Equal(t, uint16(0), base.EntityInstance)
534
535 // For the generic Test Result, get the payload data which is all the data in
536 // the test notification past the Entity Instance value.
537 payloadData, payloadErr := stringToPacket(payload)
538 assert.NotNil(t, payloadData)
539 assert.NoError(t, payloadErr)
540 assert.Equal(t, payloadData, base.Payload)
541 assert.Equal(t, payloadData, generic.Payload)
542
543 // Verify string output for message
544 packetString := packet.String()
545 assert.NotZero(t, len(packetString))
546}
547
548func TestExtendedOpticalLineSupervisionTestResultDecode(t *testing.T) {
549 // ANI-G ME for this test with just made up data
550 payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901"
551 resultLen := len(payload) / 2
552 goodMessage := "00001b0b01078001" + fmt.Sprintf("%04x", resultLen) + payload
553 data, err := stringToPacket(goodMessage)
554 assert.NoError(t, err)
555
556 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
557 assert.NotNil(t, packet)
558
559 omciLayer := packet.Layer(LayerTypeOMCI)
560 assert.NotNil(t, omciLayer)
561
562 omciMsg, ok := omciLayer.(*OMCI)
563 assert.True(t, ok)
564 assert.NotNil(t, omciMsg)
565 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
566 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
567 assert.Equal(t, LayerTypeTestResult, omciMsg.NextLayerType())
568 assert.Equal(t, uint16(0x0000), omciMsg.TransactionID)
569 assert.Equal(t, TestResultType, omciMsg.MessageType)
570 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
571 assert.Equal(t, uint16(resultLen), omciMsg.Length)
572
573 msgLayer := packet.Layer(LayerTypeTestResult)
574 assert.NotNil(t, msgLayer)
575
576 // This is a optical line test results
577 optical, ok2 := msgLayer.(*OpticalLineSupervisionTestResult)
578 assert.True(t, ok2)
579 assert.NotNil(t, optical)
580 assert.Equal(t, LayerTypeTestResult, optical.LayerType())
581 assert.Equal(t, LayerTypeTestResult, optical.CanDecode())
582 assert.Equal(t, gopacket.LayerTypePayload, optical.NextLayerType())
583
584 // Get the Managed Entity class ID and instance ID from the base packet
585 base := optical.MeBasePacket
586 assert.Equal(t, me.AniGClassID, base.EntityClass)
587 assert.Equal(t, uint16(0x8001), base.EntityInstance)
588
589 assert.Equal(t, uint8(1), optical.PowerFeedVoltageType)
590 assert.Equal(t, uint16(0x34), optical.PowerFeedVoltage)
591
592 assert.Equal(t, uint8(3), optical.ReceivedOpticalPowerType)
593 assert.Equal(t, uint16(0x67), optical.ReceivedOpticalPower)
594
595 assert.Equal(t, uint8(5), optical.MeanOpticalLaunchType)
596 assert.Equal(t, uint16(0x91), optical.MeanOpticalLaunch)
597
598 assert.Equal(t, uint8(9), optical.LaserBiasCurrentType)
599 assert.Equal(t, uint16(0x34), optical.LaserBiasCurrent)
600
601 assert.Equal(t, uint8(12), optical.TemperatureType)
602 assert.Equal(t, uint16(0x67), optical.Temperature)
603
604 assert.Equal(t, uint16(0x8901), optical.GeneralPurposeBuffer)
605
606 // Verify string output for message
607 packetString := packet.String()
608 assert.NotZero(t, len(packetString))
609}
610
611func TestExtendedGenericTestResultSerialize(t *testing.T) {
612 payload := "12345678901234567890"
613 resultLen := len(payload) / 2
614 goodMessage := "00001b0b01000000" + fmt.Sprintf("%04x", resultLen) + payload
615
616 omciLayer := &OMCI{
617 // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000
618 MessageType: TestResultType,
619 DeviceIdentifier: ExtendedIdent,
620 // Length parameter is optional for Extended message format serialization
621 // and if present it will be overwritten during the serialization with the
622 // actual value.
623 }
624 data, derr := stringToPacket(payload)
625 assert.NoError(t, derr)
626
627 request := &TestResultNotification{
628 MeBasePacket: MeBasePacket{
629 EntityClass: me.OnuGClassID,
630 EntityInstance: uint16(0),
631 Extended: true,
632 },
633 Payload: data,
634 }
635 // Test serialization back to former string
636 var options gopacket.SerializeOptions
637 options.FixLengths = true
638
639 buffer := gopacket.NewSerializeBuffer()
640 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
641 assert.NoError(t, err)
642
643 outgoingPacket := buffer.Bytes()
644 reconstituted := packetToString(outgoingPacket)
645 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
646}
647
648func TestExtendedOpticalLineSupervisionTestResultSerialize(t *testing.T) {
649 // ANI-G ME for this test with just made up data
650 payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901"
651 resultLen := len(payload) / 2
652 goodMessage := "00001b0b01078001" + fmt.Sprintf("%04x", resultLen) + payload
653
654 omciLayer := &OMCI{
655 // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000
656 MessageType: TestResultType,
657 DeviceIdentifier: ExtendedIdent,
658 // Length parameter is optional for Extended message format serialization
659 // and if present it will be overwritten during the serialization with the
660 // actual value.
661 }
662 request := &OpticalLineSupervisionTestResult{
663 MeBasePacket: MeBasePacket{
664 EntityClass: me.AniGClassID,
665 EntityInstance: uint16(0x8001),
666 Extended: true,
667 },
668 PowerFeedVoltageType: uint8(1),
669 PowerFeedVoltage: uint16(0x34),
670 ReceivedOpticalPowerType: uint8(3),
671 ReceivedOpticalPower: uint16(0x67),
672 MeanOpticalLaunchType: uint8(5),
673 MeanOpticalLaunch: uint16(0x91),
674 LaserBiasCurrentType: uint8(9),
675 LaserBiasCurrent: uint16(0x34),
676 TemperatureType: uint8(12),
677 Temperature: uint16(0x67),
678 GeneralPurposeBuffer: uint16(0x8901),
679 }
680 // Test serialization back to former string
681 var options gopacket.SerializeOptions
682 options.FixLengths = true
683
684 buffer := gopacket.NewSerializeBuffer()
685 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
686 assert.NoError(t, err)
687
688 outgoingPacket := buffer.Bytes()
689 reconstituted := packetToString(outgoingPacket)
690 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
691}