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