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