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