blob: d07ad51e5fb2346ff4c642ca5077ec611424eae6 [file] [log] [blame]
Matteo Scandolocedde462021-03-09 17:37:16 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package omci
18
19import (
Holger Hildebrandt96382572022-05-31 09:41:38 +000020 "testing"
21
Matteo Scandolocedde462021-03-09 17:37:16 -080022 "github.com/google/gopacket"
Andrea Campanella10426e22021-10-15 17:58:04 +020023 "github.com/opencord/omci-lib-go/v2"
24 me "github.com/opencord/omci-lib-go/v2/generated"
Matteo Scandolocedde462021-03-09 17:37:16 -080025 "gotest.tools/assert"
Matteo Scandolocedde462021-03-09 17:37:16 -080026)
27
28func omciToStartSoftwareDownloadResponse(t *testing.T, omciPkt *gopacket.Packet) *omci.StartSoftwareDownloadResponse {
29 msgLayer := (*omciPkt).Layer(omci.LayerTypeStartSoftwareDownloadResponse)
30 if msgLayer == nil {
31 t.Fatal("omci Msg layer could not be detected for StartSoftwareDownloadResponse")
32 }
33 msgObj, msgOk := msgLayer.(*omci.StartSoftwareDownloadResponse)
34 if !msgOk {
35 t.Fatal("omci Msg layer could not be assigned for StartSoftwareDownloadResponse")
36 }
37 return msgObj
38}
39
40func TestCreateStartSoftwareDownloadResponse(t *testing.T) {
41 omciReq := &omci.StartSoftwareDownloadRequest{
42 MeBasePacket: omci.MeBasePacket{
43 EntityClass: me.SoftwareImageClassID,
44 EntityInstance: 1,
45 },
46 ImageSize: 32768,
47 NumberOfCircuitPacks: 1,
48 WindowSize: 31,
49 CircuitPacks: []uint16{0},
50 }
51
52 omciReqPkt, err := Serialize(omci.StartSoftwareDownloadRequestType, omciReq, 66)
53 if err != nil {
54 t.Fatal(err.Error())
55 }
56
57 omciReqPkt, _ = HexEncode(omciReqPkt)
58
59 // start test
60 pkt, msg, _ := ParseOpenOltOmciPacket(omciReqPkt)
61 responsePkt, err := CreateStartSoftwareDownloadResponse(pkt, msg)
62 assert.NilError(t, err)
63
64 omciResponseMsg, omciResponsePkt := omciBytesToMsg(t, responsePkt)
65 assert.Equal(t, omciResponseMsg.MessageType, omci.StartSoftwareDownloadResponseType)
66
67 getResponseLayer := omciToStartSoftwareDownloadResponse(t, omciResponsePkt)
68
69 assert.Equal(t, getResponseLayer.Result, me.Success)
70}
71
72func TestComputeDownloadSectionsCount(t *testing.T) {
73 omciReq := &omci.StartSoftwareDownloadRequest{
74 MeBasePacket: omci.MeBasePacket{
75 EntityClass: me.SoftwareImageClassID,
76 EntityInstance: 1,
77 },
78 ImageSize: 32768,
79 NumberOfCircuitPacks: 1,
80 WindowSize: 31,
81 CircuitPacks: []uint16{0},
82 }
83
84 omciReqPkt, err := Serialize(omci.StartSoftwareDownloadRequestType, omciReq, 66)
85 if err != nil {
86 t.Fatal(err.Error())
87 }
88
89 omciReqPkt, _ = HexEncode(omciReqPkt)
90 pkt, _, _ := ParseOpenOltOmciPacket(omciReqPkt)
91
92 count := ComputeDownloadSectionsCount(pkt)
Holger Hildebrandt96382572022-05-31 09:41:38 +000093 assert.Equal(t, count, uint32(1058))
Matteo Scandolocedde462021-03-09 17:37:16 -080094}