blob: 287b3a93de497888ac30a1cc0407bcedbcb684c8 [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"
Elia Battistonb7bea222022-02-18 16:25:00 +010022 "time"
23
Matteo Scandolo8a574812021-05-20 15:18:53 -070024 bbsim_common "github.com/opencord/bbsim/internal/common"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070025 omcilib "github.com/opencord/bbsim/internal/common/omci"
Matteo Scandolo1f9f4b22021-12-14 11:51:55 -080026 "github.com/opencord/voltha-protos/v5/go/extension"
Matteo Scandolo8a574812021-05-20 15:18:53 -070027 log "github.com/sirupsen/logrus"
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000028
Matteo Scandolof9d43412021-01-12 11:11:34 -080029 "github.com/opencord/bbsim/internal/bbsim/types"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000030 "github.com/opencord/voltha-protos/v5/go/ext/config"
Shrey Baid688b4242020-07-10 20:40:10 +053031
David K. Bainbridgec415efe2021-08-19 13:05:21 +000032 "github.com/opencord/voltha-protos/v5/go/openolt"
33 "github.com/opencord/voltha-protos/v5/go/tech_profile"
Matteo Scandolo99f18462019-10-28 14:14:28 -070034 "google.golang.org/grpc"
Matteo Scandolo99f18462019-10-28 14:14:28 -070035)
36
Matteo Scandolo8a574812021-05-20 15:18:53 -070037func init() {
38 bbsim_common.SetLogLevel(log.StandardLogger(), "error", false)
39}
40
Matteo Scandolo99f18462019-10-28 14:14:28 -070041type FlowAddSpy struct {
42 CallCount int
43 Calls map[int]*openolt.Flow
44}
45
46type mockClient struct {
47 FlowAddSpy
48 fail bool
49}
50
51func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
52 return nil, errors.New("unimplemented-in-mock-client")
53}
54func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
55 return nil, errors.New("unimplemented-in-mock-client")
56}
57func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
58 return nil, errors.New("unimplemented-in-mock-client")
59}
60func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
61 return nil, errors.New("unimplemented-in-mock-client")
62}
63func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
64 return nil, errors.New("unimplemented-in-mock-client")
65}
66func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
67 return nil, errors.New("unimplemented-in-mock-client")
68}
69func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
70 return nil, errors.New("unimplemented-in-mock-client")
71}
72func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
73 return nil, errors.New("unimplemented-in-mock-client")
74}
75func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
76 s.FlowAddSpy.CallCount++
77 if s.fail {
78 return nil, errors.New("fake-error")
79 }
80 s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in
81 return &openolt.Empty{}, nil
82}
83func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
84 return nil, errors.New("unimplemented-in-mock-client")
85}
86func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
87 return nil, errors.New("unimplemented-in-mock-client")
88}
89func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
90 return nil, errors.New("unimplemented-in-mock-client")
91}
92func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
93 return nil, errors.New("unimplemented-in-mock-client")
94}
95func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
96 return nil, errors.New("unimplemented-in-mock-client")
97}
98func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
99 return nil, errors.New("unimplemented-in-mock-client")
100}
101func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
102 return nil, errors.New("unimplemented-in-mock-client")
103}
104func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
105 return nil, errors.New("unimplemented-in-mock-client")
106}
107func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
108 return nil, errors.New("unimplemented-in-mock-client")
109}
110func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
111 return nil, errors.New("unimplemented-in-mock-client")
112}
113func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
114 return nil, errors.New("unimplemented-in-mock-client")
115}
116func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
117 return nil, errors.New("unimplemented-in-mock-client")
118}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700119func (s *mockClient) PerformGroupOperation(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
120 return nil, errors.New("unimplemented-in-mock-client")
121}
122func (s *mockClient) DeleteGroup(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
123 return nil, errors.New("unimplemented-in-mock-client")
124}
Matteo Scandolo1f9f4b22021-12-14 11:51:55 -0800125func (s *mockClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*extension.ReturnValues, error) {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700126 return nil, errors.New("unimplemented-in-mock-client")
127}
128func (s *mockClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
129 return nil, errors.New("unimplemented-in-mock-client")
130}
131func (s *mockClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
132 return nil, errors.New("unimplemented-in-mock-client")
133}
134func (s *mockClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
135 return nil, errors.New("unimplemented-in-mock-client")
136}
Matteo Scandolo99f18462019-10-28 14:14:28 -0700137
Matteo Scandolo96f89192021-03-12 13:17:26 -0800138func (s *mockClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) {
139 return nil, errors.New("unimplemented-in-mock-client")
140}
141
142func (s *mockClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) {
143 return nil, errors.New("unimplemented-in-mock-client")
144}
145
Girish Gowdra62f24292021-05-12 16:28:39 -0700146func (s *mockClient) GetPonRxPower(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.PonRxPowerData, error) {
147 return nil, errors.New("unimplemented-in-mock-client")
148}
149
Matteo Scandoloc1147092019-10-29 09:38:33 -0700150// this method creates a fake ONU used in the tests
Matteo Scandolo4a036262020-08-17 15:56:13 -0700151func createMockOnu(id uint32, ponPortId uint32) *Onu {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700152 o := Onu{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800153 ID: id,
154 PonPortID: ponPortId,
Matteo Scandolo4a036262020-08-17 15:56:13 -0700155 PonPort: &PonPort{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800156 AllocatedGemPorts: make(map[uint16]*openolt.SerialNumber),
Girish Gowdra574834a2022-02-04 15:15:15 -0800157 AllocatedAllocIds: make(map[AllocIDKey]*AllocIDVal),
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800158 Olt: &OltDevice{},
Matteo Scandolo4a036262020-08-17 15:56:13 -0700159 },
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000160 OmciResponseRate: 10,
161 OmciMsgCounter: 0,
Matteo Scandolo99f18462019-10-28 14:14:28 -0700162 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800163 o.SerialNumber = NewSN(0, ponPortId, o.ID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800164 o.Channel = make(chan types.Message, 10)
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700165
Matteo Scandolo8a574812021-05-20 15:18:53 -0700166 unis := []UniPortIf{
167 &UniPort{ID: 0, Onu: &o, PortNo: 16, MeId: omcilib.GenerateUniPortEntityId(1), logger: uniLogger},
168 &UniPort{ID: 1, Onu: &o, PortNo: 17, MeId: omcilib.GenerateUniPortEntityId(2), logger: uniLogger},
169 &UniPort{ID: 2, Onu: &o, PortNo: 18, MeId: omcilib.GenerateUniPortEntityId(3), logger: uniLogger},
170 &UniPort{ID: 3, Onu: &o, PortNo: 19, MeId: omcilib.GenerateUniPortEntityId(4), logger: uniLogger},
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700171 }
172
173 o.UniPorts = unis
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800174 return &o
Matteo Scandolo99f18462019-10-28 14:14:28 -0700175}
Matteo Scandoloc1147092019-10-29 09:38:33 -0700176
177// this method creates a real ONU to be used in the tests
178func createTestOnu() *Onu {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700179 nextCtag := map[string]int{}
180 nextStag := map[string]int{}
181
Matteo Scandoloc1147092019-10-29 09:38:33 -0700182 olt := OltDevice{
Andrea Campanellabe1b7cf2021-04-30 09:53:40 +0200183 ID: 0,
184 OmciResponseRate: 10,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700185 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800186
Elia Battistonb7bea222022-02-18 16:25:00 +0100187 pon := CreatePonPort(&olt, 1, bbsim_common.XGSPON)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800188
Matteo Scandolo8a574812021-05-20 15:18:53 -0700189 onu := CreateONU(&olt, pon, 1, time.Duration(1*time.Millisecond), nextCtag, nextStag, true)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100190 // NOTE we need this in order to create the OnuChannel
Matteo Scandolocedde462021-03-09 17:37:16 -0800191 _ = onu.InternalState.Event(OnuTxInitialize)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800192 onu.DiscoveryRetryDelay = 100 * time.Millisecond
Matteo Scandoloc1147092019-10-29 09:38:33 -0700193 return onu
194}