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