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