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