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