blob: cbd64ff477c7f1c06afd324a4cebfc9058023630 [file] [log] [blame]
Matteo Scandolo4b077aa2021-02-16 17:33:37 -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 (
Elia Battiston9bfe1102022-02-03 10:38:03 +010020 "testing"
21
Matteo Scandolo4b077aa2021-02-16 17:33:37 -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 Scandolo4b077aa2021-02-16 17:33:37 -080025 "gotest.tools/assert"
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080026)
27
28func omciToCreateResponse(t *testing.T, omciPkt *gopacket.Packet) *omci.CreateResponse {
29 msgLayer := (*omciPkt).Layer(omci.LayerTypeCreateResponse)
30 if msgLayer == nil {
31 t.Fatal("omci Msg layer could not be detected for CreateResponse - handling of MibSyncChan stopped")
32 }
33 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
34 if !msgOk {
35 t.Fatal("omci Msg layer could not be assigned for CreateResponse - handling of MibSyncChan stopped")
36 }
37 return msgObj
38}
39
40type createArgs struct {
41 omciPkt []byte
42 result me.Results
43}
44
45type createWant struct {
46 result me.Results
47}
48
49func TestCreateResponse(t *testing.T) {
50
51 // generate a CreateRequest packet to create a GemPort
52 omciReq := &omci.CreateRequest{
53 MeBasePacket: omci.MeBasePacket{
54 EntityClass: me.GemPortNetworkCtpClassID,
55 EntityInstance: 12,
56 },
57 Attributes: me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +010058 me.GemPortNetworkCtp_PortId: 0,
59 me.GemPortNetworkCtp_TContPointer: 0,
60 me.GemPortNetworkCtp_Direction: 0,
61 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: 0,
62 me.GemPortNetworkCtp_TrafficDescriptorProfilePointerForUpstream: 0,
63 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: 0,
64 me.GemPortNetworkCtp_TrafficDescriptorProfilePointerForDownstream: 0,
65 me.GemPortNetworkCtp_EncryptionKeyRing: 0,
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080066 },
67 }
68 omciPkt, err := Serialize(omci.CreateRequestType, omciReq, 66)
69 if err != nil {
70 t.Fatal(err.Error())
71 }
72
73 omciPkt, _ = HexEncode(omciPkt)
74
75 tests := []struct {
76 name string
77 args createArgs
78 want createWant
79 }{
80 {"createSuccess",
81 createArgs{omciPkt, me.Success},
82 createWant{me.Success},
83 },
84 {"createProcessingError",
85 createArgs{omciPkt, me.ProcessingError},
86 createWant{me.ProcessingError},
87 },
88 }
89 for _, tt := range tests {
90 t.Run(tt.name, func(t *testing.T) {
91 pkt, msg, _ := ParseOpenOltOmciPacket(tt.args.omciPkt)
92 requestPkt, _ := CreateCreateResponse(pkt, msg, tt.args.result)
93
94 omciMsg, omciPkt := omciBytesToMsg(t, requestPkt)
95
96 assert.Equal(t, omciMsg.MessageType, omci.CreateResponseType)
97
98 getResponseLayer := omciToCreateResponse(t, omciPkt)
99
100 assert.Equal(t, getResponseLayer.Result, tt.want.result)
101
102 })
103 }
104}