blob: 992d3665f76c65466a5b64dd1cd31c748df75e21 [file] [log] [blame]
kdarapu891693b2019-09-16 12:33:49 +05301/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002 * Copyright 2018-2024 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
Akash Reddy Kankanalac6b6ca12025-06-12 14:26:57 +053025 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo106c61a2021-08-11 18:05:46 -040026 config "github.com/opencord/voltha-protos/v5/go/ext/config"
khenaidoodc2116e2021-10-19 17:33:19 -040027 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo106c61a2021-08-11 18:05:46 -040028 openolt "github.com/opencord/voltha-protos/v5/go/openolt"
29 tech_profile "github.com/opencord/voltha-protos/v5/go/tech_profile"
kdarapu891693b2019-09-16 12:33:49 +053030 "google.golang.org/grpc"
31 "google.golang.org/grpc/metadata"
32)
33
34// MockOpenoltClient mock struct for OpenoltClient.
35type MockOpenoltClient struct {
Gamze Abakac2c32a62021-03-11 11:44:18 +000036 counter int
37 IsRestarted bool
kdarapu891693b2019-09-16 12:33:49 +053038}
39
40// DisableOlt mocks the DisableOlt function of Openoltclient.
41func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
Akash Kankanala041a2122024-10-16 15:49:22 +053042 // return &openolt.Empty{}, nil
kdarapu891693b2019-09-16 12:33:49 +053043 if ooc.counter == 0 {
44 ooc.counter++
45 return &openolt.Empty{}, nil
46 }
47 return nil, errors.New("disableOlt failed")
48}
49
50// ReenableOlt mocks the ReenableOlt function of Openoltclient.
51func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
52 if ooc.counter == 0 {
53 ooc.counter++
54 return &openolt.Empty{}, nil
55 }
56 return nil, errors.New("reenable olt failed")
57}
58
59// ActivateOnu mocks the ActivateOnu function of Openoltclient.
60func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
61 if in == nil {
62 return nil, errors.New("invalid onuId")
63 }
64 return &openolt.Empty{}, nil
65}
66
67// DeactivateOnu mocks the DeactivateOnu function of Openoltclient.
68func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
69 return &openolt.Empty{}, nil
70}
71
72// DeleteOnu mocks the DeleteOnu function of Openoltclient.
73func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
74 return &openolt.Empty{}, nil
75}
76
77// OmciMsgOut mocks the OmciMsgOut function of Openoltclient.
78func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
79 if in == nil {
80 return nil, errors.New("invalid Omci Msg")
81 }
82 return &openolt.Empty{}, nil
83}
84
85// OnuPacketOut mocks the OnuPacketOut function of Openoltclient.
86func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
87 return &openolt.Empty{}, nil
88}
89
90// UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient.
91func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
92 return &openolt.Empty{}, nil
93}
94
95// FlowAdd mocks the FlowAdd function of Openoltclient.
96func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
97 return &openolt.Empty{}, nil
98}
99
100// FlowRemove mocks the FlowRemove function of Openoltclient.
101func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
102 return &openolt.Empty{}, nil
103}
104
105// HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient.
106func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
107 return nil, nil
108}
109
110// EnablePonIf mocks the EnablePonIf function of Openoltclient.
111func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
112 return &openolt.Empty{}, nil
113}
114
115// DisablePonIf mocks the DisablePonIf function of Openoltclient.
116func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
117 return &openolt.Empty{}, nil
118}
119
120// GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient.
121func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
122 if ooc.counter == 0 {
123 ooc.counter++
124 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"}
125 return deviceInfo, nil
126 }
127 if ooc.counter == 1 {
128 ooc.counter++
129 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"}
130 return deviceInfo, nil
131 }
132 if ooc.counter == 2 {
133 ooc.counter++
134 return nil, nil
135 }
136
137 return nil, errors.New("device info not found")
138}
139
140// Reboot mocks the Reboot function of Openoltclient.
141func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
142 if ooc.counter == 0 {
143 ooc.counter++
Gamze Abakac2c32a62021-03-11 11:44:18 +0000144 ooc.IsRestarted = true
kdarapu891693b2019-09-16 12:33:49 +0530145 return &openolt.Empty{}, nil
146 }
147 return nil, errors.New("reboot failed")
148}
149
150// CollectStatistics mocks the CollectStatistics function of Openoltclient.
151func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
152 return &openolt.Empty{}, nil
153}
154
155// CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient.
156func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
157 return &openolt.Empty{}, nil
158}
159
160// RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient.
161func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
162 return &openolt.Empty{}, nil
163}
164
165// CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient.
166func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
167 return &openolt.Empty{}, nil
168}
169
170// RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient.
171func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
172 return &openolt.Empty{}, nil
173}
174
Girish Gowdra631ef3d2020-06-15 10:45:52 -0700175// DeleteGroup mocks the DeleteGroup RPC of Openoltclient.
176func (ooc *MockOpenoltClient) DeleteGroup(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
177 return &openolt.Empty{}, nil
178}
179
180// GetLogicalOnuDistance mocks the GetLogicalOnuDistance RPC of Openoltclient.
181func (ooc *MockOpenoltClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
182 return &openolt.OnuLogicalDistance{}, nil
183}
184
185// GetLogicalOnuDistanceZero mocks the GetLogicalOnuDistanceZero RPC of Openoltclient.
186func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
187 return &openolt.OnuLogicalDistance{}, nil
188}
189
kdarapu891693b2019-09-16 12:33:49 +0530190// EnableIndication mocks the EnableIndication function of Openoltclient.
191func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
192 if ooc.counter < 2 {
193 ooc.counter++
194 mockInd := &mockOpenoltEnableIndicationClient{0}
195 return mockInd, nil
196 }
197 if ooc.counter == 2 {
198 ooc.counter++
199 return nil, nil
200 }
201 return nil, errors.New("invalid method invocation")
202}
203
204type mockOpenoltEnableIndicationClient struct {
205 count int
206}
207
208func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) {
209 if mock.count == 0 {
Akash Kankanala041a2122024-10-16 15:49:22 +0530210 mock.count++
kdarapu891693b2019-09-16 12:33:49 +0530211 indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}}
212 return indi, nil
213 }
214 if mock.count == 1 {
Akash Kankanala041a2122024-10-16 15:49:22 +0530215 mock.count++
kdarapu891693b2019-09-16 12:33:49 +0530216 return nil, errors.New("error, while processing indication")
217 }
218
219 return nil, io.EOF
220}
221
222func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
223 return nil, nil
224}
225
226func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
227 return nil
228}
229
230func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
231 return nil
232}
233
234func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
235 return context.Background()
236}
237
238func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
239 return nil
240}
241
242func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
243 return nil
244}
Esin Karamanccb714b2019-11-29 15:02:06 +0000245
Andrea Campanella9931ad62020-04-28 15:11:06 +0200246// GetExtValue mocks the GetExtValue function of Openoltclient.
khenaidoodc2116e2021-10-19 17:33:19 -0400247func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*extension.ReturnValues, error) {
248 return &extension.ReturnValues{}, nil
Andrea Campanella9931ad62020-04-28 15:11:06 +0200249}
250
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000251// OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient.
kesavand494c2082020-08-31 11:16:12 +0530252func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000253 return &openolt.Empty{}, nil
254}
255
Esin Karamanccb714b2019-11-29 15:02:06 +0000256// PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient.
257func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
258 return &openolt.Empty{}, nil
259}
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000260
sepon82ac7582023-06-12 21:05:41 +0300261// GetOnuStatistics mocks the GetOnuStatistics function of Openoltclient.
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000262func (ooc *MockOpenoltClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) {
263 return &openolt.OnuStatistics{}, nil
264}
265
sepon82ac7582023-06-12 21:05:41 +0300266// GetGemPortStatistics mocks the GetGemPortStatistics function of Openoltclient.
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000267func (ooc *MockOpenoltClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) {
268 return &openolt.GemPortStatistics{}, nil
269}
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530270
sepon82ac7582023-06-12 21:05:41 +0300271// GetPonRxPower mocks the GetPonRxPower function of Openoltclient.
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530272func (ooc *MockOpenoltClient) GetPonRxPower(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.PonRxPowerData, error) {
273 return &openolt.PonRxPowerData{}, nil
274}
sepon82ac7582023-06-12 21:05:41 +0300275
276// GetOnuInfo mocks the GetOnuInfo function of Openoltclient.
277func (ooc *MockOpenoltClient) GetOnuInfo(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuInfo, error) {
278 return &openolt.OnuInfo{}, nil
279}
280
281// GetPonInterfaceInfo mocks the GetPonInterfaceInfo function of Openoltclient.
282func (ooc *MockOpenoltClient) GetPonInterfaceInfo(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.PonIntfInfo, error) {
283 return &openolt.PonIntfInfo{}, nil
284}
Akash Reddy Kankanalac6b6ca12025-06-12 14:26:57 +0530285
286// GetAllocIdStatistics mocks base method.
287func (m *MockOpenoltClient) GetAllocIdStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.OnuAllocIdStatistics, error) {
288 return &openolt.OnuAllocIdStatistics{}, nil
289}
290
291// GetNniPortStatistics mocks base method.
292func (m *MockOpenoltClient) GetNniPortStatistics(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*common.PortStatistics, error) {
293 return &common.PortStatistics{}, nil
294}
295
296// GetPonPortStatistics mocks base method.
297func (m *MockOpenoltClient) GetPonPortStatistics(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*common.PortStatistics, error) {
298 return &common.PortStatistics{}, nil
299}