blob: e441e73ffd3b0223015f5e10b3c27941008eb4ca [file] [log] [blame]
Matteo Scandolo99f18462019-10-28 14:14:28 -07001/*
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 devices
18
19import (
20 "context"
21 "errors"
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000022 "time"
23
Matteo Scandolof9d43412021-01-12 11:11:34 -080024 "github.com/opencord/bbsim/internal/bbsim/types"
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070025 "github.com/opencord/voltha-protos/v4/go/common"
26 "github.com/opencord/voltha-protos/v4/go/ext/config"
Shrey Baid688b4242020-07-10 20:40:10 +053027
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070028 "github.com/opencord/voltha-protos/v4/go/openolt"
29 "github.com/opencord/voltha-protos/v4/go/tech_profile"
Matteo Scandolo99f18462019-10-28 14:14:28 -070030 "google.golang.org/grpc"
Matteo Scandolo99f18462019-10-28 14:14:28 -070031)
32
33type FlowAddSpy struct {
34 CallCount int
35 Calls map[int]*openolt.Flow
36}
37
38type mockClient struct {
39 FlowAddSpy
40 fail bool
41}
42
43func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
44 return nil, errors.New("unimplemented-in-mock-client")
45}
46func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
47 return nil, errors.New("unimplemented-in-mock-client")
48}
49func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
50 return nil, errors.New("unimplemented-in-mock-client")
51}
52func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
53 return nil, errors.New("unimplemented-in-mock-client")
54}
55func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
56 return nil, errors.New("unimplemented-in-mock-client")
57}
58func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
59 return nil, errors.New("unimplemented-in-mock-client")
60}
61func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
62 return nil, errors.New("unimplemented-in-mock-client")
63}
64func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
65 return nil, errors.New("unimplemented-in-mock-client")
66}
67func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
68 s.FlowAddSpy.CallCount++
69 if s.fail {
70 return nil, errors.New("fake-error")
71 }
72 s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in
73 return &openolt.Empty{}, nil
74}
75func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
76 return nil, errors.New("unimplemented-in-mock-client")
77}
78func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
79 return nil, errors.New("unimplemented-in-mock-client")
80}
81func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
82 return nil, errors.New("unimplemented-in-mock-client")
83}
84func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
85 return nil, errors.New("unimplemented-in-mock-client")
86}
87func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
88 return nil, errors.New("unimplemented-in-mock-client")
89}
90func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
91 return nil, errors.New("unimplemented-in-mock-client")
92}
93func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
94 return nil, errors.New("unimplemented-in-mock-client")
95}
96func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
97 return nil, errors.New("unimplemented-in-mock-client")
98}
99func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
100 return nil, errors.New("unimplemented-in-mock-client")
101}
102func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
103 return nil, errors.New("unimplemented-in-mock-client")
104}
105func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
106 return nil, errors.New("unimplemented-in-mock-client")
107}
108func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
109 return nil, errors.New("unimplemented-in-mock-client")
110}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700111func (s *mockClient) PerformGroupOperation(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
112 return nil, errors.New("unimplemented-in-mock-client")
113}
114func (s *mockClient) DeleteGroup(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
115 return nil, errors.New("unimplemented-in-mock-client")
116}
117func (s *mockClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*common.ReturnValues, error) {
118 return nil, errors.New("unimplemented-in-mock-client")
119}
120func (s *mockClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
121 return nil, errors.New("unimplemented-in-mock-client")
122}
123func (s *mockClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
124 return nil, errors.New("unimplemented-in-mock-client")
125}
126func (s *mockClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
127 return nil, errors.New("unimplemented-in-mock-client")
128}
Matteo Scandolo99f18462019-10-28 14:14:28 -0700129
Matteo Scandolo96f89192021-03-12 13:17:26 -0800130func (s *mockClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) {
131 return nil, errors.New("unimplemented-in-mock-client")
132}
133
134func (s *mockClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) {
135 return nil, errors.New("unimplemented-in-mock-client")
136}
137
Matteo Scandoloc1147092019-10-29 09:38:33 -0700138// this method creates a fake ONU used in the tests
Matteo Scandolo4a036262020-08-17 15:56:13 -0700139func createMockOnu(id uint32, ponPortId uint32) *Onu {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700140 o := Onu{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800141 ID: id,
142 PonPortID: ponPortId,
143 PortNo: 0,
Matteo Scandolo4a036262020-08-17 15:56:13 -0700144 PonPort: &PonPort{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800145 AllocatedGemPorts: make(map[uint16]*openolt.SerialNumber),
146 AllocatedAllocIds: make(map[uint16]*openolt.SerialNumber),
147 Olt: &OltDevice{},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700148 },
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000149 OmciResponseRate: 10,
150 OmciMsgCounter: 0,
Matteo Scandolo99f18462019-10-28 14:14:28 -0700151 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800152 o.SerialNumber = NewSN(0, ponPortId, o.ID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800153 o.Channel = make(chan types.Message, 10)
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800154 return &o
Matteo Scandolo99f18462019-10-28 14:14:28 -0700155}
Matteo Scandoloc1147092019-10-29 09:38:33 -0700156
157// this method creates a real ONU to be used in the tests
158func createTestOnu() *Onu {
159 olt := OltDevice{
160 ID: 0,
161 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800162
163 pon := CreatePonPort(&olt, 1)
164
165 onu := CreateONU(&olt, pon, 1, time.Duration(1*time.Millisecond), true)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100166 // NOTE we need this in order to create the OnuChannel
Matteo Scandolocedde462021-03-09 17:37:16 -0800167 _ = onu.InternalState.Event(OnuTxInitialize)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800168 onu.DiscoveryRetryDelay = 100 * time.Millisecond
Matteo Scandoloc1147092019-10-29 09:38:33 -0700169 return onu
170}