khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 17 | package mocks |
| 18 | |
| 19 | import ( |
| 20 | "context" |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 21 | "errors" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 22 | "fmt" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 23 | "strings" |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 24 | "sync" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 25 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 26 | "github.com/gogo/protobuf/proto" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 27 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 28 | com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common" |
| 29 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 30 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 31 | of "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v3/go/voltha" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | const ( |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 36 | numONUPerOLT = 4 |
| 37 | startingUNIPortNo = 100 |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 38 | ) |
| 39 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 40 | // OLTAdapter represent OLT adapter |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 41 | type OLTAdapter struct { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 42 | flows map[uint64]*voltha.OfpFlowStats |
| 43 | lock sync.Mutex |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 44 | Adapter |
| 45 | } |
| 46 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 47 | // NewOLTAdapter - creates OLT adapter instance |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 48 | func NewOLTAdapter(cp adapterif.CoreProxy) *OLTAdapter { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 49 | return &OLTAdapter{ |
| 50 | flows: map[uint64]*voltha.OfpFlowStats{}, |
| 51 | Adapter: Adapter{ |
| 52 | coreProxy: cp, |
| 53 | }, |
| 54 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 55 | } |
| 56 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 57 | // Adopt_device creates new handler for added device |
| 58 | func (oltA *OLTAdapter) Adopt_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 59 | go func() { |
| 60 | d := proto.Clone(device).(*voltha.Device) |
| 61 | d.Root = true |
| 62 | d.Vendor = "olt_adapter_mock" |
| 63 | d.Model = "go-mock" |
| 64 | d.SerialNumber = com.GetRandomSerialNumber() |
| 65 | d.MacAddress = strings.ToUpper(com.GetRandomMacAddress()) |
| 66 | oltA.storeDevice(d) |
| 67 | if res := oltA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 68 | logger.Fatalf("deviceUpdate-failed-%s", res) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 69 | } |
| 70 | nniPort := &voltha.Port{ |
| 71 | PortNo: 2, |
| 72 | Label: fmt.Sprintf("nni-%d", 2), |
| 73 | Type: voltha.Port_ETHERNET_NNI, |
| 74 | OperStatus: voltha.OperStatus_ACTIVE, |
| 75 | } |
| 76 | var err error |
| 77 | if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, nniPort); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 78 | logger.Fatalf("PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | ponPort := &voltha.Port{ |
| 82 | PortNo: 1, |
| 83 | Label: fmt.Sprintf("pon-%d", 1), |
| 84 | Type: voltha.Port_PON_OLT, |
| 85 | OperStatus: voltha.OperStatus_ACTIVE, |
| 86 | } |
| 87 | if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 88 | logger.Fatalf("PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | d.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 92 | d.OperStatus = voltha.OperStatus_ACTIVE |
| 93 | |
| 94 | if err = oltA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 95 | logger.Fatalf("Device-state-update-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | //Get the latest device data from the Core |
| 99 | if d, err = oltA.coreProxy.GetDevice(context.TODO(), d.Id, d.Id); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 100 | logger.Fatalf("getting-device-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | if err = oltA.updateDevice(d); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 104 | logger.Fatalf("saving-device-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // Register Child devices |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 108 | initialUniPortNo := startingUNIPortNo |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 109 | for i := 0; i < numONUPerOLT; i++ { |
| 110 | go func(seqNo int) { |
| 111 | if _, err := oltA.coreProxy.ChildDeviceDetected( |
| 112 | context.TODO(), |
| 113 | d.Id, |
| 114 | 1, |
| 115 | "onu_adapter_mock", |
| 116 | initialUniPortNo+seqNo, |
| 117 | "onu_adapter_mock", |
| 118 | com.GetRandomSerialNumber(), |
| 119 | int64(seqNo)); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 120 | logger.Fatalf("failure-sending-child-device-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 121 | } |
| 122 | }(i) |
| 123 | } |
| 124 | }() |
| 125 | return nil |
| 126 | } |
| 127 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 128 | // Get_ofp_device_info returns ofp device info |
| 129 | func (oltA *OLTAdapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 130 | if d := oltA.getDevice(device.Id); d == nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 131 | logger.Fatalf("device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 132 | } |
| 133 | return &ic.SwitchCapability{ |
| 134 | Desc: &of.OfpDesc{ |
| 135 | HwDesc: "olt_adapter_mock", |
| 136 | SwDesc: "olt_adapter_mock", |
| 137 | SerialNum: "12345678", |
| 138 | }, |
| 139 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 140 | NBuffers: 256, |
| 141 | NTables: 2, |
| 142 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 143 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 144 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 145 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 146 | }, |
| 147 | }, nil |
| 148 | } |
| 149 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 150 | // Get_ofp_port_info returns ofp port info |
| 151 | func (oltA *OLTAdapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 152 | if d := oltA.getDevice(device.Id); d == nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 153 | logger.Fatalf("device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 154 | } |
| 155 | capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
| 156 | return &ic.PortCapability{ |
| 157 | Port: &voltha.LogicalPort{ |
| 158 | OfpPort: &of.OfpPort{ |
| 159 | HwAddr: macAddressToUint32Array("11:22:33:44:55:66"), |
| 160 | Config: 0, |
| 161 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
| 162 | Curr: capability, |
| 163 | Advertised: capability, |
| 164 | Peer: capability, |
| 165 | CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 166 | MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 167 | }, |
| 168 | DeviceId: device.Id, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 169 | DevicePortNo: uint32(portNo), |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 170 | }, |
| 171 | }, nil |
| 172 | } |
| 173 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 174 | // GetNumONUPerOLT returns number of ONUs per OLT |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 175 | func (oltA *OLTAdapter) GetNumONUPerOLT() int { |
| 176 | return numONUPerOLT |
| 177 | } |
| 178 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 179 | // Returns the starting UNI port number |
| 180 | func (oltA *OLTAdapter) GetStartingUNIPortNo() int { |
| 181 | return startingUNIPortNo |
| 182 | } |
| 183 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 184 | // Disable_device disables device |
| 185 | func (oltA *OLTAdapter) Disable_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 186 | go func() { |
| 187 | if d := oltA.getDevice(device.Id); d == nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 188 | logger.Fatalf("device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | cloned := proto.Clone(device).(*voltha.Device) |
| 192 | // Update the all ports state on that device to disable |
| 193 | if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 194 | logger.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 197 | //Update the device operational state |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 198 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 199 | // The device is still reachable after it has been disabled, so the connection status should not be changed. |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 200 | |
| 201 | if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 202 | // Device may already have been deleted in the core |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 203 | logger.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 204 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | if err := oltA.updateDevice(cloned); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 208 | logger.Fatalf("saving-device-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Tell the Core that all child devices have been disabled (by default it's an action already taken by the Core |
| 212 | if err := oltA.coreProxy.ChildDevicesLost(context.TODO(), cloned.Id); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 213 | // Device may already have been deleted in the core |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 214 | logger.Warnw("lost-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 215 | } |
| 216 | }() |
| 217 | return nil |
| 218 | } |
| 219 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 220 | // Reenable_device reenables device |
| 221 | func (oltA *OLTAdapter) Reenable_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 222 | go func() { |
| 223 | if d := oltA.getDevice(device.Id); d == nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 224 | logger.Fatalf("device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | cloned := proto.Clone(device).(*voltha.Device) |
| 228 | // Update the all ports state on that device to enable |
| 229 | if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 230 | logger.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | //Update the device state |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 234 | cloned.OperStatus = voltha.OperStatus_ACTIVE |
| 235 | |
| 236 | if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 237 | logger.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // Tell the Core that all child devices have been enabled |
| 241 | if err := oltA.coreProxy.ChildDevicesDetected(context.TODO(), cloned.Id); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 242 | logger.Fatalf("detection-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 243 | } |
| 244 | }() |
| 245 | return nil |
| 246 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 247 | |
| 248 | // Enable_port - |
| 249 | func (oltA *OLTAdapter) Enable_port(deviceId string, Port *voltha.Port) error { //nolint |
| 250 | go func() { |
| 251 | |
| 252 | if Port.Type == voltha.Port_PON_OLT { |
| 253 | if err := oltA.coreProxy.PortStateUpdate(context.TODO(), deviceId, voltha.Port_PON_OLT, Port.PortNo, voltha.OperStatus_ACTIVE); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 254 | logger.Fatalf("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | }() |
| 259 | return nil |
| 260 | } |
| 261 | |
| 262 | // Disable_port - |
| 263 | func (oltA *OLTAdapter) Disable_port(deviceId string, Port *voltha.Port) error { //nolint |
| 264 | go func() { |
| 265 | |
| 266 | if Port.Type == voltha.Port_PON_OLT { |
| 267 | if err := oltA.coreProxy.PortStateUpdate(context.TODO(), deviceId, voltha.Port_PON_OLT, Port.PortNo, voltha.OperStatus_DISCOVERED); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 268 | // Corresponding device may have been deleted |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 269 | logger.Warnw("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | }() |
| 273 | return nil |
| 274 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 275 | |
| 276 | // Child_device_lost deletes ONU and its references |
| 277 | func (oltA *OLTAdapter) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { // nolint |
| 278 | return nil |
| 279 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 280 | |
| 281 | // Update_flows_incrementally mocks the incremental flow update |
| 282 | func (oltA *OLTAdapter) Update_flows_incrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { // nolint |
| 283 | oltA.lock.Lock() |
| 284 | defer oltA.lock.Unlock() |
| 285 | |
| 286 | if flows.ToAdd != nil { |
| 287 | for _, f := range flows.ToAdd.Items { |
| 288 | oltA.flows[f.Id] = f |
| 289 | } |
| 290 | } |
| 291 | if flows.ToRemove != nil { |
| 292 | for _, f := range flows.ToRemove.Items { |
| 293 | delete(oltA.flows, f.Id) |
| 294 | } |
| 295 | } |
| 296 | return nil |
| 297 | } |
| 298 | |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 299 | // Reboot_device - |
| 300 | func (oltA *OLTAdapter) Reboot_device(device *voltha.Device) error { // nolint |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 301 | logger.Infow("reboot-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 302 | |
| 303 | go func() { |
| 304 | if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), device.Id, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 305 | logger.Fatalf("device-state-update-failed", log.Fields{"device-id": device.Id}) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 306 | } |
| 307 | if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), device.Id, voltha.OperStatus_UNKNOWN); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 308 | logger.Fatalf("port-update-failed", log.Fields{"device-id": device.Id}) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 309 | } |
| 310 | }() |
| 311 | return nil |
| 312 | } |
| 313 | |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 314 | // TODO: REMOVE Start_omci_test begins an omci self-test |
| 315 | func (oltA *OLTAdapter) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*ic.TestResponse, error) { // nolint |
| 316 | _ = device |
| 317 | return nil, errors.New("start-omci-test-not-implemented") |
| 318 | } |
| 319 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 320 | // GetFlowCount returns the total number of flows presently under this adapter |
| 321 | func (oltA *OLTAdapter) GetFlowCount() int { |
| 322 | oltA.lock.Lock() |
| 323 | defer oltA.lock.Unlock() |
| 324 | |
| 325 | return len(oltA.flows) |
| 326 | } |
| 327 | |
| 328 | // ClearFlows removes all flows in this adapter |
| 329 | func (oltA *OLTAdapter) ClearFlows() { |
| 330 | oltA.lock.Lock() |
| 331 | defer oltA.lock.Unlock() |
| 332 | |
| 333 | oltA.flows = map[uint64]*voltha.OfpFlowStats{} |
| 334 | } |