Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 1 | /* |
| 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 devices |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "errors" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame^] | 22 | "time" |
| 23 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 24 | "github.com/opencord/bbsim/internal/bbsim/types" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/v4/go/common" |
| 26 | "github.com/opencord/voltha-protos/v4/go/ext/config" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 27 | |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 29 | "github.com/opencord/voltha-protos/v4/go/tech_profile" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 30 | "google.golang.org/grpc" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | type FlowAddSpy struct { |
| 34 | CallCount int |
| 35 | Calls map[int]*openolt.Flow |
| 36 | } |
| 37 | |
| 38 | type mockClient struct { |
| 39 | FlowAddSpy |
| 40 | fail bool |
| 41 | } |
| 42 | |
| 43 | func (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 | } |
| 46 | func (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 | } |
| 49 | func (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 | } |
| 52 | func (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 | } |
| 55 | func (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 | } |
| 58 | func (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 | } |
| 61 | func (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 | } |
| 64 | func (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 | } |
| 67 | func (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 | } |
| 75 | func (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 | } |
| 78 | func (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 | } |
| 81 | func (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 | } |
| 84 | func (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 | } |
| 87 | func (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 | } |
| 90 | func (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 | } |
| 93 | func (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 | } |
| 96 | func (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 | } |
| 99 | func (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 | } |
| 102 | func (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 | } |
| 105 | func (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 | } |
| 108 | func (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 Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 111 | func (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 | } |
| 114 | func (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 | } |
| 117 | func (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 | } |
| 120 | func (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 | } |
| 123 | func (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 | } |
| 126 | func (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 Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 129 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 130 | func (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 | |
| 134 | func (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 Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 138 | // this method creates a fake ONU used in the tests |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 139 | func createMockOnu(id uint32, ponPortId uint32) *Onu { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 140 | o := Onu{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 141 | ID: id, |
| 142 | PonPortID: ponPortId, |
| 143 | PortNo: 0, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 144 | PonPort: &PonPort{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 145 | AllocatedGemPorts: make(map[uint16]*openolt.SerialNumber), |
| 146 | AllocatedAllocIds: make(map[uint16]*openolt.SerialNumber), |
| 147 | Olt: &OltDevice{}, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 148 | }, |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame^] | 149 | OmciResponseRate: 10, |
| 150 | OmciMsgCounter: 0, |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 151 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 152 | o.SerialNumber = NewSN(0, ponPortId, o.ID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 153 | o.Channel = make(chan types.Message, 10) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 154 | return &o |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 155 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 156 | |
| 157 | // this method creates a real ONU to be used in the tests |
| 158 | func createTestOnu() *Onu { |
| 159 | olt := OltDevice{ |
| 160 | ID: 0, |
| 161 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 162 | |
| 163 | pon := CreatePonPort(&olt, 1) |
| 164 | |
| 165 | onu := CreateONU(&olt, pon, 1, time.Duration(1*time.Millisecond), true) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 166 | // NOTE we need this in order to create the OnuChannel |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 167 | _ = onu.InternalState.Event(OnuTxInitialize) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 168 | onu.DiscoveryRetryDelay = 100 * time.Millisecond |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 169 | return onu |
| 170 | } |