Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | 2c03936 | 2024-02-04 18:51:52 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 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 | |
| 17 | package omci |
| 18 | |
| 19 | import ( |
Holger Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 20 | "testing" |
| 21 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 22 | "github.com/google/gopacket" |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 23 | "github.com/opencord/omci-lib-go/v2" |
| 24 | me "github.com/opencord/omci-lib-go/v2/generated" |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 25 | "gotest.tools/assert" |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func 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 | |
| 40 | func 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 | |
| 72 | func 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 Hildebrandt | 9638257 | 2022-05-31 09:41:38 +0000 | [diff] [blame] | 93 | assert.Equal(t, count, uint32(1058)) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 94 | } |