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