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