blob: 1d48662cffd711801fae956b18457d372d538661 [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"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070022 omcilib "github.com/opencord/bbsim/internal/common/omci"
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000023 "time"
24
Matteo Scandolof9d43412021-01-12 11:11:34 -080025 "github.com/opencord/bbsim/internal/bbsim/types"
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070026 "github.com/opencord/voltha-protos/v4/go/common"
27 "github.com/opencord/voltha-protos/v4/go/ext/config"
Shrey Baid688b4242020-07-10 20:40:10 +053028
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070029 "github.com/opencord/voltha-protos/v4/go/openolt"
30 "github.com/opencord/voltha-protos/v4/go/tech_profile"
Matteo Scandolo99f18462019-10-28 14:14:28 -070031 "google.golang.org/grpc"
Matteo Scandolo99f18462019-10-28 14:14:28 -070032)
33
34type FlowAddSpy struct {
35 CallCount int
36 Calls map[int]*openolt.Flow
37}
38
39type mockClient struct {
40 FlowAddSpy
41 fail bool
42}
43
44func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
45 return nil, errors.New("unimplemented-in-mock-client")
46}
47func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
48 return nil, errors.New("unimplemented-in-mock-client")
49}
50func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
51 return nil, errors.New("unimplemented-in-mock-client")
52}
53func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
54 return nil, errors.New("unimplemented-in-mock-client")
55}
56func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
57 return nil, errors.New("unimplemented-in-mock-client")
58}
59func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
60 return nil, errors.New("unimplemented-in-mock-client")
61}
62func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
63 return nil, errors.New("unimplemented-in-mock-client")
64}
65func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
66 return nil, errors.New("unimplemented-in-mock-client")
67}
68func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
69 s.FlowAddSpy.CallCount++
70 if s.fail {
71 return nil, errors.New("fake-error")
72 }
73 s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in
74 return &openolt.Empty{}, nil
75}
76func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
77 return nil, errors.New("unimplemented-in-mock-client")
78}
79func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
80 return nil, errors.New("unimplemented-in-mock-client")
81}
82func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
83 return nil, errors.New("unimplemented-in-mock-client")
84}
85func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
86 return nil, errors.New("unimplemented-in-mock-client")
87}
88func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
89 return nil, errors.New("unimplemented-in-mock-client")
90}
91func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
92 return nil, errors.New("unimplemented-in-mock-client")
93}
94func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
95 return nil, errors.New("unimplemented-in-mock-client")
96}
97func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
98 return nil, errors.New("unimplemented-in-mock-client")
99}
100func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
101 return nil, errors.New("unimplemented-in-mock-client")
102}
103func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
104 return nil, errors.New("unimplemented-in-mock-client")
105}
106func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
107 return nil, errors.New("unimplemented-in-mock-client")
108}
109func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
110 return nil, errors.New("unimplemented-in-mock-client")
111}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700112func (s *mockClient) PerformGroupOperation(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
113 return nil, errors.New("unimplemented-in-mock-client")
114}
115func (s *mockClient) DeleteGroup(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
116 return nil, errors.New("unimplemented-in-mock-client")
117}
118func (s *mockClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*common.ReturnValues, error) {
119 return nil, errors.New("unimplemented-in-mock-client")
120}
121func (s *mockClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
122 return nil, errors.New("unimplemented-in-mock-client")
123}
124func (s *mockClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
125 return nil, errors.New("unimplemented-in-mock-client")
126}
127func (s *mockClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
128 return nil, errors.New("unimplemented-in-mock-client")
129}
Matteo Scandolo99f18462019-10-28 14:14:28 -0700130
Matteo Scandolo96f89192021-03-12 13:17:26 -0800131func (s *mockClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) {
132 return nil, errors.New("unimplemented-in-mock-client")
133}
134
135func (s *mockClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) {
136 return nil, errors.New("unimplemented-in-mock-client")
137}
138
Matteo Scandoloc1147092019-10-29 09:38:33 -0700139// this method creates a fake ONU used in the tests
Matteo Scandolo4a036262020-08-17 15:56:13 -0700140func createMockOnu(id uint32, ponPortId uint32) *Onu {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700141 o := Onu{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800142 ID: id,
143 PonPortID: ponPortId,
144 PortNo: 0,
Matteo Scandolo4a036262020-08-17 15:56:13 -0700145 PonPort: &PonPort{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800146 AllocatedGemPorts: make(map[uint16]*openolt.SerialNumber),
147 AllocatedAllocIds: make(map[uint16]*openolt.SerialNumber),
148 Olt: &OltDevice{},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700149 },
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000150 OmciResponseRate: 10,
151 OmciMsgCounter: 0,
Matteo Scandolo99f18462019-10-28 14:14:28 -0700152 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800153 o.SerialNumber = NewSN(0, ponPortId, o.ID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800154 o.Channel = make(chan types.Message, 10)
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700155
156 unis := []*UniPort{
157 {ID: 0, Onu: &o, MeId: omcilib.GenerateUniPortEntityId(1)},
158 {ID: 1, Onu: &o, MeId: omcilib.GenerateUniPortEntityId(2)},
159 {ID: 2, Onu: &o, MeId: omcilib.GenerateUniPortEntityId(3)},
160 {ID: 3, Onu: &o, MeId: omcilib.GenerateUniPortEntityId(4)},
161 }
162
163 o.UniPorts = unis
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800164 return &o
Matteo Scandolo99f18462019-10-28 14:14:28 -0700165}
Matteo Scandoloc1147092019-10-29 09:38:33 -0700166
167// this method creates a real ONU to be used in the tests
168func createTestOnu() *Onu {
169 olt := OltDevice{
Andrea Campanellabe1b7cf2021-04-30 09:53:40 +0200170 ID: 0,
171 OmciResponseRate: 10,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700172 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800173
174 pon := CreatePonPort(&olt, 1)
175
176 onu := CreateONU(&olt, pon, 1, time.Duration(1*time.Millisecond), true)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100177 // NOTE we need this in order to create the OnuChannel
Matteo Scandolocedde462021-03-09 17:37:16 -0800178 _ = onu.InternalState.Event(OnuTxInitialize)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800179 onu.DiscoveryRetryDelay = 100 * time.Millisecond
Matteo Scandoloc1147092019-10-29 09:38:33 -0700180 return onu
181}