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" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 22 | "github.com/opencord/bbsim/internal/bbsim/types" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 23 | "github.com/opencord/voltha-protos/v4/go/common" |
| 24 | "github.com/opencord/voltha-protos/v4/go/ext/config" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 25 | "time" |
| 26 | |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 27 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 28 | "github.com/opencord/voltha-protos/v4/go/tech_profile" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 29 | "google.golang.org/grpc" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | type FlowAddSpy struct { |
| 33 | CallCount int |
| 34 | Calls map[int]*openolt.Flow |
| 35 | } |
| 36 | |
| 37 | type mockClient struct { |
| 38 | FlowAddSpy |
| 39 | fail bool |
| 40 | } |
| 41 | |
| 42 | func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 43 | return nil, errors.New("unimplemented-in-mock-client") |
| 44 | } |
| 45 | func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 46 | return nil, errors.New("unimplemented-in-mock-client") |
| 47 | } |
| 48 | func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 49 | return nil, errors.New("unimplemented-in-mock-client") |
| 50 | } |
| 51 | func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 52 | return nil, errors.New("unimplemented-in-mock-client") |
| 53 | } |
| 54 | func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 55 | return nil, errors.New("unimplemented-in-mock-client") |
| 56 | } |
| 57 | func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 58 | return nil, errors.New("unimplemented-in-mock-client") |
| 59 | } |
| 60 | func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 61 | return nil, errors.New("unimplemented-in-mock-client") |
| 62 | } |
| 63 | func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 64 | return nil, errors.New("unimplemented-in-mock-client") |
| 65 | } |
| 66 | func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 67 | s.FlowAddSpy.CallCount++ |
| 68 | if s.fail { |
| 69 | return nil, errors.New("fake-error") |
| 70 | } |
| 71 | s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in |
| 72 | return &openolt.Empty{}, nil |
| 73 | } |
| 74 | func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 75 | return nil, errors.New("unimplemented-in-mock-client") |
| 76 | } |
| 77 | func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) { |
| 78 | return nil, errors.New("unimplemented-in-mock-client") |
| 79 | } |
| 80 | func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 81 | return nil, errors.New("unimplemented-in-mock-client") |
| 82 | } |
| 83 | func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 84 | return nil, errors.New("unimplemented-in-mock-client") |
| 85 | } |
| 86 | func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) { |
| 87 | return nil, errors.New("unimplemented-in-mock-client") |
| 88 | } |
| 89 | func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 90 | return nil, errors.New("unimplemented-in-mock-client") |
| 91 | } |
| 92 | func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 93 | return nil, errors.New("unimplemented-in-mock-client") |
| 94 | } |
| 95 | func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 96 | return nil, errors.New("unimplemented-in-mock-client") |
| 97 | } |
| 98 | func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 99 | return nil, errors.New("unimplemented-in-mock-client") |
| 100 | } |
| 101 | func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 102 | return nil, errors.New("unimplemented-in-mock-client") |
| 103 | } |
| 104 | func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 105 | return nil, errors.New("unimplemented-in-mock-client") |
| 106 | } |
| 107 | func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) { |
| 108 | return nil, errors.New("unimplemented-in-mock-client") |
| 109 | } |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 110 | func (s *mockClient) PerformGroupOperation(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 111 | return nil, errors.New("unimplemented-in-mock-client") |
| 112 | } |
| 113 | func (s *mockClient) DeleteGroup(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 114 | return nil, errors.New("unimplemented-in-mock-client") |
| 115 | } |
| 116 | func (s *mockClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*common.ReturnValues, error) { |
| 117 | return nil, errors.New("unimplemented-in-mock-client") |
| 118 | } |
| 119 | func (s *mockClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 120 | return nil, errors.New("unimplemented-in-mock-client") |
| 121 | } |
| 122 | func (s *mockClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 123 | return nil, errors.New("unimplemented-in-mock-client") |
| 124 | } |
| 125 | func (s *mockClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 126 | return nil, errors.New("unimplemented-in-mock-client") |
| 127 | } |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 128 | |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 129 | // this method creates a fake ONU used in the tests |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 130 | func createMockOnu(id uint32, ponPortId uint32) *Onu { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 131 | o := Onu{ |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 132 | ID: id, |
| 133 | PonPortID: ponPortId, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 134 | PortNo: 0, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 135 | GemPortAdded: true, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 136 | PonPort: &PonPort{ |
| 137 | Olt: &OltDevice{}, |
| 138 | }, |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 139 | } |
| 140 | o.SerialNumber = o.NewSN(0, ponPortId, o.ID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 141 | o.Channel = make(chan types.Message, 10) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 142 | return &o |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 143 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 144 | |
| 145 | // this method creates a real ONU to be used in the tests |
| 146 | func createTestOnu() *Onu { |
| 147 | olt := OltDevice{ |
| 148 | ID: 0, |
| 149 | } |
| 150 | pon := PonPort{ |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 151 | ID: 1, |
| 152 | Olt: &olt, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 153 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 154 | onu := CreateONU(&olt, &pon, 1, time.Duration(1*time.Millisecond), true) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 155 | // NOTE we need this in order to create the OnuChannel |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 156 | _ = onu.InternalState.Event("initialize") |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 157 | onu.DiscoveryRetryDelay = 100 * time.Millisecond |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 158 | return onu |
| 159 | } |