blob: 91784914b09d14155d0f68439a0d97f915d2ff75 [file] [log] [blame]
Matteo Scandolo11006992019-08-28 11:29:46 -07001/*
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 Scandolo4747d292019-08-05 11:50:18 -070017package devices
18
19import (
20 "context"
Matteo Scandolo4a036262020-08-17 15:56:13 -070021 "encoding/hex"
Matteo Scandolo4747d292019-08-05 11:50:18 -070022 "fmt"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020023 "net"
Matteo Scandolof9d43412021-01-12 11:11:34 -080024 "strconv"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020025 "sync"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010026 "time"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020027
Elia Battistonac63b112022-01-12 18:40:49 +010028 "github.com/opencord/voltha-protos/v5/go/extension"
29
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000030 "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. Bainbridgec415efe2021-08-19 13:05:21 +000033 "github.com/opencord/voltha-protos/v5/go/ext/config"
Holger Hildebrandtc10bab12021-04-27 09:23:48 +000034
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070035 "github.com/google/gopacket"
36 "github.com/google/gopacket/layers"
Matteo Scandolo4747d292019-08-05 11:50:18 -070037 "github.com/looplab/fsm"
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070038 "github.com/opencord/bbsim/internal/bbsim/packetHandlers"
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010039 "github.com/opencord/bbsim/internal/common"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000040 "github.com/opencord/voltha-protos/v5/go/openolt"
41 "github.com/opencord/voltha-protos/v5/go/tech_profile"
Matteo Scandolo4747d292019-08-05 11:50:18 -070042 log "github.com/sirupsen/logrus"
43 "google.golang.org/grpc"
Pragya Arya8bdb4532020-03-02 17:08:09 +053044 "google.golang.org/grpc/codes"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010045 "google.golang.org/grpc/reflection"
Pragya Arya8bdb4532020-03-02 17:08:09 +053046 "google.golang.org/grpc/status"
Matteo Scandolo4747d292019-08-05 11:50:18 -070047)
48
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070049var oltLogger = log.WithFields(log.Fields{
Matteo Scandolo84f7d482019-08-08 19:00:47 -070050 "module": "OLT",
51})
52
Matteo Scandolocedde462021-03-09 17:37:16 -080053const (
Elia Battiston67e9e4c2022-02-15 16:38:40 +010054 //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 Scandolocedde462021-03-09 17:37:16 -080065)
66
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070067type OltDevice struct {
David Bainbridge103cf022019-12-16 20:11:35 +000068 sync.Mutex
Hardik Windlassefdb4b62021-03-18 10:33:24 +000069 OltServer *grpc.Server
David Bainbridge103cf022019-12-16 20:11:35 +000070
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070071 // BBSIM Internals
Pragya Arya2225f202020-01-29 18:05:01 +053072 ID int
73 SerialNumber string
74 NumNni int
Elia Battiston420c9092022-02-02 12:17:54 +010075 NniSpeed uint32
Pragya Arya2225f202020-01-29 18:05:01 +053076 NumPon int
77 NumOnuPerPon int
Mahir Gunyela1753ae2021-06-23 00:24:56 -070078 NumUni int
Elia Battistonac63b112022-01-12 18:40:49 +010079 NumPots int
Andrea Campanella6f5f3552022-03-10 17:14:25 +010080 NniDhcpTrapVid int
Pragya Arya2225f202020-01-29 18:05:01 +053081 InternalState *fsm.FSM
Matteo Scandolof9d43412021-01-12 11:11:34 -080082 channel chan types.Message
Matteo Scandolo90d08f62020-10-29 12:06:55 -070083 dhcpServer dhcp.DHCPServerIf
Andrea Campanellabe8e12f2020-12-14 18:43:41 +010084 Flows sync.Map
Pragya Arya2225f202020-01-29 18:05:01 +053085 Delay int
86 ControlledActivation mode
Pragya Arya324337e2020-02-20 14:35:08 +053087 EventChannel chan common.Event
88 PublishEvents bool
Pragya Arya996a0892020-03-09 21:47:52 +053089 PortStatsInterval int
Matteo Scandolo96f89192021-03-12 13:17:26 -080090 PreviouslyConnected bool
Matteo Scandoloe33447a2019-10-31 12:38:23 -070091
Matteo Scandolo27428702019-10-11 16:21:16 -070092 Pons []*PonPort
93 Nnis []*NniPort
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070094
95 // OLT Attributes
96 OperState *fsm.FSM
David Bainbridge103cf022019-12-16 20:11:35 +000097
98 enableContext context.Context
99 enableContextCancel context.CancelFunc
Pragya Arya1cbefa42020-01-13 12:15:29 +0530100
Matteo Scandolo4a036262020-08-17 15:56:13 -0700101 OpenoltStream openolt.Openolt_EnableIndicationServer
Anand S Katti09541352020-01-29 15:54:01 +0530102 enablePerf bool
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800103
104 // Allocated Resources
105 // this data are to verify that the openolt adapter does not duplicate resources
Holger Hildebrandtc10bab12021-04-27 09:23:48 +0000106 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 Scandolo4747d292019-08-05 11:50:18 -0700111}
112
Matteo Scandolo27428702019-10-11 16:21:16 -0700113var olt OltDevice
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700114
Matteo Scandolo27428702019-10-11 16:21:16 -0700115func GetOLT() *OltDevice {
116 return &olt
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700117}
118
Matteo Scandolo4a036262020-08-17 15:56:13 -0700119func CreateOLT(options common.GlobalConfig, services []common.ServiceYaml, isMock bool) *OltDevice {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700120 oltLogger.WithFields(log.Fields{
Andrea Campanella6f5f3552022-03-10 17:14:25 +0100121 "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 Scandolo4747d292019-08-05 11:50:18 -0700129 }).Debug("CreateOLT")
130
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700131 olt = OltDevice{
Pragya Arya996a0892020-03-09 21:47:52 +0530132 ID: options.Olt.ID,
133 SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", options.Olt.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700134 OperState: getOperStateFSM(func(e *fsm.Event) {
135 oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst)
136 }),
Matteo Scandolo96f89192021-03-12 13:17:26 -0800137 NumNni: int(options.Olt.NniPorts),
Elia Battiston420c9092022-02-02 12:17:54 +0100138 NniSpeed: options.Olt.NniSpeed,
Matteo Scandolo96f89192021-03-12 13:17:26 -0800139 NumPon: int(options.Olt.PonPorts),
140 NumOnuPerPon: int(options.Olt.OnusPonPort),
Mahir Gunyela1753ae2021-06-23 00:24:56 -0700141 NumUni: int(options.Olt.UniPorts),
Elia Battistonac63b112022-01-12 18:40:49 +0100142 NumPots: int(options.Olt.PotsPorts),
Andrea Campanella6f5f3552022-03-10 17:14:25 +0100143 NniDhcpTrapVid: int(options.Olt.NniDhcpTrapVid),
Matteo Scandolo96f89192021-03-12 13:17:26 -0800144 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 Scandolo4b077aa2021-02-16 17:33:37 -0800152 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 Hildebrandtc10bab12021-04-27 09:23:48 +0000154 OmciResponseRate: options.Olt.OmciResponseRate,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700155 }
156
Pragya Arya996a0892020-03-09 21:47:52 +0530157 if val, ok := ControlledActivationModes[options.BBSim.ControlledActivation]; ok {
Pragya Arya2225f202020-01-29 18:05:01 +0530158 olt.ControlledActivation = val
159 } else {
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700160 // FIXME throw an error if the ControlledActivation is not valid
Pragya Arya2225f202020-01-29 18:05:01 +0530161 oltLogger.Warn("Unknown ControlledActivation Mode given, running in Default mode")
162 olt.ControlledActivation = Default
163 }
164
Matteo Scandolo4747d292019-08-05 11:50:18 -0700165 // OLT State machine
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700166 // NOTE do we need 2 state machines for the OLT? (InternalState and OperState)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700167 olt.InternalState = fsm.NewFSM(
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100168 OltInternalStateCreated,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700169 fsm.Events{
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100170 {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 Scandolo635b2bf2020-09-04 10:23:40 -0700173 // delete event in enabled state below is for reboot OLT case.
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100174 {Name: OltInternalTxDelete, Src: []string{OltInternalStateDisabled, OltInternalStateEnabled}, Dst: OltInternalStateDeleted},
Matteo Scandolo4747d292019-08-05 11:50:18 -0700175 },
176 fsm.Callbacks{
177 "enter_state": func(e *fsm.Event) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700178 oltLogger.Debugf("Changing OLT InternalState from %s to %s", e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700179 },
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100180 fmt.Sprintf("enter_%s", OltInternalStateInitialized): func(e *fsm.Event) { olt.InitOlt() },
181 fmt.Sprintf("enter_%s", OltInternalStateDeleted): func(e *fsm.Event) {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800182 // remove all the resource allocations
183 olt.clearAllResources()
184 },
Matteo Scandolo4747d292019-08-05 11:50:18 -0700185 },
186 )
187
Shrey Baid688b4242020-07-10 20:40:10 +0530188 if !isMock {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700189 // create NNI Port
190 nniPort, err := CreateNNI(&olt)
191 if err != nil {
192 oltLogger.Fatalf("Couldn't create NNI Port: %v", err)
193 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700194
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700195 olt.Nnis = append(olt.Nnis, &nniPort)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700196 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700197
Matteo Scandolo4a036262020-08-17 15:56:13 -0700198 // Create device and Services
Matteo Scandolo4a036262020-08-17 15:56:13 -0700199 nextCtag := map[string]int{}
200 nextStag := map[string]int{}
201
Matteo Scandolo4747d292019-08-05 11:50:18 -0700202 // create PON ports
Matteo Scandolo4a036262020-08-17 15:56:13 -0700203 for i := 0; i < olt.NumPon; i++ {
Elia Battistonb7bea222022-02-18 16:25:00 +0100204 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 Scandolo4b077aa2021-02-16 17:33:37 -0800219
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 Battistonb7bea222022-02-18 16:25:00 +0100224 p := CreatePonPort(&olt, uint32(i), tech)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700225
Matteo Scandolo4a036262020-08-17 15:56:13 -0700226 // create ONU devices
Elia Battistonb7bea222022-02-18 16:25:00 +0100227 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 Scandolo4a036262020-08-17 15:56:13 -0700236 for j := 0; j < olt.NumOnuPerPon; j++ {
237 delay := time.Duration(olt.Delay*j) * time.Millisecond
Matteo Scandolo8a574812021-05-20 15:18:53 -0700238 o := CreateONU(&olt, p, uint32(j+1), delay, nextCtag, nextStag, isMock)
Matteo Scandolof65e6872020-04-15 15:18:43 -0700239
Matteo Scandolo4a036262020-08-17 15:56:13 -0700240 p.Onus = append(p.Onus, o)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700241 }
Matteo Scandolo4a036262020-08-17 15:56:13 -0700242 olt.Pons = append(olt.Pons, p)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700243 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100244
Shrey Baid688b4242020-07-10 20:40:10 +0530245 if !isMock {
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100246 if err := olt.InternalState.Event(OltInternalTxInitialize); err != nil {
Matteo Scandolod32c3822019-11-26 15:57:46 -0700247 log.Errorf("Error initializing OLT: %v", err)
248 return nil
249 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100250 }
251
Pragya Arya324337e2020-02-20 14:35:08 +0530252 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 Scandolo40e067f2019-10-16 16:59:41 -0700258 return &olt
259}
Matteo Scandolo4747d292019-08-05 11:50:18 -0700260
Shrey Baid688b4242020-07-10 20:40:10 +0530261func (o *OltDevice) InitOlt() {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100262
Hardik Windlassefdb4b62021-03-18 10:33:24 +0000263 if o.OltServer == nil {
264 o.OltServer, _ = o.StartOltServer()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100265 } else {
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800266 oltLogger.Fatal("OLT server already running.")
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100267 }
268
269 // create new channel for processOltMessages Go routine
Matteo Scandolof9d43412021-01-12 11:11:34 -0800270 o.channel = make(chan types.Message)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100271
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100272 // FIXME we are assuming we have only one NNI
273 if o.Nnis[0] != nil {
Matteo Scandolo401503a2019-12-11 14:48:14 -0800274 // 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 Bozakov681364d2019-11-10 14:28:46 +0100278 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800279
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 Scandolo4747d292019-08-05 11:50:18 -0700285}
286
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800287func (o *OltDevice) RestartOLT() error {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100288
Matteo Scandolo96f89192021-03-12 13:17:26 -0800289 o.PreviouslyConnected = false
290
Matteo Scandolo635b2bf2020-09-04 10:23:40 -0700291 softReboot := false
Matteo Scandolo4a036262020-08-17 15:56:13 -0700292 rebootDelay := common.Config.Olt.OltRebootDelay
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800293
294 oltLogger.WithFields(log.Fields{
295 "oltId": o.ID,
296 }).Infof("Simulating OLT restart... (%ds)", rebootDelay)
297
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100298 if o.InternalState.Is(OltInternalStateEnabled) {
Matteo Scandolo635b2bf2020-09-04 10:23:40 -0700299 oltLogger.WithFields(log.Fields{
300 "oltId": o.ID,
301 }).Info("This is an OLT soft reboot")
302 softReboot = true
303 }
304
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800305 // transition internal state to deleted
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100306 if err := o.InternalState.Event(OltInternalTxDelete); err != nil {
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800307 oltLogger.WithFields(log.Fields{
308 "oltId": o.ID,
309 }).Errorf("Error deleting OLT: %v", err)
310 return err
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100311 }
312
Matteo Scandolo635b2bf2020-09-04 10:23:40 -0700313 if softReboot {
314 for _, pon := range o.Pons {
315 if pon.InternalState.Current() == "enabled" {
316 // disable PONs
Matteo Scandolof9d43412021-01-12 11:11:34 -0800317 msg := types.Message{
318 Type: types.PonIndication,
319 Data: types.PonIndicationMessage{
320 OperState: types.DOWN,
Matteo Scandolo635b2bf2020-09-04 10:23:40 -0700321 PonPortID: pon.ID,
322 },
323 }
324 o.channel <- msg
325 }
326
327 for _, onu := range pon.Onus {
Andrea Campanella8ad54a42022-03-09 14:36:55 +0100328 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 Scandolo635b2bf2020-09-04 10:23:40 -0700333 }
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 Campanella8ad54a42022-03-09 14:36:55 +0100341 err := onu.InternalState.Event(OnuTxDisable)
342 oltLogger.WithFields(log.Fields{
343 "oltId": o.ID,
344 "onuId": onu.ID,
345 }).Errorf("Error disabling ONUs on OLT reboot: %v", err)
Matteo Scandolo635b2bf2020-09-04 10:23:40 -0700346 }
Pragya Arya2225f202020-01-29 18:05:01 +0530347 }
348 }
349
Matteo Scandolob307d8a2021-05-10 15:19:27 -0700350 time.Sleep(1 * time.Second) // we need to give the OLT the time to respond to all the pending gRPC request before stopping the server
351 o.StopOltServer()
352
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100353 // terminate the OLT's processOltMessages go routine
354 close(o.channel)
Matteo Scandolo90d08f62020-10-29 12:06:55 -0700355
Andrea Campanella8ad54a42022-03-09 14:36:55 +0100356 oltLogger.WithFields(log.Fields{
357 "oltId": o.ID,
358 }).Infof("Waiting OLT restart for... (%ds)", rebootDelay)
359
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100360 //Prevents Enable to progress before the reboot is completed (VOL-4616)
361 o.Lock()
Matteo Scandoloe9f5a6b2020-09-16 15:54:38 -0700362 o.enableContextCancel()
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +0100363 time.Sleep(time.Duration(rebootDelay) * time.Second)
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100364 o.Unlock()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100365
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100366 if err := o.InternalState.Event(OltInternalTxInitialize); err != nil {
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800367 oltLogger.WithFields(log.Fields{
368 "oltId": o.ID,
369 }).Errorf("Error initializing OLT: %v", err)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100370 return err
371 }
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800372 oltLogger.WithFields(log.Fields{
373 "oltId": o.ID,
374 }).Info("OLT restart completed")
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100375 return nil
376}
377
378// newOltServer launches a new grpc server for OpenOLT
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800379func (o *OltDevice) newOltServer() (*grpc.Server, error) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700380 address := common.Config.BBSim.OpenOltAddress
Matteo Scandolo4747d292019-08-05 11:50:18 -0700381 lis, err := net.Listen("tcp", address)
382 if err != nil {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700383 oltLogger.Fatalf("OLT failed to listen: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700384 }
385 grpcServer := grpc.NewServer()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100386
Matteo Scandolo4747d292019-08-05 11:50:18 -0700387 openolt.RegisterOpenoltServer(grpcServer, o)
388
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100389 reflection.Register(grpcServer)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700390
Shrey Baid688b4242020-07-10 20:40:10 +0530391 go func() { _ = grpcServer.Serve(lis) }()
Zdravko Bozakov958d81c2019-12-13 22:09:48 +0100392 oltLogger.Debugf("OLT listening on %v", address)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700393
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100394 return grpcServer, nil
395}
396
Matteo Scandolo88c204a2020-11-03 10:34:24 -0800397// StartOltServer will create the grpc server that VOLTHA uses
398// to communicate with the device
399func (o *OltDevice) StartOltServer() (*grpc.Server, error) {
400 oltServer, err := o.newOltServer()
401 if err != nil {
402 oltLogger.WithFields(log.Fields{
403 "err": err,
404 }).Error("Cannot OLT gRPC server")
405 return nil, err
406 }
407 return oltServer, nil
408}
409
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100410// StopOltServer stops the OpenOLT grpc server
Matteo Scandolo88c204a2020-11-03 10:34:24 -0800411func (o *OltDevice) StopOltServer() {
Hardik Windlassefdb4b62021-03-18 10:33:24 +0000412 if o.OltServer != nil {
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800413 oltLogger.WithFields(log.Fields{
414 "oltId": o.SerialNumber,
415 }).Warnf("Stopping OLT gRPC server")
Hardik Windlassefdb4b62021-03-18 10:33:24 +0000416 o.OltServer.Stop()
417 o.OltServer = nil
Andrea Campanella8ad54a42022-03-09 14:36:55 +0100418 } else {
419 oltLogger.WithFields(log.Fields{
420 "oltId": o.SerialNumber,
421 }).Warnf("OLT gRPC server is already stopped")
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700422 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700423}
424
425// Device Methods
426
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100427// Enable implements the OpenOLT EnableIndicationServer functionality
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100428func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700429 oltLogger.Debug("Enable OLT called")
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100430
431 if o.InternalState.Is(OltInternalStateDeleted) {
432 err := fmt.Errorf("Cannot enable OLT while it is rebooting")
433 oltLogger.WithFields(log.Fields{
434 "oltId": o.SerialNumber,
435 "internalState": o.InternalState.Current(),
436 }).Error(err)
437 return err
438 }
439
Pragya Arya2225f202020-01-29 18:05:01 +0530440 rebootFlag := false
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700441
David Bainbridge103cf022019-12-16 20:11:35 +0000442 // If enabled has already been called then an enabled context has
443 // been created. If this is the case then we want to cancel all the
444 // proessing loops associated with that enable before we recreate
445 // new ones
446 o.Lock()
447 if o.enableContext != nil && o.enableContextCancel != nil {
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700448 oltLogger.Info("This is an OLT reboot or a reconcile")
David Bainbridge103cf022019-12-16 20:11:35 +0000449 o.enableContextCancel()
Pragya Arya2225f202020-01-29 18:05:01 +0530450 rebootFlag = true
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700451 time.Sleep(1 * time.Second)
David Bainbridge103cf022019-12-16 20:11:35 +0000452 }
453 o.enableContext, o.enableContextCancel = context.WithCancel(context.TODO())
454 o.Unlock()
455
Matteo Scandolo4747d292019-08-05 11:50:18 -0700456 wg := sync.WaitGroup{}
Matteo Scandolo4747d292019-08-05 11:50:18 -0700457
Matteo Scandolo4a036262020-08-17 15:56:13 -0700458 o.OpenoltStream = stream
Pragya Arya1cbefa42020-01-13 12:15:29 +0530459
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100460 // create Go routine to process all OLT events
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700461 wg.Add(1)
David Bainbridge103cf022019-12-16 20:11:35 +0000462 go o.processOltMessages(o.enableContext, stream, &wg)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700463
464 // enable the OLT
Matteo Scandolof9d43412021-01-12 11:11:34 -0800465 oltMsg := types.Message{
466 Type: types.OltIndication,
467 Data: types.OltIndicationMessage{
468 OperState: types.UP,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700469 },
470 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100471 o.channel <- oltMsg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700472
473 // send NNI Port Indications
474 for _, nni := range o.Nnis {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800475 msg := types.Message{
476 Type: types.NniIndication,
477 Data: types.NniIndicationMessage{
478 OperState: types.UP,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700479 NniPortID: nni.ID,
480 },
481 }
482 o.channel <- msg
483 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100484
Shrey Baid688b4242020-07-10 20:40:10 +0530485 if rebootFlag {
Pragya Arya2225f202020-01-29 18:05:01 +0530486 for _, pon := range o.Pons {
487 if pon.InternalState.Current() == "disabled" {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800488 msg := types.Message{
489 Type: types.PonIndication,
490 Data: types.PonIndicationMessage{
491 OperState: types.UP,
Pragya Arya2225f202020-01-29 18:05:01 +0530492 PonPortID: pon.ID,
493 },
494 }
495 o.channel <- msg
Matteo Scandoloe60a5052020-02-07 00:31:14 +0000496 }
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700497 // when the enableContext was canceled the ONUs stopped listening on the channel
498 for _, onu := range pon.Onus {
499 go onu.ProcessOnuMessages(o.enableContext, stream, nil)
500
501 // update the stream on all the services
Matteo Scandolo8a574812021-05-20 15:18:53 -0700502 for _, uni := range onu.UniPorts {
503 uni.UpdateStream(stream)
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700504 }
505 }
Pragya Arya2225f202020-01-29 18:05:01 +0530506 }
507 } else {
508
509 // 1. controlledActivation == Default: Send both PON and ONUs indications
510 // 2. controlledActivation == only-onu: that means only ONUs will be controlled activated, so auto send PON indications
511
512 if o.ControlledActivation == Default || o.ControlledActivation == OnlyONU {
513 // send PON Port indications
514 for _, pon := range o.Pons {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800515 msg := types.Message{
516 Type: types.PonIndication,
517 Data: types.PonIndicationMessage{
518 OperState: types.UP,
Pragya Arya2225f202020-01-29 18:05:01 +0530519 PonPortID: pon.ID,
520 },
521 }
522 o.channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700523 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700524 }
525 }
526
Pragya Arya996a0892020-03-09 21:47:52 +0530527 if !o.enablePerf {
528 // Start a go routine to send periodic port stats to openolt adapter
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700529 wg.Add(1)
530 go o.periodicPortStats(o.enableContext, &wg, stream)
Pragya Arya996a0892020-03-09 21:47:52 +0530531 }
532
Matteo Scandolo4747d292019-08-05 11:50:18 -0700533 wg.Wait()
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700534 oltLogger.WithFields(log.Fields{
535 "stream": stream,
536 }).Debug("OpenOLT Stream closed")
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100537
538 return nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700539}
540
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700541func (o *OltDevice) periodicPortStats(ctx context.Context, wg *sync.WaitGroup, stream openolt.Openolt_EnableIndicationServer) {
Pragya Arya996a0892020-03-09 21:47:52 +0530542 var portStats *openolt.PortStatistics
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700543
544loop:
Pragya Arya996a0892020-03-09 21:47:52 +0530545 for {
546 select {
547 case <-time.After(time.Duration(o.PortStatsInterval) * time.Second):
548 // send NNI port stats
549 for _, port := range o.Nnis {
550 incrementStat := true
551 if port.OperState.Current() == "down" {
552 incrementStat = false
553 }
554 portStats, port.PacketCount = getPortStats(port.PacketCount, incrementStat)
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700555 o.sendPortStatsIndication(portStats, port.ID, port.Type, stream)
Pragya Arya996a0892020-03-09 21:47:52 +0530556 }
557
558 // send PON port stats
559 for _, port := range o.Pons {
560 incrementStat := true
561 // do not increment port stats if PON port is down or no ONU is activated on PON port
562 if port.OperState.Current() == "down" || port.GetNumOfActiveOnus() < 1 {
563 incrementStat = false
564 }
565 portStats, port.PacketCount = getPortStats(port.PacketCount, incrementStat)
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700566 o.sendPortStatsIndication(portStats, port.ID, port.Type, stream)
Pragya Arya996a0892020-03-09 21:47:52 +0530567 }
568 case <-ctx.Done():
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700569 oltLogger.Debug("Stop sending port stats")
570 break loop
Pragya Arya996a0892020-03-09 21:47:52 +0530571 }
Pragya Arya996a0892020-03-09 21:47:52 +0530572 }
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700573 wg.Done()
Pragya Arya996a0892020-03-09 21:47:52 +0530574}
575
Matteo Scandolo4747d292019-08-05 11:50:18 -0700576// Helpers method
577
Matteo Scandolof9d43412021-01-12 11:11:34 -0800578func (o *OltDevice) SetAlarm(interfaceId uint32, interfaceType string, alarmStatus string) error {
579
580 switch interfaceType {
581 case "nni":
582 if !o.HasNni(interfaceId) {
583 return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" NNI not present in olt")
584 }
585
586 case "pon":
587 if !o.HasPon(interfaceId) {
588 return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" PON not present in olt")
589 }
590 }
591
592 alarmIndication := &openolt.AlarmIndication{
593 Data: &openolt.AlarmIndication_LosInd{LosInd: &openolt.LosIndication{
594 Status: alarmStatus,
595 IntfId: InterfaceIDToPortNo(interfaceId, interfaceType),
596 }},
597 }
598
599 msg := types.Message{
600 Type: types.AlarmIndication,
601 Data: alarmIndication,
602 }
603
604 o.channel <- msg
605
606 return nil
607}
608
609func (o *OltDevice) HasNni(id uint32) bool {
610 for _, intf := range o.Nnis {
611 if intf.ID == id {
612 return true
613 }
614 }
615 return false
616}
617
618func (o *OltDevice) HasPon(id uint32) bool {
619 for _, intf := range o.Pons {
620 if intf.ID == id {
621 return true
622 }
623 }
624 return false
625}
626
Shrey Baid688b4242020-07-10 20:40:10 +0530627func (o *OltDevice) GetPonById(id uint32) (*PonPort, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700628 for _, pon := range o.Pons {
629 if pon.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -0700630 return pon, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700631 }
632 }
Shrey Baid688b4242020-07-10 20:40:10 +0530633 return nil, fmt.Errorf("Cannot find PonPort with id %d in OLT %d", id, o.ID)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700634}
635
Shrey Baid688b4242020-07-10 20:40:10 +0530636func (o *OltDevice) getNniById(id uint32) (*NniPort, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700637 for _, nni := range o.Nnis {
638 if nni.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -0700639 return nni, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700640 }
641 }
Shrey Baid688b4242020-07-10 20:40:10 +0530642 return nil, fmt.Errorf("Cannot find NniPort with id %d in OLT %d", id, o.ID)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700643}
644
Scott Baker41724b82020-01-21 19:54:53 -0800645func (o *OltDevice) sendAlarmIndication(alarmInd *openolt.AlarmIndication, stream openolt.Openolt_EnableIndicationServer) {
646 data := &openolt.Indication_AlarmInd{AlarmInd: alarmInd}
647 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
648 oltLogger.Errorf("Failed to send Alarm Indication: %v", err)
649 return
650 }
651
652 oltLogger.WithFields(log.Fields{
653 "AlarmIndication": alarmInd,
654 }).Debug("Sent Indication_AlarmInd")
655}
656
Matteo Scandolof9d43412021-01-12 11:11:34 -0800657func (o *OltDevice) sendOltIndication(msg types.OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700658 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}}
659 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700660 oltLogger.Errorf("Failed to send Indication_OltInd: %v", err)
Matteo Scandolo08badf42019-12-12 11:21:50 -0800661 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700662 }
663
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700664 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700665 "OperState": msg.OperState,
666 }).Debug("Sent Indication_OltInd")
667}
668
Matteo Scandolof9d43412021-01-12 11:11:34 -0800669func (o *OltDevice) sendNniIndication(msg types.NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700670 nni, _ := o.getNniById(msg.NniPortID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800671 if msg.OperState == types.UP {
Matteo Scandolo401503a2019-12-11 14:48:14 -0800672 if err := nni.OperState.Event("enable"); err != nil {
673 log.WithFields(log.Fields{
674 "Type": nni.Type,
675 "IntfId": nni.ID,
676 "OperState": nni.OperState.Current(),
677 }).Errorf("Can't move NNI Port to enabled state: %v", err)
678 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800679 } else if msg.OperState == types.DOWN {
Matteo Scandolo401503a2019-12-11 14:48:14 -0800680 if err := nni.OperState.Event("disable"); err != nil {
681 log.WithFields(log.Fields{
682 "Type": nni.Type,
683 "IntfId": nni.ID,
684 "OperState": nni.OperState.Current(),
685 }).Errorf("Can't move NNI Port to disable state: %v", err)
686 }
687 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700688 // NOTE Operstate may need to be an integer
Matteo Scandolo4747d292019-08-05 11:50:18 -0700689 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700690 Type: nni.Type,
691 IntfId: nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700692 OperState: nni.OperState.Current(),
Elia Battiston420c9092022-02-02 12:17:54 +0100693 Speed: o.NniSpeed,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700694 }}
695
696 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700697 oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err)
Matteo Scandolo08badf42019-12-12 11:21:50 -0800698 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700699 }
700
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700701 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700702 "Type": nni.Type,
703 "IntfId": nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700704 "OperState": nni.OperState.Current(),
Elia Battiston420c9092022-02-02 12:17:54 +0100705 "Speed": o.NniSpeed,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700706 }).Debug("Sent Indication_IntfOperInd for NNI")
707}
708
Pragya Arya2225f202020-01-29 18:05:01 +0530709func (o *OltDevice) sendPonIndication(ponPortID uint32) {
710
Matteo Scandolo4a036262020-08-17 15:56:13 -0700711 stream := o.OpenoltStream
Pragya Arya2225f202020-01-29 18:05:01 +0530712 pon, _ := o.GetPonById(ponPortID)
713 // Send IntfIndication for PON port
Matteo Scandolo4747d292019-08-05 11:50:18 -0700714 discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700715 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700716 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700717 }}
718
719 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700720 oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err)
Matteo Scandolo08badf42019-12-12 11:21:50 -0800721 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700722 }
723
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700724 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700725 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700726 "OperState": pon.OperState.Current(),
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700727 }).Debug("Sent Indication_IntfInd for PON")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700728
Pragya Arya2225f202020-01-29 18:05:01 +0530729 // Send IntfOperIndication for PON port
Matteo Scandolo4747d292019-08-05 11:50:18 -0700730 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700731 Type: pon.Type,
732 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700733 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700734 }}
735
736 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700737 oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err)
Matteo Scandolo08badf42019-12-12 11:21:50 -0800738 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700739 }
740
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700741 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700742 "Type": pon.Type,
743 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700744 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700745 }).Debug("Sent Indication_IntfOperInd for PON")
746}
747
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700748func (o *OltDevice) sendPortStatsIndication(stats *openolt.PortStatistics, portID uint32, portType string, stream openolt.Openolt_EnableIndicationServer) {
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100749 if o.InternalState.Current() == OltInternalStateEnabled {
Shrey Baid55f328c2020-07-07 19:20:42 +0530750 oltLogger.WithFields(log.Fields{
751 "Type": portType,
752 "IntfId": portID,
753 }).Trace("Sending port stats")
754 stats.IntfId = InterfaceIDToPortNo(portID, portType)
755 data := &openolt.Indication_PortStats{
756 PortStats: stats,
757 }
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700758
Shrey Baid55f328c2020-07-07 19:20:42 +0530759 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
760 oltLogger.Errorf("Failed to send PortStats: %v", err)
761 return
762 }
Pragya Arya996a0892020-03-09 21:47:52 +0530763 }
764}
765
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100766// processOltMessages handles messages received over the OpenOLT interface
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700767func (o *OltDevice) processOltMessages(ctx context.Context, stream types.Stream, wg *sync.WaitGroup) {
768 oltLogger.WithFields(log.Fields{
769 "stream": stream,
770 }).Debug("Starting OLT Indication Channel")
David Bainbridge103cf022019-12-16 20:11:35 +0000771 ch := o.channel
Matteo Scandolo4747d292019-08-05 11:50:18 -0700772
David Bainbridge103cf022019-12-16 20:11:35 +0000773loop:
774 for {
775 select {
776 case <-ctx.Done():
777 oltLogger.Debug("OLT Indication processing canceled via context")
778 break loop
Matteo Scandoloba3e9cd2021-05-14 16:19:54 -0700779 // do not terminate this loop if the stream is closed,
780 // when we restart the gRPC server it will automatically reconnect and we need this loop to send indications
781 //case <-stream.Context().Done():
782 // oltLogger.Debug("OLT Indication processing canceled via stream context")
783 // break loop
David Bainbridge103cf022019-12-16 20:11:35 +0000784 case message, ok := <-ch:
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700785 if !ok {
786 if ctx.Err() != nil {
787 oltLogger.WithField("err", ctx.Err()).Error("OLT EnableContext error")
788 }
789 oltLogger.Warn("OLT Indication processing canceled via closed channel")
David Bainbridge103cf022019-12-16 20:11:35 +0000790 break loop
Matteo Scandolo4747d292019-08-05 11:50:18 -0700791 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700792
David Bainbridge103cf022019-12-16 20:11:35 +0000793 oltLogger.WithFields(log.Fields{
794 "oltId": o.ID,
795 "messageType": message.Type,
796 }).Trace("Received message")
797
798 switch message.Type {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800799 case types.OltIndication:
800 msg, _ := message.Data.(types.OltIndicationMessage)
801 if msg.OperState == types.UP {
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100802 _ = o.InternalState.Event(OltInternalTxEnable)
Shrey Baid688b4242020-07-10 20:40:10 +0530803 _ = o.OperState.Event("enable")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800804 } else if msg.OperState == types.DOWN {
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100805 _ = o.InternalState.Event(OltInternalTxDisable)
Shrey Baid688b4242020-07-10 20:40:10 +0530806 _ = o.OperState.Event("disable")
David Bainbridge103cf022019-12-16 20:11:35 +0000807 }
808 o.sendOltIndication(msg, stream)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800809 case types.AlarmIndication:
Scott Baker41724b82020-01-21 19:54:53 -0800810 alarmInd, _ := message.Data.(*openolt.AlarmIndication)
811 o.sendAlarmIndication(alarmInd, stream)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800812 case types.NniIndication:
813 msg, _ := message.Data.(types.NniIndicationMessage)
David Bainbridge103cf022019-12-16 20:11:35 +0000814 o.sendNniIndication(msg, stream)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800815 case types.PonIndication:
816 msg, _ := message.Data.(types.PonIndicationMessage)
Pragya Arya2225f202020-01-29 18:05:01 +0530817 pon, _ := o.GetPonById(msg.PonPortID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800818 if msg.OperState == types.UP {
Hardik Windlassad790cb2020-06-17 21:26:22 +0530819 if err := pon.OperState.Event("enable"); err != nil {
820 oltLogger.WithFields(log.Fields{
821 "IntfId": msg.PonPortID,
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800822 "Err": err,
Hardik Windlassad790cb2020-06-17 21:26:22 +0530823 }).Error("Can't Enable Oper state for PON Port")
824 }
825 if err := pon.InternalState.Event("enable"); err != nil {
826 oltLogger.WithFields(log.Fields{
827 "IntfId": msg.PonPortID,
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800828 "Err": err,
Hardik Windlassad790cb2020-06-17 21:26:22 +0530829 }).Error("Can't Enable Internal state for PON Port")
830 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800831 } else if msg.OperState == types.DOWN {
Hardik Windlassad790cb2020-06-17 21:26:22 +0530832 if err := pon.OperState.Event("disable"); err != nil {
833 oltLogger.WithFields(log.Fields{
834 "IntfId": msg.PonPortID,
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800835 "Err": err,
Hardik Windlassad790cb2020-06-17 21:26:22 +0530836 }).Error("Can't Disable Oper state for PON Port")
837 }
838 if err := pon.InternalState.Event("disable"); err != nil {
839 oltLogger.WithFields(log.Fields{
840 "IntfId": msg.PonPortID,
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800841 "Err": err,
Hardik Windlassad790cb2020-06-17 21:26:22 +0530842 }).Error("Can't Disable Internal state for PON Port")
843 }
Pragya Arya2225f202020-01-29 18:05:01 +0530844 }
David Bainbridge103cf022019-12-16 20:11:35 +0000845 default:
846 oltLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
847 }
848 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700849 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100850 wg.Done()
Matteo Scandolo9ddb3a92021-04-14 16:16:20 -0700851 oltLogger.WithFields(log.Fields{
852 "stream": stream,
853 }).Warn("Stopped handling OLT Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700854}
855
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700856// returns an ONU with a given Serial Number
Shrey Baid688b4242020-07-10 20:40:10 +0530857func (o *OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700858 // NOTE this function can be a performance bottleneck when we have many ONUs,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700859 // memoizing it will remove the bottleneck
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700860 for _, pon := range o.Pons {
861 for _, onu := range pon.Onus {
862 if onu.Sn() == serialNumber {
Matteo Scandolo27428702019-10-11 16:21:16 -0700863 return onu, nil
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700864 }
865 }
866 }
867
Shrey Baid688b4242020-07-10 20:40:10 +0530868 return &Onu{}, fmt.Errorf("cannot-find-onu-by-serial-number-%s", serialNumber)
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700869}
870
William Kurkian9dadc5b2019-10-22 13:51:57 -0400871// returns an ONU with a given interface/Onu Id
Shrey Baid688b4242020-07-10 20:40:10 +0530872func (o *OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700873 // NOTE this function can be a performance bottleneck when we have many ONUs,
William Kurkian9dadc5b2019-10-22 13:51:57 -0400874 // memoizing it will remove the bottleneck
875 for _, pon := range o.Pons {
876 if pon.ID == intfId {
877 for _, onu := range pon.Onus {
878 if onu.ID == onuId {
879 return onu, nil
880 }
881 }
882 }
883 }
Shrey Baid688b4242020-07-10 20:40:10 +0530884 return &Onu{}, fmt.Errorf("cannot-find-onu-by-id-%v-%v", intfId, onuId)
William Kurkian9dadc5b2019-10-22 13:51:57 -0400885}
886
Matteo Scandolo4a036262020-08-17 15:56:13 -0700887// returns a Service with a given Mac Address
888func (o *OltDevice) FindServiceByMacAddress(mac net.HardwareAddr) (ServiceIf, error) {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700889 // NOTE this function can be a performance bottleneck when we have many ONUs,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700890 // memoizing it will remove the bottleneck
891 for _, pon := range o.Pons {
892 for _, onu := range pon.Onus {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700893 s, err := onu.findServiceByMacAddress(mac)
894 if err == nil {
895 return s, nil
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700896 }
897 }
898 }
899
Matteo Scandolo4a036262020-08-17 15:56:13 -0700900 return nil, fmt.Errorf("cannot-find-service-by-mac-address-%s", mac)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700901}
902
Matteo Scandolo4747d292019-08-05 11:50:18 -0700903// GRPC Endpoints
904
Shrey Baid688b4242020-07-10 20:40:10 +0530905func (o *OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700906
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700907 pon, _ := o.GetPonById(onu.IntfId)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800908
Matteo Scandolo8a574812021-05-20 15:18:53 -0700909 // Enable the resource maps for this ONU
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800910 olt.AllocIDs[onu.IntfId][onu.OnuId] = make(map[uint32]map[int32]map[uint64]bool)
911 olt.GemPortIDs[onu.IntfId][onu.OnuId] = make(map[uint32]map[int32]map[uint64]bool)
912
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700913 _onu, _ := pon.GetOnuBySn(onu.SerialNumber)
Matteo Scandoloba3e9cd2021-05-14 16:19:54 -0700914
915 publishEvent("ONU-activate-indication-received", int32(onu.IntfId), int32(onu.OnuId), _onu.Sn())
916 oltLogger.WithFields(log.Fields{
917 "OnuSn": _onu.Sn(),
918 }).Info("Received ActivateOnu call from VOLTHA")
919
William Kurkian0418bc82019-11-06 12:16:24 -0500920 _onu.SetID(onu.OnuId)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700921
Matteo Scandolocedde462021-03-09 17:37:16 -0800922 if err := _onu.InternalState.Event(OnuTxEnable); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700923 oltLogger.WithFields(log.Fields{
924 "IntfId": _onu.PonPortID,
925 "OnuSn": _onu.Sn(),
926 "OnuId": _onu.ID,
Matteo Scandolocedde462021-03-09 17:37:16 -0800927 }).Infof("Failed to transition ONU to %s state: %s", OnuStateEnabled, err.Error())
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700928 }
929
930 // NOTE we need to immediately activate the ONU or the OMCI state machine won't start
931
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700932 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700933}
934
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800935func (o *OltDevice) DeactivateOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700936 oltLogger.Error("DeactivateOnu not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700937 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700938}
939
Shrey Baid688b4242020-07-10 20:40:10 +0530940func (o *OltDevice) DeleteOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Pragya Arya1cbefa42020-01-13 12:15:29 +0530941 oltLogger.WithFields(log.Fields{
942 "IntfId": onu.IntfId,
943 "OnuId": onu.OnuId,
944 }).Info("Received DeleteOnu call from VOLTHA")
945
946 pon, err := o.GetPonById(onu.IntfId)
947 if err != nil {
948 oltLogger.WithFields(log.Fields{
949 "OnuId": onu.OnuId,
950 "IntfId": onu.IntfId,
951 "err": err,
952 }).Error("Can't find PonPort")
953 }
954 _onu, err := pon.GetOnuById(onu.OnuId)
955 if err != nil {
956 oltLogger.WithFields(log.Fields{
957 "OnuId": onu.OnuId,
958 "IntfId": onu.IntfId,
959 "err": err,
960 }).Error("Can't find Onu")
961 }
962
Matteo Scandolocedde462021-03-09 17:37:16 -0800963 if err := _onu.InternalState.Event(OnuTxDisable); err != nil {
Pragya Arya1cbefa42020-01-13 12:15:29 +0530964 oltLogger.WithFields(log.Fields{
965 "IntfId": _onu.PonPortID,
966 "OnuSn": _onu.Sn(),
967 "OnuId": _onu.ID,
Matteo Scandolocedde462021-03-09 17:37:16 -0800968 }).Infof("Failed to transition ONU to %s state: %s", OnuStateDisabled, err.Error())
Hardik Windlassad790cb2020-06-17 21:26:22 +0530969 }
970
Hardik Windlassad790cb2020-06-17 21:26:22 +0530971 // ONU Re-Discovery
Elia Battiston67e9e4c2022-02-15 16:38:40 +0100972 if o.InternalState.Current() == OltInternalStateEnabled && pon.InternalState.Current() == "enabled" {
Hardik Windlass7b3405b2020-07-08 15:10:05 +0530973 go _onu.ReDiscoverOnu()
Pragya Arya1cbefa42020-01-13 12:15:29 +0530974 }
975
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700976 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700977}
978
Shrey Baid688b4242020-07-10 20:40:10 +0530979func (o *OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700980 // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether?
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800981 oltLogger.WithFields(log.Fields{
982 "oltId": o.ID,
983 }).Info("Disabling OLT")
Pragya Arya324337e2020-02-20 14:35:08 +0530984 publishEvent("OLT-disable-received", -1, -1, "")
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800985
Matteo Scandolo401503a2019-12-11 14:48:14 -0800986 for _, pon := range o.Pons {
Pragya Arya2225f202020-01-29 18:05:01 +0530987 if pon.InternalState.Current() == "enabled" {
988 // disable PONs
Matteo Scandolof9d43412021-01-12 11:11:34 -0800989 msg := types.Message{
990 Type: types.PonIndication,
991 Data: types.PonIndicationMessage{
992 OperState: types.DOWN,
Pragya Arya2225f202020-01-29 18:05:01 +0530993 PonPortID: pon.ID,
994 },
995 }
996 o.channel <- msg
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800997 }
Matteo Scandolod02b79b2019-12-05 16:42:13 -0800998 }
999
Matteo Scandolo401503a2019-12-11 14:48:14 -08001000 // Note that we are not disabling the NNI as the real OLT does not.
1001 // The reason for that is in-band management
Matteo Scandolod02b79b2019-12-05 16:42:13 -08001002
1003 // disable OLT
Matteo Scandolof9d43412021-01-12 11:11:34 -08001004 oltMsg := types.Message{
1005 Type: types.OltIndication,
1006 Data: types.OltIndicationMessage{
1007 OperState: types.DOWN,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -07001008 },
1009 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +01001010 o.channel <- oltMsg
Matteo Scandoloba3e9cd2021-05-14 16:19:54 -07001011
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001012 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001013}
1014
Shrey Baid688b4242020-07-10 20:40:10 +05301015func (o *OltDevice) DisablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Hardik Windlassad790cb2020-06-17 21:26:22 +05301016 oltLogger.Infof("DisablePonIf request received for PON %d", intf.IntfId)
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001017 ponID := intf.GetIntfId()
1018 pon, _ := o.GetPonById(intf.IntfId)
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001019
Matteo Scandolof9d43412021-01-12 11:11:34 -08001020 msg := types.Message{
1021 Type: types.PonIndication,
1022 Data: types.PonIndicationMessage{
1023 OperState: types.DOWN,
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001024 PonPortID: ponID,
1025 },
1026 }
1027 o.channel <- msg
1028
1029 for _, onu := range pon.Onus {
1030
Matteo Scandolof9d43412021-01-12 11:11:34 -08001031 onuIndication := types.OnuIndicationMessage{
1032 OperState: types.DOWN,
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001033 PonPortID: ponID,
1034 OnuID: onu.ID,
1035 OnuSN: onu.SerialNumber,
1036 }
Matteo Scandolo4a036262020-08-17 15:56:13 -07001037 onu.sendOnuIndication(onuIndication, o.OpenoltStream)
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001038
1039 }
1040
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001041 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001042}
1043
Zdravko Bozakov681364d2019-11-10 14:28:46 +01001044func (o *OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -07001045 oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA")
Pragya Arya324337e2020-02-20 14:35:08 +05301046 publishEvent("OLT-enable-received", -1, -1, "")
Elia Battiston67e9e4c2022-02-15 16:38:40 +01001047 return o.Enable(stream)
Matteo Scandolo4747d292019-08-05 11:50:18 -07001048}
1049
Shrey Baid688b4242020-07-10 20:40:10 +05301050func (o *OltDevice) EnablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Hardik Windlassad790cb2020-06-17 21:26:22 +05301051 oltLogger.Infof("EnablePonIf request received for PON %d", intf.IntfId)
Pragya Arya2225f202020-01-29 18:05:01 +05301052 ponID := intf.GetIntfId()
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001053 pon, _ := o.GetPonById(intf.IntfId)
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001054
Matteo Scandolof9d43412021-01-12 11:11:34 -08001055 msg := types.Message{
1056 Type: types.PonIndication,
1057 Data: types.PonIndicationMessage{
1058 OperState: types.UP,
Pragya Arya2225f202020-01-29 18:05:01 +05301059 PonPortID: ponID,
1060 },
1061 }
1062 o.channel <- msg
1063
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001064 for _, onu := range pon.Onus {
1065
Matteo Scandolof9d43412021-01-12 11:11:34 -08001066 onuIndication := types.OnuIndicationMessage{
1067 OperState: types.UP,
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001068 PonPortID: ponID,
1069 OnuID: onu.ID,
1070 OnuSN: onu.SerialNumber,
1071 }
Matteo Scandolo4a036262020-08-17 15:56:13 -07001072 onu.sendOnuIndication(onuIndication, o.OpenoltStream)
Andrea Campanella340b9ea2020-04-28 18:34:01 +02001073
1074 }
1075
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001076 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001077}
1078
Shrey Baid688b4242020-07-10 20:40:10 +05301079func (o *OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001080 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001081 "IntfId": flow.AccessIntfId,
1082 "OnuId": flow.OnuId,
1083 "EthType": fmt.Sprintf("%x", flow.Classifier.EthType),
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001084 "InnerVlan": flow.Classifier.IVid,
1085 "OuterVlan": flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001086 "FlowType": flow.FlowType,
1087 "FlowId": flow.FlowId,
1088 "UniID": flow.UniId,
1089 "PortNo": flow.PortNo,
Pragya Arya8bdb4532020-03-02 17:08:09 +05301090 }).Tracef("OLT receives FlowAdd")
1091
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001092 flowKey := FlowKey{}
Pragya Arya8bdb4532020-03-02 17:08:09 +05301093 if !o.enablePerf {
yasin saplic07b9522022-01-27 11:23:54 +00001094 flowKey = FlowKey{ID: flow.FlowId}
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001095 olt.Flows.Store(flowKey, *flow)
Pragya Arya8bdb4532020-03-02 17:08:09 +05301096 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001097
1098 if flow.AccessIntfId == -1 {
1099 oltLogger.WithFields(log.Fields{
1100 "FlowId": flow.FlowId,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001101 }).Debug("Adding OLT flow")
Jonathan Hartb5fc46a2020-03-31 16:42:31 -07001102 } else if flow.FlowType == "multicast" {
1103 oltLogger.WithFields(log.Fields{
Matteo Scandolo618a6582020-09-09 12:21:29 -07001104 "Cookie": flow.Cookie,
1105 "DstPort": flow.Classifier.DstPort,
1106 "EthType": fmt.Sprintf("%x", flow.Classifier.EthType),
1107 "FlowId": flow.FlowId,
1108 "FlowType": flow.FlowType,
1109 "GemportId": flow.GemportId,
1110 "InnerVlan": flow.Classifier.IVid,
1111 "IntfId": flow.AccessIntfId,
1112 "IpProto": flow.Classifier.IpProto,
1113 "OnuId": flow.OnuId,
1114 "OuterVlan": flow.Classifier.OVid,
1115 "PortNo": flow.PortNo,
1116 "SrcPort": flow.Classifier.SrcPort,
1117 "UniID": flow.UniId,
1118 "ClassifierOPbits": flow.Classifier.OPbits,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001119 }).Debug("Adding OLT multicast flow")
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001120 } else {
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001121 pon, err := o.GetPonById(uint32(flow.AccessIntfId))
Matteo Scandolo27428702019-10-11 16:21:16 -07001122 if err != nil {
1123 oltLogger.WithFields(log.Fields{
1124 "OnuId": flow.OnuId,
1125 "IntfId": flow.AccessIntfId,
1126 "err": err,
1127 }).Error("Can't find PonPort")
1128 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001129 onu, err := pon.GetOnuById(uint32(flow.OnuId))
Matteo Scandolo27428702019-10-11 16:21:16 -07001130 if err != nil {
1131 oltLogger.WithFields(log.Fields{
1132 "OnuId": flow.OnuId,
1133 "IntfId": flow.AccessIntfId,
1134 "err": err,
1135 }).Error("Can't find Onu")
Jonathan Hartb5fc46a2020-03-31 16:42:31 -07001136 return nil, err
Matteo Scandolo27428702019-10-11 16:21:16 -07001137 }
Matteo Scandoloba3e9cd2021-05-14 16:19:54 -07001138
1139 // if the ONU is disabled reject the flow
1140 // as per VOL-4061 there is a small window during which the ONU is disabled
1141 // but the port has not been reported as down to ONOS
1142 if onu.InternalState.Is(OnuStatePonDisabled) || onu.InternalState.Is(OnuStateDisabled) {
1143 oltLogger.WithFields(log.Fields{
1144 "OnuId": flow.OnuId,
1145 "IntfId": flow.AccessIntfId,
1146 "Flow": flow,
1147 "SerialNumber": onu.Sn(),
1148 "InternalState": onu.InternalState.Current(),
1149 }).Error("rejected-flow-because-of-onu-state")
1150 return nil, fmt.Errorf("onu-%s-is-currently-%s", onu.Sn(), onu.InternalState.Current())
1151 }
1152
Pragya Arya8bdb4532020-03-02 17:08:09 +05301153 if !o.enablePerf {
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001154 onu.Flows = append(onu.Flows, flowKey)
Pragya Arya1d5ffb82020-03-20 18:51:37 +05301155 // Generate event on first flow for ONU
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001156 if len(onu.Flows) == 1 {
Matteo Scandoloba3e9cd2021-05-14 16:19:54 -07001157 publishEvent("Flow-add-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn())
Pragya Arya1d5ffb82020-03-20 18:51:37 +05301158 }
Pragya Arya8bdb4532020-03-02 17:08:09 +05301159 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001160
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001161 // validate that the flow reference correct IDs (Alloc, Gem)
1162 if err := o.validateFlow(flow); err != nil {
1163 oltLogger.WithFields(log.Fields{
1164 "OnuId": flow.OnuId,
1165 "IntfId": flow.AccessIntfId,
1166 "Flow": flow,
1167 "SerialNumber": onu.Sn(),
1168 "err": err,
1169 }).Error("invalid-flow-for-onu")
1170 return nil, err
1171 }
1172
Matteo Scandoloa8eca492021-03-23 09:45:16 -07001173 o.storeGemPortIdByFlow(flow)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001174 o.storeAllocId(flow)
1175
Matteo Scandolof9d43412021-01-12 11:11:34 -08001176 msg := types.Message{
1177 Type: types.FlowAdd,
1178 Data: types.OnuFlowUpdateMessage{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001179 PonPortID: pon.ID,
1180 OnuID: onu.ID,
1181 Flow: flow,
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001182 },
1183 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -07001184 onu.Channel <- msg
Matteo Scandolo3bc73742019-08-20 14:04:04 -07001185 }
1186
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001187 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001188}
1189
Pragya Arya8bdb4532020-03-02 17:08:09 +05301190// FlowRemove request from VOLTHA
Shrey Baid688b4242020-07-10 20:40:10 +05301191func (o *OltDevice) FlowRemove(_ context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001192
Pragya Arya8bdb4532020-03-02 17:08:09 +05301193 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001194 "AllocId": flow.AllocId,
1195 "Cookie": flow.Cookie,
1196 "FlowId": flow.FlowId,
1197 "FlowType": flow.FlowType,
1198 "GemportId": flow.GemportId,
1199 "IntfId": flow.AccessIntfId,
1200 "OnuId": flow.OnuId,
1201 "PortNo": flow.PortNo,
1202 "UniID": flow.UniId,
1203 "ReplicateFlow": flow.ReplicateFlow,
1204 "PbitToGemport": flow.PbitToGemport,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001205 }).Debug("OLT receives FlowRemove")
Pragya Arya8bdb4532020-03-02 17:08:09 +05301206
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001207 olt.freeGemPortId(flow)
1208 olt.freeAllocId(flow)
1209
Pragya Arya8bdb4532020-03-02 17:08:09 +05301210 if !o.enablePerf { // remove only if flow were stored
yasin saplic07b9522022-01-27 11:23:54 +00001211 flowKey := FlowKey{ID: flow.FlowId}
Pragya Arya8bdb4532020-03-02 17:08:09 +05301212 // Check if flow exists
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001213 storedFlowIntf, ok := o.Flows.Load(flowKey)
Pragya Arya8bdb4532020-03-02 17:08:09 +05301214 if !ok {
1215 oltLogger.Errorf("Flow %v not found", flow)
1216 return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found")
1217 }
1218
Andrea Campanellabe8e12f2020-12-14 18:43:41 +01001219 storedFlow := storedFlowIntf.(openolt.Flow)
1220
Pragya Arya8bdb4532020-03-02 17:08:09 +05301221 // if its ONU flow remove it from ONU also
1222 if storedFlow.AccessIntfId != -1 {
Matteo Scandolocedde462021-03-09 17:37:16 -08001223 pon, err := o.GetPonById(uint32(storedFlow.AccessIntfId))
1224 if err != nil {
1225 oltLogger.WithFields(log.Fields{
1226 "OnuId": storedFlow.OnuId,
1227 "IntfId": storedFlow.AccessIntfId,
1228 "PONs": olt.Pons,
1229 "err": err,
1230 }).Error("PON-port-not-found")
1231 return new(openolt.Empty), nil
1232 }
Pragya Arya8bdb4532020-03-02 17:08:09 +05301233 onu, err := pon.GetOnuById(uint32(storedFlow.OnuId))
1234 if err != nil {
1235 oltLogger.WithFields(log.Fields{
1236 "OnuId": storedFlow.OnuId,
1237 "IntfId": storedFlow.AccessIntfId,
1238 "err": err,
Matteo Scandolocedde462021-03-09 17:37:16 -08001239 }).Error("ONU-not-found")
Pragya Arya8bdb4532020-03-02 17:08:09 +05301240 return new(openolt.Empty), nil
1241 }
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001242 onu.DeleteFlow(flowKey)
Matteo Scandoloba3e9cd2021-05-14 16:19:54 -07001243 publishEvent("Flow-remove-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn())
Pragya Arya8bdb4532020-03-02 17:08:09 +05301244 }
1245
1246 // delete from olt flows
Andrea Campanellacc9b1662022-01-26 17:47:48 +01001247 o.Flows.Delete(flowKey)
Pragya Arya8bdb4532020-03-02 17:08:09 +05301248 }
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001249
1250 if flow.AccessIntfId == -1 {
1251 oltLogger.WithFields(log.Fields{
1252 "FlowId": flow.FlowId,
1253 }).Debug("Removing OLT flow")
1254 } else if flow.FlowType == "multicast" {
1255 oltLogger.WithFields(log.Fields{
1256 "FlowId": flow.FlowId,
1257 }).Debug("Removing OLT multicast flow")
1258 } else {
1259
1260 onu, err := o.GetOnuByFlowId(flow.FlowId)
1261 if err != nil {
1262 oltLogger.WithFields(log.Fields{
1263 "OnuId": flow.OnuId,
1264 "IntfId": flow.AccessIntfId,
1265 "err": err,
1266 }).Error("Can't find Onu")
1267 return nil, err
1268 }
1269
Matteo Scandolof9d43412021-01-12 11:11:34 -08001270 msg := types.Message{
1271 Type: types.FlowRemoved,
1272 Data: types.OnuFlowUpdateMessage{
Shrey Baid55f328c2020-07-07 19:20:42 +05301273 Flow: flow,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001274 },
1275 }
1276 onu.Channel <- msg
1277 }
1278
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001279 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001280}
1281
Shrey Baid688b4242020-07-10 20:40:10 +05301282func (o *OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) {
Matteo Scandolo18859852020-01-15 13:33:57 -08001283 res := openolt.Heartbeat{HeartbeatSignature: uint32(time.Now().Unix())}
1284 oltLogger.WithFields(log.Fields{
1285 "signature": res.HeartbeatSignature,
1286 }).Trace("HeartbeatCheck")
1287 return &res, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001288}
1289
Matteo Scandolo4f4ac792020-10-01 16:33:21 -07001290func (o *OltDevice) GetOnuByFlowId(flowId uint64) (*Onu, error) {
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001291 for _, pon := range o.Pons {
1292 for _, onu := range pon.Onus {
1293 for _, fId := range onu.FlowIds {
1294 if fId == flowId {
1295 return onu, nil
1296 }
1297 }
1298 }
1299 }
Shrey Baid688b4242020-07-10 20:40:10 +05301300 return nil, fmt.Errorf("Cannot find Onu by flowId %d", flowId)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -07001301}
1302
Shrey Baid688b4242020-07-10 20:40:10 +05301303func (o *OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) {
Matteo Scandolocedde462021-03-09 17:37:16 -08001304 devinfo := &openolt.DeviceInfo{
1305 Vendor: common.Config.Olt.Vendor,
1306 Model: common.Config.Olt.Model,
1307 HardwareVersion: common.Config.Olt.HardwareVersion,
1308 FirmwareVersion: common.Config.Olt.FirmwareVersion,
Matteo Scandolocedde462021-03-09 17:37:16 -08001309 PonPorts: uint32(o.NumPon),
Matteo Scandolocedde462021-03-09 17:37:16 -08001310 DeviceSerialNumber: o.SerialNumber,
1311 DeviceId: common.Config.Olt.DeviceId,
1312 PreviouslyConnected: o.PreviouslyConnected,
Elia Battistonb7bea222022-02-18 16:25:00 +01001313 Ranges: []*openolt.DeviceInfo_DeviceResourceRanges{},
1314 }
1315
1316 for _, resRange := range common.PonsConfig.Ranges {
1317 intfIDs := []uint32{}
1318 for i := resRange.PonRange.StartId; i <= resRange.PonRange.EndId; i++ {
1319 intfIDs = append(intfIDs, uint32(i))
1320 }
1321
1322 devinfo.Ranges = append(devinfo.Ranges, &openolt.DeviceInfo_DeviceResourceRanges{
1323 IntfIds: intfIDs,
1324 Technology: resRange.Technology,
1325 Pools: []*openolt.DeviceInfo_DeviceResourceRanges_Pool{
1326 {
1327 Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID,
1328 Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF,
1329 Start: resRange.OnuRange.StartId,
1330 End: resRange.OnuRange.EndId,
1331 },
1332 {
1333 Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID,
1334 Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF,
1335 Start: resRange.AllocIdRange.StartId,
1336 End: resRange.AllocIdRange.EndId,
1337 },
1338 {
1339 Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID,
1340 Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF,
1341 Start: resRange.GemportRange.StartId,
1342 End: resRange.GemportRange.EndId,
Matteo Scandolocedde462021-03-09 17:37:16 -08001343 },
1344 },
Elia Battistonb7bea222022-02-18 16:25:00 +01001345 })
Matteo Scandolocedde462021-03-09 17:37:16 -08001346 }
Matteo Scandolo96f89192021-03-12 13:17:26 -08001347
1348 oltLogger.WithFields(log.Fields{
1349 "Vendor": devinfo.Vendor,
1350 "Model": devinfo.Model,
1351 "HardwareVersion": devinfo.HardwareVersion,
1352 "FirmwareVersion": devinfo.FirmwareVersion,
Matteo Scandolo96f89192021-03-12 13:17:26 -08001353 "PonPorts": devinfo.PonPorts,
Matteo Scandolo96f89192021-03-12 13:17:26 -08001354 "DeviceSerialNumber": devinfo.DeviceSerialNumber,
1355 "DeviceId": devinfo.DeviceId,
1356 "PreviouslyConnected": devinfo.PreviouslyConnected,
1357 }).Info("OLT receives GetDeviceInfo call from VOLTHA")
1358
1359 // once we connect, set the flag
1360 o.PreviouslyConnected = true
Matteo Scandolo4747d292019-08-05 11:50:18 -07001361
1362 return devinfo, nil
1363}
1364
Shrey Baid688b4242020-07-10 20:40:10 +05301365func (o *OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) {
Jonathan Hartacfa20e2020-03-31 15:20:14 -07001366 pon, err := o.GetPonById(omci_msg.IntfId)
1367 if err != nil {
1368 oltLogger.WithFields(log.Fields{
Matteo Scandolof65e6872020-04-15 15:18:43 -07001369 "error": err,
Jonathan Hartacfa20e2020-03-31 15:20:14 -07001370 "onu_id": omci_msg.OnuId,
1371 "pon_id": omci_msg.IntfId,
1372 }).Error("pon ID not found")
1373 return nil, err
1374 }
1375
1376 onu, err := pon.GetOnuById(omci_msg.OnuId)
1377 if err != nil {
1378 oltLogger.WithFields(log.Fields{
Matteo Scandolof65e6872020-04-15 15:18:43 -07001379 "error": err,
Jonathan Hartacfa20e2020-03-31 15:20:14 -07001380 "onu_id": omci_msg.OnuId,
1381 "pon_id": omci_msg.IntfId,
1382 }).Error("onu ID not found")
1383 return nil, err
1384 }
1385
Matteo Scandolo10f965c2019-09-24 10:40:46 -07001386 oltLogger.WithFields(log.Fields{
1387 "IntfId": onu.PonPortID,
1388 "OnuId": onu.ID,
1389 "OnuSn": onu.Sn(),
1390 }).Tracef("Received OmciMsgOut")
Matteo Scandolob5913142021-03-19 16:10:18 -07001391 omciPkt, omciMsg, err := omcilib.ParseOpenOltOmciPacket(omci_msg.Pkt)
1392 if err != nil {
1393 log.WithFields(log.Fields{
1394 "IntfId": onu.PonPortID,
1395 "SerialNumber": onu.Sn(),
Holger Hildebrandt02101a62022-04-06 13:00:51 +00001396 "omciPacket": hex.EncodeToString(omci_msg.Pkt),
Matteo Scandolob5913142021-03-19 16:10:18 -07001397 "err": err.Error(),
1398 }).Error("cannot-parse-OMCI-packet")
1399 return nil, fmt.Errorf("olt-received-malformed-omci-packet")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -07001400 }
Matteo Scandolob5913142021-03-19 16:10:18 -07001401 if onu.InternalState.Current() == OnuStateDisabled {
1402 // if the ONU is disabled just drop the message
1403 log.WithFields(log.Fields{
1404 "IntfId": onu.PonPortID,
1405 "SerialNumber": onu.Sn(),
1406 "omciBytes": hex.EncodeToString(omciPkt.Data()),
1407 "omciPkt": omciPkt,
1408 "omciMsgType": omciMsg.MessageType,
1409 }).Warn("dropping-omci-message")
1410 } else {
1411 msg := types.Message{
1412 Type: types.OMCI,
1413 Data: types.OmciMessage{
1414 OnuSN: onu.SerialNumber,
1415 OnuID: onu.ID,
1416 OmciMsg: omciMsg,
1417 OmciPkt: omciPkt,
1418 },
1419 }
1420 onu.Channel <- msg
1421 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001422 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001423}
1424
Matteo Scandolo8a574812021-05-20 15:18:53 -07001425// this gRPC methods receives packets from VOLTHA and sends them to the subscriber on the ONU
Shrey Baid688b4242020-07-10 20:40:10 +05301426func (o *OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001427 pon, err := o.GetPonById(onuPkt.IntfId)
Matteo Scandolo27428702019-10-11 16:21:16 -07001428 if err != nil {
1429 oltLogger.WithFields(log.Fields{
1430 "OnuId": onuPkt.OnuId,
1431 "IntfId": onuPkt.IntfId,
1432 "err": err,
1433 }).Error("Can't find PonPort")
1434 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001435 onu, err := pon.GetOnuById(onuPkt.OnuId)
Matteo Scandolo27428702019-10-11 16:21:16 -07001436 if err != nil {
1437 oltLogger.WithFields(log.Fields{
1438 "OnuId": onuPkt.OnuId,
1439 "IntfId": onuPkt.IntfId,
1440 "err": err,
1441 }).Error("Can't find Onu")
1442 }
Matteo Scandolo47e69bb2019-08-28 15:41:12 -07001443
Matteo Scandolo075b1892019-10-07 12:11:07 -07001444 oltLogger.WithFields(log.Fields{
1445 "IntfId": onu.PonPortID,
1446 "OnuId": onu.ID,
1447 "OnuSn": onu.Sn(),
Matteo Scandoloadc72a82020-09-08 18:46:08 -07001448 "Packet": hex.EncodeToString(onuPkt.Pkt),
Matteo Scandolo75ed5b92020-09-03 09:03:16 -07001449 }).Trace("Received OnuPacketOut")
Matteo Scandolo075b1892019-10-07 12:11:07 -07001450
Matteo Scandolo47e69bb2019-08-28 15:41:12 -07001451 rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default)
Matteo Scandolo618a6582020-09-09 12:21:29 -07001452
1453 pktType, err := packetHandlers.GetPktType(rawpkt)
Matteo Scandoloadc72a82020-09-08 18:46:08 -07001454 if err != nil {
1455 onuLogger.WithFields(log.Fields{
1456 "IntfId": onu.PonPortID,
1457 "OnuId": onu.ID,
1458 "OnuSn": onu.Sn(),
Matteo Scandolo618a6582020-09-09 12:21:29 -07001459 "Pkt": hex.EncodeToString(rawpkt.Data()),
Matteo Scandoloadc72a82020-09-08 18:46:08 -07001460 }).Error("Can't find pktType in packet, droppint it")
1461 return new(openolt.Empty), nil
1462 }
Matteo Scandolo47e69bb2019-08-28 15:41:12 -07001463
Matteo Scandolo4a036262020-08-17 15:56:13 -07001464 pktMac, err := packetHandlers.GetDstMacAddressFromPacket(rawpkt)
Matteo Scandolo4a036262020-08-17 15:56:13 -07001465 if err != nil {
Matteo Scandoloadc72a82020-09-08 18:46:08 -07001466 onuLogger.WithFields(log.Fields{
Matteo Scandolo4a036262020-08-17 15:56:13 -07001467 "IntfId": onu.PonPortID,
1468 "OnuId": onu.ID,
1469 "OnuSn": onu.Sn(),
1470 "Pkt": rawpkt.Data(),
1471 }).Error("Can't find Dst MacAddress in packet, droppint it")
1472 return new(openolt.Empty), nil
1473 }
1474
Matteo Scandolof9d43412021-01-12 11:11:34 -08001475 msg := types.Message{
1476 Type: types.OnuPacketOut,
1477 Data: types.OnuPacketMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -07001478 IntfId: onuPkt.IntfId,
1479 OnuId: onuPkt.OnuId,
Matteo Scandolo8a574812021-05-20 15:18:53 -07001480 PortNo: onuPkt.PortNo,
Matteo Scandolo4a036262020-08-17 15:56:13 -07001481 Packet: rawpkt,
1482 Type: pktType,
1483 MacAddress: pktMac,
Matteo Scandolo075b1892019-10-07 12:11:07 -07001484 },
Matteo Scandolo47e69bb2019-08-28 15:41:12 -07001485 }
Matteo Scandolo4a036262020-08-17 15:56:13 -07001486
Matteo Scandolo075b1892019-10-07 12:11:07 -07001487 onu.Channel <- msg
1488
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001489 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001490}
1491
Shrey Baid688b4242020-07-10 20:40:10 +05301492func (o *OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo635b2bf2020-09-04 10:23:40 -07001493
1494 // OLT Reboot is called in two cases:
1495 // - when an OLT is being removed (voltctl device disable -> voltctl device delete are called, then a new voltctl device create -> voltctl device enable will be issued)
1496 // - when an OLT needs to be rebooted (voltcl device reboot)
1497
Matteo Scandolod02b79b2019-12-05 16:42:13 -08001498 oltLogger.WithFields(log.Fields{
1499 "oltId": o.ID,
1500 }).Info("Shutting down")
Pragya Arya324337e2020-02-20 14:35:08 +05301501 publishEvent("OLT-reboot-received", -1, -1, "")
Shrey Baid688b4242020-07-10 20:40:10 +05301502 go func() { _ = o.RestartOLT() }()
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001503 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001504}
1505
Shrey Baid688b4242020-07-10 20:40:10 +05301506func (o *OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Pragya Arya6a708d62020-01-01 17:17:20 +05301507 oltLogger.WithFields(log.Fields{
1508 "oltId": o.ID,
1509 }).Info("Received ReenableOlt request from VOLTHA")
Pragya Arya324337e2020-02-20 14:35:08 +05301510 publishEvent("OLT-reenable-received", -1, -1, "")
Pragya Arya6a708d62020-01-01 17:17:20 +05301511
Pragya Arya2225f202020-01-29 18:05:01 +05301512 // enable OLT
Matteo Scandolof9d43412021-01-12 11:11:34 -08001513 oltMsg := types.Message{
1514 Type: types.OltIndication,
1515 Data: types.OltIndicationMessage{
1516 OperState: types.UP,
Pragya Arya2225f202020-01-29 18:05:01 +05301517 },
Pragya Arya1881df02020-01-29 18:05:01 +05301518 }
Pragya Arya2225f202020-01-29 18:05:01 +05301519 o.channel <- oltMsg
Pragya Arya6a708d62020-01-01 17:17:20 +05301520
Pragya Arya2225f202020-01-29 18:05:01 +05301521 for _, pon := range o.Pons {
1522 if pon.InternalState.Current() == "disabled" {
Matteo Scandolof9d43412021-01-12 11:11:34 -08001523 msg := types.Message{
1524 Type: types.PonIndication,
1525 Data: types.PonIndicationMessage{
1526 OperState: types.UP,
Pragya Arya2225f202020-01-29 18:05:01 +05301527 PonPortID: pon.ID,
1528 },
1529 }
1530 o.channel <- msg
1531 }
1532 }
Matteo Scandoloe60a5052020-02-07 00:31:14 +00001533
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001534 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001535}
1536
Shrey Baid688b4242020-07-10 20:40:10 +05301537func (o *OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001538 pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
1539
Matteo Scandolo90d08f62020-10-29 12:06:55 -07001540 err := o.Nnis[0].handleNniPacket(pkt) // FIXME we are assuming we have only one NNI
1541
1542 if err != nil {
1543 return nil, err
1544 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001545 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001546}
1547
Shrey Baid688b4242020-07-10 20:40:10 +05301548func (o *OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -07001549 oltLogger.Error("CollectStatistics not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001550 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001551}
1552
Shrey Baid688b4242020-07-10 20:40:10 +05301553func (o *OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -07001554 oltLogger.Error("GetOnuInfo not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001555 return new(openolt.OnuIndication), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -07001556}
1557
Shrey Baid688b4242020-07-10 20:40:10 +05301558func (o *OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -07001559 oltLogger.Error("GetPonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001560 return new(openolt.IntfIndication), nil
Matteo Scandolod54283a2019-08-13 16:22:31 -07001561}
1562
Shrey Baid688b4242020-07-10 20:40:10 +05301563func (s *OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -07001564 oltLogger.Info("received CreateTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -07001565 return new(openolt.Empty), nil
1566}
1567
Matteo Scandolo8a574812021-05-20 15:18:53 -07001568func (s *OltDevice) RemoveTrafficQueues(_ context.Context, tq *tech_profile.TrafficQueues) (*openolt.Empty, error) {
1569 oltLogger.WithFields(log.Fields{
1570 "OnuId": tq.OnuId,
1571 "IntfId": tq.IntfId,
1572 "OnuPortNo": tq.PortNo,
1573 "UniId": tq.UniId,
1574 }).Info("received RemoveTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -07001575 return new(openolt.Empty), nil
1576}
1577
Matteo Scandolo8a574812021-05-20 15:18:53 -07001578func (s *OltDevice) CreateTrafficSchedulers(_ context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Anand S Katti09541352020-01-29 15:54:01 +05301579 oltLogger.WithFields(log.Fields{
1580 "OnuId": trafficSchedulers.OnuId,
1581 "IntfId": trafficSchedulers.IntfId,
1582 "OnuPortNo": trafficSchedulers.PortNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -07001583 "UniId": trafficSchedulers.UniId,
Anand S Katti09541352020-01-29 15:54:01 +05301584 }).Info("received CreateTrafficSchedulers")
1585
1586 if !s.enablePerf {
1587 pon, err := s.GetPonById(trafficSchedulers.IntfId)
1588 if err != nil {
1589 oltLogger.Errorf("Error retrieving PON by IntfId: %v", err)
1590 return new(openolt.Empty), err
1591 }
1592 onu, err := pon.GetOnuById(trafficSchedulers.OnuId)
1593 if err != nil {
1594 oltLogger.Errorf("Error retrieving ONU from pon by OnuId: %v", err)
1595 return new(openolt.Empty), err
1596 }
1597 onu.TrafficSchedulers = trafficSchedulers
1598 }
Matteo Scandolod54283a2019-08-13 16:22:31 -07001599 return new(openolt.Empty), nil
1600}
1601
Shrey Baid688b4242020-07-10 20:40:10 +05301602func (s *OltDevice) RemoveTrafficSchedulers(context context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Anand S Katti09541352020-01-29 15:54:01 +05301603 oltLogger.WithFields(log.Fields{
1604 "OnuId": trafficSchedulers.OnuId,
1605 "IntfId": trafficSchedulers.IntfId,
1606 "OnuPortNo": trafficSchedulers.PortNo,
1607 }).Info("received RemoveTrafficSchedulers")
1608 if !s.enablePerf {
1609 pon, err := s.GetPonById(trafficSchedulers.IntfId)
1610 if err != nil {
1611 oltLogger.Errorf("Error retrieving PON by IntfId: %v", err)
1612 return new(openolt.Empty), err
1613 }
1614 onu, err := pon.GetOnuById(trafficSchedulers.OnuId)
1615 if err != nil {
1616 oltLogger.Errorf("Error retrieving ONU from pon by OnuId: %v", err)
1617 return new(openolt.Empty), err
1618 }
1619
1620 onu.TrafficSchedulers = nil
1621 }
Matteo Scandolod54283a2019-08-13 16:22:31 -07001622 return new(openolt.Empty), nil
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -07001623}
Scott Baker41724b82020-01-21 19:54:53 -08001624
Matteo Scandolo618a6582020-09-09 12:21:29 -07001625func (o *OltDevice) PerformGroupOperation(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) {
1626 oltLogger.WithFields(log.Fields{
1627 "GroupId": group.GroupId,
1628 "Command": group.Command,
1629 "Members": group.Members,
1630 "Action": group.Action,
1631 }).Debug("received PerformGroupOperation")
1632 return &openolt.Empty{}, nil
1633}
1634
1635func (o *OltDevice) DeleteGroup(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) {
1636 oltLogger.WithFields(log.Fields{
1637 "GroupId": group.GroupId,
1638 "Command": group.Command,
1639 "Members": group.Members,
1640 "Action": group.Action,
1641 }).Debug("received PerformGroupOperation")
1642 return &openolt.Empty{}, nil
1643}
1644
Matteo Scandolo1f9f4b22021-12-14 11:51:55 -08001645func (o *OltDevice) GetExtValue(ctx context.Context, in *openolt.ValueParam) (*extension.ReturnValues, error) {
1646 return &extension.ReturnValues{}, nil
Matteo Scandolo618a6582020-09-09 12:21:29 -07001647}
1648
1649func (o *OltDevice) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm) (*openolt.Empty, error) {
1650 return &openolt.Empty{}, nil
1651}
1652
1653func (o *OltDevice) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu) (*openolt.OnuLogicalDistance, error) {
1654 return &openolt.OnuLogicalDistance{}, nil
1655}
1656
1657func (o *OltDevice) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu) (*openolt.OnuLogicalDistance, error) {
1658 return &openolt.OnuLogicalDistance{}, nil
1659}
Matteo Scandolo96f89192021-03-12 13:17:26 -08001660
Girish Gowdra62f24292021-05-12 16:28:39 -07001661func (o *OltDevice) GetPonRxPower(ctx context.Context, in *openolt.Onu) (*openolt.PonRxPowerData, error) {
1662 return &openolt.PonRxPowerData{}, nil
1663}
1664
Matteo Scandolo96f89192021-03-12 13:17:26 -08001665func (o *OltDevice) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket) (*openolt.GemPortStatistics, error) {
1666 return &openolt.GemPortStatistics{}, nil
1667}
1668
1669func (o *OltDevice) GetOnuStatistics(ctx context.Context, in *openolt.Onu) (*openolt.OnuStatistics, error) {
1670 return &openolt.OnuStatistics{}, nil
1671}
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001672
1673func (o *OltDevice) storeAllocId(flow *openolt.Flow) {
1674 o.AllocIDsLock.Lock()
1675 defer o.AllocIDsLock.Unlock()
1676
Matteo Scandolo21195d62021-04-07 14:31:23 -07001677 if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)]; !ok {
1678 oltLogger.WithFields(log.Fields{
1679 "IntfId": flow.AccessIntfId,
1680 "OnuId": flow.OnuId,
1681 "PortNo": flow.PortNo,
1682 "GemportId": flow.GemportId,
1683 "FlowId": flow.FlowId,
1684 }).Error("trying-to-store-alloc-id-for-unknown-onu")
1685 }
1686
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001687 oltLogger.WithFields(log.Fields{
Matteo Scandolo21195d62021-04-07 14:31:23 -07001688 "IntfId": flow.AccessIntfId,
1689 "OnuId": flow.OnuId,
1690 "PortNo": flow.PortNo,
1691 "GemportId": flow.GemportId,
1692 "FlowId": flow.FlowId,
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001693 }).Trace("storing-alloc-id-via-flow")
1694
1695 if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo]; !ok {
1696 o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo] = make(map[int32]map[uint64]bool)
1697 }
1698 if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId]; !ok {
1699 o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId] = make(map[uint64]bool)
1700 }
1701 o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId][flow.FlowId] = true
1702}
1703
1704func (o *OltDevice) freeAllocId(flow *openolt.Flow) {
1705 // if this is the last flow referencing the AllocId then remove it
1706 o.AllocIDsLock.Lock()
1707 defer o.AllocIDsLock.Unlock()
1708
1709 oltLogger.WithFields(log.Fields{
1710 "IntfId": flow.AccessIntfId,
1711 "OnuId": flow.OnuId,
1712 "PortNo": flow.PortNo,
1713 "GemportId": flow.GemportId,
1714 }).Trace("freeing-alloc-id-via-flow")
1715
1716 // NOTE look at the freeGemPortId implementation for comments and context
1717 for ponId, ponValues := range o.AllocIDs {
1718 for onuId, onuValues := range ponValues {
1719 for uniId, uniValues := range onuValues {
1720 for allocId, flows := range uniValues {
1721 for flowId := range flows {
1722 // if the flow matches, remove it from the map.
1723 if flow.FlowId == flowId {
1724 delete(o.AllocIDs[ponId][onuId][uniId][allocId], flow.FlowId)
1725 }
1726 // if that was the last flow for a particular allocId, remove the entire allocId
1727 if len(o.AllocIDs[ponId][onuId][uniId][allocId]) == 0 {
1728 delete(o.AllocIDs[ponId][onuId][uniId], allocId)
1729 }
1730 }
1731 }
1732 }
1733 }
1734 }
1735}
1736
Matteo Scandoloa8eca492021-03-23 09:45:16 -07001737func (o *OltDevice) storeGemPortId(ponId uint32, onuId uint32, portNo uint32, gemId int32, flowId uint64) {
Matteo Scandolo21195d62021-04-07 14:31:23 -07001738 o.GemPortIDsLock.Lock()
1739 defer o.GemPortIDsLock.Unlock()
1740
1741 if _, ok := o.GemPortIDs[ponId][onuId]; !ok {
1742 oltLogger.WithFields(log.Fields{
1743 "IntfId": ponId,
1744 "OnuId": onuId,
1745 "PortNo": portNo,
1746 "GemportId": gemId,
1747 "FlowId": flowId,
1748 }).Error("trying-to-store-gemport-for-unknown-onu")
1749 }
1750
1751 oltLogger.WithFields(log.Fields{
1752 "IntfId": ponId,
1753 "OnuId": onuId,
1754 "PortNo": portNo,
1755 "GemportId": gemId,
1756 "FlowId": flowId,
1757 }).Trace("storing-alloc-id-via-flow")
1758
Matteo Scandoloa8eca492021-03-23 09:45:16 -07001759 if _, ok := o.GemPortIDs[ponId][onuId][portNo]; !ok {
1760 o.GemPortIDs[ponId][onuId][portNo] = make(map[int32]map[uint64]bool)
1761 }
1762 if _, ok := o.GemPortIDs[ponId][onuId][portNo][gemId]; !ok {
1763 o.GemPortIDs[ponId][onuId][portNo][gemId] = make(map[uint64]bool)
1764 }
1765 o.GemPortIDs[ponId][onuId][portNo][gemId][flowId] = true
1766}
1767
1768func (o *OltDevice) storeGemPortIdByFlow(flow *openolt.Flow) {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001769 oltLogger.WithFields(log.Fields{
Matteo Scandolo21195d62021-04-07 14:31:23 -07001770 "IntfId": flow.AccessIntfId,
1771 "OnuId": flow.OnuId,
1772 "PortNo": flow.PortNo,
1773 "GemportId": flow.GemportId,
1774 "FlowId": flow.FlowId,
1775 "ReplicateFlow": flow.ReplicateFlow,
1776 "PbitToGemport": flow.PbitToGemport,
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001777 }).Trace("storing-gem-port-id-via-flow")
1778
Matteo Scandoloa8eca492021-03-23 09:45:16 -07001779 if flow.ReplicateFlow {
1780 for _, gem := range flow.PbitToGemport {
1781 o.storeGemPortId(uint32(flow.AccessIntfId), uint32(flow.OnuId), flow.PortNo, int32(gem), flow.FlowId)
1782 }
1783 } else {
1784 o.storeGemPortId(uint32(flow.AccessIntfId), uint32(flow.OnuId), flow.PortNo, flow.GemportId, flow.FlowId)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001785 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001786}
1787
1788func (o *OltDevice) freeGemPortId(flow *openolt.Flow) {
1789 // if this is the last flow referencing the GemPort then remove it
1790 o.GemPortIDsLock.Lock()
1791 defer o.GemPortIDsLock.Unlock()
1792
1793 oltLogger.WithFields(log.Fields{
1794 "IntfId": flow.AccessIntfId,
1795 "OnuId": flow.OnuId,
1796 "PortNo": flow.PortNo,
1797 "GemportId": flow.GemportId,
1798 }).Trace("freeing-gem-port-id-via-flow")
1799
1800 // NOTE that this loop is not very performant, it would be better if the flow carries
1801 // the same information that it carries during a FlowAdd. If so we can directly remove
1802 // items from the map
1803
1804 //delete(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.GemportId], flow.FlowId)
1805 //if len(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.GemportId]) == 0 {
1806 // delete(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo], flow.GemportId)
1807 //}
1808
1809 // NOTE this loop assumes that flow IDs are unique per device
1810 for ponId, ponValues := range o.GemPortIDs {
1811 for onuId, onuValues := range ponValues {
1812 for uniId, uniValues := range onuValues {
1813 for gemId, flows := range uniValues {
1814 for flowId := range flows {
1815 // if the flow matches, remove it from the map.
1816 if flow.FlowId == flowId {
1817 delete(o.GemPortIDs[ponId][onuId][uniId][gemId], flow.FlowId)
1818 }
1819 // if that was the last flow for a particular gem, remove the entire gem
1820 if len(o.GemPortIDs[ponId][onuId][uniId][gemId]) == 0 {
1821 delete(o.GemPortIDs[ponId][onuId][uniId], gemId)
1822 }
1823 }
1824 }
1825 }
1826 }
1827 }
1828}
1829
1830// validateFlow checks that:
1831// - the AllocId is not used in any flow referencing other ONUs/UNIs on the same PON
1832// - the GemPortId is not used in any flow referencing other ONUs/UNIs on the same PON
1833func (o *OltDevice) validateFlow(flow *openolt.Flow) error {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001834 // validate gemPort
1835 o.GemPortIDsLock.RLock()
Matteo Scandolo21195d62021-04-07 14:31:23 -07001836 defer o.GemPortIDsLock.RUnlock()
1837 for onuId, onu := range o.GemPortIDs[uint32(flow.AccessIntfId)] {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001838 if onuId == uint32(flow.OnuId) {
1839 continue
1840 }
1841 for uniId, uni := range onu {
1842 for gem := range uni {
Matteo Scandoloa8eca492021-03-23 09:45:16 -07001843 if flow.ReplicateFlow {
1844 for _, flowGem := range flow.PbitToGemport {
1845 if gem == int32(flowGem) {
1846 return fmt.Errorf("gem-%d-already-in-use-on-uni-%d-onu-%d-replicated-flow-%d", gem, uniId, onuId, flow.FlowId)
1847 }
1848 }
1849 } else {
1850 if gem == flow.GemportId {
1851 return fmt.Errorf("gem-%d-already-in-use-on-uni-%d-onu-%d-flow-%d", gem, uniId, onuId, flow.FlowId)
1852 }
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001853 }
1854 }
1855 }
1856 }
1857
1858 o.AllocIDsLock.RLock()
Matteo Scandolo21195d62021-04-07 14:31:23 -07001859 defer o.AllocIDsLock.RUnlock()
1860 for onuId, onu := range o.AllocIDs[uint32(flow.AccessIntfId)] {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001861 if onuId == uint32(flow.OnuId) {
1862 continue
1863 }
1864 for uniId, uni := range onu {
1865 for allocId := range uni {
1866 if allocId == flow.AllocId {
Matteo Scandoloa8eca492021-03-23 09:45:16 -07001867 return fmt.Errorf("allocId-%d-already-in-use-on-uni-%d-onu-%d-flow-%d", allocId, uniId, onuId, flow.FlowId)
Matteo Scandolo4b077aa2021-02-16 17:33:37 -08001868 }
1869 }
1870 }
1871 }
1872
1873 return nil
1874}
1875
1876// clearAllResources is invoked up OLT Reboot to remove all the allocated
1877// GemPorts, AllocId and ONU-IDs across the PONs
1878func (o *OltDevice) clearAllResources() {
1879
1880 // remove the resources received via flows
1881 o.GemPortIDsLock.Lock()
1882 o.GemPortIDs = make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool)
1883 o.GemPortIDsLock.Unlock()
1884 o.AllocIDsLock.Lock()
1885 o.AllocIDs = make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool)
1886 o.AllocIDsLock.Unlock()
1887
1888 // remove the resources received via OMCI
1889 for _, pon := range o.Pons {
1890 pon.removeAllAllocIds()
1891 pon.removeAllGemPorts()
1892 pon.removeAllOnuIds()
1893 }
1894}