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" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 23 | "net" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 24 | "strconv" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 25 | "sync" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 26 | "time" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 27 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 29 | |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 30 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 31 | "github.com/opencord/bbsim/internal/bbsim/types" |
| 32 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 33 | "github.com/opencord/voltha-protos/v5/go/ext/config" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 34 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 35 | "github.com/google/gopacket" |
| 36 | "github.com/google/gopacket/layers" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 37 | "github.com/looplab/fsm" |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 38 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 39 | "github.com/opencord/bbsim/internal/common" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 40 | "github.com/opencord/voltha-protos/v5/go/openolt" |
| 41 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 42 | log "github.com/sirupsen/logrus" |
| 43 | "google.golang.org/grpc" |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 44 | "google.golang.org/grpc/codes" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 45 | "google.golang.org/grpc/reflection" |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 46 | "google.golang.org/grpc/status" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 47 | ) |
| 48 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 49 | var oltLogger = log.WithFields(log.Fields{ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 50 | "module": "OLT", |
| 51 | }) |
| 52 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 53 | const ( |
Girish Gowdra | 3015ff7 | 2021-06-28 11:48:56 -0700 | [diff] [blame] | 54 | onuIdStart = 1 |
| 55 | // Least pon port on the real OLTs we test with today have 16 ports (not including the pluggable OLTs). |
| 56 | // Given that we have to support 512 ONUs per OLT, we have to have up to 32 ONU per PON (could be less |
| 57 | // on a higher density port OLT). |
| 58 | // We pass just enough limits here to ensure the resource pool is as |
| 59 | // compact as possible on the etcd to reduce storage. |
| 60 | onuIdEnd = onuIdStart + 31 |
| 61 | allocIdStart = 1024 |
| 62 | allocIdPerOnu = 4 |
| 63 | allocIdEnd = allocIdStart + (onuIdEnd-onuIdStart+1)*allocIdPerOnu // up to 4 alloc-id per ONU |
| 64 | gemPortIdPerAllocId = 8 |
| 65 | gemportIdStart = 1024 |
| 66 | gemportIdEnd = gemportIdStart + (onuIdEnd-onuIdStart+1)*allocIdPerOnu*gemPortIdPerAllocId // up to 8 gemport-id per tcont/alloc-id |
| 67 | // The flow ids are no more necessary by the adapter, but still need to pass something dummy. Pass a very small valid range. |
| 68 | flowIdStart = 1 |
| 69 | flowIdEnd = flowIdStart + 1 |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 70 | ) |
| 71 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 72 | type OltDevice struct { |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 73 | sync.Mutex |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 74 | OltServer *grpc.Server |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 75 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 76 | // BBSIM Internals |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 77 | ID int |
| 78 | SerialNumber string |
| 79 | NumNni int |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame^] | 80 | NniSpeed uint32 |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 81 | NumPon int |
| 82 | NumOnuPerPon int |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 83 | NumUni int |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 84 | NumPots int |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 85 | InternalState *fsm.FSM |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 86 | channel chan types.Message |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 87 | dhcpServer dhcp.DHCPServerIf |
Andrea Campanella | be8e12f | 2020-12-14 18:43:41 +0100 | [diff] [blame] | 88 | Flows sync.Map |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 89 | Delay int |
| 90 | ControlledActivation mode |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 91 | EventChannel chan common.Event |
| 92 | PublishEvents bool |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 93 | PortStatsInterval int |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 94 | PreviouslyConnected bool |
Matteo Scandolo | e33447a | 2019-10-31 12:38:23 -0700 | [diff] [blame] | 95 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 96 | Pons []*PonPort |
| 97 | Nnis []*NniPort |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 98 | |
| 99 | // OLT Attributes |
| 100 | OperState *fsm.FSM |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 101 | |
| 102 | enableContext context.Context |
| 103 | enableContextCancel context.CancelFunc |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 104 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 105 | OpenoltStream openolt.Openolt_EnableIndicationServer |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 106 | enablePerf bool |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 107 | |
| 108 | // Allocated Resources |
| 109 | // this data are to verify that the openolt adapter does not duplicate resources |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 110 | AllocIDsLock sync.RWMutex |
| 111 | AllocIDs map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool // map[ponPortId]map[OnuId]map[PortNo]map[AllocIds]map[FlowId]bool |
| 112 | GemPortIDsLock sync.RWMutex |
| 113 | GemPortIDs map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool // map[ponPortId]map[OnuId]map[PortNo]map[GemPortIDs]map[FlowId]bool |
| 114 | OmciResponseRate uint8 |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 117 | var olt OltDevice |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 118 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 119 | func GetOLT() *OltDevice { |
| 120 | return &olt |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 123 | func CreateOLT(options common.GlobalConfig, services []common.ServiceYaml, isMock bool) *OltDevice { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 124 | oltLogger.WithFields(log.Fields{ |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 125 | "ID": options.Olt.ID, |
| 126 | "NumNni": options.Olt.NniPorts, |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame^] | 127 | "NniSpeed": options.Olt.NniSpeed, |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 128 | "NumPon": options.Olt.PonPorts, |
| 129 | "NumOnuPerPon": options.Olt.OnusPonPort, |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 130 | "NumUni": options.Olt.UniPorts, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 131 | "NumPots": options.Olt.PotsPorts, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 132 | }).Debug("CreateOLT") |
| 133 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 134 | olt = OltDevice{ |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 135 | ID: options.Olt.ID, |
| 136 | SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", options.Olt.ID), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 137 | OperState: getOperStateFSM(func(e *fsm.Event) { |
| 138 | oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst) |
| 139 | }), |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 140 | NumNni: int(options.Olt.NniPorts), |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame^] | 141 | NniSpeed: options.Olt.NniSpeed, |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 142 | NumPon: int(options.Olt.PonPorts), |
| 143 | NumOnuPerPon: int(options.Olt.OnusPonPort), |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 144 | NumUni: int(options.Olt.UniPorts), |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 145 | NumPots: int(options.Olt.PotsPorts), |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 146 | Pons: []*PonPort{}, |
| 147 | Nnis: []*NniPort{}, |
| 148 | Delay: options.BBSim.Delay, |
| 149 | enablePerf: options.BBSim.EnablePerf, |
| 150 | PublishEvents: options.BBSim.Events, |
| 151 | PortStatsInterval: options.Olt.PortStatsInterval, |
| 152 | dhcpServer: dhcp.NewDHCPServer(), |
| 153 | PreviouslyConnected: false, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 154 | AllocIDs: make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool), |
| 155 | GemPortIDs: make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool), |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 156 | OmciResponseRate: options.Olt.OmciResponseRate, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 159 | if val, ok := ControlledActivationModes[options.BBSim.ControlledActivation]; ok { |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 160 | olt.ControlledActivation = val |
| 161 | } else { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 162 | // FIXME throw an error if the ControlledActivation is not valid |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 163 | oltLogger.Warn("Unknown ControlledActivation Mode given, running in Default mode") |
| 164 | olt.ControlledActivation = Default |
| 165 | } |
| 166 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 167 | // OLT State machine |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 168 | // 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] | 169 | olt.InternalState = fsm.NewFSM( |
| 170 | "created", |
| 171 | fsm.Events{ |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 172 | {Name: "initialize", Src: []string{"created", "deleted"}, Dst: "initialized"}, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 173 | {Name: "enable", Src: []string{"initialized", "disabled"}, Dst: "enabled"}, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 174 | {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"}, |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 175 | // delete event in enabled state below is for reboot OLT case. |
Mahir Gunyel | 6dad445 | 2020-01-06 12:59:04 -0800 | [diff] [blame] | 176 | {Name: "delete", Src: []string{"disabled", "enabled"}, Dst: "deleted"}, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 177 | }, |
| 178 | fsm.Callbacks{ |
| 179 | "enter_state": func(e *fsm.Event) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 180 | 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] | 181 | }, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 182 | "enter_initialized": func(e *fsm.Event) { olt.InitOlt() }, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 183 | "enter_deleted": func(e *fsm.Event) { |
| 184 | // remove all the resource allocations |
| 185 | olt.clearAllResources() |
| 186 | }, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 187 | }, |
| 188 | ) |
| 189 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 190 | if !isMock { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 191 | // create NNI Port |
| 192 | nniPort, err := CreateNNI(&olt) |
| 193 | if err != nil { |
| 194 | oltLogger.Fatalf("Couldn't create NNI Port: %v", err) |
| 195 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 196 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 197 | olt.Nnis = append(olt.Nnis, &nniPort) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 198 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 199 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 200 | // Create device and Services |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 201 | nextCtag := map[string]int{} |
| 202 | nextStag := map[string]int{} |
| 203 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 204 | // create PON ports |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 205 | for i := 0; i < olt.NumPon; i++ { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 206 | |
| 207 | // initialize the resource maps for every PON Ports |
| 208 | olt.AllocIDs[uint32(i)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 209 | olt.GemPortIDs[uint32(i)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 210 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 211 | p := CreatePonPort(&olt, uint32(i)) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 212 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 213 | // create ONU devices |
| 214 | for j := 0; j < olt.NumOnuPerPon; j++ { |
| 215 | delay := time.Duration(olt.Delay*j) * time.Millisecond |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 216 | o := CreateONU(&olt, p, uint32(j+1), delay, nextCtag, nextStag, isMock) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 217 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 218 | p.Onus = append(p.Onus, o) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 219 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 220 | olt.Pons = append(olt.Pons, p) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 221 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 222 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 223 | if !isMock { |
Matteo Scandolo | d32c382 | 2019-11-26 15:57:46 -0700 | [diff] [blame] | 224 | if err := olt.InternalState.Event("initialize"); err != nil { |
| 225 | log.Errorf("Error initializing OLT: %v", err) |
| 226 | return nil |
| 227 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 230 | if olt.PublishEvents { |
| 231 | log.Debugf("BBSim event publishing is enabled") |
| 232 | // Create a channel to write event messages |
| 233 | olt.EventChannel = make(chan common.Event, 100) |
| 234 | } |
| 235 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 236 | return &olt |
| 237 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 238 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 239 | func (o *OltDevice) InitOlt() { |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 240 | |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 241 | if o.OltServer == nil { |
| 242 | o.OltServer, _ = o.StartOltServer() |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 243 | } else { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 244 | oltLogger.Fatal("OLT server already running.") |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | // create new channel for processOltMessages Go routine |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 248 | o.channel = make(chan types.Message) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 249 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 250 | // FIXME we are assuming we have only one NNI |
| 251 | if o.Nnis[0] != nil { |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 252 | // NOTE we want to make sure the state is down when we initialize the OLT, |
| 253 | // the NNI may be in a bad state after a disable/reboot as we are not disabling it for |
| 254 | // in-band management |
| 255 | o.Nnis[0].OperState.SetState("down") |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 256 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 257 | |
| 258 | for ponId := range o.Pons { |
| 259 | // initialize the resource maps for every PON Ports |
| 260 | olt.AllocIDs[uint32(ponId)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 261 | olt.GemPortIDs[uint32(ponId)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 262 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 265 | func (o *OltDevice) RestartOLT() error { |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 266 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 267 | o.PreviouslyConnected = false |
| 268 | |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 269 | softReboot := false |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 270 | rebootDelay := common.Config.Olt.OltRebootDelay |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 271 | |
| 272 | oltLogger.WithFields(log.Fields{ |
| 273 | "oltId": o.ID, |
| 274 | }).Infof("Simulating OLT restart... (%ds)", rebootDelay) |
| 275 | |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 276 | if o.InternalState.Is("enabled") { |
| 277 | oltLogger.WithFields(log.Fields{ |
| 278 | "oltId": o.ID, |
| 279 | }).Info("This is an OLT soft reboot") |
| 280 | softReboot = true |
| 281 | } |
| 282 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 283 | // transition internal state to deleted |
| 284 | if err := o.InternalState.Event("delete"); err != nil { |
| 285 | oltLogger.WithFields(log.Fields{ |
| 286 | "oltId": o.ID, |
| 287 | }).Errorf("Error deleting OLT: %v", err) |
| 288 | return err |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 291 | if softReboot { |
| 292 | for _, pon := range o.Pons { |
| 293 | if pon.InternalState.Current() == "enabled" { |
| 294 | // disable PONs |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 295 | msg := types.Message{ |
| 296 | Type: types.PonIndication, |
| 297 | Data: types.PonIndicationMessage{ |
| 298 | OperState: types.DOWN, |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 299 | PonPortID: pon.ID, |
| 300 | }, |
| 301 | } |
| 302 | o.channel <- msg |
| 303 | } |
| 304 | |
| 305 | for _, onu := range pon.Onus { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 306 | _ = onu.InternalState.Event(OnuTxDisable) |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } else { |
| 310 | // PONs are already handled in the Disable call |
| 311 | for _, pon := range olt.Pons { |
| 312 | // ONUs are not automatically disabled when a PON goes down |
| 313 | // as it's possible that it's an admin down and in that case the ONUs need to keep their state |
| 314 | for _, onu := range pon.Onus { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 315 | _ = onu.InternalState.Event(OnuTxDisable) |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 316 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Matteo Scandolo | b307d8a | 2021-05-10 15:19:27 -0700 | [diff] [blame] | 320 | 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 |
| 321 | o.StopOltServer() |
| 322 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 323 | // terminate the OLT's processOltMessages go routine |
| 324 | close(o.channel) |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 325 | |
Matteo Scandolo | e9f5a6b | 2020-09-16 15:54:38 -0700 | [diff] [blame] | 326 | o.enableContextCancel() |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 327 | time.Sleep(time.Duration(rebootDelay) * time.Second) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 328 | |
| 329 | if err := o.InternalState.Event("initialize"); err != nil { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 330 | oltLogger.WithFields(log.Fields{ |
| 331 | "oltId": o.ID, |
| 332 | }).Errorf("Error initializing OLT: %v", err) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 333 | return err |
| 334 | } |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 335 | oltLogger.WithFields(log.Fields{ |
| 336 | "oltId": o.ID, |
| 337 | }).Info("OLT restart completed") |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 338 | return nil |
| 339 | } |
| 340 | |
| 341 | // newOltServer launches a new grpc server for OpenOLT |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 342 | func (o *OltDevice) newOltServer() (*grpc.Server, error) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 343 | address := common.Config.BBSim.OpenOltAddress |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 344 | lis, err := net.Listen("tcp", address) |
| 345 | if err != nil { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 346 | oltLogger.Fatalf("OLT failed to listen: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 347 | } |
| 348 | grpcServer := grpc.NewServer() |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 349 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 350 | openolt.RegisterOpenoltServer(grpcServer, o) |
| 351 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 352 | reflection.Register(grpcServer) |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 353 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 354 | go func() { _ = grpcServer.Serve(lis) }() |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 355 | oltLogger.Debugf("OLT listening on %v", address) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 356 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 357 | return grpcServer, nil |
| 358 | } |
| 359 | |
Matteo Scandolo | 88c204a | 2020-11-03 10:34:24 -0800 | [diff] [blame] | 360 | // StartOltServer will create the grpc server that VOLTHA uses |
| 361 | // to communicate with the device |
| 362 | func (o *OltDevice) StartOltServer() (*grpc.Server, error) { |
| 363 | oltServer, err := o.newOltServer() |
| 364 | if err != nil { |
| 365 | oltLogger.WithFields(log.Fields{ |
| 366 | "err": err, |
| 367 | }).Error("Cannot OLT gRPC server") |
| 368 | return nil, err |
| 369 | } |
| 370 | return oltServer, nil |
| 371 | } |
| 372 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 373 | // StopOltServer stops the OpenOLT grpc server |
Matteo Scandolo | 88c204a | 2020-11-03 10:34:24 -0800 | [diff] [blame] | 374 | func (o *OltDevice) StopOltServer() { |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 375 | if o.OltServer != nil { |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 376 | oltLogger.WithFields(log.Fields{ |
| 377 | "oltId": o.SerialNumber, |
| 378 | }).Warnf("Stopping OLT gRPC server") |
Hardik Windlass | efdb4b6 | 2021-03-18 10:33:24 +0000 | [diff] [blame] | 379 | o.OltServer.Stop() |
| 380 | o.OltServer = nil |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 381 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // Device Methods |
| 385 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 386 | // Enable implements the OpenOLT EnableIndicationServer functionality |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 387 | func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 388 | oltLogger.Debug("Enable OLT called") |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 389 | rebootFlag := false |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 390 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 391 | // If enabled has already been called then an enabled context has |
| 392 | // been created. If this is the case then we want to cancel all the |
| 393 | // proessing loops associated with that enable before we recreate |
| 394 | // new ones |
| 395 | o.Lock() |
| 396 | if o.enableContext != nil && o.enableContextCancel != nil { |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 397 | oltLogger.Info("This is an OLT reboot or a reconcile") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 398 | o.enableContextCancel() |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 399 | rebootFlag = true |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 400 | time.Sleep(1 * time.Second) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 401 | } |
| 402 | o.enableContext, o.enableContextCancel = context.WithCancel(context.TODO()) |
| 403 | o.Unlock() |
| 404 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 405 | wg := sync.WaitGroup{} |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 406 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 407 | o.OpenoltStream = stream |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 408 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 409 | // create Go routine to process all OLT events |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 410 | wg.Add(1) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 411 | go o.processOltMessages(o.enableContext, stream, &wg) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 412 | |
| 413 | // enable the OLT |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 414 | oltMsg := types.Message{ |
| 415 | Type: types.OltIndication, |
| 416 | Data: types.OltIndicationMessage{ |
| 417 | OperState: types.UP, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 418 | }, |
| 419 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 420 | o.channel <- oltMsg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 421 | |
| 422 | // send NNI Port Indications |
| 423 | for _, nni := range o.Nnis { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 424 | msg := types.Message{ |
| 425 | Type: types.NniIndication, |
| 426 | Data: types.NniIndicationMessage{ |
| 427 | OperState: types.UP, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 428 | NniPortID: nni.ID, |
| 429 | }, |
| 430 | } |
| 431 | o.channel <- msg |
| 432 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 433 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 434 | if rebootFlag { |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 435 | for _, pon := range o.Pons { |
| 436 | if pon.InternalState.Current() == "disabled" { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 437 | msg := types.Message{ |
| 438 | Type: types.PonIndication, |
| 439 | Data: types.PonIndicationMessage{ |
| 440 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 441 | PonPortID: pon.ID, |
| 442 | }, |
| 443 | } |
| 444 | o.channel <- msg |
Matteo Scandolo | e60a505 | 2020-02-07 00:31:14 +0000 | [diff] [blame] | 445 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 446 | // when the enableContext was canceled the ONUs stopped listening on the channel |
| 447 | for _, onu := range pon.Onus { |
| 448 | go onu.ProcessOnuMessages(o.enableContext, stream, nil) |
| 449 | |
| 450 | // update the stream on all the services |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 451 | for _, uni := range onu.UniPorts { |
| 452 | uni.UpdateStream(stream) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 455 | } |
| 456 | } else { |
| 457 | |
| 458 | // 1. controlledActivation == Default: Send both PON and ONUs indications |
| 459 | // 2. controlledActivation == only-onu: that means only ONUs will be controlled activated, so auto send PON indications |
| 460 | |
| 461 | if o.ControlledActivation == Default || o.ControlledActivation == OnlyONU { |
| 462 | // send PON Port indications |
| 463 | for _, pon := range o.Pons { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 464 | msg := types.Message{ |
| 465 | Type: types.PonIndication, |
| 466 | Data: types.PonIndicationMessage{ |
| 467 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 468 | PonPortID: pon.ID, |
| 469 | }, |
| 470 | } |
| 471 | o.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 472 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 476 | if !o.enablePerf { |
| 477 | // Start a go routine to send periodic port stats to openolt adapter |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 478 | wg.Add(1) |
| 479 | go o.periodicPortStats(o.enableContext, &wg, stream) |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 480 | } |
| 481 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 482 | wg.Wait() |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 483 | oltLogger.WithFields(log.Fields{ |
| 484 | "stream": stream, |
| 485 | }).Debug("OpenOLT Stream closed") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 488 | func (o *OltDevice) periodicPortStats(ctx context.Context, wg *sync.WaitGroup, stream openolt.Openolt_EnableIndicationServer) { |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 489 | var portStats *openolt.PortStatistics |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 490 | |
| 491 | loop: |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 492 | for { |
| 493 | select { |
| 494 | case <-time.After(time.Duration(o.PortStatsInterval) * time.Second): |
| 495 | // send NNI port stats |
| 496 | for _, port := range o.Nnis { |
| 497 | incrementStat := true |
| 498 | if port.OperState.Current() == "down" { |
| 499 | incrementStat = false |
| 500 | } |
| 501 | portStats, port.PacketCount = getPortStats(port.PacketCount, incrementStat) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 502 | o.sendPortStatsIndication(portStats, port.ID, port.Type, stream) |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | // send PON port stats |
| 506 | for _, port := range o.Pons { |
| 507 | incrementStat := true |
| 508 | // do not increment port stats if PON port is down or no ONU is activated on PON port |
| 509 | if port.OperState.Current() == "down" || port.GetNumOfActiveOnus() < 1 { |
| 510 | incrementStat = false |
| 511 | } |
| 512 | portStats, port.PacketCount = getPortStats(port.PacketCount, incrementStat) |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 513 | o.sendPortStatsIndication(portStats, port.ID, port.Type, stream) |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 514 | } |
| 515 | case <-ctx.Done(): |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 516 | oltLogger.Debug("Stop sending port stats") |
| 517 | break loop |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 518 | } |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 519 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 520 | wg.Done() |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 521 | } |
| 522 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 523 | // Helpers method |
| 524 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 525 | func (o *OltDevice) SetAlarm(interfaceId uint32, interfaceType string, alarmStatus string) error { |
| 526 | |
| 527 | switch interfaceType { |
| 528 | case "nni": |
| 529 | if !o.HasNni(interfaceId) { |
| 530 | return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" NNI not present in olt") |
| 531 | } |
| 532 | |
| 533 | case "pon": |
| 534 | if !o.HasPon(interfaceId) { |
| 535 | return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" PON not present in olt") |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | alarmIndication := &openolt.AlarmIndication{ |
| 540 | Data: &openolt.AlarmIndication_LosInd{LosInd: &openolt.LosIndication{ |
| 541 | Status: alarmStatus, |
| 542 | IntfId: InterfaceIDToPortNo(interfaceId, interfaceType), |
| 543 | }}, |
| 544 | } |
| 545 | |
| 546 | msg := types.Message{ |
| 547 | Type: types.AlarmIndication, |
| 548 | Data: alarmIndication, |
| 549 | } |
| 550 | |
| 551 | o.channel <- msg |
| 552 | |
| 553 | return nil |
| 554 | } |
| 555 | |
| 556 | func (o *OltDevice) HasNni(id uint32) bool { |
| 557 | for _, intf := range o.Nnis { |
| 558 | if intf.ID == id { |
| 559 | return true |
| 560 | } |
| 561 | } |
| 562 | return false |
| 563 | } |
| 564 | |
| 565 | func (o *OltDevice) HasPon(id uint32) bool { |
| 566 | for _, intf := range o.Pons { |
| 567 | if intf.ID == id { |
| 568 | return true |
| 569 | } |
| 570 | } |
| 571 | return false |
| 572 | } |
| 573 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 574 | func (o *OltDevice) GetPonById(id uint32) (*PonPort, error) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 575 | for _, pon := range o.Pons { |
| 576 | if pon.ID == id { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 577 | return pon, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 580 | 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] | 581 | } |
| 582 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 583 | func (o *OltDevice) getNniById(id uint32) (*NniPort, error) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 584 | for _, nni := range o.Nnis { |
| 585 | if nni.ID == id { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 586 | return nni, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 587 | } |
| 588 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 589 | 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] | 590 | } |
| 591 | |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 592 | func (o *OltDevice) sendAlarmIndication(alarmInd *openolt.AlarmIndication, stream openolt.Openolt_EnableIndicationServer) { |
| 593 | data := &openolt.Indication_AlarmInd{AlarmInd: alarmInd} |
| 594 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 595 | oltLogger.Errorf("Failed to send Alarm Indication: %v", err) |
| 596 | return |
| 597 | } |
| 598 | |
| 599 | oltLogger.WithFields(log.Fields{ |
| 600 | "AlarmIndication": alarmInd, |
| 601 | }).Debug("Sent Indication_AlarmInd") |
| 602 | } |
| 603 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 604 | func (o *OltDevice) sendOltIndication(msg types.OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 605 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}} |
| 606 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 607 | oltLogger.Errorf("Failed to send Indication_OltInd: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 608 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 611 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 612 | "OperState": msg.OperState, |
| 613 | }).Debug("Sent Indication_OltInd") |
| 614 | } |
| 615 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 616 | func (o *OltDevice) sendNniIndication(msg types.NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 617 | nni, _ := o.getNniById(msg.NniPortID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 618 | if msg.OperState == types.UP { |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 619 | if err := nni.OperState.Event("enable"); err != nil { |
| 620 | log.WithFields(log.Fields{ |
| 621 | "Type": nni.Type, |
| 622 | "IntfId": nni.ID, |
| 623 | "OperState": nni.OperState.Current(), |
| 624 | }).Errorf("Can't move NNI Port to enabled state: %v", err) |
| 625 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 626 | } else if msg.OperState == types.DOWN { |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 627 | if err := nni.OperState.Event("disable"); err != nil { |
| 628 | log.WithFields(log.Fields{ |
| 629 | "Type": nni.Type, |
| 630 | "IntfId": nni.ID, |
| 631 | "OperState": nni.OperState.Current(), |
| 632 | }).Errorf("Can't move NNI Port to disable state: %v", err) |
| 633 | } |
| 634 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 635 | // NOTE Operstate may need to be an integer |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 636 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 637 | Type: nni.Type, |
| 638 | IntfId: nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 639 | OperState: nni.OperState.Current(), |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame^] | 640 | Speed: o.NniSpeed, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 641 | }} |
| 642 | |
| 643 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 644 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 645 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 648 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 649 | "Type": nni.Type, |
| 650 | "IntfId": nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 651 | "OperState": nni.OperState.Current(), |
Elia Battiston | 420c909 | 2022-02-02 12:17:54 +0100 | [diff] [blame^] | 652 | "Speed": o.NniSpeed, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 653 | }).Debug("Sent Indication_IntfOperInd for NNI") |
| 654 | } |
| 655 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 656 | func (o *OltDevice) sendPonIndication(ponPortID uint32) { |
| 657 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 658 | stream := o.OpenoltStream |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 659 | pon, _ := o.GetPonById(ponPortID) |
| 660 | // Send IntfIndication for PON port |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 661 | discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 662 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 663 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 664 | }} |
| 665 | |
| 666 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 667 | oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 668 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 671 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 672 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 673 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 674 | }).Debug("Sent Indication_IntfInd for PON") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 675 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 676 | // Send IntfOperIndication for PON port |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 677 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 678 | Type: pon.Type, |
| 679 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 680 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 681 | }} |
| 682 | |
| 683 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 684 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err) |
Matteo Scandolo | 08badf4 | 2019-12-12 11:21:50 -0800 | [diff] [blame] | 685 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 688 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 689 | "Type": pon.Type, |
| 690 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 691 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 692 | }).Debug("Sent Indication_IntfOperInd for PON") |
| 693 | } |
| 694 | |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 695 | func (o *OltDevice) sendPortStatsIndication(stats *openolt.PortStatistics, portID uint32, portType string, stream openolt.Openolt_EnableIndicationServer) { |
Shrey Baid | 55f328c | 2020-07-07 19:20:42 +0530 | [diff] [blame] | 696 | if o.InternalState.Current() == "enabled" { |
| 697 | oltLogger.WithFields(log.Fields{ |
| 698 | "Type": portType, |
| 699 | "IntfId": portID, |
| 700 | }).Trace("Sending port stats") |
| 701 | stats.IntfId = InterfaceIDToPortNo(portID, portType) |
| 702 | data := &openolt.Indication_PortStats{ |
| 703 | PortStats: stats, |
| 704 | } |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 705 | |
Shrey Baid | 55f328c | 2020-07-07 19:20:42 +0530 | [diff] [blame] | 706 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 707 | oltLogger.Errorf("Failed to send PortStats: %v", err) |
| 708 | return |
| 709 | } |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 713 | // processOltMessages handles messages received over the OpenOLT interface |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 714 | func (o *OltDevice) processOltMessages(ctx context.Context, stream types.Stream, wg *sync.WaitGroup) { |
| 715 | oltLogger.WithFields(log.Fields{ |
| 716 | "stream": stream, |
| 717 | }).Debug("Starting OLT Indication Channel") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 718 | ch := o.channel |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 719 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 720 | loop: |
| 721 | for { |
| 722 | select { |
| 723 | case <-ctx.Done(): |
| 724 | oltLogger.Debug("OLT Indication processing canceled via context") |
| 725 | break loop |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 726 | // do not terminate this loop if the stream is closed, |
| 727 | // when we restart the gRPC server it will automatically reconnect and we need this loop to send indications |
| 728 | //case <-stream.Context().Done(): |
| 729 | // oltLogger.Debug("OLT Indication processing canceled via stream context") |
| 730 | // break loop |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 731 | case message, ok := <-ch: |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 732 | if !ok { |
| 733 | if ctx.Err() != nil { |
| 734 | oltLogger.WithField("err", ctx.Err()).Error("OLT EnableContext error") |
| 735 | } |
| 736 | oltLogger.Warn("OLT Indication processing canceled via closed channel") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 737 | break loop |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 738 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 739 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 740 | oltLogger.WithFields(log.Fields{ |
| 741 | "oltId": o.ID, |
| 742 | "messageType": message.Type, |
| 743 | }).Trace("Received message") |
| 744 | |
| 745 | switch message.Type { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 746 | case types.OltIndication: |
| 747 | msg, _ := message.Data.(types.OltIndicationMessage) |
| 748 | if msg.OperState == types.UP { |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 749 | _ = o.InternalState.Event("enable") |
| 750 | _ = o.OperState.Event("enable") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 751 | } else if msg.OperState == types.DOWN { |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 752 | _ = o.InternalState.Event("disable") |
| 753 | _ = o.OperState.Event("disable") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 754 | } |
| 755 | o.sendOltIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 756 | case types.AlarmIndication: |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 757 | alarmInd, _ := message.Data.(*openolt.AlarmIndication) |
| 758 | o.sendAlarmIndication(alarmInd, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 759 | case types.NniIndication: |
| 760 | msg, _ := message.Data.(types.NniIndicationMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 761 | o.sendNniIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 762 | case types.PonIndication: |
| 763 | msg, _ := message.Data.(types.PonIndicationMessage) |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 764 | pon, _ := o.GetPonById(msg.PonPortID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 765 | if msg.OperState == types.UP { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 766 | if err := pon.OperState.Event("enable"); err != nil { |
| 767 | oltLogger.WithFields(log.Fields{ |
| 768 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 769 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 770 | }).Error("Can't Enable Oper state for PON Port") |
| 771 | } |
| 772 | if err := pon.InternalState.Event("enable"); err != nil { |
| 773 | oltLogger.WithFields(log.Fields{ |
| 774 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 775 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 776 | }).Error("Can't Enable Internal state for PON Port") |
| 777 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 778 | } else if msg.OperState == types.DOWN { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 779 | if err := pon.OperState.Event("disable"); err != nil { |
| 780 | oltLogger.WithFields(log.Fields{ |
| 781 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 782 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 783 | }).Error("Can't Disable Oper state for PON Port") |
| 784 | } |
| 785 | if err := pon.InternalState.Event("disable"); err != nil { |
| 786 | oltLogger.WithFields(log.Fields{ |
| 787 | "IntfId": msg.PonPortID, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 788 | "Err": err, |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 789 | }).Error("Can't Disable Internal state for PON Port") |
| 790 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 791 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 792 | default: |
| 793 | oltLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type) |
| 794 | } |
| 795 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 796 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 797 | wg.Done() |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 798 | oltLogger.WithFields(log.Fields{ |
| 799 | "stream": stream, |
| 800 | }).Warn("Stopped handling OLT Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 803 | // returns an ONU with a given Serial Number |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 804 | func (o *OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 805 | // NOTE this function can be a performance bottleneck when we have many ONUs, |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 806 | // memoizing it will remove the bottleneck |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 807 | for _, pon := range o.Pons { |
| 808 | for _, onu := range pon.Onus { |
| 809 | if onu.Sn() == serialNumber { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 810 | return onu, nil |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 815 | return &Onu{}, fmt.Errorf("cannot-find-onu-by-serial-number-%s", serialNumber) |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 816 | } |
| 817 | |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 818 | // returns an ONU with a given interface/Onu Id |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 819 | func (o *OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 820 | // NOTE this function can be a performance bottleneck when we have many ONUs, |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 821 | // memoizing it will remove the bottleneck |
| 822 | for _, pon := range o.Pons { |
| 823 | if pon.ID == intfId { |
| 824 | for _, onu := range pon.Onus { |
| 825 | if onu.ID == onuId { |
| 826 | return onu, nil |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 831 | 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] | 832 | } |
| 833 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 834 | // returns a Service with a given Mac Address |
| 835 | func (o *OltDevice) FindServiceByMacAddress(mac net.HardwareAddr) (ServiceIf, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 836 | // NOTE this function can be a performance bottleneck when we have many ONUs, |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 837 | // memoizing it will remove the bottleneck |
| 838 | for _, pon := range o.Pons { |
| 839 | for _, onu := range pon.Onus { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 840 | s, err := onu.findServiceByMacAddress(mac) |
| 841 | if err == nil { |
| 842 | return s, nil |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 847 | return nil, fmt.Errorf("cannot-find-service-by-mac-address-%s", mac) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 850 | // GRPC Endpoints |
| 851 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 852 | 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] | 853 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 854 | pon, _ := o.GetPonById(onu.IntfId) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 855 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 856 | // Enable the resource maps for this ONU |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 857 | olt.AllocIDs[onu.IntfId][onu.OnuId] = make(map[uint32]map[int32]map[uint64]bool) |
| 858 | olt.GemPortIDs[onu.IntfId][onu.OnuId] = make(map[uint32]map[int32]map[uint64]bool) |
| 859 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 860 | _onu, _ := pon.GetOnuBySn(onu.SerialNumber) |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 861 | |
| 862 | publishEvent("ONU-activate-indication-received", int32(onu.IntfId), int32(onu.OnuId), _onu.Sn()) |
| 863 | oltLogger.WithFields(log.Fields{ |
| 864 | "OnuSn": _onu.Sn(), |
| 865 | }).Info("Received ActivateOnu call from VOLTHA") |
| 866 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 867 | _onu.SetID(onu.OnuId) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 868 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 869 | if err := _onu.InternalState.Event(OnuTxEnable); err != nil { |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 870 | oltLogger.WithFields(log.Fields{ |
| 871 | "IntfId": _onu.PonPortID, |
| 872 | "OnuSn": _onu.Sn(), |
| 873 | "OnuId": _onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 874 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateEnabled, err.Error()) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | // NOTE we need to immediately activate the ONU or the OMCI state machine won't start |
| 878 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 879 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 882 | func (o *OltDevice) DeactivateOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 883 | oltLogger.Error("DeactivateOnu not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 884 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 887 | func (o *OltDevice) DeleteOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 888 | oltLogger.WithFields(log.Fields{ |
| 889 | "IntfId": onu.IntfId, |
| 890 | "OnuId": onu.OnuId, |
| 891 | }).Info("Received DeleteOnu call from VOLTHA") |
| 892 | |
| 893 | pon, err := o.GetPonById(onu.IntfId) |
| 894 | if err != nil { |
| 895 | oltLogger.WithFields(log.Fields{ |
| 896 | "OnuId": onu.OnuId, |
| 897 | "IntfId": onu.IntfId, |
| 898 | "err": err, |
| 899 | }).Error("Can't find PonPort") |
| 900 | } |
| 901 | _onu, err := pon.GetOnuById(onu.OnuId) |
| 902 | if err != nil { |
| 903 | oltLogger.WithFields(log.Fields{ |
| 904 | "OnuId": onu.OnuId, |
| 905 | "IntfId": onu.IntfId, |
| 906 | "err": err, |
| 907 | }).Error("Can't find Onu") |
| 908 | } |
| 909 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 910 | if err := _onu.InternalState.Event(OnuTxDisable); err != nil { |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 911 | oltLogger.WithFields(log.Fields{ |
| 912 | "IntfId": _onu.PonPortID, |
| 913 | "OnuSn": _onu.Sn(), |
| 914 | "OnuId": _onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 915 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateDisabled, err.Error()) |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 916 | } |
| 917 | |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 918 | // ONU Re-Discovery |
| 919 | if o.InternalState.Current() == "enabled" && pon.InternalState.Current() == "enabled" { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 920 | go _onu.ReDiscoverOnu() |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 921 | } |
| 922 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 923 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 926 | func (o *OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 927 | // 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] | 928 | oltLogger.WithFields(log.Fields{ |
| 929 | "oltId": o.ID, |
| 930 | }).Info("Disabling OLT") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 931 | publishEvent("OLT-disable-received", -1, -1, "") |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 932 | |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 933 | for _, pon := range o.Pons { |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 934 | if pon.InternalState.Current() == "enabled" { |
| 935 | // disable PONs |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 936 | msg := types.Message{ |
| 937 | Type: types.PonIndication, |
| 938 | Data: types.PonIndicationMessage{ |
| 939 | OperState: types.DOWN, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 940 | PonPortID: pon.ID, |
| 941 | }, |
| 942 | } |
| 943 | o.channel <- msg |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 944 | } |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Matteo Scandolo | 401503a | 2019-12-11 14:48:14 -0800 | [diff] [blame] | 947 | // Note that we are not disabling the NNI as the real OLT does not. |
| 948 | // The reason for that is in-band management |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 949 | |
| 950 | // disable OLT |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 951 | oltMsg := types.Message{ |
| 952 | Type: types.OltIndication, |
| 953 | Data: types.OltIndicationMessage{ |
| 954 | OperState: types.DOWN, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 955 | }, |
| 956 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 957 | o.channel <- oltMsg |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 958 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 959 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 962 | func (o *OltDevice) DisablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 963 | oltLogger.Infof("DisablePonIf request received for PON %d", intf.IntfId) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 964 | ponID := intf.GetIntfId() |
| 965 | pon, _ := o.GetPonById(intf.IntfId) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 966 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 967 | msg := types.Message{ |
| 968 | Type: types.PonIndication, |
| 969 | Data: types.PonIndicationMessage{ |
| 970 | OperState: types.DOWN, |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 971 | PonPortID: ponID, |
| 972 | }, |
| 973 | } |
| 974 | o.channel <- msg |
| 975 | |
| 976 | for _, onu := range pon.Onus { |
| 977 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 978 | onuIndication := types.OnuIndicationMessage{ |
| 979 | OperState: types.DOWN, |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 980 | PonPortID: ponID, |
| 981 | OnuID: onu.ID, |
| 982 | OnuSN: onu.SerialNumber, |
| 983 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 984 | onu.sendOnuIndication(onuIndication, o.OpenoltStream) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 985 | |
| 986 | } |
| 987 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 988 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 991 | func (o *OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 992 | oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 993 | publishEvent("OLT-enable-received", -1, -1, "") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 994 | o.Enable(stream) |
| 995 | return nil |
| 996 | } |
| 997 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 998 | func (o *OltDevice) EnablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 999 | oltLogger.Infof("EnablePonIf request received for PON %d", intf.IntfId) |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1000 | ponID := intf.GetIntfId() |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1001 | pon, _ := o.GetPonById(intf.IntfId) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1002 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1003 | msg := types.Message{ |
| 1004 | Type: types.PonIndication, |
| 1005 | Data: types.PonIndicationMessage{ |
| 1006 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1007 | PonPortID: ponID, |
| 1008 | }, |
| 1009 | } |
| 1010 | o.channel <- msg |
| 1011 | |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1012 | for _, onu := range pon.Onus { |
| 1013 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1014 | onuIndication := types.OnuIndicationMessage{ |
| 1015 | OperState: types.UP, |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1016 | PonPortID: ponID, |
| 1017 | OnuID: onu.ID, |
| 1018 | OnuSN: onu.SerialNumber, |
| 1019 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1020 | onu.sendOnuIndication(onuIndication, o.OpenoltStream) |
Andrea Campanella | 340b9ea | 2020-04-28 18:34:01 +0200 | [diff] [blame] | 1021 | |
| 1022 | } |
| 1023 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1024 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1027 | func (o *OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1028 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1029 | "IntfId": flow.AccessIntfId, |
| 1030 | "OnuId": flow.OnuId, |
| 1031 | "EthType": fmt.Sprintf("%x", flow.Classifier.EthType), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1032 | "InnerVlan": flow.Classifier.IVid, |
| 1033 | "OuterVlan": flow.Classifier.OVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1034 | "FlowType": flow.FlowType, |
| 1035 | "FlowId": flow.FlowId, |
| 1036 | "UniID": flow.UniId, |
| 1037 | "PortNo": flow.PortNo, |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1038 | }).Tracef("OLT receives FlowAdd") |
| 1039 | |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1040 | flowKey := FlowKey{} |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1041 | if !o.enablePerf { |
yasin sapli | c07b952 | 2022-01-27 11:23:54 +0000 | [diff] [blame] | 1042 | flowKey = FlowKey{ID: flow.FlowId} |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1043 | olt.Flows.Store(flowKey, *flow) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1044 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1045 | |
| 1046 | if flow.AccessIntfId == -1 { |
| 1047 | oltLogger.WithFields(log.Fields{ |
| 1048 | "FlowId": flow.FlowId, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1049 | }).Debug("Adding OLT flow") |
Jonathan Hart | b5fc46a | 2020-03-31 16:42:31 -0700 | [diff] [blame] | 1050 | } else if flow.FlowType == "multicast" { |
| 1051 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1052 | "Cookie": flow.Cookie, |
| 1053 | "DstPort": flow.Classifier.DstPort, |
| 1054 | "EthType": fmt.Sprintf("%x", flow.Classifier.EthType), |
| 1055 | "FlowId": flow.FlowId, |
| 1056 | "FlowType": flow.FlowType, |
| 1057 | "GemportId": flow.GemportId, |
| 1058 | "InnerVlan": flow.Classifier.IVid, |
| 1059 | "IntfId": flow.AccessIntfId, |
| 1060 | "IpProto": flow.Classifier.IpProto, |
| 1061 | "OnuId": flow.OnuId, |
| 1062 | "OuterVlan": flow.Classifier.OVid, |
| 1063 | "PortNo": flow.PortNo, |
| 1064 | "SrcPort": flow.Classifier.SrcPort, |
| 1065 | "UniID": flow.UniId, |
| 1066 | "ClassifierOPbits": flow.Classifier.OPbits, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1067 | }).Debug("Adding OLT multicast flow") |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1068 | } else { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1069 | pon, err := o.GetPonById(uint32(flow.AccessIntfId)) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1070 | if err != nil { |
| 1071 | oltLogger.WithFields(log.Fields{ |
| 1072 | "OnuId": flow.OnuId, |
| 1073 | "IntfId": flow.AccessIntfId, |
| 1074 | "err": err, |
| 1075 | }).Error("Can't find PonPort") |
| 1076 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1077 | onu, err := pon.GetOnuById(uint32(flow.OnuId)) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1078 | if err != nil { |
| 1079 | oltLogger.WithFields(log.Fields{ |
| 1080 | "OnuId": flow.OnuId, |
| 1081 | "IntfId": flow.AccessIntfId, |
| 1082 | "err": err, |
| 1083 | }).Error("Can't find Onu") |
Jonathan Hart | b5fc46a | 2020-03-31 16:42:31 -0700 | [diff] [blame] | 1084 | return nil, err |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1085 | } |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1086 | |
| 1087 | // if the ONU is disabled reject the flow |
| 1088 | // as per VOL-4061 there is a small window during which the ONU is disabled |
| 1089 | // but the port has not been reported as down to ONOS |
| 1090 | if onu.InternalState.Is(OnuStatePonDisabled) || onu.InternalState.Is(OnuStateDisabled) { |
| 1091 | oltLogger.WithFields(log.Fields{ |
| 1092 | "OnuId": flow.OnuId, |
| 1093 | "IntfId": flow.AccessIntfId, |
| 1094 | "Flow": flow, |
| 1095 | "SerialNumber": onu.Sn(), |
| 1096 | "InternalState": onu.InternalState.Current(), |
| 1097 | }).Error("rejected-flow-because-of-onu-state") |
| 1098 | return nil, fmt.Errorf("onu-%s-is-currently-%s", onu.Sn(), onu.InternalState.Current()) |
| 1099 | } |
| 1100 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1101 | if !o.enablePerf { |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1102 | onu.Flows = append(onu.Flows, flowKey) |
Pragya Arya | 1d5ffb8 | 2020-03-20 18:51:37 +0530 | [diff] [blame] | 1103 | // Generate event on first flow for ONU |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1104 | if len(onu.Flows) == 1 { |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1105 | publishEvent("Flow-add-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn()) |
Pragya Arya | 1d5ffb8 | 2020-03-20 18:51:37 +0530 | [diff] [blame] | 1106 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1107 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1108 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1109 | // validate that the flow reference correct IDs (Alloc, Gem) |
| 1110 | if err := o.validateFlow(flow); err != nil { |
| 1111 | oltLogger.WithFields(log.Fields{ |
| 1112 | "OnuId": flow.OnuId, |
| 1113 | "IntfId": flow.AccessIntfId, |
| 1114 | "Flow": flow, |
| 1115 | "SerialNumber": onu.Sn(), |
| 1116 | "err": err, |
| 1117 | }).Error("invalid-flow-for-onu") |
| 1118 | return nil, err |
| 1119 | } |
| 1120 | |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1121 | o.storeGemPortIdByFlow(flow) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1122 | o.storeAllocId(flow) |
| 1123 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1124 | msg := types.Message{ |
| 1125 | Type: types.FlowAdd, |
| 1126 | Data: types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1127 | PonPortID: pon.ID, |
| 1128 | OnuID: onu.ID, |
| 1129 | Flow: flow, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1130 | }, |
| 1131 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 1132 | onu.Channel <- msg |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1135 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1138 | // FlowRemove request from VOLTHA |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1139 | func (o *OltDevice) FlowRemove(_ context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1140 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1141 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1142 | "AllocId": flow.AllocId, |
| 1143 | "Cookie": flow.Cookie, |
| 1144 | "FlowId": flow.FlowId, |
| 1145 | "FlowType": flow.FlowType, |
| 1146 | "GemportId": flow.GemportId, |
| 1147 | "IntfId": flow.AccessIntfId, |
| 1148 | "OnuId": flow.OnuId, |
| 1149 | "PortNo": flow.PortNo, |
| 1150 | "UniID": flow.UniId, |
| 1151 | "ReplicateFlow": flow.ReplicateFlow, |
| 1152 | "PbitToGemport": flow.PbitToGemport, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1153 | }).Debug("OLT receives FlowRemove") |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1154 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1155 | olt.freeGemPortId(flow) |
| 1156 | olt.freeAllocId(flow) |
| 1157 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1158 | if !o.enablePerf { // remove only if flow were stored |
yasin sapli | c07b952 | 2022-01-27 11:23:54 +0000 | [diff] [blame] | 1159 | flowKey := FlowKey{ID: flow.FlowId} |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1160 | // Check if flow exists |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1161 | storedFlowIntf, ok := o.Flows.Load(flowKey) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1162 | if !ok { |
| 1163 | oltLogger.Errorf("Flow %v not found", flow) |
| 1164 | return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found") |
| 1165 | } |
| 1166 | |
Andrea Campanella | be8e12f | 2020-12-14 18:43:41 +0100 | [diff] [blame] | 1167 | storedFlow := storedFlowIntf.(openolt.Flow) |
| 1168 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1169 | // if its ONU flow remove it from ONU also |
| 1170 | if storedFlow.AccessIntfId != -1 { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1171 | pon, err := o.GetPonById(uint32(storedFlow.AccessIntfId)) |
| 1172 | if err != nil { |
| 1173 | oltLogger.WithFields(log.Fields{ |
| 1174 | "OnuId": storedFlow.OnuId, |
| 1175 | "IntfId": storedFlow.AccessIntfId, |
| 1176 | "PONs": olt.Pons, |
| 1177 | "err": err, |
| 1178 | }).Error("PON-port-not-found") |
| 1179 | return new(openolt.Empty), nil |
| 1180 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1181 | onu, err := pon.GetOnuById(uint32(storedFlow.OnuId)) |
| 1182 | if err != nil { |
| 1183 | oltLogger.WithFields(log.Fields{ |
| 1184 | "OnuId": storedFlow.OnuId, |
| 1185 | "IntfId": storedFlow.AccessIntfId, |
| 1186 | "err": err, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1187 | }).Error("ONU-not-found") |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1188 | return new(openolt.Empty), nil |
| 1189 | } |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1190 | onu.DeleteFlow(flowKey) |
Matteo Scandolo | ba3e9cd | 2021-05-14 16:19:54 -0700 | [diff] [blame] | 1191 | publishEvent("Flow-remove-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn()) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | // delete from olt flows |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 1195 | o.Flows.Delete(flowKey) |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1196 | } |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1197 | |
| 1198 | if flow.AccessIntfId == -1 { |
| 1199 | oltLogger.WithFields(log.Fields{ |
| 1200 | "FlowId": flow.FlowId, |
| 1201 | }).Debug("Removing OLT flow") |
| 1202 | } else if flow.FlowType == "multicast" { |
| 1203 | oltLogger.WithFields(log.Fields{ |
| 1204 | "FlowId": flow.FlowId, |
| 1205 | }).Debug("Removing OLT multicast flow") |
| 1206 | } else { |
| 1207 | |
| 1208 | onu, err := o.GetOnuByFlowId(flow.FlowId) |
| 1209 | if err != nil { |
| 1210 | oltLogger.WithFields(log.Fields{ |
| 1211 | "OnuId": flow.OnuId, |
| 1212 | "IntfId": flow.AccessIntfId, |
| 1213 | "err": err, |
| 1214 | }).Error("Can't find Onu") |
| 1215 | return nil, err |
| 1216 | } |
| 1217 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1218 | msg := types.Message{ |
| 1219 | Type: types.FlowRemoved, |
| 1220 | Data: types.OnuFlowUpdateMessage{ |
Shrey Baid | 55f328c | 2020-07-07 19:20:42 +0530 | [diff] [blame] | 1221 | Flow: flow, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1222 | }, |
| 1223 | } |
| 1224 | onu.Channel <- msg |
| 1225 | } |
| 1226 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1227 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1230 | func (o *OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) { |
Matteo Scandolo | 1885985 | 2020-01-15 13:33:57 -0800 | [diff] [blame] | 1231 | res := openolt.Heartbeat{HeartbeatSignature: uint32(time.Now().Unix())} |
| 1232 | oltLogger.WithFields(log.Fields{ |
| 1233 | "signature": res.HeartbeatSignature, |
| 1234 | }).Trace("HeartbeatCheck") |
| 1235 | return &res, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1238 | func (o *OltDevice) GetOnuByFlowId(flowId uint64) (*Onu, error) { |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1239 | for _, pon := range o.Pons { |
| 1240 | for _, onu := range pon.Onus { |
| 1241 | for _, fId := range onu.FlowIds { |
| 1242 | if fId == flowId { |
| 1243 | return onu, nil |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1248 | return nil, fmt.Errorf("Cannot find Onu by flowId %d", flowId) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1251 | func (o *OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1252 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1253 | intfIDs := []uint32{} |
| 1254 | for i := 0; i < o.NumPon; i++ { |
| 1255 | intfIDs = append(intfIDs, uint32(i)) |
| 1256 | } |
| 1257 | |
| 1258 | devinfo := &openolt.DeviceInfo{ |
| 1259 | Vendor: common.Config.Olt.Vendor, |
| 1260 | Model: common.Config.Olt.Model, |
| 1261 | HardwareVersion: common.Config.Olt.HardwareVersion, |
| 1262 | FirmwareVersion: common.Config.Olt.FirmwareVersion, |
| 1263 | Technology: common.Config.Olt.Technology, |
| 1264 | PonPorts: uint32(o.NumPon), |
| 1265 | OnuIdStart: onuIdStart, |
| 1266 | OnuIdEnd: onuIdEnd, |
| 1267 | AllocIdStart: allocIdStart, |
| 1268 | AllocIdEnd: allocIdEnd, |
| 1269 | GemportIdStart: gemportIdStart, |
| 1270 | GemportIdEnd: gemportIdEnd, |
| 1271 | FlowIdStart: flowIdStart, |
| 1272 | FlowIdEnd: flowIdEnd, |
| 1273 | DeviceSerialNumber: o.SerialNumber, |
| 1274 | DeviceId: common.Config.Olt.DeviceId, |
| 1275 | PreviouslyConnected: o.PreviouslyConnected, |
| 1276 | Ranges: []*openolt.DeviceInfo_DeviceResourceRanges{ |
| 1277 | { |
| 1278 | IntfIds: intfIDs, |
| 1279 | Technology: common.Config.Olt.Technology, |
| 1280 | Pools: []*openolt.DeviceInfo_DeviceResourceRanges_Pool{ |
| 1281 | { |
| 1282 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID, |
| 1283 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF, |
| 1284 | Start: onuIdStart, |
| 1285 | End: onuIdEnd, |
| 1286 | }, |
| 1287 | { |
| 1288 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID, |
| 1289 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF, |
| 1290 | Start: allocIdStart, |
| 1291 | End: allocIdEnd, |
| 1292 | }, |
| 1293 | { |
| 1294 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID, |
| 1295 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF, |
| 1296 | Start: gemportIdStart, |
| 1297 | End: gemportIdEnd, |
| 1298 | }, |
| 1299 | { |
| 1300 | Type: openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID, |
| 1301 | Sharing: openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH, |
| 1302 | Start: flowIdStart, |
| 1303 | End: flowIdEnd, |
| 1304 | }, |
| 1305 | }, |
| 1306 | }, |
| 1307 | }, |
| 1308 | } |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1309 | |
| 1310 | oltLogger.WithFields(log.Fields{ |
| 1311 | "Vendor": devinfo.Vendor, |
| 1312 | "Model": devinfo.Model, |
| 1313 | "HardwareVersion": devinfo.HardwareVersion, |
| 1314 | "FirmwareVersion": devinfo.FirmwareVersion, |
| 1315 | "Technology": devinfo.Technology, |
| 1316 | "PonPorts": devinfo.PonPorts, |
| 1317 | "OnuIdStart": devinfo.OnuIdStart, |
| 1318 | "OnuIdEnd": devinfo.OnuIdEnd, |
| 1319 | "AllocIdStart": devinfo.AllocIdStart, |
| 1320 | "AllocIdEnd": devinfo.AllocIdEnd, |
| 1321 | "GemportIdStart": devinfo.GemportIdStart, |
| 1322 | "GemportIdEnd": devinfo.GemportIdEnd, |
| 1323 | "FlowIdStart": devinfo.FlowIdStart, |
| 1324 | "FlowIdEnd": devinfo.FlowIdEnd, |
| 1325 | "DeviceSerialNumber": devinfo.DeviceSerialNumber, |
| 1326 | "DeviceId": devinfo.DeviceId, |
| 1327 | "PreviouslyConnected": devinfo.PreviouslyConnected, |
| 1328 | }).Info("OLT receives GetDeviceInfo call from VOLTHA") |
| 1329 | |
| 1330 | // once we connect, set the flag |
| 1331 | o.PreviouslyConnected = true |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1332 | |
| 1333 | return devinfo, nil |
| 1334 | } |
| 1335 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1336 | 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] | 1337 | pon, err := o.GetPonById(omci_msg.IntfId) |
| 1338 | if err != nil { |
| 1339 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 1340 | "error": err, |
Jonathan Hart | acfa20e | 2020-03-31 15:20:14 -0700 | [diff] [blame] | 1341 | "onu_id": omci_msg.OnuId, |
| 1342 | "pon_id": omci_msg.IntfId, |
| 1343 | }).Error("pon ID not found") |
| 1344 | return nil, err |
| 1345 | } |
| 1346 | |
| 1347 | onu, err := pon.GetOnuById(omci_msg.OnuId) |
| 1348 | if err != nil { |
| 1349 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 1350 | "error": err, |
Jonathan Hart | acfa20e | 2020-03-31 15:20:14 -0700 | [diff] [blame] | 1351 | "onu_id": omci_msg.OnuId, |
| 1352 | "pon_id": omci_msg.IntfId, |
| 1353 | }).Error("onu ID not found") |
| 1354 | return nil, err |
| 1355 | } |
| 1356 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 1357 | oltLogger.WithFields(log.Fields{ |
| 1358 | "IntfId": onu.PonPortID, |
| 1359 | "OnuId": onu.ID, |
| 1360 | "OnuSn": onu.Sn(), |
| 1361 | }).Tracef("Received OmciMsgOut") |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1362 | omciPkt, omciMsg, err := omcilib.ParseOpenOltOmciPacket(omci_msg.Pkt) |
| 1363 | if err != nil { |
| 1364 | log.WithFields(log.Fields{ |
| 1365 | "IntfId": onu.PonPortID, |
| 1366 | "SerialNumber": onu.Sn(), |
| 1367 | "omciPacket": omcilib.HexDecode(omci_msg.Pkt), |
| 1368 | "err": err.Error(), |
| 1369 | }).Error("cannot-parse-OMCI-packet") |
| 1370 | return nil, fmt.Errorf("olt-received-malformed-omci-packet") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1371 | } |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1372 | if onu.InternalState.Current() == OnuStateDisabled { |
| 1373 | // if the ONU is disabled just drop the message |
| 1374 | log.WithFields(log.Fields{ |
| 1375 | "IntfId": onu.PonPortID, |
| 1376 | "SerialNumber": onu.Sn(), |
| 1377 | "omciBytes": hex.EncodeToString(omciPkt.Data()), |
| 1378 | "omciPkt": omciPkt, |
| 1379 | "omciMsgType": omciMsg.MessageType, |
| 1380 | }).Warn("dropping-omci-message") |
| 1381 | } else { |
| 1382 | msg := types.Message{ |
| 1383 | Type: types.OMCI, |
| 1384 | Data: types.OmciMessage{ |
| 1385 | OnuSN: onu.SerialNumber, |
| 1386 | OnuID: onu.ID, |
| 1387 | OmciMsg: omciMsg, |
| 1388 | OmciPkt: omciPkt, |
| 1389 | }, |
| 1390 | } |
| 1391 | onu.Channel <- msg |
| 1392 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1393 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1396 | // this gRPC methods receives packets from VOLTHA and sends them to the subscriber on the ONU |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1397 | 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] | 1398 | pon, err := o.GetPonById(onuPkt.IntfId) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1399 | if err != nil { |
| 1400 | oltLogger.WithFields(log.Fields{ |
| 1401 | "OnuId": onuPkt.OnuId, |
| 1402 | "IntfId": onuPkt.IntfId, |
| 1403 | "err": err, |
| 1404 | }).Error("Can't find PonPort") |
| 1405 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1406 | onu, err := pon.GetOnuById(onuPkt.OnuId) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1407 | if err != nil { |
| 1408 | oltLogger.WithFields(log.Fields{ |
| 1409 | "OnuId": onuPkt.OnuId, |
| 1410 | "IntfId": onuPkt.IntfId, |
| 1411 | "err": err, |
| 1412 | }).Error("Can't find Onu") |
| 1413 | } |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1414 | |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1415 | oltLogger.WithFields(log.Fields{ |
| 1416 | "IntfId": onu.PonPortID, |
| 1417 | "OnuId": onu.ID, |
| 1418 | "OnuSn": onu.Sn(), |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1419 | "Packet": hex.EncodeToString(onuPkt.Pkt), |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 1420 | }).Trace("Received OnuPacketOut") |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1421 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1422 | rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1423 | |
| 1424 | pktType, err := packetHandlers.GetPktType(rawpkt) |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1425 | if err != nil { |
| 1426 | onuLogger.WithFields(log.Fields{ |
| 1427 | "IntfId": onu.PonPortID, |
| 1428 | "OnuId": onu.ID, |
| 1429 | "OnuSn": onu.Sn(), |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1430 | "Pkt": hex.EncodeToString(rawpkt.Data()), |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1431 | }).Error("Can't find pktType in packet, droppint it") |
| 1432 | return new(openolt.Empty), nil |
| 1433 | } |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1434 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1435 | pktMac, err := packetHandlers.GetDstMacAddressFromPacket(rawpkt) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1436 | if err != nil { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1437 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1438 | "IntfId": onu.PonPortID, |
| 1439 | "OnuId": onu.ID, |
| 1440 | "OnuSn": onu.Sn(), |
| 1441 | "Pkt": rawpkt.Data(), |
| 1442 | }).Error("Can't find Dst MacAddress in packet, droppint it") |
| 1443 | return new(openolt.Empty), nil |
| 1444 | } |
| 1445 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1446 | msg := types.Message{ |
| 1447 | Type: types.OnuPacketOut, |
| 1448 | Data: types.OnuPacketMessage{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1449 | IntfId: onuPkt.IntfId, |
| 1450 | OnuId: onuPkt.OnuId, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1451 | PortNo: onuPkt.PortNo, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1452 | Packet: rawpkt, |
| 1453 | Type: pktType, |
| 1454 | MacAddress: pktMac, |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1455 | }, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1456 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1457 | |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 1458 | onu.Channel <- msg |
| 1459 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1460 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1463 | func (o *OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 635b2bf | 2020-09-04 10:23:40 -0700 | [diff] [blame] | 1464 | |
| 1465 | // OLT Reboot is called in two cases: |
| 1466 | // - 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) |
| 1467 | // - when an OLT needs to be rebooted (voltcl device reboot) |
| 1468 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 1469 | oltLogger.WithFields(log.Fields{ |
| 1470 | "oltId": o.ID, |
| 1471 | }).Info("Shutting down") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1472 | publishEvent("OLT-reboot-received", -1, -1, "") |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1473 | go func() { _ = o.RestartOLT() }() |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1474 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1477 | func (o *OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 1478 | oltLogger.WithFields(log.Fields{ |
| 1479 | "oltId": o.ID, |
| 1480 | }).Info("Received ReenableOlt request from VOLTHA") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1481 | publishEvent("OLT-reenable-received", -1, -1, "") |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 1482 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1483 | // enable OLT |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1484 | oltMsg := types.Message{ |
| 1485 | Type: types.OltIndication, |
| 1486 | Data: types.OltIndicationMessage{ |
| 1487 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1488 | }, |
Pragya Arya | 1881df0 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1489 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1490 | o.channel <- oltMsg |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 1491 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1492 | for _, pon := range o.Pons { |
| 1493 | if pon.InternalState.Current() == "disabled" { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1494 | msg := types.Message{ |
| 1495 | Type: types.PonIndication, |
| 1496 | Data: types.PonIndicationMessage{ |
| 1497 | OperState: types.UP, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 1498 | PonPortID: pon.ID, |
| 1499 | }, |
| 1500 | } |
| 1501 | o.channel <- msg |
| 1502 | } |
| 1503 | } |
Matteo Scandolo | e60a505 | 2020-02-07 00:31:14 +0000 | [diff] [blame] | 1504 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1505 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1508 | 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] | 1509 | pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 1510 | |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 1511 | err := o.Nnis[0].handleNniPacket(pkt) // FIXME we are assuming we have only one NNI |
| 1512 | |
| 1513 | if err != nil { |
| 1514 | return nil, err |
| 1515 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1516 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1519 | func (o *OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 1520 | oltLogger.Error("CollectStatistics not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1521 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1524 | 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] | 1525 | oltLogger.Error("GetOnuInfo not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1526 | return new(openolt.OnuIndication), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1529 | 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] | 1530 | oltLogger.Error("GetPonIf not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1531 | return new(openolt.IntfIndication), nil |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1534 | func (s *OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1535 | oltLogger.Info("received CreateTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1536 | return new(openolt.Empty), nil |
| 1537 | } |
| 1538 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1539 | func (s *OltDevice) RemoveTrafficQueues(_ context.Context, tq *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
| 1540 | oltLogger.WithFields(log.Fields{ |
| 1541 | "OnuId": tq.OnuId, |
| 1542 | "IntfId": tq.IntfId, |
| 1543 | "OnuPortNo": tq.PortNo, |
| 1544 | "UniId": tq.UniId, |
| 1545 | }).Info("received RemoveTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1546 | return new(openolt.Empty), nil |
| 1547 | } |
| 1548 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1549 | func (s *OltDevice) CreateTrafficSchedulers(_ context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1550 | oltLogger.WithFields(log.Fields{ |
| 1551 | "OnuId": trafficSchedulers.OnuId, |
| 1552 | "IntfId": trafficSchedulers.IntfId, |
| 1553 | "OnuPortNo": trafficSchedulers.PortNo, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1554 | "UniId": trafficSchedulers.UniId, |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1555 | }).Info("received CreateTrafficSchedulers") |
| 1556 | |
| 1557 | if !s.enablePerf { |
| 1558 | pon, err := s.GetPonById(trafficSchedulers.IntfId) |
| 1559 | if err != nil { |
| 1560 | oltLogger.Errorf("Error retrieving PON by IntfId: %v", err) |
| 1561 | return new(openolt.Empty), err |
| 1562 | } |
| 1563 | onu, err := pon.GetOnuById(trafficSchedulers.OnuId) |
| 1564 | if err != nil { |
| 1565 | oltLogger.Errorf("Error retrieving ONU from pon by OnuId: %v", err) |
| 1566 | return new(openolt.Empty), err |
| 1567 | } |
| 1568 | onu.TrafficSchedulers = trafficSchedulers |
| 1569 | } |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1570 | return new(openolt.Empty), nil |
| 1571 | } |
| 1572 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 1573 | 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] | 1574 | oltLogger.WithFields(log.Fields{ |
| 1575 | "OnuId": trafficSchedulers.OnuId, |
| 1576 | "IntfId": trafficSchedulers.IntfId, |
| 1577 | "OnuPortNo": trafficSchedulers.PortNo, |
| 1578 | }).Info("received RemoveTrafficSchedulers") |
| 1579 | if !s.enablePerf { |
| 1580 | pon, err := s.GetPonById(trafficSchedulers.IntfId) |
| 1581 | if err != nil { |
| 1582 | oltLogger.Errorf("Error retrieving PON by IntfId: %v", err) |
| 1583 | return new(openolt.Empty), err |
| 1584 | } |
| 1585 | onu, err := pon.GetOnuById(trafficSchedulers.OnuId) |
| 1586 | if err != nil { |
| 1587 | oltLogger.Errorf("Error retrieving ONU from pon by OnuId: %v", err) |
| 1588 | return new(openolt.Empty), err |
| 1589 | } |
| 1590 | |
| 1591 | onu.TrafficSchedulers = nil |
| 1592 | } |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 1593 | return new(openolt.Empty), nil |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1594 | } |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 1595 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1596 | func (o *OltDevice) PerformGroupOperation(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) { |
| 1597 | oltLogger.WithFields(log.Fields{ |
| 1598 | "GroupId": group.GroupId, |
| 1599 | "Command": group.Command, |
| 1600 | "Members": group.Members, |
| 1601 | "Action": group.Action, |
| 1602 | }).Debug("received PerformGroupOperation") |
| 1603 | return &openolt.Empty{}, nil |
| 1604 | } |
| 1605 | |
| 1606 | func (o *OltDevice) DeleteGroup(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) { |
| 1607 | oltLogger.WithFields(log.Fields{ |
| 1608 | "GroupId": group.GroupId, |
| 1609 | "Command": group.Command, |
| 1610 | "Members": group.Members, |
| 1611 | "Action": group.Action, |
| 1612 | }).Debug("received PerformGroupOperation") |
| 1613 | return &openolt.Empty{}, nil |
| 1614 | } |
| 1615 | |
Matteo Scandolo | 1f9f4b2 | 2021-12-14 11:51:55 -0800 | [diff] [blame] | 1616 | func (o *OltDevice) GetExtValue(ctx context.Context, in *openolt.ValueParam) (*extension.ReturnValues, error) { |
| 1617 | return &extension.ReturnValues{}, nil |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | func (o *OltDevice) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm) (*openolt.Empty, error) { |
| 1621 | return &openolt.Empty{}, nil |
| 1622 | } |
| 1623 | |
| 1624 | func (o *OltDevice) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu) (*openolt.OnuLogicalDistance, error) { |
| 1625 | return &openolt.OnuLogicalDistance{}, nil |
| 1626 | } |
| 1627 | |
| 1628 | func (o *OltDevice) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu) (*openolt.OnuLogicalDistance, error) { |
| 1629 | return &openolt.OnuLogicalDistance{}, nil |
| 1630 | } |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1631 | |
Girish Gowdra | 62f2429 | 2021-05-12 16:28:39 -0700 | [diff] [blame] | 1632 | func (o *OltDevice) GetPonRxPower(ctx context.Context, in *openolt.Onu) (*openolt.PonRxPowerData, error) { |
| 1633 | return &openolt.PonRxPowerData{}, nil |
| 1634 | } |
| 1635 | |
Matteo Scandolo | 96f8919 | 2021-03-12 13:17:26 -0800 | [diff] [blame] | 1636 | func (o *OltDevice) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket) (*openolt.GemPortStatistics, error) { |
| 1637 | return &openolt.GemPortStatistics{}, nil |
| 1638 | } |
| 1639 | |
| 1640 | func (o *OltDevice) GetOnuStatistics(ctx context.Context, in *openolt.Onu) (*openolt.OnuStatistics, error) { |
| 1641 | return &openolt.OnuStatistics{}, nil |
| 1642 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1643 | |
| 1644 | func (o *OltDevice) storeAllocId(flow *openolt.Flow) { |
| 1645 | o.AllocIDsLock.Lock() |
| 1646 | defer o.AllocIDsLock.Unlock() |
| 1647 | |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1648 | if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)]; !ok { |
| 1649 | oltLogger.WithFields(log.Fields{ |
| 1650 | "IntfId": flow.AccessIntfId, |
| 1651 | "OnuId": flow.OnuId, |
| 1652 | "PortNo": flow.PortNo, |
| 1653 | "GemportId": flow.GemportId, |
| 1654 | "FlowId": flow.FlowId, |
| 1655 | }).Error("trying-to-store-alloc-id-for-unknown-onu") |
| 1656 | } |
| 1657 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1658 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1659 | "IntfId": flow.AccessIntfId, |
| 1660 | "OnuId": flow.OnuId, |
| 1661 | "PortNo": flow.PortNo, |
| 1662 | "GemportId": flow.GemportId, |
| 1663 | "FlowId": flow.FlowId, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1664 | }).Trace("storing-alloc-id-via-flow") |
| 1665 | |
| 1666 | if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo]; !ok { |
| 1667 | o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo] = make(map[int32]map[uint64]bool) |
| 1668 | } |
| 1669 | if _, ok := o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId]; !ok { |
| 1670 | o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId] = make(map[uint64]bool) |
| 1671 | } |
| 1672 | o.AllocIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.AllocId][flow.FlowId] = true |
| 1673 | } |
| 1674 | |
| 1675 | func (o *OltDevice) freeAllocId(flow *openolt.Flow) { |
| 1676 | // if this is the last flow referencing the AllocId then remove it |
| 1677 | o.AllocIDsLock.Lock() |
| 1678 | defer o.AllocIDsLock.Unlock() |
| 1679 | |
| 1680 | oltLogger.WithFields(log.Fields{ |
| 1681 | "IntfId": flow.AccessIntfId, |
| 1682 | "OnuId": flow.OnuId, |
| 1683 | "PortNo": flow.PortNo, |
| 1684 | "GemportId": flow.GemportId, |
| 1685 | }).Trace("freeing-alloc-id-via-flow") |
| 1686 | |
| 1687 | // NOTE look at the freeGemPortId implementation for comments and context |
| 1688 | for ponId, ponValues := range o.AllocIDs { |
| 1689 | for onuId, onuValues := range ponValues { |
| 1690 | for uniId, uniValues := range onuValues { |
| 1691 | for allocId, flows := range uniValues { |
| 1692 | for flowId := range flows { |
| 1693 | // if the flow matches, remove it from the map. |
| 1694 | if flow.FlowId == flowId { |
| 1695 | delete(o.AllocIDs[ponId][onuId][uniId][allocId], flow.FlowId) |
| 1696 | } |
| 1697 | // if that was the last flow for a particular allocId, remove the entire allocId |
| 1698 | if len(o.AllocIDs[ponId][onuId][uniId][allocId]) == 0 { |
| 1699 | delete(o.AllocIDs[ponId][onuId][uniId], allocId) |
| 1700 | } |
| 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | } |
| 1706 | } |
| 1707 | |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1708 | func (o *OltDevice) storeGemPortId(ponId uint32, onuId uint32, portNo uint32, gemId int32, flowId uint64) { |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1709 | o.GemPortIDsLock.Lock() |
| 1710 | defer o.GemPortIDsLock.Unlock() |
| 1711 | |
| 1712 | if _, ok := o.GemPortIDs[ponId][onuId]; !ok { |
| 1713 | oltLogger.WithFields(log.Fields{ |
| 1714 | "IntfId": ponId, |
| 1715 | "OnuId": onuId, |
| 1716 | "PortNo": portNo, |
| 1717 | "GemportId": gemId, |
| 1718 | "FlowId": flowId, |
| 1719 | }).Error("trying-to-store-gemport-for-unknown-onu") |
| 1720 | } |
| 1721 | |
| 1722 | oltLogger.WithFields(log.Fields{ |
| 1723 | "IntfId": ponId, |
| 1724 | "OnuId": onuId, |
| 1725 | "PortNo": portNo, |
| 1726 | "GemportId": gemId, |
| 1727 | "FlowId": flowId, |
| 1728 | }).Trace("storing-alloc-id-via-flow") |
| 1729 | |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1730 | if _, ok := o.GemPortIDs[ponId][onuId][portNo]; !ok { |
| 1731 | o.GemPortIDs[ponId][onuId][portNo] = make(map[int32]map[uint64]bool) |
| 1732 | } |
| 1733 | if _, ok := o.GemPortIDs[ponId][onuId][portNo][gemId]; !ok { |
| 1734 | o.GemPortIDs[ponId][onuId][portNo][gemId] = make(map[uint64]bool) |
| 1735 | } |
| 1736 | o.GemPortIDs[ponId][onuId][portNo][gemId][flowId] = true |
| 1737 | } |
| 1738 | |
| 1739 | func (o *OltDevice) storeGemPortIdByFlow(flow *openolt.Flow) { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1740 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1741 | "IntfId": flow.AccessIntfId, |
| 1742 | "OnuId": flow.OnuId, |
| 1743 | "PortNo": flow.PortNo, |
| 1744 | "GemportId": flow.GemportId, |
| 1745 | "FlowId": flow.FlowId, |
| 1746 | "ReplicateFlow": flow.ReplicateFlow, |
| 1747 | "PbitToGemport": flow.PbitToGemport, |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1748 | }).Trace("storing-gem-port-id-via-flow") |
| 1749 | |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1750 | if flow.ReplicateFlow { |
| 1751 | for _, gem := range flow.PbitToGemport { |
| 1752 | o.storeGemPortId(uint32(flow.AccessIntfId), uint32(flow.OnuId), flow.PortNo, int32(gem), flow.FlowId) |
| 1753 | } |
| 1754 | } else { |
| 1755 | o.storeGemPortId(uint32(flow.AccessIntfId), uint32(flow.OnuId), flow.PortNo, flow.GemportId, flow.FlowId) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1756 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | func (o *OltDevice) freeGemPortId(flow *openolt.Flow) { |
| 1760 | // if this is the last flow referencing the GemPort then remove it |
| 1761 | o.GemPortIDsLock.Lock() |
| 1762 | defer o.GemPortIDsLock.Unlock() |
| 1763 | |
| 1764 | oltLogger.WithFields(log.Fields{ |
| 1765 | "IntfId": flow.AccessIntfId, |
| 1766 | "OnuId": flow.OnuId, |
| 1767 | "PortNo": flow.PortNo, |
| 1768 | "GemportId": flow.GemportId, |
| 1769 | }).Trace("freeing-gem-port-id-via-flow") |
| 1770 | |
| 1771 | // NOTE that this loop is not very performant, it would be better if the flow carries |
| 1772 | // the same information that it carries during a FlowAdd. If so we can directly remove |
| 1773 | // items from the map |
| 1774 | |
| 1775 | //delete(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.GemportId], flow.FlowId) |
| 1776 | //if len(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo][flow.GemportId]) == 0 { |
| 1777 | // delete(o.GemPortIDs[uint32(flow.AccessIntfId)][uint32(flow.OnuId)][flow.PortNo], flow.GemportId) |
| 1778 | //} |
| 1779 | |
| 1780 | // NOTE this loop assumes that flow IDs are unique per device |
| 1781 | for ponId, ponValues := range o.GemPortIDs { |
| 1782 | for onuId, onuValues := range ponValues { |
| 1783 | for uniId, uniValues := range onuValues { |
| 1784 | for gemId, flows := range uniValues { |
| 1785 | for flowId := range flows { |
| 1786 | // if the flow matches, remove it from the map. |
| 1787 | if flow.FlowId == flowId { |
| 1788 | delete(o.GemPortIDs[ponId][onuId][uniId][gemId], flow.FlowId) |
| 1789 | } |
| 1790 | // if that was the last flow for a particular gem, remove the entire gem |
| 1791 | if len(o.GemPortIDs[ponId][onuId][uniId][gemId]) == 0 { |
| 1792 | delete(o.GemPortIDs[ponId][onuId][uniId], gemId) |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | // validateFlow checks that: |
| 1802 | // - the AllocId is not used in any flow referencing other ONUs/UNIs on the same PON |
| 1803 | // - the GemPortId is not used in any flow referencing other ONUs/UNIs on the same PON |
| 1804 | func (o *OltDevice) validateFlow(flow *openolt.Flow) error { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1805 | // validate gemPort |
| 1806 | o.GemPortIDsLock.RLock() |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1807 | defer o.GemPortIDsLock.RUnlock() |
| 1808 | for onuId, onu := range o.GemPortIDs[uint32(flow.AccessIntfId)] { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1809 | if onuId == uint32(flow.OnuId) { |
| 1810 | continue |
| 1811 | } |
| 1812 | for uniId, uni := range onu { |
| 1813 | for gem := range uni { |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1814 | if flow.ReplicateFlow { |
| 1815 | for _, flowGem := range flow.PbitToGemport { |
| 1816 | if gem == int32(flowGem) { |
| 1817 | return fmt.Errorf("gem-%d-already-in-use-on-uni-%d-onu-%d-replicated-flow-%d", gem, uniId, onuId, flow.FlowId) |
| 1818 | } |
| 1819 | } |
| 1820 | } else { |
| 1821 | if gem == flow.GemportId { |
| 1822 | return fmt.Errorf("gem-%d-already-in-use-on-uni-%d-onu-%d-flow-%d", gem, uniId, onuId, flow.FlowId) |
| 1823 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1824 | } |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | o.AllocIDsLock.RLock() |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 1830 | defer o.AllocIDsLock.RUnlock() |
| 1831 | for onuId, onu := range o.AllocIDs[uint32(flow.AccessIntfId)] { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1832 | if onuId == uint32(flow.OnuId) { |
| 1833 | continue |
| 1834 | } |
| 1835 | for uniId, uni := range onu { |
| 1836 | for allocId := range uni { |
| 1837 | if allocId == flow.AllocId { |
Matteo Scandolo | a8eca49 | 2021-03-23 09:45:16 -0700 | [diff] [blame] | 1838 | return fmt.Errorf("allocId-%d-already-in-use-on-uni-%d-onu-%d-flow-%d", allocId, uniId, onuId, flow.FlowId) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | return nil |
| 1845 | } |
| 1846 | |
| 1847 | // clearAllResources is invoked up OLT Reboot to remove all the allocated |
| 1848 | // GemPorts, AllocId and ONU-IDs across the PONs |
| 1849 | func (o *OltDevice) clearAllResources() { |
| 1850 | |
| 1851 | // remove the resources received via flows |
| 1852 | o.GemPortIDsLock.Lock() |
| 1853 | o.GemPortIDs = make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 1854 | o.GemPortIDsLock.Unlock() |
| 1855 | o.AllocIDsLock.Lock() |
| 1856 | o.AllocIDs = make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool) |
| 1857 | o.AllocIDsLock.Unlock() |
| 1858 | |
| 1859 | // remove the resources received via OMCI |
| 1860 | for _, pon := range o.Pons { |
| 1861 | pon.removeAllAllocIds() |
| 1862 | pon.removeAllGemPorts() |
| 1863 | pon.removeAllOnuIds() |
| 1864 | } |
| 1865 | } |