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