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