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 | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 22 | bbsim_common "github.com/opencord/bbsim/internal/common" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 23 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
Matteo Scandolo | 1f9f4b2 | 2021-12-14 11:51:55 -0800 | [diff] [blame] | 24 | "github.com/opencord/voltha-protos/v5/go/extension" |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 25 | log "github.com/sirupsen/logrus" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 26 | "time" |
| 27 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 28 | "github.com/opencord/bbsim/internal/bbsim/types" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v5/go/ext/config" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 30 | |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 31 | "github.com/opencord/voltha-protos/v5/go/openolt" |
| 32 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 33 | "google.golang.org/grpc" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 34 | ) |
| 35 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 36 | func init() { |
| 37 | bbsim_common.SetLogLevel(log.StandardLogger(), "error", false) |
| 38 | } |
| 39 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 40 | type FlowAddSpy struct { |
| 41 | CallCount int |
| 42 | Calls map[int]*openolt.Flow |
| 43 | } |
| 44 | |
| 45 | type mockClient struct { |
| 46 | FlowAddSpy |
| 47 | fail bool |
| 48 | } |
| 49 | |
| 50 | func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 51 | return nil, errors.New("unimplemented-in-mock-client") |
| 52 | } |
| 53 | func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 54 | return nil, errors.New("unimplemented-in-mock-client") |
| 55 | } |
| 56 | func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 57 | return nil, errors.New("unimplemented-in-mock-client") |
| 58 | } |
| 59 | func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 60 | return nil, errors.New("unimplemented-in-mock-client") |
| 61 | } |
| 62 | func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 63 | return nil, errors.New("unimplemented-in-mock-client") |
| 64 | } |
| 65 | func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 66 | return nil, errors.New("unimplemented-in-mock-client") |
| 67 | } |
| 68 | func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 69 | return nil, errors.New("unimplemented-in-mock-client") |
| 70 | } |
| 71 | func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 72 | return nil, errors.New("unimplemented-in-mock-client") |
| 73 | } |
| 74 | func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 75 | s.FlowAddSpy.CallCount++ |
| 76 | if s.fail { |
| 77 | return nil, errors.New("fake-error") |
| 78 | } |
| 79 | s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in |
| 80 | return &openolt.Empty{}, nil |
| 81 | } |
| 82 | func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 83 | return nil, errors.New("unimplemented-in-mock-client") |
| 84 | } |
| 85 | func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) { |
| 86 | return nil, errors.New("unimplemented-in-mock-client") |
| 87 | } |
| 88 | func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 89 | return nil, errors.New("unimplemented-in-mock-client") |
| 90 | } |
| 91 | func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 92 | return nil, errors.New("unimplemented-in-mock-client") |
| 93 | } |
| 94 | func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) { |
| 95 | return nil, errors.New("unimplemented-in-mock-client") |
| 96 | } |
| 97 | func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 98 | return nil, errors.New("unimplemented-in-mock-client") |
| 99 | } |
| 100 | func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 101 | return nil, errors.New("unimplemented-in-mock-client") |
| 102 | } |
| 103 | func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 104 | return nil, errors.New("unimplemented-in-mock-client") |
| 105 | } |
| 106 | func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 107 | return nil, errors.New("unimplemented-in-mock-client") |
| 108 | } |
| 109 | func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 110 | return nil, errors.New("unimplemented-in-mock-client") |
| 111 | } |
| 112 | func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 113 | return nil, errors.New("unimplemented-in-mock-client") |
| 114 | } |
| 115 | func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) { |
| 116 | return nil, errors.New("unimplemented-in-mock-client") |
| 117 | } |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 118 | func (s *mockClient) PerformGroupOperation(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 119 | return nil, errors.New("unimplemented-in-mock-client") |
| 120 | } |
| 121 | func (s *mockClient) DeleteGroup(ctx context.Context, group *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 122 | return nil, errors.New("unimplemented-in-mock-client") |
| 123 | } |
Matteo Scandolo | 1f9f4b2 | 2021-12-14 11:51:55 -0800 | [diff] [blame] | 124 | func (s *mockClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*extension.ReturnValues, error) { |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 125 | return nil, errors.New("unimplemented-in-mock-client") |
| 126 | } |
| 127 | func (s *mockClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 128 | return nil, errors.New("unimplemented-in-mock-client") |
| 129 | } |
| 130 | func (s *mockClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 131 | return nil, errors.New("unimplemented-in-mock-client") |
| 132 | } |
| 133 | func (s *mockClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 134 | return nil, errors.New("unimplemented-in-mock-client") |
| 135 | } |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 136 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 137 | func (s *mockClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) { |
| 138 | return nil, errors.New("unimplemented-in-mock-client") |
| 139 | } |
| 140 | |
| 141 | func (s *mockClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) { |
| 142 | return nil, errors.New("unimplemented-in-mock-client") |
| 143 | } |
| 144 | |
Girish Gowdra | 62f2429 | 2021-05-12 16:28:39 -0700 | [diff] [blame] | 145 | func (s *mockClient) GetPonRxPower(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.PonRxPowerData, error) { |
| 146 | return nil, errors.New("unimplemented-in-mock-client") |
| 147 | } |
| 148 | |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 149 | // this method creates a fake ONU used in the tests |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 150 | func createMockOnu(id uint32, ponPortId uint32) *Onu { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 151 | o := Onu{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 152 | ID: id, |
| 153 | PonPortID: ponPortId, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 154 | PonPort: &PonPort{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 155 | AllocatedGemPorts: make(map[uint16]*openolt.SerialNumber), |
Girish Gowdra | 08b5839 | 2022-01-31 16:59:24 -0800 | [diff] [blame^] | 156 | AllocatedAllocIds: make(map[uint16]*AllocIDKey), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 157 | Olt: &OltDevice{}, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 158 | }, |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 159 | OmciResponseRate: 10, |
| 160 | OmciMsgCounter: 0, |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 161 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 162 | o.SerialNumber = NewSN(0, ponPortId, o.ID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 163 | o.Channel = make(chan types.Message, 10) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 164 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 165 | unis := []UniPortIf{ |
| 166 | &UniPort{ID: 0, Onu: &o, PortNo: 16, MeId: omcilib.GenerateUniPortEntityId(1), logger: uniLogger}, |
| 167 | &UniPort{ID: 1, Onu: &o, PortNo: 17, MeId: omcilib.GenerateUniPortEntityId(2), logger: uniLogger}, |
| 168 | &UniPort{ID: 2, Onu: &o, PortNo: 18, MeId: omcilib.GenerateUniPortEntityId(3), logger: uniLogger}, |
| 169 | &UniPort{ID: 3, Onu: &o, PortNo: 19, MeId: omcilib.GenerateUniPortEntityId(4), logger: uniLogger}, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | o.UniPorts = unis |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 173 | return &o |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 174 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 175 | |
| 176 | // this method creates a real ONU to be used in the tests |
| 177 | func createTestOnu() *Onu { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 178 | nextCtag := map[string]int{} |
| 179 | nextStag := map[string]int{} |
| 180 | |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 181 | olt := OltDevice{ |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 182 | ID: 0, |
| 183 | OmciResponseRate: 10, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 184 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 185 | |
| 186 | pon := CreatePonPort(&olt, 1) |
| 187 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 188 | onu := CreateONU(&olt, pon, 1, time.Duration(1*time.Millisecond), nextCtag, nextStag, true) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 189 | // NOTE we need this in order to create the OnuChannel |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 190 | _ = onu.InternalState.Event(OnuTxInitialize) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 191 | onu.DiscoveryRetryDelay = 100 * time.Millisecond |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 192 | return onu |
| 193 | } |