blob: ad07eac1ff026c8ee7a20c6b6f0764ec46151aa1 [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 (
20 "github.com/google/gopacket"
21 "github.com/opencord/omci-lib-go"
22 me "github.com/opencord/omci-lib-go/generated"
23 "gotest.tools/assert"
24 "testing"
25)
26
27func omciToStartSoftwareDownloadResponse(t *testing.T, omciPkt *gopacket.Packet) *omci.StartSoftwareDownloadResponse {
28 msgLayer := (*omciPkt).Layer(omci.LayerTypeStartSoftwareDownloadResponse)
29 if msgLayer == nil {
30 t.Fatal("omci Msg layer could not be detected for StartSoftwareDownloadResponse")
31 }
32 msgObj, msgOk := msgLayer.(*omci.StartSoftwareDownloadResponse)
33 if !msgOk {
34 t.Fatal("omci Msg layer could not be assigned for StartSoftwareDownloadResponse")
35 }
36 return msgObj
37}
38
39func TestCreateStartSoftwareDownloadResponse(t *testing.T) {
40 omciReq := &omci.StartSoftwareDownloadRequest{
41 MeBasePacket: omci.MeBasePacket{
42 EntityClass: me.SoftwareImageClassID,
43 EntityInstance: 1,
44 },
45 ImageSize: 32768,
46 NumberOfCircuitPacks: 1,
47 WindowSize: 31,
48 CircuitPacks: []uint16{0},
49 }
50
51 omciReqPkt, err := Serialize(omci.StartSoftwareDownloadRequestType, omciReq, 66)
52 if err != nil {
53 t.Fatal(err.Error())
54 }
55
56 omciReqPkt, _ = HexEncode(omciReqPkt)
57
58 // start test
59 pkt, msg, _ := ParseOpenOltOmciPacket(omciReqPkt)
60 responsePkt, err := CreateStartSoftwareDownloadResponse(pkt, msg)
61 assert.NilError(t, err)
62
63 omciResponseMsg, omciResponsePkt := omciBytesToMsg(t, responsePkt)
64 assert.Equal(t, omciResponseMsg.MessageType, omci.StartSoftwareDownloadResponseType)
65
66 getResponseLayer := omciToStartSoftwareDownloadResponse(t, omciResponsePkt)
67
68 assert.Equal(t, getResponseLayer.Result, me.Success)
69}
70
71func TestComputeDownloadSectionsCount(t *testing.T) {
72 omciReq := &omci.StartSoftwareDownloadRequest{
73 MeBasePacket: omci.MeBasePacket{
74 EntityClass: me.SoftwareImageClassID,
75 EntityInstance: 1,
76 },
77 ImageSize: 32768,
78 NumberOfCircuitPacks: 1,
79 WindowSize: 31,
80 CircuitPacks: []uint16{0},
81 }
82
83 omciReqPkt, err := Serialize(omci.StartSoftwareDownloadRequestType, omciReq, 66)
84 if err != nil {
85 t.Fatal(err.Error())
86 }
87
88 omciReqPkt, _ = HexEncode(omciReqPkt)
89 pkt, _, _ := ParseOpenOltOmciPacket(omciReqPkt)
90
91 count := ComputeDownloadSectionsCount(pkt)
92 assert.Equal(t, count, 1058)
93}