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