blob: eb780d006621d87565a45fd7635c23cc21e8a59b [file] [log] [blame]
kdarapu891693b2019-09-16 12:33:49 +05301/*
Joey Armstrongf9bffdf2022-12-27 07:05:28 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
kdarapu891693b2019-09-16 12:33:49 +05303
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
sepon82ac7582023-06-12 21:05:41 +030017// Package mocks provides the mocks for openolt-adapter.
kdarapu891693b2019-09-16 12:33:49 +053018package mocks
19
20import (
21 "context"
22 "errors"
23 "io"
24
khenaidoo106c61a2021-08-11 18:05:46 -040025 config "github.com/opencord/voltha-protos/v5/go/ext/config"
khenaidoodc2116e2021-10-19 17:33:19 -040026 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo106c61a2021-08-11 18:05:46 -040027 openolt "github.com/opencord/voltha-protos/v5/go/openolt"
28 tech_profile "github.com/opencord/voltha-protos/v5/go/tech_profile"
kdarapu891693b2019-09-16 12:33:49 +053029 "google.golang.org/grpc"
30 "google.golang.org/grpc/metadata"
31)
32
33// MockOpenoltClient mock struct for OpenoltClient.
34type MockOpenoltClient struct {
Gamze Abakac2c32a62021-03-11 11:44:18 +000035 counter int
36 IsRestarted bool
kdarapu891693b2019-09-16 12:33:49 +053037}
38
39// DisableOlt mocks the DisableOlt function of Openoltclient.
40func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
41 //return &openolt.Empty{}, nil
42 if ooc.counter == 0 {
43 ooc.counter++
44 return &openolt.Empty{}, nil
45 }
46 return nil, errors.New("disableOlt failed")
47}
48
49// ReenableOlt mocks the ReenableOlt function of Openoltclient.
50func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
51 if ooc.counter == 0 {
52 ooc.counter++
53 return &openolt.Empty{}, nil
54 }
55 return nil, errors.New("reenable olt failed")
56}
57
58// ActivateOnu mocks the ActivateOnu function of Openoltclient.
59func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
60 if in == nil {
61 return nil, errors.New("invalid onuId")
62 }
63 return &openolt.Empty{}, nil
64}
65
66// DeactivateOnu mocks the DeactivateOnu function of Openoltclient.
67func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
68 return &openolt.Empty{}, nil
69}
70
71// DeleteOnu mocks the DeleteOnu function of Openoltclient.
72func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
73 return &openolt.Empty{}, nil
74}
75
76// OmciMsgOut mocks the OmciMsgOut function of Openoltclient.
77func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
78 if in == nil {
79 return nil, errors.New("invalid Omci Msg")
80 }
81 return &openolt.Empty{}, nil
82}
83
84// OnuPacketOut mocks the OnuPacketOut function of Openoltclient.
85func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
86 return &openolt.Empty{}, nil
87}
88
89// UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient.
90func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
91 return &openolt.Empty{}, nil
92}
93
94// FlowAdd mocks the FlowAdd function of Openoltclient.
95func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
96 return &openolt.Empty{}, nil
97}
98
99// FlowRemove mocks the FlowRemove function of Openoltclient.
100func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
101 return &openolt.Empty{}, nil
102}
103
104// HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient.
105func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
106 return nil, nil
107}
108
109// EnablePonIf mocks the EnablePonIf function of Openoltclient.
110func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
111 return &openolt.Empty{}, nil
112}
113
114// DisablePonIf mocks the DisablePonIf function of Openoltclient.
115func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
116 return &openolt.Empty{}, nil
117}
118
119// GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient.
120func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
121 if ooc.counter == 0 {
122 ooc.counter++
123 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"}
124 return deviceInfo, nil
125 }
126 if ooc.counter == 1 {
127 ooc.counter++
128 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"}
129 return deviceInfo, nil
130 }
131 if ooc.counter == 2 {
132 ooc.counter++
133 return nil, nil
134 }
135
136 return nil, errors.New("device info not found")
137}
138
139// Reboot mocks the Reboot function of Openoltclient.
140func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
141 if ooc.counter == 0 {
142 ooc.counter++
Gamze Abakac2c32a62021-03-11 11:44:18 +0000143 ooc.IsRestarted = true
kdarapu891693b2019-09-16 12:33:49 +0530144 return &openolt.Empty{}, nil
145 }
146 return nil, errors.New("reboot failed")
147}
148
149// CollectStatistics mocks the CollectStatistics function of Openoltclient.
150func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
151 return &openolt.Empty{}, nil
152}
153
154// CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient.
155func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
156 return &openolt.Empty{}, nil
157}
158
159// RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient.
160func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
161 return &openolt.Empty{}, nil
162}
163
164// CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient.
165func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
166 return &openolt.Empty{}, nil
167}
168
169// RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient.
170func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
171 return &openolt.Empty{}, nil
172}
173
Girish Gowdra631ef3d2020-06-15 10:45:52 -0700174// DeleteGroup mocks the DeleteGroup RPC of Openoltclient.
175func (ooc *MockOpenoltClient) DeleteGroup(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
176 return &openolt.Empty{}, nil
177}
178
179// GetLogicalOnuDistance mocks the GetLogicalOnuDistance RPC of Openoltclient.
180func (ooc *MockOpenoltClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
181 return &openolt.OnuLogicalDistance{}, nil
182}
183
184// GetLogicalOnuDistanceZero mocks the GetLogicalOnuDistanceZero RPC of Openoltclient.
185func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
186 return &openolt.OnuLogicalDistance{}, nil
187}
188
kdarapu891693b2019-09-16 12:33:49 +0530189// EnableIndication mocks the EnableIndication function of Openoltclient.
190func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
191 if ooc.counter < 2 {
192 ooc.counter++
193 mockInd := &mockOpenoltEnableIndicationClient{0}
194 return mockInd, nil
195 }
196 if ooc.counter == 2 {
197 ooc.counter++
198 return nil, nil
199 }
200 return nil, errors.New("invalid method invocation")
201}
202
203type mockOpenoltEnableIndicationClient struct {
204 count int
205}
206
207func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) {
208 if mock.count == 0 {
209 mock.count = mock.count + 1
210 indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}}
211 return indi, nil
212 }
213 if mock.count == 1 {
214 mock.count = mock.count + 1
215 return nil, errors.New("error, while processing indication")
216 }
217
218 return nil, io.EOF
219}
220
221func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
222 return nil, nil
223}
224
225func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
226 return nil
227}
228
229func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
230 return nil
231}
232
233func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
234 return context.Background()
235}
236
237func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
238 return nil
239}
240
241func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
242 return nil
243}
Esin Karamanccb714b2019-11-29 15:02:06 +0000244
Andrea Campanella9931ad62020-04-28 15:11:06 +0200245// GetExtValue mocks the GetExtValue function of Openoltclient.
khenaidoodc2116e2021-10-19 17:33:19 -0400246func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*extension.ReturnValues, error) {
247 return &extension.ReturnValues{}, nil
Andrea Campanella9931ad62020-04-28 15:11:06 +0200248}
249
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000250// OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient.
kesavand494c2082020-08-31 11:16:12 +0530251func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000252 return &openolt.Empty{}, nil
253}
254
Esin Karamanccb714b2019-11-29 15:02:06 +0000255// PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient.
256func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
257 return &openolt.Empty{}, nil
258}
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000259
sepon82ac7582023-06-12 21:05:41 +0300260// GetOnuStatistics mocks the GetOnuStatistics function of Openoltclient.
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000261func (ooc *MockOpenoltClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) {
262 return &openolt.OnuStatistics{}, nil
263}
264
sepon82ac7582023-06-12 21:05:41 +0300265// GetGemPortStatistics mocks the GetGemPortStatistics function of Openoltclient.
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000266func (ooc *MockOpenoltClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) {
267 return &openolt.GemPortStatistics{}, nil
268}
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530269
sepon82ac7582023-06-12 21:05:41 +0300270// GetPonRxPower mocks the GetPonRxPower function of Openoltclient.
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530271func (ooc *MockOpenoltClient) GetPonRxPower(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.PonRxPowerData, error) {
272 return &openolt.PonRxPowerData{}, nil
273}
sepon82ac7582023-06-12 21:05:41 +0300274
275// GetOnuInfo mocks the GetOnuInfo function of Openoltclient.
276func (ooc *MockOpenoltClient) GetOnuInfo(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuInfo, error) {
277 return &openolt.OnuInfo{}, nil
278}
279
280// GetPonInterfaceInfo mocks the GetPonInterfaceInfo function of Openoltclient.
281func (ooc *MockOpenoltClient) GetPonInterfaceInfo(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.PonIntfInfo, error) {
282 return &openolt.PonIntfInfo{}, nil
283}