kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 1 | /* |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame^] | 2 | * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 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 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package uniprt provides the utilities for uni port configuration |
| 18 | package uniprt |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 22 | "time" |
| 23 | |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 24 | "github.com/opencord/omci-lib-go/v2" |
| 25 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 26 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 27 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/v5/go/extension" |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 29 | ) |
| 30 | |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 31 | const uniStatusTimeout = 3 |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 32 | |
| 33 | //UniPortStatus implements methods to get uni port status info |
| 34 | type UniPortStatus struct { |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 35 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 36 | pDeviceHandler cmn.IdeviceHandler |
| 37 | pOmiCC *cmn.OmciCC |
| 38 | omciRespChn chan cmn.Message |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 39 | pLastTxMeInstance *me.ManagedEntity |
| 40 | } |
| 41 | |
| 42 | //NewUniPortStatus creates a new instance of UniPortStatus |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 43 | func NewUniPortStatus(apDeviceHandler cmn.IdeviceHandler, apOmicc *cmn.OmciCC) *UniPortStatus { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 44 | return &UniPortStatus{ |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 45 | deviceID: apDeviceHandler.GetDeviceID(), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 46 | pDeviceHandler: apDeviceHandler, |
| 47 | pOmiCC: apOmicc, |
| 48 | omciRespChn: make(chan cmn.Message), |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } |
| 52 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 53 | // GetUniPortStatus - TODO: add comment |
| 54 | func (portStatus *UniPortStatus) GetUniPortStatus(ctx context.Context, uniIdx uint32) *extension.SingleGetValueResponse { |
| 55 | for _, uniPort := range *portStatus.pDeviceHandler.GetUniEntityMap() { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 56 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 57 | if uniPort.UniID == uint8(uniIdx) && uniPort.PortType == cmn.UniPPTP { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 58 | |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 59 | requestedAttributes := me.AttributeValueMap{ |
| 60 | me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: 0, |
| 61 | me.PhysicalPathTerminationPointEthernetUni_OperationalState: 0, |
| 62 | me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd: 0} |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 63 | // Note: No reference to fetch the OMCI timeout configuration value, so hard code it to 10s |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 64 | meInstance, err := portStatus.pOmiCC.SendGetMe(ctx, me.PhysicalPathTerminationPointEthernetUniClassID, |
| 65 | uniPort.EntityID, requestedAttributes, 10, true, portStatus.omciRespChn, false) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 66 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 67 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 68 | } |
| 69 | if meInstance != nil { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 70 | portStatus.pLastTxMeInstance = meInstance |
| 71 | |
| 72 | //verify response |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 73 | return portStatus.waitforGetUniPortStatus(ctx, meInstance) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 77 | logger.Errorw(ctx, "GetUniPortStatus uniIdx is not valid", log.Fields{"uniIdx": uniIdx, "device-id": portStatus.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 78 | return PostUniStatusErrResponse(extension.GetValueResponse_INVALID_PORT_TYPE) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 81 | func (portStatus *UniPortStatus) waitforGetUniPortStatus(ctx context.Context, apMeInstance *me.ManagedEntity) *extension.SingleGetValueResponse { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 82 | |
| 83 | select { |
| 84 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 85 | case <-ctx.Done(): |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 86 | logger.Errorw(ctx, "waitforGetUniPortStatus Context done", log.Fields{"device-id": portStatus.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 87 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 88 | case <-time.After(uniStatusTimeout * time.Second): |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 89 | logger.Errorw(ctx, "waitforGetUniPortStatus timeout", log.Fields{"device-id": portStatus.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 90 | return PostUniStatusErrResponse(extension.GetValueResponse_TIMEOUT) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 91 | |
| 92 | case omciMsg := <-portStatus.omciRespChn: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 93 | if omciMsg.Type != cmn.OMCI { |
| 94 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 95 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 96 | msg, _ := omciMsg.Data.(cmn.OmciMessage) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 97 | return portStatus.processGetUnitStatusResp(ctx, msg) |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 102 | func (portStatus *UniPortStatus) processGetUnitStatusResp(ctx context.Context, msg cmn.OmciMessage) *extension.SingleGetValueResponse { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 103 | logger.Debugw(ctx, "processGetUniStatusResp:", log.Fields{"msg.Omci.MessageType": msg.OmciMsg.MessageType, |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 104 | "msg.OmciMsg.TransactionID": msg.OmciMsg.TransactionID, "DeviceIdentfier": msg.OmciMsg.DeviceIdentifier, |
| 105 | "device-id": portStatus.deviceID}) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 106 | |
| 107 | if msg.OmciMsg.MessageType != omci.GetResponseType { |
| 108 | logger.Debugw(ctx, "processGetUniStatusResp error", log.Fields{"incorrect RespType": msg.OmciMsg.MessageType, |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 109 | "expected": omci.GetResponseType, "device-id": portStatus.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 110 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 114 | if msgLayer == nil { |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 115 | logger.Errorw(ctx, "processGetUniStatusResp omci Msg layer not found", log.Fields{"device-id": portStatus.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 116 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 117 | |
| 118 | } |
| 119 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 120 | if !msgOk { |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 121 | logger.Errorw(ctx, "processGetUniStatusResp omci msgObj layer could not be found", log.Fields{"device-id": portStatus.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 122 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 123 | |
| 124 | } |
| 125 | |
| 126 | if msgObj.Result != me.Success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 127 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 128 | } |
| 129 | meAttributes := msgObj.Attributes |
| 130 | |
| 131 | singleValResp := extension.SingleGetValueResponse{ |
| 132 | Response: &extension.GetValueResponse{ |
| 133 | Status: extension.GetValueResponse_OK, |
| 134 | Response: &extension.GetValueResponse_UniInfo{ |
| 135 | UniInfo: &extension.GetOnuUniInfoResponse{}, |
| 136 | }, |
| 137 | }, |
| 138 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 139 | if pptpEthUniOperState, ok := meAttributes[me.PhysicalPathTerminationPointEthernetUni_OperationalState]; ok { |
| 140 | if pptpEthUniOperState.(uint8) == 0 { |
| 141 | singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_ENABLED |
| 142 | } else if pptpEthUniOperState.(uint8) == 1 { |
| 143 | singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_DISABLED |
| 144 | } else { |
| 145 | singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_OPERSTATE_UNDEFINED |
| 146 | } |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 147 | } else { |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 148 | logger.Infow(ctx, "processGetUniStatusResp - optional attribute pptpEthUniOperState not present!", |
| 149 | log.Fields{"device-id": portStatus.deviceID}) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 150 | singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_OPERSTATE_UNDEFINED |
| 151 | } |
| 152 | |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 153 | if pptpEthUniAdminState, ok := meAttributes[me.PhysicalPathTerminationPointEthernetUni_OperationalState]; ok { |
| 154 | if pptpEthUniAdminState.(uint8) == 0 { |
| 155 | singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_UNLOCKED |
| 156 | } else if pptpEthUniAdminState.(uint8) == 1 { |
| 157 | singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_LOCKED |
| 158 | } else { |
| 159 | singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_ADMSTATE_UNDEFINED |
| 160 | } |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 161 | } else { |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 162 | logger.Errorw(ctx, "processGetUniStatusResp - mandatory attribute pptpEthUniAdminState not present!", |
| 163 | log.Fields{"device-id": portStatus.deviceID}) |
| 164 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 165 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 166 | |
| 167 | if pptpEthUniConfigInd, ok := meAttributes[me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd]; ok { |
| 168 | configIndMap := map[uint8]extension.GetOnuUniInfoResponse_ConfigurationInd{ |
| 169 | 0: 0, |
| 170 | 1: extension.GetOnuUniInfoResponse_TEN_BASE_T_FDX, |
| 171 | 2: extension.GetOnuUniInfoResponse_HUNDRED_BASE_T_FDX, |
| 172 | 3: extension.GetOnuUniInfoResponse_GIGABIT_ETHERNET_FDX, |
| 173 | 4: extension.GetOnuUniInfoResponse_TEN_G_ETHERNET_FDX, |
| 174 | 17: extension.GetOnuUniInfoResponse_TEN_BASE_T_HDX, |
| 175 | 18: extension.GetOnuUniInfoResponse_HUNDRED_BASE_T_HDX, |
| 176 | 19: extension.GetOnuUniInfoResponse_GIGABIT_ETHERNET_HDX, |
| 177 | } |
| 178 | configInd := pptpEthUniConfigInd.(uint8) |
| 179 | singleValResp.Response.GetUniInfo().ConfigInd = configIndMap[configInd] |
| 180 | } else { |
| 181 | logger.Errorw(ctx, "processGetUniStatusResp - mandatory attribute pptpEthUniConfigInd not present!", |
| 182 | log.Fields{"device-id": portStatus.deviceID}) |
| 183 | return PostUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 184 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 185 | |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 186 | return &singleValResp |
| 187 | } |
| 188 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 189 | // PostUniStatusErrResponse - TODO: add comment |
| 190 | func PostUniStatusErrResponse(reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 191 | return &extension.SingleGetValueResponse{ |
| 192 | Response: &extension.GetValueResponse{ |
| 193 | Status: extension.GetValueResponse_ERROR, |
| 194 | ErrReason: reason, |
| 195 | }, |
| 196 | } |
| 197 | } |