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