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