blob: 89babc5788d513179dad0010418ff22f5f9961f2 [file] [log] [blame]
kdarapu891693b2019-09-16 12:33:49 +05301/*
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
17//Package mocks provides the mocks for openolt-adapter.
18package mocks
19
20import (
21 "context"
22 "errors"
23 "io"
24
Girish Gowdraa09aeab2020-09-14 16:30:52 -070025 config "github.com/opencord/voltha-protos/v4/go/ext/config"
26 openolt "github.com/opencord/voltha-protos/v4/go/openolt"
27 tech_profile "github.com/opencord/voltha-protos/v4/go/tech_profile"
kdarapu891693b2019-09-16 12:33:49 +053028 "google.golang.org/grpc"
29 "google.golang.org/grpc/metadata"
30)
31
32// MockOpenoltClient mock struct for OpenoltClient.
33type MockOpenoltClient struct {
Gamze Abakac2c32a62021-03-11 11:44:18 +000034 counter int
35 IsRestarted bool
kdarapu891693b2019-09-16 12:33:49 +053036}
37
38// DisableOlt mocks the DisableOlt function of Openoltclient.
39func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
40 //return &openolt.Empty{}, nil
41 if ooc.counter == 0 {
42 ooc.counter++
43 return &openolt.Empty{}, nil
44 }
45 return nil, errors.New("disableOlt failed")
46}
47
48// ReenableOlt mocks the ReenableOlt function of Openoltclient.
49func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
50 if ooc.counter == 0 {
51 ooc.counter++
52 return &openolt.Empty{}, nil
53 }
54 return nil, errors.New("reenable olt failed")
55}
56
57// ActivateOnu mocks the ActivateOnu function of Openoltclient.
58func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
59 if in == nil {
60 return nil, errors.New("invalid onuId")
61 }
62 return &openolt.Empty{}, nil
63}
64
65// DeactivateOnu mocks the DeactivateOnu function of Openoltclient.
66func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
67 return &openolt.Empty{}, nil
68}
69
70// DeleteOnu mocks the DeleteOnu function of Openoltclient.
71func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
72 return &openolt.Empty{}, nil
73}
74
75// OmciMsgOut mocks the OmciMsgOut function of Openoltclient.
76func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
77 if in == nil {
78 return nil, errors.New("invalid Omci Msg")
79 }
80 return &openolt.Empty{}, nil
81}
82
83// OnuPacketOut mocks the OnuPacketOut function of Openoltclient.
84func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
85 return &openolt.Empty{}, nil
86}
87
88// UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient.
89func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
90 return &openolt.Empty{}, nil
91}
92
93// FlowAdd mocks the FlowAdd function of Openoltclient.
94func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
95 return &openolt.Empty{}, nil
96}
97
98// FlowRemove mocks the FlowRemove function of Openoltclient.
99func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
100 return &openolt.Empty{}, nil
101}
102
103// HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient.
104func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
105 return nil, nil
106}
107
108// EnablePonIf mocks the EnablePonIf function of Openoltclient.
109func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
110 return &openolt.Empty{}, nil
111}
112
113// DisablePonIf mocks the DisablePonIf function of Openoltclient.
114func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
115 return &openolt.Empty{}, nil
116}
117
118// GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient.
119func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
120 if ooc.counter == 0 {
121 ooc.counter++
122 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"}
123 return deviceInfo, nil
124 }
125 if ooc.counter == 1 {
126 ooc.counter++
127 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"}
128 return deviceInfo, nil
129 }
130 if ooc.counter == 2 {
131 ooc.counter++
132 return nil, nil
133 }
134
135 return nil, errors.New("device info not found")
136}
137
138// Reboot mocks the Reboot function of Openoltclient.
139func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
140 if ooc.counter == 0 {
141 ooc.counter++
Gamze Abakac2c32a62021-03-11 11:44:18 +0000142 ooc.IsRestarted = true
kdarapu891693b2019-09-16 12:33:49 +0530143 return &openolt.Empty{}, nil
144 }
145 return nil, errors.New("reboot failed")
146}
147
148// CollectStatistics mocks the CollectStatistics function of Openoltclient.
149func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
150 return &openolt.Empty{}, nil
151}
152
153// CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient.
154func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
155 return &openolt.Empty{}, nil
156}
157
158// RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient.
159func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
160 return &openolt.Empty{}, nil
161}
162
163// CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient.
164func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
165 return &openolt.Empty{}, nil
166}
167
168// RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient.
169func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
170 return &openolt.Empty{}, nil
171}
172
Girish Gowdra631ef3d2020-06-15 10:45:52 -0700173// DeleteGroup mocks the DeleteGroup RPC of Openoltclient.
174func (ooc *MockOpenoltClient) DeleteGroup(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
175 return &openolt.Empty{}, nil
176}
177
178// GetLogicalOnuDistance mocks the GetLogicalOnuDistance RPC of Openoltclient.
179func (ooc *MockOpenoltClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
180 return &openolt.OnuLogicalDistance{}, nil
181}
182
183// GetLogicalOnuDistanceZero mocks the GetLogicalOnuDistanceZero RPC of Openoltclient.
184func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
185 return &openolt.OnuLogicalDistance{}, nil
186}
187
kdarapu891693b2019-09-16 12:33:49 +0530188// EnableIndication mocks the EnableIndication function of Openoltclient.
189func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
190 if ooc.counter < 2 {
191 ooc.counter++
192 mockInd := &mockOpenoltEnableIndicationClient{0}
193 return mockInd, nil
194 }
195 if ooc.counter == 2 {
196 ooc.counter++
197 return nil, nil
198 }
199 return nil, errors.New("invalid method invocation")
200}
201
202type mockOpenoltEnableIndicationClient struct {
203 count int
204}
205
206func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) {
207 if mock.count == 0 {
208 mock.count = mock.count + 1
209 indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}}
210 return indi, nil
211 }
212 if mock.count == 1 {
213 mock.count = mock.count + 1
214 return nil, errors.New("error, while processing indication")
215 }
216
217 return nil, io.EOF
218}
219
220func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
221 return nil, nil
222}
223
224func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
225 return nil
226}
227
228func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
229 return nil
230}
231
232func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
233 return context.Background()
234}
235
236func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
237 return nil
238}
239
240func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
241 return nil
242}
Esin Karamanccb714b2019-11-29 15:02:06 +0000243
Andrea Campanella9931ad62020-04-28 15:11:06 +0200244// GetExtValue mocks the GetExtValue function of Openoltclient.
245func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*openolt.ReturnValues, error) {
246 return &openolt.ReturnValues{}, nil
247}
248
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000249// OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient.
kesavand494c2082020-08-31 11:16:12 +0530250func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000251 return &openolt.Empty{}, nil
252}
253
Esin Karamanccb714b2019-11-29 15:02:06 +0000254// PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient.
255func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
256 return &openolt.Empty{}, nil
257}
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000258
259//GetOnuStatistics mocks the GetOnuStatistics function of Openoltclient.
260func (ooc *MockOpenoltClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) {
261 return &openolt.OnuStatistics{}, nil
262}
263
264//GetGemPortStatistics mocks the GetGemPortStatistics function of Openoltclient.
265func (ooc *MockOpenoltClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) {
266 return &openolt.GemPortStatistics{}, nil
267}
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530268
269//GetPonRxPower mocks the GetPonRxPower function of Openoltclient.
270func (ooc *MockOpenoltClient) GetPonRxPower(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.PonRxPowerData, error) {
271 return &openolt.PonRxPowerData{}, nil
272}