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