blob: f47a514d1651760a6ebb9abd70c847402aa42124 [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 {
34 counter int
35}
36
37// DisableOlt mocks the DisableOlt function of Openoltclient.
38func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
39 //return &openolt.Empty{}, nil
40 if ooc.counter == 0 {
41 ooc.counter++
42 return &openolt.Empty{}, nil
43 }
44 return nil, errors.New("disableOlt failed")
45}
46
47// ReenableOlt mocks the ReenableOlt function of Openoltclient.
48func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
49 if ooc.counter == 0 {
50 ooc.counter++
51 return &openolt.Empty{}, nil
52 }
53 return nil, errors.New("reenable olt failed")
54}
55
56// ActivateOnu mocks the ActivateOnu function of Openoltclient.
57func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
58 if in == nil {
59 return nil, errors.New("invalid onuId")
60 }
61 return &openolt.Empty{}, nil
62}
63
64// DeactivateOnu mocks the DeactivateOnu function of Openoltclient.
65func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
66 return &openolt.Empty{}, nil
67}
68
69// DeleteOnu mocks the DeleteOnu function of Openoltclient.
70func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
71 return &openolt.Empty{}, nil
72}
73
74// OmciMsgOut mocks the OmciMsgOut function of Openoltclient.
75func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
76 if in == nil {
77 return nil, errors.New("invalid Omci Msg")
78 }
79 return &openolt.Empty{}, nil
80}
81
82// OnuPacketOut mocks the OnuPacketOut function of Openoltclient.
83func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
84 return &openolt.Empty{}, nil
85}
86
87// UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient.
88func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
89 return &openolt.Empty{}, nil
90}
91
92// FlowAdd mocks the FlowAdd function of Openoltclient.
93func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
94 return &openolt.Empty{}, nil
95}
96
97// FlowRemove mocks the FlowRemove function of Openoltclient.
98func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
99 return &openolt.Empty{}, nil
100}
101
102// HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient.
103func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
104 return nil, nil
105}
106
107// EnablePonIf mocks the EnablePonIf function of Openoltclient.
108func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
109 return &openolt.Empty{}, nil
110}
111
112// DisablePonIf mocks the DisablePonIf function of Openoltclient.
113func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
114 return &openolt.Empty{}, nil
115}
116
117// GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient.
118func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
119 if ooc.counter == 0 {
120 ooc.counter++
121 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"}
122 return deviceInfo, nil
123 }
124 if ooc.counter == 1 {
125 ooc.counter++
126 deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"}
127 return deviceInfo, nil
128 }
129 if ooc.counter == 2 {
130 ooc.counter++
131 return nil, nil
132 }
133
134 return nil, errors.New("device info not found")
135}
136
137// Reboot mocks the Reboot function of Openoltclient.
138func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
139 if ooc.counter == 0 {
140 ooc.counter++
141 return &openolt.Empty{}, nil
142 }
143 return nil, errors.New("reboot failed")
144}
145
146// CollectStatistics mocks the CollectStatistics function of Openoltclient.
147func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
148 return &openolt.Empty{}, nil
149}
150
151// CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient.
152func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
153 return &openolt.Empty{}, nil
154}
155
156// RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient.
157func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
158 return &openolt.Empty{}, nil
159}
160
161// CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient.
162func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
163 return &openolt.Empty{}, nil
164}
165
166// RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient.
167func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
168 return &openolt.Empty{}, nil
169}
170
Girish Gowdra631ef3d2020-06-15 10:45:52 -0700171// DeleteGroup mocks the DeleteGroup RPC of Openoltclient.
172func (ooc *MockOpenoltClient) DeleteGroup(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
173 return &openolt.Empty{}, nil
174}
175
176// GetLogicalOnuDistance mocks the GetLogicalOnuDistance RPC of Openoltclient.
177func (ooc *MockOpenoltClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
178 return &openolt.OnuLogicalDistance{}, nil
179}
180
181// GetLogicalOnuDistanceZero mocks the GetLogicalOnuDistanceZero RPC of Openoltclient.
182func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
183 return &openolt.OnuLogicalDistance{}, nil
184}
185
kdarapu891693b2019-09-16 12:33:49 +0530186// EnableIndication mocks the EnableIndication function of Openoltclient.
187func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
188 if ooc.counter < 2 {
189 ooc.counter++
190 mockInd := &mockOpenoltEnableIndicationClient{0}
191 return mockInd, nil
192 }
193 if ooc.counter == 2 {
194 ooc.counter++
195 return nil, nil
196 }
197 return nil, errors.New("invalid method invocation")
198}
199
200type mockOpenoltEnableIndicationClient struct {
201 count int
202}
203
204func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) {
205 if mock.count == 0 {
206 mock.count = mock.count + 1
207 indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}}
208 return indi, nil
209 }
210 if mock.count == 1 {
211 mock.count = mock.count + 1
212 return nil, errors.New("error, while processing indication")
213 }
214
215 return nil, io.EOF
216}
217
218func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
219 return nil, nil
220}
221
222func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
223 return nil
224}
225
226func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
227 return nil
228}
229
230func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
231 return context.Background()
232}
233
234func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
235 return nil
236}
237
238func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
239 return nil
240}
Esin Karamanccb714b2019-11-29 15:02:06 +0000241
Andrea Campanella9931ad62020-04-28 15:11:06 +0200242// GetExtValue mocks the GetExtValue function of Openoltclient.
243func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*openolt.ReturnValues, error) {
244 return &openolt.ReturnValues{}, nil
245}
246
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000247// OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient.
kesavand494c2082020-08-31 11:16:12 +0530248func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000249 return &openolt.Empty{}, nil
250}
251
Esin Karamanccb714b2019-11-29 15:02:06 +0000252// PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient.
253func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
254 return &openolt.Empty{}, nil
255}