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