Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -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 | 1100699 | 2019-08-28 11:29:46 -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 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
| 19 | import ( |
| 20 | "context" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 21 | "encoding/hex" |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 22 | "errors" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 23 | "fmt" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 24 | "net" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 25 | "strconv" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 26 | "sync" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 27 | "time" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 28 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 30 | |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 31 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 32 | "github.com/opencord/bbsim/internal/bbsim/types" |
| 33 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 34 | "github.com/opencord/voltha-protos/v5/go/ext/config" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 35 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 36 | "github.com/google/gopacket" |
| 37 | "github.com/google/gopacket/layers" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 38 | "github.com/looplab/fsm" |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 39 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 40 | "github.com/opencord/bbsim/internal/common" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 41 | "github.com/opencord/voltha-protos/v5/go/openolt" |
| 42 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 43 | log "github.com/sirupsen/logrus" |
| 44 | "google.golang.org/grpc" |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 45 | "google.golang.org/grpc/codes" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 46 | "google.golang.org/grpc/reflection" |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 47 | "google.golang.org/grpc/status" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 48 | ) |
| 49 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 50 | var oltLogger = log.WithFields(log.Fields{ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 51 | "module": "OLT", |
| 52 | }) |
| 53 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 54 | const ( |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 55 | multicastGemPortId = 4069 |
| 56 | ) |
| 57 | |
| 58 | const ( |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 59 | //InternalState FSM states and transitions |
| 60 | OltInternalStateCreated = "created" |
| 61 | OltInternalStateInitialized = "initialized" |
| 62 | OltInternalStateEnabled = "enabled" |
| 63 | OltInternalStateDisabled = "disabled" |
| 64 | OltInternalStateDeleted = "deleted" |
| 65 | |
| 66 | OltInternalTxInitialize = "initialize" |
| 67 | OltInternalTxEnable = "enable" |
| 68 | OltInternalTxDisable = "disable" |
| 69 | OltInternalTxDelete = "delete" |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 70 | ) |
| 71 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 72 | type OltDevice struct { |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 73 | sync.Mutex |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 74 | OltServer *grpc.Server |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 75 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 76 | // BBSIM Internals |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 77 | ID int |
| 78 | SerialNumber string |
| 79 | NumNni int |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame] | 80 | NniSpeed uint32 |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 81 | NumPon int |
| 82 | NumOnuPerPon int |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 83 | NumUni int |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 84 | NumPots int |
Andrea Campanella | 6f5f355 | 2022-03-10 17:14:25 +0100 | [diff] [blame] | 85 | NniDhcpTrapVid int |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 86 | InternalState *fsm.FSM |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 87 | channel chan types.Message |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 88 | dhcpServer dhcp.DHCPServerIf |
Andrea Campanella | be8e12f | 2020-12-14 18:43:41 +0100 | [diff] [blame] | 89 | Flows sync.Map |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 90 | Delay int |
| 91 | ControlledActivation mode |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 92 | EventChannel chan common.Event |
| 93 | PublishEvents bool |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 94 | PortStatsInterval int |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 95 | PreviouslyConnected bool |
Matteo Scandolo | e33447a | 2019-10-31 12:38:23 -0700 | [diff] [blame] | 96 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 97 | Pons []*PonPort |
| 98 | Nnis []*NniPort |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 99 | |
| 100 | // OLT Attributes |
| 101 | OperState *fsm.FSM |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 102 | |
| 103 | enableContext context.Context |
| 104 | enableContextCancel context.CancelFunc |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 105 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 106 | OpenoltStream openolt.Openolt_EnableIndicationServer |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 107 | enablePerf bool |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 108 | |
| 109 | // Allocated Resources |
| 110 | // this data are to verify that the openolt adapter does not duplicate resources |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 111 | AllocIDsLock sync.RWMutex |
| 112 | AllocIDs map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool // map[ponPortId]map[OnuId]map[PortNo]map[AllocIds]map[FlowId]bool |
| 113 | GemPortIDsLock sync.RWMutex |
| 114 | GemPortIDs map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool // map[ponPortId]map[OnuId]map[PortNo]map[GemPortIDs]map[FlowId]bool |
| 115 | OmciResponseRate uint8 |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 116 | signature uint32 |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 119 | var olt OltDevice |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 120 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 121 | func GetOLT() *OltDevice { |
| 122 | return &olt |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 125 | func CreateOLT(options common.GlobalConfig, services []common.ServiceYaml, isMock bool) *OltDevice { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 126 | oltLogger.WithFields(log.Fields{ |
Andrea Campanella | 6f5f355 | 2022-03-10 17:14:25 +0100 | [diff] [blame] | 127 | "ID": options.Olt.ID, |
| 128 | "NumNni": options.Olt.NniPorts, |
| 129 | "NniSpeed": options.Olt.NniSpeed, |
| 130 | "NumPon": options.Olt.PonPorts, |
| 131 | "NumOnuPerPon": options.Olt.OnusPonPort, |
| 132 | "NumUni": options.Olt.UniPorts, |
| 133 | "NumPots": options.Olt.PotsPorts, |
| 134 | "NniDhcpTrapVid": options.Olt.NniDhcpTrapVid, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 135 | }).Debug("CreateOLT") |
| 136 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 137 | olt = OltDevice{ |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 138 | ID: options.Olt.ID, |
| 139 | SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", options.Olt.ID), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 140 | OperState: getOperStateFSM(func(e *fsm.Event) { |
| 141 | oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst) |
| 142 | }), |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 143 | NumNni: int(options.Olt.NniPorts), |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame] | 144 | NniSpeed: options.Olt.NniSpeed, |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 145 | NumPon: int(options.Olt.PonPorts), |
| 146 | NumOnuPerPon: int(options.Olt.OnusPonPort), |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 147 | NumUni: int(options.Olt.UniPorts), |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 148 | NumPots: int(options.Olt.PotsPorts), |
Andrea Campanella | 6f5f355 | 2022-03-10 17:14:25 +0100 | [diff] [blame] | 149 | NniDhcpTrapVid: int(options.Olt.NniDhcpTrapVid), |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 150 | Pons: []*PonPort{}, |
| 151 | Nnis: []*NniPort{}, |
| 152 | Delay: options.BBSim.Delay, |
| 153 | enablePerf: options.BBSim.EnablePerf, |
| 154 | PublishEvents: options.BBSim.Events, |
| 155 | PortStatsInterval: options.Olt.PortStatsInterval, |
| 156 | dhcpServer: dhcp.NewDHCPServer(), |
| 157 | PreviouslyConnected: false, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 158 | AllocIDs: make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool), |
| 159 | GemPortIDs: make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool), |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 160 | OmciResponseRate: options.Olt.OmciResponseRate, |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 161 | signature: uint32(time.Now().Unix()), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 164 | if val, ok := ControlledActivationModes[options.BBSim.ControlledActivation]; ok { |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 165 | olt.ControlledActivation = val |
| 166 | } else { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 167 | // FIXME throw an error if the ControlledActivation is not valid |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 168 | oltLogger.Warn("Unknown ControlledActivation Mode given, running in Default mode") |
| 169 | olt.ControlledActivation = Default |
| 170 | } |
| 171 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 172 | // OLT State machine |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 173 | // NOTE do we need 2 state machines for the OLT? (InternalState and OperState) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 174 | olt.InternalState = fsm.NewFSM( |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 175 | OltInternalStateCreated, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 176 | fsm.Events{ |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 177 | {Name: OltInternalTxInitialize, Src: []string{OltInternalStateCreated, OltInternalStateDeleted}, Dst: OltInternalStateInitialized}, |
| 178 | {Name: OltInternalTxEnable, Src: []string{OltInternalStateInitialized, OltInternalStateDisabled}, Dst: OltInternalStateEnabled}, |
| 179 | {Name: OltInternalTxDisable, Src: []string{OltInternalStateEnabled}, Dst: OltInternalStateDisabled}, |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 180 | // delete event in enabled state below is for reboot OLT case. |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 181 | {Name: OltInternalTxDelete, Src: []string{OltInternalStateDisabled, OltInternalStateEnabled}, Dst: OltInternalStateDeleted}, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 182 | }, |
| 183 | fsm.Callbacks{ |
| 184 | "enter_state": func(e *fsm.Event) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 185 | oltLogger.Debugf("Changing OLT InternalState from %s to %s", e.Src, e.Dst) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 186 | }, |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 187 | fmt.Sprintf("enter_%s", OltInternalStateInitialized): func(e *fsm.Event) { olt.InitOlt() }, |
| 188 | fmt.Sprintf("enter_%s", OltInternalStateDeleted): func(e *fsm.Event) { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 189 | // remove all the resource allocations |
| 190 | olt.clearAllResources() |
| 191 | }, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 192 | }, |
| 193 | ) |
| 194 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 195 | if !isMock { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 196 | // create NNI Port |
| 197 | nniPort, err := CreateNNI(&olt) |
| 198 | if err != nil { |
| 199 | oltLogger.Fatalf("Couldn't create NNI Port: %v", err) |
| 200 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 201 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 202 | olt.Nnis = append(olt.Nnis, &nniPort) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 203 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 204 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 205 | // Create device and Services |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 206 | nextCtag := map[string]int{} |
| 207 | nextStag := map[string]int{} |
| 208 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 209 | // create PON ports |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 210 | for i := 0; i < olt.NumPon; i++ { |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 211 | ponConf, err := common.GetPonConfigById(uint32(i)) |
| 212 | if err != nil { |
| 213 | oltLogger.WithFields(log.Fields{ |
| 214 | "Err": err, |
| 215 | "IntfId": i, |
| 216 | }).Fatal("cannot-get-pon-configuration") |
| 217 | } |
| 218 | |
| 219 | tech, err := common.PonTechnologyFromString(ponConf.Technology) |
| 220 | if err != nil { |
| 221 | oltLogger.WithFields(log.Fields{ |
| 222 | "Err": err, |
| 223 | "IntfId": i, |
| 224 | }).Fatal("unkown-pon-port-technology") |
| 225 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 226 | |
| 227 | // initialize the resource maps for every PON Ports |
| 228 | olt.AllocIDs[uint32(i)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 229 | olt.GemPortIDs[uint32(i)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 230 | |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 231 | p := CreatePonPort(&olt, uint32(i), tech) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 232 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 233 | // create ONU devices |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 234 | if (ponConf.OnuRange.EndId - ponConf.OnuRange.StartId + 1) < uint32(olt.NumOnuPerPon) { |
| 235 | oltLogger.WithFields(log.Fields{ |
| 236 | "OnuRange": ponConf.OnuRange, |
| 237 | "RangeSize": ponConf.OnuRange.EndId - ponConf.OnuRange.StartId + 1, |
| 238 | "NumOnuPerPon": olt.NumOnuPerPon, |
| 239 | "IntfId": i, |
| 240 | }).Fatal("onus-per-pon-bigger-than-resource-range-size") |
| 241 | } |
| 242 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 243 | for j := 0; j < olt.NumOnuPerPon; j++ { |
| 244 | delay := time.Duration(olt.Delay*j) * time.Millisecond |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 245 | o := CreateONU(&olt, p, uint32(j+1), delay, nextCtag, nextStag, isMock) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 246 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 247 | p.Onus = append(p.Onus, o) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 248 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 249 | olt.Pons = append(olt.Pons, p) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 250 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 251 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 252 | if !isMock { |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 253 | if err := olt.InternalState.Event(OltInternalTxInitialize); err != nil { |
Matteo Scandolo | d32c382 | 2019-11-26 15:57:46 -0700 | [diff] [blame] | 254 | log.Errorf("Error initializing OLT: %v", err) |
| 255 | return nil |
| 256 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 259 | if olt.PublishEvents { |
| 260 | log.Debugf("BBSim event publishing is enabled") |
| 261 | // Create a channel to write event messages |
| 262 | olt.EventChannel = make(chan common.Event, 100) |
| 263 | } |
| 264 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 265 | return &olt |
| 266 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 267 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 268 | func (o *OltDevice) InitOlt() { |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 269 | |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 270 | if o.OltServer == nil { |
| 271 | o.OltServer, _ = o.StartOltServer() |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 272 | } else { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 273 | oltLogger.Fatal("OLT server already running.") |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // create new channel for processOltMessages Go routine |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 277 | o.channel = make(chan types.Message) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 278 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 279 | // FIXME we are assuming we have only one NNI |
| 280 | if o.Nnis[0] != nil { |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 281 | // NOTE we want to make sure the state is down when we initialize the OLT, |
| 282 | // the NNI may be in a bad state after a disable/reboot as we are not disabling it for |
| 283 | // in-band management |
| 284 | o.Nnis[0].OperState.SetState("down") |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 285 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 286 | |
| 287 | for ponId := range o.Pons { |
| 288 | // initialize the resource maps for every PON Ports |
| 289 | olt.AllocIDs[uint32(ponId)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 290 | olt.GemPortIDs[uint32(ponId)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 291 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 294 | func (o *OltDevice) RestartOLT() error { |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 295 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 296 | o.PreviouslyConnected = false |
| 297 | |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 298 | softReboot := false |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 299 | rebootDelay := common.Config.Olt.OltRebootDelay |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 300 | |
| 301 | oltLogger.WithFields(log.Fields{ |
| 302 | "oltId": o.ID, |
| 303 | }).Infof("Simulating OLT restart... (%ds)", rebootDelay) |
| 304 | |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 305 | if o.InternalState.Is(OltInternalStateEnabled) { |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 306 | oltLogger.WithFields(log.Fields{ |
| 307 | "oltId": o.ID, |
| 308 | }).Info("This is an OLT soft reboot") |
| 309 | softReboot = true |
| 310 | } |
| 311 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 312 | // transition internal state to deleted |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 313 | if err := o.InternalState.Event(OltInternalTxDelete); err != nil { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 314 | oltLogger.WithFields(log.Fields{ |
| 315 | "oltId": o.ID, |
| 316 | }).Errorf("Error deleting OLT: %v", err) |
| 317 | return err |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 320 | if softReboot { |
| 321 | for _, pon := range o.Pons { |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 322 | /* No need to send pon events on olt soft reboot |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 323 | if pon.InternalState.Current() == "enabled" { |
| 324 | // disable PONs |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 325 | msg := types.Message{ |
| 326 | Type: types.PonIndication, |
| 327 | Data: types.PonIndicationMessage{ |
| 328 | OperState: types.DOWN, |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 329 | PonPortID: pon.ID, |
| 330 | }, |
| 331 | } |
| 332 | o.channel <- msg |
| 333 | } |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 334 | */ |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 335 | for _, onu := range pon.Onus { |
Andrea Campanella | 8ad54a4 | 2022-03-09 14:36:55 +0100 | [diff] [blame] | 336 | err := onu.InternalState.Event(OnuTxDisable) |
| 337 | oltLogger.WithFields(log.Fields{ |
| 338 | "oltId": o.ID, |
| 339 | "onuId": onu.ID, |
| 340 | }).Errorf("Error disabling ONUs on OLT soft reboot: %v", err) |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } else { |
| 344 | // PONs are already handled in the Disable call |
| 345 | for _, pon := range olt.Pons { |
| 346 | // ONUs are not automatically disabled when a PON goes down |
| 347 | // as it's possible that it's an admin down and in that case the ONUs need to keep their state |
| 348 | for _, onu := range pon.Onus { |
Andrea Campanella | 8ad54a4 | 2022-03-09 14:36:55 +0100 | [diff] [blame] | 349 | err := onu.InternalState.Event(OnuTxDisable) |
| 350 | oltLogger.WithFields(log.Fields{ |
| 351 | "oltId": o.ID, |
| 352 | "onuId": onu.ID, |
Matteo Scandolo | fbb94ae | 2022-04-14 14:17:47 -0700 | [diff] [blame] | 353 | "OnuSn": onu.Sn(), |
Andrea Campanella | 8ad54a4 | 2022-03-09 14:36:55 +0100 | [diff] [blame] | 354 | }).Errorf("Error disabling ONUs on OLT reboot: %v", err) |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 355 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Matteo Scandolo | b307d8a | 2021-05-10 15:19:27 -0700 | [diff] [blame] | 359 | time.Sleep(1 * time.Second) // we need to give the OLT the time to respond to all the pending gRPC request before stopping the server |
| 360 | o.StopOltServer() |
| 361 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 362 | // terminate the OLT's processOltMessages go routine |
| 363 | close(o.channel) |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 364 | |
Andrea Campanella | 8ad54a4 | 2022-03-09 14:36:55 +0100 | [diff] [blame] | 365 | oltLogger.WithFields(log.Fields{ |
| 366 | "oltId": o.ID, |
| 367 | }).Infof("Waiting OLT restart for... (%ds)", rebootDelay) |
| 368 | |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 369 | //Prevents Enable to progress before the reboot is completed (VOL-4616) |
| 370 | o.Lock() |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 371 | o.enableContextCancel() |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 372 | time.Sleep(time.Duration(rebootDelay) * time.Second) |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 373 | o.Unlock() |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 374 | o.signature = uint32(time.Now().Unix()) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 375 | |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 376 | if err := o.InternalState.Event(OltInternalTxInitialize); err != nil { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 377 | oltLogger.WithFields(log.Fields{ |
| 378 | "oltId": o.ID, |
| 379 | }).Errorf("Error initializing OLT: %v", err) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 380 | return err |
| 381 | } |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 382 | oltLogger.WithFields(log.Fields{ |
| 383 | "oltId": o.ID, |
| 384 | }).Info("OLT restart completed") |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 385 | return nil |
| 386 | } |
| 387 | |
| 388 | // newOltServer launches a new grpc server for OpenOLT |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 389 | func (o *OltDevice) newOltServer() (*grpc.Server, error) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 390 | address := common.Config.BBSim.OpenOltAddress |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 391 | lis, err := net.Listen("tcp", address) |
| 392 | if err != nil { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 393 | oltLogger.Fatalf("OLT failed to listen: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 394 | } |
| 395 | grpcServer := grpc.NewServer() |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 396 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 397 | openolt.RegisterOpenoltServer(grpcServer, o) |
| 398 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 399 | reflection.Register(grpcServer) |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 400 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 401 | go func() { _ = grpcServer.Serve(lis) }() |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 402 | oltLogger.Debugf("OLT listening on %v", address) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 403 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 404 | return grpcServer, nil |
| 405 | } |
| 406 | |
Matteo Scandolo | 88c204a | 2020-11-03 10:34:24 -0800 | [diff] [blame] | 407 | // StartOltServer will create the grpc server that VOLTHA uses |
| 408 | // to communicate with the device |
| 409 | func (o *OltDevice) StartOltServer() (*grpc.Server, error) { |
| 410 | oltServer, err := o.newOltServer() |
| 411 | if err != nil { |
| 412 | oltLogger.WithFields(log.Fields{ |
| 413 | "err": err, |
| 414 | }).Error("Cannot OLT gRPC server") |
| 415 | return nil, err |
| 416 | } |
| 417 | return oltServer, nil |
| 418 | } |
| 419 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 420 | // StopOltServer stops the OpenOLT grpc server |
Matteo Scandolo | 88c204a | 2020-11-03 10:34:24 -0800 | [diff] [blame] | 421 | func (o *OltDevice) StopOltServer() { |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 422 | if o.OltServer != nil { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 423 | oltLogger.WithFields(log.Fields{ |
| 424 | "oltId": o.SerialNumber, |
| 425 | }).Warnf("Stopping OLT gRPC server") |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 426 | o.OltServer.Stop() |
| 427 | o.OltServer = nil |
Andrea Campanella | 8ad54a4 | 2022-03-09 14:36:55 +0100 | [diff] [blame] | 428 | } else { |
| 429 | oltLogger.WithFields(log.Fields{ |
| 430 | "oltId": o.SerialNumber, |
| 431 | }).Warnf("OLT gRPC server is already stopped") |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 432 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | // Device Methods |
| 436 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 437 | // Enable implements the OpenOLT EnableIndicationServer functionality |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 438 | func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 439 | oltLogger.Debug("Enable OLT called") |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 440 | |
| 441 | if o.InternalState.Is(OltInternalStateDeleted) { |
| 442 | err := fmt.Errorf("Cannot enable OLT while it is rebooting") |
| 443 | oltLogger.WithFields(log.Fields{ |
| 444 | "oltId": o.SerialNumber, |
| 445 | "internalState": o.InternalState.Current(), |
| 446 | }).Error(err) |
| 447 | return err |
| 448 | } |
| 449 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 450 | rebootFlag := false |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 451 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 452 | // If enabled has already been called then an enabled context has |
| 453 | // been created. If this is the case then we want to cancel all the |
| 454 | // proessing loops associated with that enable before we recreate |
| 455 | // new ones |
| 456 | o.Lock() |
| 457 | if o.enableContext != nil && o.enableContextCancel != nil { |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 458 | oltLogger.Info("This is an OLT reboot or a reconcile") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 459 | o.enableContextCancel() |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 460 | rebootFlag = true |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 461 | time.Sleep(1 * time.Second) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 462 | } |
| 463 | o.enableContext, o.enableContextCancel = context.WithCancel(context.TODO()) |
| 464 | o.Unlock() |
| 465 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 466 | wg := sync.WaitGroup{} |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 467 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 468 | o.OpenoltStream = stream |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 469 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 470 | // create Go routine to process all OLT events |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 471 | wg.Add(1) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 472 | go o.processOltMessages(o.enableContext, stream, &wg) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 473 | |
| 474 | // enable the OLT |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 475 | oltMsg := types.Message{ |
| 476 | Type: types.OltIndication, |
| 477 | Data: types.OltIndicationMessage{ |
| 478 | OperState: types.UP, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 479 | }, |
| 480 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 481 | o.channel <- oltMsg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 482 | |
| 483 | // send NNI Port Indications |
| 484 | for _, nni := range o.Nnis { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 485 | msg := types.Message{ |
| 486 | Type: types.NniIndication, |
| 487 | Data: types.NniIndicationMessage{ |
| 488 | OperState: types.UP, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 489 | NniPortID: nni.ID, |
| 490 | }, |
| 491 | } |
| 492 | o.channel <- msg |
| 493 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 494 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 495 | if rebootFlag { |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 496 | for _, pon := range o.Pons { |
| 497 | if pon.InternalState.Current() == "disabled" { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 498 | msg := types.Message{ |
| 499 | Type: types.PonIndication, |
| 500 | Data: types.PonIndicationMessage{ |
| 501 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 502 | PonPortID: pon.ID, |
| 503 | }, |
| 504 | } |
| 505 | o.channel <- msg |
Matteo Scandolo | e60a505 | 2020-02-07 00:31:14 +0000 | [diff] [blame] | 506 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 507 | // when the enableContext was canceled the ONUs stopped listening on the channel |
| 508 | for _, onu := range pon.Onus { |
TorstenThieme | 37ddd39 | 2022-07-13 12:56:24 +0000 | [diff] [blame] | 509 | if o.ControlledActivation != OnlyONU { |
| 510 | onu.ReDiscoverOnu(true) |
| 511 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 512 | go onu.ProcessOnuMessages(o.enableContext, stream, nil) |
| 513 | |
| 514 | // update the stream on all the services |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 515 | for _, uni := range onu.UniPorts { |
| 516 | uni.UpdateStream(stream) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 519 | } |
| 520 | } else { |
| 521 | |
| 522 | // 1. controlledActivation == Default: Send both PON and ONUs indications |
| 523 | // 2. controlledActivation == only-onu: that means only ONUs will be controlled activated, so auto send PON indications |
| 524 | |
| 525 | if o.ControlledActivation == Default || o.ControlledActivation == OnlyONU { |
| 526 | // send PON Port indications |
| 527 | for _, pon := range o.Pons { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 528 | msg := types.Message{ |
| 529 | Type: types.PonIndication, |
| 530 | Data: types.PonIndicationMessage{ |
| 531 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 532 | PonPortID: pon.ID, |
| 533 | }, |
| 534 | } |
| 535 | o.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 536 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 540 | if !o.enablePerf { |
| 541 | // Start a go routine to send periodic port stats to openolt adapter |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 542 | wg.Add(1) |
| 543 | go o.periodicPortStats(o.enableContext, &wg, stream) |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 544 | } |
| 545 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 546 | wg.Wait() |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 547 | oltLogger.WithFields(log.Fields{ |
| 548 | "stream": stream, |
| 549 | }).Debug("OpenOLT Stream closed") |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 550 | |
| 551 | return nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 554 | func (o *OltDevice) periodicPortStats(ctx context.Context, wg *sync.WaitGroup, stream openolt.Openolt_EnableIndicationServer) { |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 555 | var portStats *openolt.PortStatistics |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 556 | |
| 557 | loop: |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 558 | for { |
| 559 | select { |
| 560 | case <-time.After(time.Duration(o.PortStatsInterval) * time.Second): |
| 561 | // send NNI port stats |
| 562 | for _, port := range o.Nnis { |
| 563 | incrementStat := true |
| 564 | if port.OperState.Current() == "down" { |
| 565 | incrementStat = false |
| 566 | } |
| 567 | portStats, port.PacketCount = getPortStats(port.PacketCount, incrementStat) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 568 | o.sendPortStatsIndication(portStats, port.ID, port.Type, stream) |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | // send PON port stats |
| 572 | for _, port := range o.Pons { |
| 573 | incrementStat := true |
| 574 | // do not increment port stats if PON port is down or no ONU is activated on PON port |
| 575 | if port.OperState.Current() == "down" || port.GetNumOfActiveOnus() < 1 { |
| 576 | incrementStat = false |
| 577 | } |
| 578 | portStats, port.PacketCount = getPortStats(port.PacketCount, incrementStat) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 579 | o.sendPortStatsIndication(portStats, port.ID, port.Type, stream) |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 580 | } |
| 581 | case <-ctx.Done(): |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 582 | oltLogger.Debug("Stop sending port stats") |
| 583 | break loop |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 584 | } |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 585 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 586 | wg.Done() |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 587 | } |
| 588 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 589 | // Helpers method |
| 590 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 591 | func (o *OltDevice) SetAlarm(interfaceId uint32, interfaceType string, alarmStatus string) error { |
| 592 | |
| 593 | switch interfaceType { |
| 594 | case "nni": |
| 595 | if !o.HasNni(interfaceId) { |
| 596 | return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" NNI not present in olt") |
| 597 | } |
| 598 | |
| 599 | case "pon": |
| 600 | if !o.HasPon(interfaceId) { |
| 601 | return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" PON not present in olt") |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | alarmIndication := &openolt.AlarmIndication{ |
| 606 | Data: &openolt.AlarmIndication_LosInd{LosInd: &openolt.LosIndication{ |
| 607 | Status: alarmStatus, |
| 608 | IntfId: InterfaceIDToPortNo(interfaceId, interfaceType), |
| 609 | }}, |
| 610 | } |
| 611 | |
| 612 | msg := types.Message{ |
| 613 | Type: types.AlarmIndication, |
| 614 | Data: alarmIndication, |
| 615 | } |
| 616 | |
| 617 | o.channel <- msg |
| 618 | |
| 619 | return nil |
| 620 | } |
| 621 | |
| 622 | func (o *OltDevice) HasNni(id uint32) bool { |
| 623 | for _, intf := range o.Nnis { |
| 624 | if intf.ID == id { |
| 625 | return true |
| 626 | } |
| 627 | } |
| 628 | return false |
| 629 | } |
| 630 | |
| 631 | func (o *OltDevice) HasPon(id uint32) bool { |
| 632 | for _, intf := range o.Pons { |
| 633 | if intf.ID == id { |
| 634 | return true |
| 635 | } |
| 636 | } |
| 637 | return false |
| 638 | } |
| 639 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 640 | func (o *OltDevice) GetPonById(id uint32) (*PonPort, error) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 641 | for _, pon := range o.Pons { |
| 642 | if pon.ID == id { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 643 | return pon, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 644 | } |
| 645 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 646 | return nil, fmt.Errorf("Cannot find PonPort with id %d in OLT %d", id, o.ID) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 649 | func (o *OltDevice) getNniById(id uint32) (*NniPort, error) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 650 | for _, nni := range o.Nnis { |
| 651 | if nni.ID == id { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 652 | return nni, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 655 | return nil, fmt.Errorf("Cannot find NniPort with id %d in OLT %d", id, o.ID) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 658 | func (o *OltDevice) sendAlarmIndication(alarmInd *openolt.AlarmIndication, stream openolt.Openolt_EnableIndicationServer) { |
| 659 | data := &openolt.Indication_AlarmInd{AlarmInd: alarmInd} |
| 660 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 661 | oltLogger.Errorf("Failed to send Alarm Indication: %v", err) |
| 662 | return |
| 663 | } |
| 664 | |
| 665 | oltLogger.WithFields(log.Fields{ |
| 666 | "AlarmIndication": alarmInd, |
| 667 | }).Debug("Sent Indication_AlarmInd") |
| 668 | } |
| 669 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 670 | func (o *OltDevice) sendOltIndication(msg types.OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 671 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}} |
| 672 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 673 | oltLogger.Errorf("Failed to send Indication_OltInd: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 674 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 677 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 678 | "OperState": msg.OperState, |
| 679 | }).Debug("Sent Indication_OltInd") |
| 680 | } |
| 681 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 682 | func (o *OltDevice) sendNniIndication(msg types.NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 683 | nni, _ := o.getNniById(msg.NniPortID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 684 | if msg.OperState == types.UP { |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 685 | if err := nni.OperState.Event("enable"); err != nil { |
| 686 | log.WithFields(log.Fields{ |
| 687 | "Type": nni.Type, |
| 688 | "IntfId": nni.ID, |
| 689 | "OperState": nni.OperState.Current(), |
| 690 | }).Errorf("Can't move NNI Port to enabled state: %v", err) |
| 691 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 692 | } else if msg.OperState == types.DOWN { |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 693 | if err := nni.OperState.Event("disable"); err != nil { |
| 694 | log.WithFields(log.Fields{ |
| 695 | "Type": nni.Type, |
| 696 | "IntfId": nni.ID, |
| 697 | "OperState": nni.OperState.Current(), |
| 698 | }).Errorf("Can't move NNI Port to disable state: %v", err) |
| 699 | } |
| 700 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 701 | // NOTE Operstate may need to be an integer |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 702 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 703 | Type: nni.Type, |
| 704 | IntfId: nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 705 | OperState: nni.OperState.Current(), |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame] | 706 | Speed: o.NniSpeed, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 707 | }} |
| 708 | |
| 709 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 710 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 711 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 714 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 715 | "Type": nni.Type, |
| 716 | "IntfId": nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 717 | "OperState": nni.OperState.Current(), |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame] | 718 | "Speed": o.NniSpeed, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 719 | }).Debug("Sent Indication_IntfOperInd for NNI") |
| 720 | } |
| 721 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 722 | func (o *OltDevice) sendPonIndication(ponPortID uint32) { |
| 723 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 724 | stream := o.OpenoltStream |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 725 | pon, _ := o.GetPonById(ponPortID) |
| 726 | // Send IntfIndication for PON port |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 727 | discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 728 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 729 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 730 | }} |
| 731 | |
| 732 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 733 | oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 734 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 737 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 738 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 739 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 740 | }).Debug("Sent Indication_IntfInd for PON") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 741 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 742 | // Send IntfOperIndication for PON port |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 743 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 744 | Type: pon.Type, |
| 745 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 746 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 747 | }} |
| 748 | |
| 749 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 750 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 751 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 754 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 755 | "Type": pon.Type, |
| 756 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 757 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 758 | }).Debug("Sent Indication_IntfOperInd for PON") |
| 759 | } |
| 760 | |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 761 | func (o *OltDevice) sendPortStatsIndication(stats *openolt.PortStatistics, portID uint32, portType string, stream openolt.Openolt_EnableIndicationServer) { |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 762 | if o.InternalState.Current() == OltInternalStateEnabled { |
Shrey Baid | 55f328c | 2020-07-07 19:20:42 +0530 | [diff] [blame] | 763 | oltLogger.WithFields(log.Fields{ |
| 764 | "Type": portType, |
| 765 | "IntfId": portID, |
| 766 | }).Trace("Sending port stats") |
| 767 | stats.IntfId = InterfaceIDToPortNo(portID, portType) |
| 768 | data := &openolt.Indication_PortStats{ |
| 769 | PortStats: stats, |
| 770 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 771 | |
Shrey Baid | 55f328c | 2020-07-07 19:20:42 +0530 | [diff] [blame] | 772 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 773 | oltLogger.Errorf("Failed to send PortStats: %v", err) |
| 774 | return |
| 775 | } |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 779 | // processOltMessages handles messages received over the OpenOLT interface |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 780 | func (o *OltDevice) processOltMessages(ctx context.Context, stream types.Stream, wg *sync.WaitGroup) { |
| 781 | oltLogger.WithFields(log.Fields{ |
| 782 | "stream": stream, |
| 783 | }).Debug("Starting OLT Indication Channel") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 784 | ch := o.channel |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 785 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 786 | loop: |
| 787 | for { |
| 788 | select { |
| 789 | case <-ctx.Done(): |
| 790 | oltLogger.Debug("OLT Indication processing canceled via context") |
| 791 | break loop |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 792 | // do not terminate this loop if the stream is closed, |
| 793 | // when we restart the gRPC server it will automatically reconnect and we need this loop to send indications |
| 794 | //case <-stream.Context().Done(): |
| 795 | // oltLogger.Debug("OLT Indication processing canceled via stream context") |
| 796 | // break loop |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 797 | case message, ok := <-ch: |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 798 | if !ok { |
| 799 | if ctx.Err() != nil { |
| 800 | oltLogger.WithField("err", ctx.Err()).Error("OLT EnableContext error") |
| 801 | } |
| 802 | oltLogger.Warn("OLT Indication processing canceled via closed channel") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 803 | break loop |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 804 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 805 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 806 | oltLogger.WithFields(log.Fields{ |
| 807 | "oltId": o.ID, |
| 808 | "messageType": message.Type, |
| 809 | }).Trace("Received message") |
| 810 | |
| 811 | switch message.Type { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 812 | case types.OltIndication: |
| 813 | msg, _ := message.Data.(types.OltIndicationMessage) |
| 814 | if msg.OperState == types.UP { |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 815 | _ = o.InternalState.Event(OltInternalTxEnable) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 816 | _ = o.OperState.Event("enable") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 817 | } else if msg.OperState == types.DOWN { |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 818 | _ = o.InternalState.Event(OltInternalTxDisable) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 819 | _ = o.OperState.Event("disable") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 820 | } |
| 821 | o.sendOltIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 822 | case types.AlarmIndication: |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 823 | alarmInd, _ := message.Data.(*openolt.AlarmIndication) |
| 824 | o.sendAlarmIndication(alarmInd, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 825 | case types.NniIndication: |
| 826 | msg, _ := message.Data.(types.NniIndicationMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 827 | o.sendNniIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 828 | case types.PonIndication: |
| 829 | msg, _ := message.Data.(types.PonIndicationMessage) |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 830 | pon, _ := o.GetPonById(msg.PonPortID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 831 | if msg.OperState == types.UP { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 832 | if err := pon.OperState.Event("enable"); err != nil { |
| 833 | oltLogger.WithFields(log.Fields{ |
| 834 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 835 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 836 | }).Error("Can't Enable Oper state for PON Port") |
| 837 | } |
| 838 | if err := pon.InternalState.Event("enable"); err != nil { |
| 839 | oltLogger.WithFields(log.Fields{ |
| 840 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 841 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 842 | }).Error("Can't Enable Internal state for PON Port") |
| 843 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 844 | } else if msg.OperState == types.DOWN { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 845 | if err := pon.OperState.Event("disable"); err != nil { |
| 846 | oltLogger.WithFields(log.Fields{ |
| 847 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 848 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 849 | }).Error("Can't Disable Oper state for PON Port") |
| 850 | } |
| 851 | if err := pon.InternalState.Event("disable"); err != nil { |
| 852 | oltLogger.WithFields(log.Fields{ |
| 853 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 854 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 855 | }).Error("Can't Disable Internal state for PON Port") |
| 856 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 857 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 858 | default: |
| 859 | oltLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type) |
| 860 | } |
| 861 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 862 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 863 | wg.Done() |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 864 | oltLogger.WithFields(log.Fields{ |
| 865 | "stream": stream, |
| 866 | }).Warn("Stopped handling OLT Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 869 | // returns an ONU with a given Serial Number |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 870 | func (o *OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 871 | // NOTE this function can be a performance bottleneck when we have many ONUs, |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 872 | // memoizing it will remove the bottleneck |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 873 | for _, pon := range o.Pons { |
| 874 | for _, onu := range pon.Onus { |
| 875 | if onu.Sn() == serialNumber { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 876 | return onu, nil |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 881 | return &Onu{}, fmt.Errorf("cannot-find-onu-by-serial-number-%s", serialNumber) |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 882 | } |
| 883 | |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 884 | // returns an ONU with a given interface/Onu Id |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 885 | func (o *OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 886 | // NOTE this function can be a performance bottleneck when we have many ONUs, |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 887 | // memoizing it will remove the bottleneck |
| 888 | for _, pon := range o.Pons { |
| 889 | if pon.ID == intfId { |
| 890 | for _, onu := range pon.Onus { |
| 891 | if onu.ID == onuId { |
| 892 | return onu, nil |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 897 | return &Onu{}, fmt.Errorf("cannot-find-onu-by-id-%v-%v", intfId, onuId) |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 898 | } |
| 899 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 900 | // returns a Service with a given Mac Address |
| 901 | func (o *OltDevice) FindServiceByMacAddress(mac net.HardwareAddr) (ServiceIf, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 902 | // NOTE this function can be a performance bottleneck when we have many ONUs, |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 903 | // memoizing it will remove the bottleneck |
| 904 | for _, pon := range o.Pons { |
| 905 | for _, onu := range pon.Onus { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 906 | s, err := onu.findServiceByMacAddress(mac) |
| 907 | if err == nil { |
| 908 | return s, nil |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | } |
| 912 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 913 | return nil, fmt.Errorf("cannot-find-service-by-mac-address-%s", mac) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 916 | // GRPC Endpoints |
| 917 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 918 | func (o *OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 919 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 920 | pon, _ := o.GetPonById(onu.IntfId) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 921 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 922 | // Enable the resource maps for this ONU |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 923 | olt.AllocIDs[onu.IntfId][onu.OnuId] = make(map[uint32]map[int32]map[uint64]bool) |
| 924 | olt.GemPortIDs[onu.IntfId][onu.OnuId] = make(map[uint32]map[int32]map[uint64]bool) |
| 925 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 926 | _onu, _ := pon.GetOnuBySn(onu.SerialNumber) |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 927 | |
| 928 | publishEvent("ONU-activate-indication-received", int32(onu.IntfId), int32(onu.OnuId), _onu.Sn()) |
| 929 | oltLogger.WithFields(log.Fields{ |
| 930 | "OnuSn": _onu.Sn(), |
| 931 | }).Info("Received ActivateOnu call from VOLTHA") |
| 932 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 933 | _onu.SetID(onu.OnuId) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 934 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 935 | if err := _onu.InternalState.Event(OnuTxEnable); err != nil { |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 936 | oltLogger.WithFields(log.Fields{ |
| 937 | "IntfId": _onu.PonPortID, |
| 938 | "OnuSn": _onu.Sn(), |
| 939 | "OnuId": _onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 940 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateEnabled, err.Error()) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | // NOTE we need to immediately activate the ONU or the OMCI state machine won't start |
| 944 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 945 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 948 | func (o *OltDevice) DeactivateOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 949 | oltLogger.Error("DeactivateOnu not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 950 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 953 | func (o *OltDevice) DeleteOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 954 | oltLogger.WithFields(log.Fields{ |
| 955 | "IntfId": onu.IntfId, |
| 956 | "OnuId": onu.OnuId, |
| 957 | }).Info("Received DeleteOnu call from VOLTHA") |
| 958 | |
| 959 | pon, err := o.GetPonById(onu.IntfId) |
| 960 | if err != nil { |
| 961 | oltLogger.WithFields(log.Fields{ |
| 962 | "OnuId": onu.OnuId, |
| 963 | "IntfId": onu.IntfId, |
| 964 | "err": err, |
| 965 | }).Error("Can't find PonPort") |
| 966 | } |
| 967 | _onu, err := pon.GetOnuById(onu.OnuId) |
| 968 | if err != nil { |
| 969 | oltLogger.WithFields(log.Fields{ |
| 970 | "OnuId": onu.OnuId, |
| 971 | "IntfId": onu.IntfId, |
| 972 | "err": err, |
| 973 | }).Error("Can't find Onu") |
| 974 | } |
| 975 | |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 976 | if _onu.InternalState.Current() != OnuStateDisabled { |
| 977 | if err := _onu.InternalState.Event(OnuTxDisable); err != nil { |
| 978 | oltLogger.WithFields(log.Fields{ |
| 979 | "IntfId": _onu.PonPortID, |
| 980 | "OnuSn": _onu.Sn(), |
| 981 | "OnuId": _onu.ID, |
| 982 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateDisabled, err.Error()) |
| 983 | } |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 984 | } |
| 985 | |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 986 | // ONU Re-Discovery |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 987 | if o.InternalState.Current() == OltInternalStateEnabled && pon.InternalState.Current() == "enabled" { |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 988 | go _onu.ReDiscoverOnu(false) |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 989 | } |
| 990 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 991 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 994 | func (o *OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 995 | // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether? |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 996 | oltLogger.WithFields(log.Fields{ |
| 997 | "oltId": o.ID, |
| 998 | }).Info("Disabling OLT") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 999 | publishEvent("OLT-disable-received", -1, -1, "") |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 1000 | |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 1001 | for _, pon := range o.Pons { |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1002 | if pon.InternalState.Current() == "enabled" { |
| 1003 | // disable PONs |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1004 | msg := types.Message{ |
| 1005 | Type: types.PonIndication, |
| 1006 | Data: types.PonIndicationMessage{ |
| 1007 | OperState: types.DOWN, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1008 | PonPortID: pon.ID, |
| 1009 | }, |
| 1010 | } |
| 1011 | o.channel <- msg |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 1012 | } |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 1015 | // Note that we are not disabling the NNI as the real OLT does not. |
| 1016 | // The reason for that is in-band management |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 1017 | |
| 1018 | // disable OLT |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1019 | oltMsg := types.Message{ |
| 1020 | Type: types.OltIndication, |
| 1021 | Data: types.OltIndicationMessage{ |
| 1022 | OperState: types.DOWN, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1023 | }, |
| 1024 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 1025 | o.channel <- oltMsg |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1026 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1027 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1030 | func (o *OltDevice) DisablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 1031 | oltLogger.Infof("DisablePonIf request received for PON %d", intf.IntfId) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1032 | ponID := intf.GetIntfId() |
| 1033 | pon, _ := o.GetPonById(intf.IntfId) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1034 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1035 | msg := types.Message{ |
| 1036 | Type: types.PonIndication, |
| 1037 | Data: types.PonIndicationMessage{ |
| 1038 | OperState: types.DOWN, |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1039 | PonPortID: ponID, |
| 1040 | }, |
| 1041 | } |
| 1042 | o.channel <- msg |
| 1043 | |
| 1044 | for _, onu := range pon.Onus { |
| 1045 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1046 | onuIndication := types.OnuIndicationMessage{ |
| 1047 | OperState: types.DOWN, |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1048 | PonPortID: ponID, |
| 1049 | OnuID: onu.ID, |
| 1050 | OnuSN: onu.SerialNumber, |
| 1051 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1052 | onu.sendOnuIndication(onuIndication, o.OpenoltStream) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1053 | |
| 1054 | } |
| 1055 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1056 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 1059 | func (o *OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1060 | oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1061 | publishEvent("OLT-enable-received", -1, -1, "") |
Elia Battiston | 67e9e4c | 2022-02-15 16:38:40 +0100 | [diff] [blame] | 1062 | return o.Enable(stream) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1065 | func (o *OltDevice) EnablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 1066 | oltLogger.Infof("EnablePonIf request received for PON %d", intf.IntfId) |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1067 | ponID := intf.GetIntfId() |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1068 | pon, _ := o.GetPonById(intf.IntfId) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1069 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1070 | msg := types.Message{ |
| 1071 | Type: types.PonIndication, |
| 1072 | Data: types.PonIndicationMessage{ |
| 1073 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1074 | PonPortID: ponID, |
| 1075 | }, |
| 1076 | } |
| 1077 | o.channel <- msg |
| 1078 | |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1079 | for _, onu := range pon.Onus { |
| 1080 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1081 | onuIndication := types.OnuIndicationMessage{ |
| 1082 | OperState: types.UP, |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1083 | PonPortID: ponID, |
| 1084 | OnuID: onu.ID, |
| 1085 | OnuSN: onu.SerialNumber, |
| 1086 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1087 | onu.sendOnuIndication(onuIndication, o.OpenoltStream) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1088 | |
| 1089 | } |
| 1090 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1091 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1094 | func (o *OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1095 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1096 | "IntfId": flow.AccessIntfId, |
| 1097 | "OnuId": flow.OnuId, |
| 1098 | "EthType": fmt.Sprintf("%x", flow.Classifier.EthType), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1099 | "InnerVlan": flow.Classifier.IVid, |
| 1100 | "OuterVlan": flow.Classifier.OVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1101 | "FlowType": flow.FlowType, |
| 1102 | "FlowId": flow.FlowId, |
| 1103 | "UniID": flow.UniId, |
| 1104 | "PortNo": flow.PortNo, |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1105 | }).Tracef("OLT receives FlowAdd") |
| 1106 | |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1107 | flowKey := FlowKey{} |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1108 | if !o.enablePerf { |
yasin sapli | c07b952 | 2022-01-27 11:23:54 +0000 | [diff] [blame] | 1109 | flowKey = FlowKey{ID: flow.FlowId} |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1110 | olt.Flows.Store(flowKey, *flow) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1111 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1112 | |
| 1113 | if flow.AccessIntfId == -1 { |
| 1114 | oltLogger.WithFields(log.Fields{ |
| 1115 | "FlowId": flow.FlowId, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1116 | }).Debug("Adding OLT flow") |
Jonathan Hart | b5fc46a | 2020-03-31 16:42:31 -0700 | [diff] [blame] | 1117 | } else if flow.FlowType == "multicast" { |
| 1118 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1119 | "Cookie": flow.Cookie, |
| 1120 | "DstPort": flow.Classifier.DstPort, |
| 1121 | "EthType": fmt.Sprintf("%x", flow.Classifier.EthType), |
| 1122 | "FlowId": flow.FlowId, |
| 1123 | "FlowType": flow.FlowType, |
| 1124 | "GemportId": flow.GemportId, |
| 1125 | "InnerVlan": flow.Classifier.IVid, |
| 1126 | "IntfId": flow.AccessIntfId, |
| 1127 | "IpProto": flow.Classifier.IpProto, |
| 1128 | "OnuId": flow.OnuId, |
| 1129 | "OuterVlan": flow.Classifier.OVid, |
| 1130 | "PortNo": flow.PortNo, |
| 1131 | "SrcPort": flow.Classifier.SrcPort, |
| 1132 | "UniID": flow.UniId, |
| 1133 | "ClassifierOPbits": flow.Classifier.OPbits, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1134 | }).Debug("Adding OLT multicast flow") |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1135 | } else { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1136 | pon, err := o.GetPonById(uint32(flow.AccessIntfId)) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1137 | if err != nil { |
| 1138 | oltLogger.WithFields(log.Fields{ |
| 1139 | "OnuId": flow.OnuId, |
| 1140 | "IntfId": flow.AccessIntfId, |
| 1141 | "err": err, |
| 1142 | }).Error("Can't find PonPort") |
| 1143 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1144 | onu, err := pon.GetOnuById(uint32(flow.OnuId)) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1145 | if err != nil { |
| 1146 | oltLogger.WithFields(log.Fields{ |
| 1147 | "OnuId": flow.OnuId, |
| 1148 | "IntfId": flow.AccessIntfId, |
| 1149 | "err": err, |
| 1150 | }).Error("Can't find Onu") |
Jonathan Hart | b5fc46a | 2020-03-31 16:42:31 -0700 | [diff] [blame] | 1151 | return nil, err |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1152 | } |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1153 | |
| 1154 | // if the ONU is disabled reject the flow |
| 1155 | // as per VOL-4061 there is a small window during which the ONU is disabled |
| 1156 | // but the port has not been reported as down to ONOS |
| 1157 | if onu.InternalState.Is(OnuStatePonDisabled) || onu.InternalState.Is(OnuStateDisabled) { |
| 1158 | oltLogger.WithFields(log.Fields{ |
| 1159 | "OnuId": flow.OnuId, |
| 1160 | "IntfId": flow.AccessIntfId, |
| 1161 | "Flow": flow, |
| 1162 | "SerialNumber": onu.Sn(), |
| 1163 | "InternalState": onu.InternalState.Current(), |
| 1164 | }).Error("rejected-flow-because-of-onu-state") |
| 1165 | return nil, fmt.Errorf("onu-%s-is-currently-%s", onu.Sn(), onu.InternalState.Current()) |
| 1166 | } |
| 1167 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1168 | if !o.enablePerf { |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1169 | onu.Flows = append(onu.Flows, flowKey) |
Pragya Arya | 1d5ffb8 | 2020-03-20 18:51:37 +0530 | [diff] [blame] | 1170 | // Generate event on first flow for ONU |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1171 | if len(onu.Flows) == 1 { |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1172 | publishEvent("Flow-add-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn()) |
Pragya Arya | 1d5ffb8 | 2020-03-20 18:51:37 +0530 | [diff] [blame] | 1173 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1174 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1175 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1176 | // validate that the flow reference correct IDs (Alloc, Gem) |
| 1177 | if err := o.validateFlow(flow); err != nil { |
| 1178 | oltLogger.WithFields(log.Fields{ |
| 1179 | "OnuId": flow.OnuId, |
| 1180 | "IntfId": flow.AccessIntfId, |
| 1181 | "Flow": flow, |
| 1182 | "SerialNumber": onu.Sn(), |
| 1183 | "err": err, |
| 1184 | }).Error("invalid-flow-for-onu") |
| 1185 | return nil, err |
| 1186 | } |
| 1187 | |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1188 | if err := o.storeGemPortIdByFlow(flow); err != nil { |
| 1189 | return nil, err |
| 1190 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1191 | o.storeAllocId(flow) |
| 1192 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1193 | msg := types.Message{ |
| 1194 | Type: types.FlowAdd, |
| 1195 | Data: types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1196 | PonPortID: pon.ID, |
| 1197 | OnuID: onu.ID, |
| 1198 | Flow: flow, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1199 | }, |
| 1200 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 1201 | onu.Channel <- msg |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1204 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1207 | // FlowRemove request from VOLTHA |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1208 | func (o *OltDevice) FlowRemove(_ context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1209 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1210 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1211 | "AllocId": flow.AllocId, |
| 1212 | "Cookie": flow.Cookie, |
| 1213 | "FlowId": flow.FlowId, |
| 1214 | "FlowType": flow.FlowType, |
| 1215 | "GemportId": flow.GemportId, |
| 1216 | "IntfId": flow.AccessIntfId, |
| 1217 | "OnuId": flow.OnuId, |
| 1218 | "PortNo": flow.PortNo, |
| 1219 | "UniID": flow.UniId, |
| 1220 | "ReplicateFlow": flow.ReplicateFlow, |
| 1221 | "PbitToGemport": flow.PbitToGemport, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1222 | }).Debug("OLT receives FlowRemove") |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1223 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1224 | olt.freeGemPortId(flow) |
| 1225 | olt.freeAllocId(flow) |
| 1226 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1227 | if !o.enablePerf { // remove only if flow were stored |
yasin sapli | c07b952 | 2022-01-27 11:23:54 +0000 | [diff] [blame] | 1228 | flowKey := FlowKey{ID: flow.FlowId} |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1229 | // Check if flow exists |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1230 | storedFlowIntf, ok := o.Flows.Load(flowKey) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1231 | if !ok { |
| 1232 | oltLogger.Errorf("Flow %v not found", flow) |
| 1233 | return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found") |
| 1234 | } |
| 1235 | |
Andrea Campanella | be8e12f | 2020-12-14 18:43:41 +0100 | [diff] [blame] | 1236 | storedFlow := storedFlowIntf.(openolt.Flow) |
| 1237 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1238 | // if its ONU flow remove it from ONU also |
| 1239 | if storedFlow.AccessIntfId != -1 { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1240 | pon, err := o.GetPonById(uint32(storedFlow.AccessIntfId)) |
| 1241 | if err != nil { |
| 1242 | oltLogger.WithFields(log.Fields{ |
| 1243 | "OnuId": storedFlow.OnuId, |
| 1244 | "IntfId": storedFlow.AccessIntfId, |
| 1245 | "PONs": olt.Pons, |
| 1246 | "err": err, |
| 1247 | }).Error("PON-port-not-found") |
| 1248 | return new(openolt.Empty), nil |
| 1249 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1250 | onu, err := pon.GetOnuById(uint32(storedFlow.OnuId)) |
| 1251 | if err != nil { |
| 1252 | oltLogger.WithFields(log.Fields{ |
| 1253 | "OnuId": storedFlow.OnuId, |
| 1254 | "IntfId": storedFlow.AccessIntfId, |
| 1255 | "err": err, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1256 | }).Error("ONU-not-found") |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1257 | return new(openolt.Empty), nil |
| 1258 | } |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1259 | onu.DeleteFlow(flowKey) |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1260 | publishEvent("Flow-remove-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn()) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | // delete from olt flows |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1264 | o.Flows.Delete(flowKey) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1265 | } |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1266 | |
| 1267 | if flow.AccessIntfId == -1 { |
| 1268 | oltLogger.WithFields(log.Fields{ |
| 1269 | "FlowId": flow.FlowId, |
| 1270 | }).Debug("Removing OLT flow") |
| 1271 | } else if flow.FlowType == "multicast" { |
| 1272 | oltLogger.WithFields(log.Fields{ |
| 1273 | "FlowId": flow.FlowId, |
| 1274 | }).Debug("Removing OLT multicast flow") |
| 1275 | } else { |
| 1276 | |
| 1277 | onu, err := o.GetOnuByFlowId(flow.FlowId) |
| 1278 | if err != nil { |
| 1279 | oltLogger.WithFields(log.Fields{ |
| 1280 | "OnuId": flow.OnuId, |
| 1281 | "IntfId": flow.AccessIntfId, |
| 1282 | "err": err, |
| 1283 | }).Error("Can't find Onu") |
| 1284 | return nil, err |
| 1285 | } |
| 1286 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1287 | msg := types.Message{ |
| 1288 | Type: types.FlowRemoved, |
| 1289 | Data: types.OnuFlowUpdateMessage{ |
Shrey Baid | 55f328c | 2020-07-07 19:20:42 +0530 | [diff] [blame] | 1290 | Flow: flow, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1291 | }, |
| 1292 | } |
| 1293 | onu.Channel <- msg |
| 1294 | } |
| 1295 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1296 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1299 | func (o *OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) { |
Abhilash Laxmeshwar | 84425a0 | 2022-06-15 17:25:14 +0530 | [diff] [blame] | 1300 | res := openolt.Heartbeat{HeartbeatSignature: o.signature} |
Matteo Scandolo | 1885985 | 2020-01-15 13:33:57 -0800 | [diff] [blame] | 1301 | oltLogger.WithFields(log.Fields{ |
| 1302 | "signature": res.HeartbeatSignature, |
| 1303 | }).Trace("HeartbeatCheck") |
| 1304 | return &res, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1307 | func (o *OltDevice) GetOnuByFlowId(flowId uint64) (*Onu, error) { |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1308 | for _, pon := range o.Pons { |
| 1309 | for _, onu := range pon.Onus { |
| 1310 | for _, fId := range onu.FlowIds { |
| 1311 | if fId == flowId { |
| 1312 | return onu, nil |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1317 | return nil, fmt.Errorf("Cannot find Onu by flowId %d", flowId) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1320 | func (o *OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1321 | devinfo := &openolt.DeviceInfo{ |
| 1322 | Vendor: common.Config.Olt.Vendor, |
| 1323 | Model: common.Config.Olt.Model, |
| 1324 | HardwareVersion: common.Config.Olt.HardwareVersion, |
| 1325 | FirmwareVersion: common.Config.Olt.FirmwareVersion, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1326 | PonPorts: uint32(o.NumPon), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1327 | DeviceSerialNumber: o.SerialNumber, |
| 1328 | DeviceId: common.Config.Olt.DeviceId, |
| 1329 | PreviouslyConnected: o.PreviouslyConnected, |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 1330 | Ranges: []*openolt.DeviceInfo_DeviceResourceRanges{}, |
| 1331 | } |
| 1332 | |
| 1333 | for _, resRange := range common.PonsConfig.Ranges { |
| 1334 | intfIDs := []uint32{} |
| 1335 | for i := resRange.PonRange.StartId; i <= resRange.PonRange.EndId; i++ { |
| 1336 | intfIDs = append(intfIDs, uint32(i)) |
| 1337 | } |
| 1338 | |
| 1339 | devinfo.Ranges = append(devinfo.Ranges, &openolt.DeviceInfo_DeviceResourceRanges{ |
| 1340 | IntfIds: intfIDs, |
| 1341 | Technology: resRange.Technology, |
| 1342 | Pools: []*openolt.DeviceInfo_DeviceResourceRanges_Pool{ |
| 1343 | { |
| 1344 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID, |
| 1345 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF, |
| 1346 | Start: resRange.OnuRange.StartId, |
| 1347 | End: resRange.OnuRange.EndId, |
| 1348 | }, |
| 1349 | { |
| 1350 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID, |
| 1351 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF, |
| 1352 | Start: resRange.AllocIdRange.StartId, |
| 1353 | End: resRange.AllocIdRange.EndId, |
| 1354 | }, |
| 1355 | { |
| 1356 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID, |
| 1357 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF, |
| 1358 | Start: resRange.GemportRange.StartId, |
| 1359 | End: resRange.GemportRange.EndId, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1360 | }, |
| 1361 | }, |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 1362 | }) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1363 | } |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1364 | |
| 1365 | oltLogger.WithFields(log.Fields{ |
| 1366 | "Vendor": devinfo.Vendor, |
| 1367 | "Model": devinfo.Model, |
| 1368 | "HardwareVersion": devinfo.HardwareVersion, |
| 1369 | "FirmwareVersion": devinfo.FirmwareVersion, |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1370 | "PonPorts": devinfo.PonPorts, |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1371 | "DeviceSerialNumber": devinfo.DeviceSerialNumber, |
| 1372 | "DeviceId": devinfo.DeviceId, |
| 1373 | "PreviouslyConnected": devinfo.PreviouslyConnected, |
| 1374 | }).Info("OLT receives GetDeviceInfo call from VOLTHA") |
| 1375 | |
| 1376 | // once we connect, set the flag |
| 1377 | o.PreviouslyConnected = true |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1378 | |
| 1379 | return devinfo, nil |
| 1380 | } |
| 1381 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1382 | func (o *OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) { |
Jonathan Hart | acfa20e | 2020-03-31 15:20:14 -0700 | [diff] [blame] | 1383 | pon, err := o.GetPonById(omci_msg.IntfId) |
| 1384 | if err != nil { |
| 1385 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 1386 | "error": err, |
Jonathan Hart | acfa20e | 2020-03-31 15:20:14 -0700 | [diff] [blame] | 1387 | "onu_id": omci_msg.OnuId, |
| 1388 | "pon_id": omci_msg.IntfId, |
| 1389 | }).Error("pon ID not found") |
| 1390 | return nil, err |
| 1391 | } |
| 1392 | |
| 1393 | onu, err := pon.GetOnuById(omci_msg.OnuId) |
| 1394 | if err != nil { |
| 1395 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 1396 | "error": err, |
Jonathan Hart | acfa20e | 2020-03-31 15:20:14 -0700 | [diff] [blame] | 1397 | "onu_id": omci_msg.OnuId, |
| 1398 | "pon_id": omci_msg.IntfId, |
| 1399 | }).Error("onu ID not found") |
| 1400 | return nil, err |
| 1401 | } |
| 1402 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 1403 | oltLogger.WithFields(log.Fields{ |
| 1404 | "IntfId": onu.PonPortID, |
| 1405 | "OnuId": onu.ID, |
| 1406 | "OnuSn": onu.Sn(), |
| 1407 | }).Tracef("Received OmciMsgOut") |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1408 | omciPkt, omciMsg, err := omcilib.ParseOpenOltOmciPacket(omci_msg.Pkt) |
| 1409 | if err != nil { |
| 1410 | log.WithFields(log.Fields{ |
| 1411 | "IntfId": onu.PonPortID, |
| 1412 | "SerialNumber": onu.Sn(), |
Holger Hildebrandt | 02101a6 | 2022-04-06 13:00:51 +0000 | [diff] [blame] | 1413 | "omciPacket": hex.EncodeToString(omci_msg.Pkt), |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1414 | "err": err.Error(), |
| 1415 | }).Error("cannot-parse-OMCI-packet") |
| 1416 | return nil, fmt.Errorf("olt-received-malformed-omci-packet") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1417 | } |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1418 | if onu.InternalState.Current() == OnuStateDisabled { |
| 1419 | // if the ONU is disabled just drop the message |
| 1420 | log.WithFields(log.Fields{ |
| 1421 | "IntfId": onu.PonPortID, |
| 1422 | "SerialNumber": onu.Sn(), |
| 1423 | "omciBytes": hex.EncodeToString(omciPkt.Data()), |
| 1424 | "omciPkt": omciPkt, |
| 1425 | "omciMsgType": omciMsg.MessageType, |
| 1426 | }).Warn("dropping-omci-message") |
| 1427 | } else { |
| 1428 | msg := types.Message{ |
| 1429 | Type: types.OMCI, |
| 1430 | Data: types.OmciMessage{ |
| 1431 | OnuSN: onu.SerialNumber, |
| 1432 | OnuID: onu.ID, |
| 1433 | OmciMsg: omciMsg, |
| 1434 | OmciPkt: omciPkt, |
| 1435 | }, |
| 1436 | } |
| 1437 | onu.Channel <- msg |
| 1438 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1439 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1442 | // this gRPC methods receives packets from VOLTHA and sends them to the subscriber on the ONU |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1443 | func (o *OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1444 | pon, err := o.GetPonById(onuPkt.IntfId) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1445 | if err != nil { |
| 1446 | oltLogger.WithFields(log.Fields{ |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 1447 | "OnuId": onuPkt.OnuId, |
| 1448 | "IntfId": onuPkt.IntfId, |
| 1449 | "GemportId": onuPkt.GemportId, |
| 1450 | "err": err, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1451 | }).Error("Can't find PonPort") |
| 1452 | } |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1453 | |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 1454 | onus := make([]*Onu, 1) |
| 1455 | // If it's not addressed to multicast gem port |
| 1456 | if onuPkt.GemportId != multicastGemPortId { |
| 1457 | onus[0], err = pon.GetOnuById(onuPkt.OnuId) |
| 1458 | if err != nil { |
| 1459 | oltLogger.WithFields(log.Fields{ |
| 1460 | "OnuId": onuPkt.OnuId, |
| 1461 | "IntfId": onuPkt.IntfId, |
| 1462 | "GemportId": onuPkt.GemportId, |
| 1463 | "err": err, |
| 1464 | }).Error("Can't find Onu") |
| 1465 | return new(openolt.Empty), errors.New("cant-find-onu-by-id") |
| 1466 | } |
| 1467 | oltLogger.WithFields(log.Fields{ |
| 1468 | "IntfId": onus[0].PonPortID, |
| 1469 | "OnuId": onus[0].ID, |
| 1470 | "OnuSn": onus[0].Sn(), |
| 1471 | "GemportId": onuPkt.GemportId, |
| 1472 | "Packet": hex.EncodeToString(onuPkt.Pkt), |
| 1473 | }).Trace("Received OnuPacketOut") |
| 1474 | } else { |
| 1475 | onus = pon.GetAllOnus() |
| 1476 | oltLogger.WithFields(log.Fields{ |
| 1477 | "IntfId": onuPkt.IntfId, |
| 1478 | "GemportId": onuPkt.GemportId, |
| 1479 | "Packet": hex.EncodeToString(onuPkt.Pkt), |
| 1480 | }).Trace("Received OnuPacketOut to multicast gem port") |
| 1481 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1482 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1483 | rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1484 | |
| 1485 | pktType, err := packetHandlers.GetPktType(rawpkt) |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1486 | if err != nil { |
| 1487 | onuLogger.WithFields(log.Fields{ |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 1488 | "IntfId": onuPkt.IntfId, |
| 1489 | "OnuId": onuPkt.OnuId, |
| 1490 | "GemportId": onuPkt.GemportId, |
| 1491 | "Pkt": hex.EncodeToString(rawpkt.Data()), |
| 1492 | }).Debug("Can't find pktType in packet, dropping it") |
| 1493 | return new(openolt.Empty), errors.New("malformed-packet") |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1494 | } |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1495 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1496 | pktMac, err := packetHandlers.GetDstMacAddressFromPacket(rawpkt) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1497 | if err != nil { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1498 | onuLogger.WithFields(log.Fields{ |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 1499 | "IntfId": onuPkt.IntfId, |
| 1500 | "OnuId": onuPkt.OnuId, |
| 1501 | "GemportId": onuPkt.GemportId, |
| 1502 | "Pkt": rawpkt.Data(), |
| 1503 | }).Debug("Can't find Dst MacAddress in packet, droppint it") |
| 1504 | return new(openolt.Empty), errors.New("dst-mac-can-not-found-in-packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1507 | msg := types.Message{ |
| 1508 | Type: types.OnuPacketOut, |
| 1509 | Data: types.OnuPacketMessage{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1510 | IntfId: onuPkt.IntfId, |
| 1511 | OnuId: onuPkt.OnuId, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1512 | PortNo: onuPkt.PortNo, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1513 | Packet: rawpkt, |
| 1514 | Type: pktType, |
| 1515 | MacAddress: pktMac, |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1516 | }, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1517 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1518 | |
Baris Ertas | 53ab13c | 2023-05-25 16:31:48 +0300 | [diff] [blame] | 1519 | for _, onu := range onus { |
| 1520 | if onu.InternalState.Current() == OnuStateEnabled { |
| 1521 | oltLogger.WithFields(log.Fields{ |
| 1522 | "IntfId": onu.PonPortID, |
| 1523 | "OnuId": onu.ID, |
| 1524 | "OnuSn": onu.Sn(), |
| 1525 | }).Trace("Sending to onuchannel") |
| 1526 | onu.Channel <- msg |
| 1527 | } else { |
| 1528 | oltLogger.WithFields(log.Fields{ |
| 1529 | "IntfId": onu.PonPortID, |
| 1530 | "OnuId": onu.ID, |
| 1531 | "OnuSn": onu.Sn(), |
| 1532 | }).Debug("can-not-send-onu-packet-out-to-onu") |
| 1533 | } |
| 1534 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1535 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1536 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1539 | func (o *OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 1540 | |
| 1541 | // OLT Reboot is called in two cases: |
| 1542 | // - when an OLT is being removed (voltctl device disable -> voltctl device delete are called, then a new voltctl device create -> voltctl device enable will be issued) |
| 1543 | // - when an OLT needs to be rebooted (voltcl device reboot) |
| 1544 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 1545 | oltLogger.WithFields(log.Fields{ |
| 1546 | "oltId": o.ID, |
| 1547 | }).Info("Shutting down") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1548 | publishEvent("OLT-reboot-received", -1, -1, "") |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1549 | go func() { _ = o.RestartOLT() }() |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1550 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1553 | func (o *OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 1554 | oltLogger.WithFields(log.Fields{ |
| 1555 | "oltId": o.ID, |
| 1556 | }).Info("Received ReenableOlt request from VOLTHA") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1557 | publishEvent("OLT-reenable-received", -1, -1, "") |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 1558 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1559 | // enable OLT |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1560 | oltMsg := types.Message{ |
| 1561 | Type: types.OltIndication, |
| 1562 | Data: types.OltIndicationMessage{ |
| 1563 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1564 | }, |
Pragya Arya | 1881df0 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1565 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1566 | o.channel <- oltMsg |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 1567 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1568 | for _, pon := range o.Pons { |
| 1569 | if pon.InternalState.Current() == "disabled" { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1570 | msg := types.Message{ |
| 1571 | Type: types.PonIndication, |
| 1572 | Data: types.PonIndicationMessage{ |
| 1573 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1574 | PonPortID: pon.ID, |
| 1575 | }, |
| 1576 | } |
| 1577 | o.channel <- msg |
| 1578 | } |
| 1579 | } |
Matteo Scandolo | e60a505 | 2020-02-07 00:31:14 +0000 | [diff] [blame] | 1580 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1581 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1584 | func (o *OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1585 | pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 1586 | |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 1587 | err := o.Nnis[0].handleNniPacket(pkt) // FIXME we are assuming we have only one NNI |
| 1588 | |
| 1589 | if err != nil { |
| 1590 | return nil, err |
| 1591 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1592 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1595 | func (o *OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1596 | oltLogger.Error("CollectStatistics not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1597 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
nikesh.krishnan | dd07b92 | 2023-07-05 23:55:42 +0530 | [diff] [blame^] | 1600 | func (o *OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuInfo, error) { |
| 1601 | pon, err := o.GetPonById(packet.GetIntfId()) |
| 1602 | if err != nil { |
| 1603 | log.WithFields(log.Fields{ |
| 1604 | "OnuId": packet.GetOnuId(), |
| 1605 | "IntfId": packet.GetIntfId(), |
| 1606 | "err": err, |
| 1607 | }).Error("Can't find PonPort") |
| 1608 | return nil, err |
| 1609 | } |
| 1610 | onu, _ := pon.GetOnuById(packet.GetOnuId()) |
| 1611 | if err != nil { |
| 1612 | log.WithFields(log.Fields{ |
| 1613 | "OnuId": packet.GetOnuId(), |
| 1614 | "IntfId": packet.GetIntfId(), |
| 1615 | "err": err, |
| 1616 | }).Error("Can't find Onu") |
| 1617 | return nil, err |
| 1618 | } |
| 1619 | |
| 1620 | resp := new(openolt.OnuInfo) |
| 1621 | resp.OnuId = packet.GetOnuId() |
| 1622 | if onu.OperState.Current() == "up" { |
| 1623 | resp.Losi = openolt.AlarmState_OFF |
| 1624 | resp.Lofi = openolt.AlarmState_OFF |
| 1625 | resp.Loami = openolt.AlarmState_OFF |
| 1626 | } else if onu.OperState.Current() == "down" { |
| 1627 | resp.Losi = openolt.AlarmState_ON |
| 1628 | resp.Lofi = openolt.AlarmState_ON |
| 1629 | resp.Loami = openolt.AlarmState_ON |
| 1630 | } |
| 1631 | if onu.InternalState.Current() == OnuStateEnabled { |
| 1632 | resp.State = openolt.OnuInfo_ACTIVE |
| 1633 | } else if onu.InternalState.Current() == OnuStateDisabled { |
| 1634 | resp.State = openolt.OnuInfo_INACTIVE |
| 1635 | } else if onu.InternalState.Current() == OnuStateCreated || (onu.InternalState.Current() == OnuStateInitialized) { |
| 1636 | resp.State = openolt.OnuInfo_NOT_CONFIGURED |
| 1637 | } else { |
| 1638 | resp.State = openolt.OnuInfo_UNKNOWN |
| 1639 | } |
| 1640 | log.WithFields(log.Fields{ |
| 1641 | "OnuId": packet.GetOnuId(), |
| 1642 | "IntfId": packet.GetIntfId(), |
| 1643 | "response": resp, |
| 1644 | }).Info("Response for onu info") |
| 1645 | return resp, nil |
| 1646 | } |
| 1647 | |
| 1648 | func (o *OltDevice) GetPonInterfaceInfo(context context.Context, packet *openolt.Interface) (*openolt.PonIntfInfo, error) { |
| 1649 | ponPort, err := o.GetPonById(packet.GetIntfId()) |
| 1650 | if err != nil { |
| 1651 | log.WithFields(log.Fields{ |
| 1652 | "IntfId": packet.GetIntfId(), |
| 1653 | "err": err, |
| 1654 | }).Error("Can't find PonPort") |
| 1655 | return nil, err |
| 1656 | } |
| 1657 | resp := new(openolt.PonIntfInfo) |
| 1658 | resp.IntfId = packet.GetIntfId() |
| 1659 | if ponPort.OperState.Current() == "up" { |
| 1660 | resp.Los = openolt.AlarmState_OFF |
| 1661 | } else if ponPort.OperState.Current() == "down" { |
| 1662 | resp.Los = openolt.AlarmState_ON |
| 1663 | } |
| 1664 | if ponPort.InternalState.Current() == "enabled" { |
| 1665 | resp.State = openolt.PonIntfInfo_ACTIVE_WORKING |
| 1666 | } else if ponPort.InternalState.Current() == "disabled" { |
| 1667 | resp.State = openolt.PonIntfInfo_INACTIVE |
| 1668 | } else if ponPort.InternalState.Current() == "created" { |
| 1669 | resp.State = openolt.PonIntfInfo_ACTIVE_STANDBY |
| 1670 | } else { |
| 1671 | resp.State = openolt.PonIntfInfo_UNKNOWN |
| 1672 | } |
| 1673 | log.WithFields(log.Fields{ |
| 1674 | "IntfId": packet.GetIntfId(), |
| 1675 | "response": resp, |
| 1676 | }).Info("Response for pon info") |
| 1677 | return resp, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1680 | func (o *OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1681 | oltLogger.Error("GetPonIf not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1682 | return new(openolt.IntfIndication), nil |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1685 | func (s *OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1686 | oltLogger.Info("received CreateTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1687 | return new(openolt.Empty), nil |
| 1688 | } |
| 1689 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1690 | func (s *OltDevice) RemoveTrafficQueues(_ context.Context, tq *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
| 1691 | oltLogger.WithFields(log.Fields{ |
| 1692 | "OnuId": tq.OnuId, |
| 1693 | "IntfId": tq.IntfId, |
| 1694 | "OnuPortNo": tq.PortNo, |
| 1695 | "UniId": tq.UniId, |
| 1696 | }).Info("received RemoveTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1697 | return new(openolt.Empty), nil |
| 1698 | } |
| 1699 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1700 | func (s *OltDevice) CreateTrafficSchedulers(_ context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1701 | oltLogger.WithFields(log.Fields{ |
| 1702 | "OnuId": trafficSchedulers.OnuId, |
| 1703 | "IntfId": trafficSchedulers.IntfId, |
| 1704 | "OnuPortNo": trafficSchedulers.PortNo, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1705 | "UniId": trafficSchedulers.UniId, |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1706 | }).Info("received CreateTrafficSchedulers") |
| 1707 | |
| 1708 | if !s.enablePerf { |
| 1709 | pon, err := s.GetPonById(trafficSchedulers.IntfId) |
| 1710 | if err != nil { |
| 1711 | oltLogger.Errorf("Error retrieving PON by IntfId: %v", err) |
| 1712 | return new(openolt.Empty), err |
| 1713 | } |
| 1714 | onu, err := pon.GetOnuById(trafficSchedulers.OnuId) |
| 1715 | if err != nil { |
| 1716 | oltLogger.Errorf("Error retrieving ONU from pon by OnuId: %v", err) |
| 1717 | return new(openolt.Empty), err |
| 1718 | } |
| 1719 | onu.TrafficSchedulers = trafficSchedulers |
| 1720 | } |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1721 | return new(openolt.Empty), nil |
| 1722 | } |
| 1723 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1724 | func (s *OltDevice) RemoveTrafficSchedulers(context context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1725 | oltLogger.WithFields(log.Fields{ |
| 1726 | "OnuId": trafficSchedulers.OnuId, |
| 1727 | "IntfId": trafficSchedulers.IntfId, |
| 1728 | "OnuPortNo": trafficSchedulers.PortNo, |
| 1729 | }).Info("received RemoveTrafficSchedulers") |
| 1730 | if !s.enablePerf { |
| 1731 | pon, err := s.GetPonById(trafficSchedulers.IntfId) |
| 1732 | if err != nil { |
| 1733 | oltLogger.Errorf("Error retrieving PON by IntfId: %v", err) |
| 1734 | return new(openolt.Empty), err |
| 1735 | } |
| 1736 | onu, err := pon.GetOnuById(trafficSchedulers.OnuId) |
| 1737 | if err != nil { |
| 1738 | oltLogger.Errorf("Error retrieving ONU from pon by OnuId: %v", err) |
| 1739 | return new(openolt.Empty), err |
| 1740 | } |
| 1741 | |
| 1742 | onu.TrafficSchedulers = nil |
| 1743 | } |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1744 | return new(openolt.Empty), nil |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1745 | } |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 1746 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1747 | func (o *OltDevice) PerformGroupOperation(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) { |
| 1748 | oltLogger.WithFields(log.Fields{ |
| 1749 | "GroupId": group.GroupId, |
| 1750 | "Command": group.Command, |
| 1751 | "Members": group.Members, |
| 1752 | "Action": group.Action, |
| 1753 | }).Debug("received PerformGroupOperation") |
| 1754 | return &openolt.Empty{}, nil |
| 1755 | } |
| 1756 | |
| 1757 | func (o *OltDevice) DeleteGroup(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) { |
| 1758 | oltLogger.WithFields(log.Fields{ |
| 1759 | "GroupId": group.GroupId, |
| 1760 | "Command": group.Command, |
| 1761 | "Members": group.Members, |
| 1762 | "Action": group.Action, |
| 1763 | }).Debug("received PerformGroupOperation") |
| 1764 | return &openolt.Empty{}, nil |
| 1765 | } |
| 1766 | |
Matteo Scandolo | 1f9f4b2 | 2021-12-14 11:51:55 -0800 | [diff] [blame] | 1767 | func (o *OltDevice) GetExtValue(ctx context.Context, in *openolt.ValueParam) (*extension.ReturnValues, error) { |
| 1768 | return &extension.ReturnValues{}, nil |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | func (o *OltDevice) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm) (*openolt.Empty, error) { |
| 1772 | return &openolt.Empty{}, nil |
| 1773 | } |
| 1774 | |
| 1775 | func (o *OltDevice) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu) (*openolt.OnuLogicalDistance, error) { |
| 1776 | return &openolt.OnuLogicalDistance{}, nil |
| 1777 | } |
| 1778 | |
| 1779 | func (o *OltDevice) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu) (*openolt.OnuLogicalDistance, error) { |
| 1780 | return &openolt.OnuLogicalDistance{}, nil |
| 1781 | } |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1782 | |
Girish Gowdra | 62f2429 | 2021-05-12 16:28:39 -0700 | [diff] [blame] | 1783 | func (o *OltDevice) GetPonRxPower(ctx context.Context, in *openolt.Onu) (*openolt.PonRxPowerData, error) { |
praneeth.nalmas | 7aa24df | 2023-03-24 10:49:43 +0530 | [diff] [blame] | 1784 | //VOL-4878:Hardcoding the power levels for testing as BBSIM is a simulator |
| 1785 | return &openolt.PonRxPowerData{IntfId: in.IntfId, OnuId: in.OnuId, Status: "success", FailReason: 0, RxPowerMeanDbm: -6}, nil |
Girish Gowdra | 62f2429 | 2021-05-12 16:28:39 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1788 | func (o *OltDevice) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket) (*openolt.GemPortStatistics, error) { |
| 1789 | return &openolt.GemPortStatistics{}, nil |
| 1790 | } |
| 1791 | |
| 1792 | func (o *OltDevice) GetOnuStatistics(ctx context.Context, in *openolt.Onu) (*openolt.OnuStatistics, error) { |
| 1793 | return &openolt.OnuStatistics{}, nil |
| 1794 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1795 | |
| 1796 | func (o *OltDevice) storeAllocId(flow *openolt.Flow) { |
| 1797 | o.AllocIDsLock.Lock() |
| 1798 | defer o.AllocIDsLock.Unlock() |
| 1799 | |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1800 | if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)]; !ok { |
| 1801 | oltLogger.WithFields(log.Fields{ |
| 1802 | "IntfId": flow.AccessIntfId, |
| 1803 | "OnuId": flow.OnuId, |
| 1804 | "PortNo": flow.PortNo, |
| 1805 | "GemportId": flow.GemportId, |
| 1806 | "FlowId": flow.FlowId, |
| 1807 | }).Error("trying-to-store-alloc-id-for-unknown-onu") |
| 1808 | } |
| 1809 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1810 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1811 | "IntfId": flow.AccessIntfId, |
| 1812 | "OnuId": flow.OnuId, |
| 1813 | "PortNo": flow.PortNo, |
| 1814 | "GemportId": flow.GemportId, |
| 1815 | "FlowId": flow.FlowId, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1816 | }).Trace("storing-alloc-id-via-flow") |
| 1817 | |
| 1818 | if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo]; !ok { |
| 1819 | o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo] = make(map[int32]map[uint64]bool) |
| 1820 | } |
| 1821 | if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId]; !ok { |
| 1822 | o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId] = make(map[uint64]bool) |
| 1823 | } |
| 1824 | o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId][flow.FlowId] = true |
| 1825 | } |
| 1826 | |
| 1827 | func (o *OltDevice) freeAllocId(flow *openolt.Flow) { |
| 1828 | // if this is the last flow referencing the AllocId then remove it |
| 1829 | o.AllocIDsLock.Lock() |
| 1830 | defer o.AllocIDsLock.Unlock() |
| 1831 | |
| 1832 | oltLogger.WithFields(log.Fields{ |
| 1833 | "IntfId": flow.AccessIntfId, |
| 1834 | "OnuId": flow.OnuId, |
| 1835 | "PortNo": flow.PortNo, |
| 1836 | "GemportId": flow.GemportId, |
| 1837 | }).Trace("freeing-alloc-id-via-flow") |
| 1838 | |
| 1839 | // NOTE look at the freeGemPortId implementation for comments and context |
| 1840 | for ponId, ponValues := range o.AllocIDs { |
| 1841 | for onuId, onuValues := range ponValues { |
| 1842 | for uniId, uniValues := range onuValues { |
| 1843 | for allocId, flows := range uniValues { |
| 1844 | for flowId := range flows { |
| 1845 | // if the flow matches, remove it from the map. |
| 1846 | if flow.FlowId == flowId { |
| 1847 | delete(o.AllocIDs[ponId][onuId][uniId][allocId], flow.FlowId) |
| 1848 | } |
| 1849 | // if that was the last flow for a particular allocId, remove the entire allocId |
| 1850 | if len(o.AllocIDs[ponId][onuId][uniId][allocId]) == 0 { |
| 1851 | delete(o.AllocIDs[ponId][onuId][uniId], allocId) |
| 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1860 | func (o *OltDevice) storeGemPortId(ponId uint32, onuId uint32, portNo uint32, gemId int32, flowId uint64) error { |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1861 | o.GemPortIDsLock.Lock() |
| 1862 | defer o.GemPortIDsLock.Unlock() |
| 1863 | |
| 1864 | if _, ok := o.GemPortIDs[ponId][onuId]; !ok { |
| 1865 | oltLogger.WithFields(log.Fields{ |
| 1866 | "IntfId": ponId, |
| 1867 | "OnuId": onuId, |
| 1868 | "PortNo": portNo, |
| 1869 | "GemportId": gemId, |
| 1870 | "FlowId": flowId, |
| 1871 | }).Error("trying-to-store-gemport-for-unknown-onu") |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1872 | return fmt.Errorf("failed-trying-to-store-gemport-%d-for-unknown-onu-%d-and-IntfId-%d", gemId, onuId, ponId) |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | oltLogger.WithFields(log.Fields{ |
| 1876 | "IntfId": ponId, |
| 1877 | "OnuId": onuId, |
| 1878 | "PortNo": portNo, |
| 1879 | "GemportId": gemId, |
| 1880 | "FlowId": flowId, |
| 1881 | }).Trace("storing-alloc-id-via-flow") |
| 1882 | |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1883 | if _, ok := o.GemPortIDs[ponId][onuId][portNo]; !ok { |
| 1884 | o.GemPortIDs[ponId][onuId][portNo] = make(map[int32]map[uint64]bool) |
| 1885 | } |
| 1886 | if _, ok := o.GemPortIDs[ponId][onuId][portNo][gemId]; !ok { |
| 1887 | o.GemPortIDs[ponId][onuId][portNo][gemId] = make(map[uint64]bool) |
| 1888 | } |
| 1889 | o.GemPortIDs[ponId][onuId][portNo][gemId][flowId] = true |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1890 | |
| 1891 | return nil |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1894 | func (o *OltDevice) storeGemPortIdByFlow(flow *openolt.Flow) error { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1895 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1896 | "IntfId": flow.AccessIntfId, |
| 1897 | "OnuId": flow.OnuId, |
| 1898 | "PortNo": flow.PortNo, |
| 1899 | "GemportId": flow.GemportId, |
| 1900 | "FlowId": flow.FlowId, |
| 1901 | "ReplicateFlow": flow.ReplicateFlow, |
| 1902 | "PbitToGemport": flow.PbitToGemport, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1903 | }).Trace("storing-gem-port-id-via-flow") |
| 1904 | |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1905 | if flow.ReplicateFlow { |
| 1906 | for _, gem := range flow.PbitToGemport { |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1907 | err := o.storeGemPortId(uint32(flow.AccessIntfId), uint32(flow.OnuId), flow.PortNo, int32(gem), flow.FlowId) |
| 1908 | if err != nil { |
| 1909 | return err |
| 1910 | } |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1911 | } |
| 1912 | } else { |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1913 | err := o.storeGemPortId(uint32(flow.AccessIntfId), uint32(flow.OnuId), flow.PortNo, flow.GemportId, flow.FlowId) |
| 1914 | if err != nil { |
| 1915 | return err |
| 1916 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1917 | } |
Abhay Kumar | 5f9b7f2 | 2023-08-03 13:09:08 +0530 | [diff] [blame] | 1918 | |
| 1919 | return nil |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | func (o *OltDevice) freeGemPortId(flow *openolt.Flow) { |
| 1923 | // if this is the last flow referencing the GemPort then remove it |
| 1924 | o.GemPortIDsLock.Lock() |
| 1925 | defer o.GemPortIDsLock.Unlock() |
| 1926 | |
| 1927 | oltLogger.WithFields(log.Fields{ |
| 1928 | "IntfId": flow.AccessIntfId, |
| 1929 | "OnuId": flow.OnuId, |
| 1930 | "PortNo": flow.PortNo, |
| 1931 | "GemportId": flow.GemportId, |
| 1932 | }).Trace("freeing-gem-port-id-via-flow") |
| 1933 | |
| 1934 | // NOTE that this loop is not very performant, it would be better if the flow carries |
| 1935 | // the same information that it carries during a FlowAdd. If so we can directly remove |
| 1936 | // items from the map |
| 1937 | |
| 1938 | //delete(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.GemportId], flow.FlowId) |
| 1939 | //if len(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.GemportId]) == 0 { |
| 1940 | // delete(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo], flow.GemportId) |
| 1941 | //} |
| 1942 | |
| 1943 | // NOTE this loop assumes that flow IDs are unique per device |
| 1944 | for ponId, ponValues := range o.GemPortIDs { |
| 1945 | for onuId, onuValues := range ponValues { |
| 1946 | for uniId, uniValues := range onuValues { |
| 1947 | for gemId, flows := range uniValues { |
| 1948 | for flowId := range flows { |
| 1949 | // if the flow matches, remove it from the map. |
| 1950 | if flow.FlowId == flowId { |
| 1951 | delete(o.GemPortIDs[ponId][onuId][uniId][gemId], flow.FlowId) |
| 1952 | } |
| 1953 | // if that was the last flow for a particular gem, remove the entire gem |
| 1954 | if len(o.GemPortIDs[ponId][onuId][uniId][gemId]) == 0 { |
| 1955 | delete(o.GemPortIDs[ponId][onuId][uniId], gemId) |
| 1956 | } |
| 1957 | } |
| 1958 | } |
| 1959 | } |
| 1960 | } |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | // validateFlow checks that: |
| 1965 | // - the AllocId is not used in any flow referencing other ONUs/UNIs on the same PON |
| 1966 | // - the GemPortId is not used in any flow referencing other ONUs/UNIs on the same PON |
| 1967 | func (o *OltDevice) validateFlow(flow *openolt.Flow) error { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1968 | // validate gemPort |
| 1969 | o.GemPortIDsLock.RLock() |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1970 | defer o.GemPortIDsLock.RUnlock() |
| 1971 | for onuId, onu := range o.GemPortIDs[uint32(flow.AccessIntfId)] { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1972 | if onuId == uint32(flow.OnuId) { |
| 1973 | continue |
| 1974 | } |
| 1975 | for uniId, uni := range onu { |
| 1976 | for gem := range uni { |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1977 | if flow.ReplicateFlow { |
| 1978 | for _, flowGem := range flow.PbitToGemport { |
| 1979 | if gem == int32(flowGem) { |
| 1980 | return fmt.Errorf("gem-%d-already-in-use-on-uni-%d-onu-%d-replicated-flow-%d", gem, uniId, onuId, flow.FlowId) |
| 1981 | } |
| 1982 | } |
| 1983 | } else { |
| 1984 | if gem == flow.GemportId { |
| 1985 | return fmt.Errorf("gem-%d-already-in-use-on-uni-%d-onu-%d-flow-%d", gem, uniId, onuId, flow.FlowId) |
| 1986 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | o.AllocIDsLock.RLock() |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1993 | defer o.AllocIDsLock.RUnlock() |
| 1994 | for onuId, onu := range o.AllocIDs[uint32(flow.AccessIntfId)] { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1995 | if onuId == uint32(flow.OnuId) { |
| 1996 | continue |
| 1997 | } |
| 1998 | for uniId, uni := range onu { |
| 1999 | for allocId := range uni { |
| 2000 | if allocId == flow.AllocId { |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 2001 | return fmt.Errorf("allocId-%d-already-in-use-on-uni-%d-onu-%d-flow-%d", allocId, uniId, onuId, flow.FlowId) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | return nil |
| 2008 | } |
| 2009 | |
| 2010 | // clearAllResources is invoked up OLT Reboot to remove all the allocated |
| 2011 | // GemPorts, AllocId and ONU-IDs across the PONs |
| 2012 | func (o *OltDevice) clearAllResources() { |
| 2013 | |
| 2014 | // remove the resources received via flows |
| 2015 | o.GemPortIDsLock.Lock() |
| 2016 | o.GemPortIDs = make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 2017 | o.GemPortIDsLock.Unlock() |
| 2018 | o.AllocIDsLock.Lock() |
| 2019 | o.AllocIDs = make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 2020 | o.AllocIDsLock.Unlock() |
| 2021 | |
| 2022 | // remove the resources received via OMCI |
| 2023 | for _, pon := range o.Pons { |
| 2024 | pon.removeAllAllocIds() |
| 2025 | pon.removeAllGemPorts() |
| 2026 | pon.removeAllOnuIds() |
| 2027 | } |
| 2028 | } |