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