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