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