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