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