Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 14628cd | 2023-01-10 08:38:31 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 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" |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 22 | "time" |
| 23 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 24 | bbsim_common "github.com/opencord/bbsim/internal/common" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 25 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
Matteo Scandolo | 1f9f4b2 | 2021-12-14 11:51:55 -0800 | [diff] [blame] | 26 | "github.com/opencord/voltha-protos/v5/go/extension" |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 27 | log "github.com/sirupsen/logrus" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 28 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 29 | "github.com/opencord/bbsim/internal/bbsim/types" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v5/go/ext/config" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 31 | |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 32 | "github.com/opencord/voltha-protos/v5/go/openolt" |
| 33 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 34 | "google.golang.org/grpc" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 35 | ) |
| 36 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 37 | func init() { |
| 38 | bbsim_common.SetLogLevel(log.StandardLogger(), "error", false) |
| 39 | } |
| 40 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 41 | type FlowAddSpy struct { |
| 42 | CallCount int |
| 43 | Calls map[int]*openolt.Flow |
| 44 | } |
| 45 | |
| 46 | type mockClient struct { |
| 47 | FlowAddSpy |
| 48 | fail bool |
| 49 | } |
| 50 | |
| 51 | func (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 | } |
| 54 | func (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 | } |
| 57 | func (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 | } |
| 60 | func (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 | } |
| 63 | func (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 | } |
| 66 | func (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 | } |
| 69 | func (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 | } |
| 72 | func (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 | } |
| 75 | func (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 | } |
| 83 | func (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 | } |
| 86 | func (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 | } |
| 89 | func (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 | } |
| 92 | func (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 | } |
| 95 | func (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 | } |
| 98 | func (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 | } |
| 101 | func (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 | } |
| 104 | func (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 | } |
| 107 | func (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 | } |
| 110 | func (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 | } |
| 113 | func (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 | } |
| 116 | func (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 Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 119 | func (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 | } |
| 122 | func (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 Scandolo | 1f9f4b2 | 2021-12-14 11:51:55 -0800 | [diff] [blame] | 125 | 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] | 126 | return nil, errors.New("unimplemented-in-mock-client") |
| 127 | } |
| 128 | func (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 | } |
| 131 | func (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 | } |
| 134 | func (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 Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 137 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 138 | func (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 | |
| 142 | func (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 Gowdra | 62f2429 | 2021-05-12 16:28:39 -0700 | [diff] [blame] | 146 | func (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 | |
nikesh.krishnan | dd07b92 | 2023-07-05 23:55:42 +0530 | [diff] [blame^] | 150 | func (s *mockClient) GetOnuInfo(context context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuInfo, error) { |
| 151 | return nil, errors.New("unimplemented-in-mock-client") |
| 152 | } |
| 153 | |
| 154 | func (s *mockClient) GetPonInterfaceInfo(context context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.PonIntfInfo, error) { |
| 155 | return nil, errors.New("unimplemented-in-mock-client") |
| 156 | } |
| 157 | |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 158 | // this method creates a fake ONU used in the tests |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 159 | func createMockOnu(id uint32, ponPortId uint32) *Onu { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 160 | o := Onu{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 161 | ID: id, |
| 162 | PonPortID: ponPortId, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 163 | PonPort: &PonPort{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 164 | AllocatedGemPorts: make(map[uint16]*openolt.SerialNumber), |
Girish Gowdra | 574834a | 2022-02-04 15:15:15 -0800 | [diff] [blame] | 165 | AllocatedAllocIds: make(map[AllocIDKey]*AllocIDVal), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 166 | Olt: &OltDevice{}, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 167 | }, |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 168 | OmciResponseRate: 10, |
| 169 | OmciMsgCounter: 0, |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 170 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 171 | o.SerialNumber = NewSN(0, ponPortId, o.ID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 172 | o.Channel = make(chan types.Message, 10) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 173 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 174 | unis := []UniPortIf{ |
| 175 | &UniPort{ID: 0, Onu: &o, PortNo: 16, MeId: omcilib.GenerateUniPortEntityId(1), logger: uniLogger}, |
| 176 | &UniPort{ID: 1, Onu: &o, PortNo: 17, MeId: omcilib.GenerateUniPortEntityId(2), logger: uniLogger}, |
| 177 | &UniPort{ID: 2, Onu: &o, PortNo: 18, MeId: omcilib.GenerateUniPortEntityId(3), logger: uniLogger}, |
| 178 | &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] | 179 | } |
| 180 | |
| 181 | o.UniPorts = unis |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 182 | return &o |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 183 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 184 | |
| 185 | // this method creates a real ONU to be used in the tests |
| 186 | func createTestOnu() *Onu { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 187 | nextCtag := map[string]int{} |
| 188 | nextStag := map[string]int{} |
| 189 | |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 190 | olt := OltDevice{ |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 191 | ID: 0, |
| 192 | OmciResponseRate: 10, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 193 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 194 | |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 195 | pon := CreatePonPort(&olt, 1, bbsim_common.XGSPON) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 196 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 197 | 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] | 198 | // NOTE we need this in order to create the OnuChannel |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 199 | _ = onu.InternalState.Event(OnuTxInitialize) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 200 | onu.DiscoveryRetryDelay = 100 * time.Millisecond |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 201 | return onu |
| 202 | } |