blob: fe9af4c91cc3b494856cf3625c779f80fcb313ad [file] [log] [blame]
kesavandfdf77632021-01-26 23:40:33 -05001/*
2 * Copyright 2020-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
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "context"
22 "github.com/opencord/omci-lib-go"
23 me "github.com/opencord/omci-lib-go/generated"
Girish Gowdra50e56422021-06-01 16:46:04 -070024 "github.com/opencord/voltha-lib-go/v5/pkg/log"
kesavandfdf77632021-01-26 23:40:33 -050025 "github.com/opencord/voltha-protos/v4/go/extension"
26 "time"
27)
28
29const (
30 uniStatusTimeout = 3
31 adminState = "AdministrativeState"
32 operationalState = "OperationalState"
33 configInd = "ConfigurationInd"
34)
35
36//UniPortStatus implements methods to get uni port status info
37type UniPortStatus struct {
38 omciRespChn chan Message
39 pOmiCC *omciCC
40 pLastTxMeInstance *me.ManagedEntity
41}
42
43//NewUniPortStatus creates a new instance of UniPortStatus
44func NewUniPortStatus(pOmicc *omciCC) *UniPortStatus {
45 return &UniPortStatus{
46 omciRespChn: make(chan Message),
47 pOmiCC: pOmicc,
48 }
49
50}
51
52func (portStatus *UniPortStatus) getUniPortStatus(ctx context.Context, uniIdx uint32) *extension.SingleGetValueResponse {
53 for _, uniPort := range portStatus.pOmiCC.pBaseDeviceHandler.uniEntityMap {
54
55 if uniPort.uniID == uint8(uniIdx) && uniPort.portType == uniPPTP {
56
57 requestedAttributes := me.AttributeValueMap{adminState: 0, operationalState: 0, configInd: 0}
Girish Gowdra0b235842021-03-09 13:06:46 -080058 // Note: No reference to fetch the OMCI timeout configuration value, so hard code it to 10s
ozgecanetsiab36ed572021-04-01 10:38:48 +030059 meInstance, err := portStatus.pOmiCC.sendGetMe(ctx, me.PhysicalPathTerminationPointEthernetUniClassID, uniPort.entityID, requestedAttributes, 10, true, portStatus.omciRespChn)
60 if err != nil {
61 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
62 }
63 if meInstance != nil {
kesavandfdf77632021-01-26 23:40:33 -050064 portStatus.pLastTxMeInstance = meInstance
65
66 //verify response
67 return portStatus.waitforgetUniPortStatus(ctx, meInstance)
68 }
69 }
70 }
71 logger.Errorw(ctx, "getUniPortStatus uniIdx is not valid", log.Fields{"uniIdx": uniIdx})
72 return postUniStatusErrResponse(extension.GetValueResponse_INVALID_PORT_TYPE)
73}
74
75func (portStatus *UniPortStatus) waitforgetUniPortStatus(ctx context.Context, apMeInstance *me.ManagedEntity) *extension.SingleGetValueResponse {
76
77 select {
78 // maybe be also some outside cancel (but no context modeled for the moment ...)
79 case <-ctx.Done():
80 logger.Errorf(ctx, "waitforgetUniPortStatus Context done")
81 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
82 case <-time.After(uniStatusTimeout * time.Second):
83 logger.Errorf(ctx, "waitforgetUniPortStatus timeout")
84 return postUniStatusErrResponse(extension.GetValueResponse_TIMEOUT)
85
86 case omciMsg := <-portStatus.omciRespChn:
87 if omciMsg.Type != OMCI {
88 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
89 }
90 msg, _ := omciMsg.Data.(OmciMessage)
91 return portStatus.processGetUnitStatusResp(ctx, msg)
92 }
93
94}
95
96func (portStatus *UniPortStatus) processGetUnitStatusResp(ctx context.Context, msg OmciMessage) *extension.SingleGetValueResponse {
97 logger.Debugw(ctx, "processGetUniStatusResp:", log.Fields{"msg.Omci.MessageType": msg.OmciMsg.MessageType,
98 "msg.OmciMsg.TransactionID": msg.OmciMsg.TransactionID, "DeviceIdentfier": msg.OmciMsg.DeviceIdentifier})
99
100 if msg.OmciMsg.MessageType != omci.GetResponseType {
101 logger.Debugw(ctx, "processGetUniStatusResp error", log.Fields{"incorrect RespType": msg.OmciMsg.MessageType,
102 "expected": omci.GetResponseType})
103 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
104 }
105
106 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
107 if msgLayer == nil {
108 logger.Errorf(ctx, "processGetUniStatusResp omci Msg layer not found - ")
109 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
110
111 }
112 msgObj, msgOk := msgLayer.(*omci.GetResponse)
113 if !msgOk {
114 logger.Errorf(ctx, "processGetUniStatusResp omci msgObj layer could not be found ")
115 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
116
117 }
118
119 if msgObj.Result != me.Success {
120 return postUniStatusErrResponse(extension.GetValueResponse_INTERNAL_ERROR)
121 }
122 meAttributes := msgObj.Attributes
123
124 singleValResp := extension.SingleGetValueResponse{
125 Response: &extension.GetValueResponse{
126 Status: extension.GetValueResponse_OK,
127 Response: &extension.GetValueResponse_UniInfo{
128 UniInfo: &extension.GetOnuUniInfoResponse{},
129 },
130 },
131 }
132 if meAttributes[operationalState].(uint8) == 0 {
133 singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_ENABLED
134 } else if meAttributes[operationalState].(uint8) == 1 {
135 singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_DISABLED
136 } else {
137 singleValResp.Response.GetUniInfo().OperState = extension.GetOnuUniInfoResponse_OPERSTATE_UNDEFINED
138 }
139
140 if meAttributes[adminState].(uint8) == 0 {
141 singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_UNLOCKED
142 } else if meAttributes[adminState].(uint8) == 1 {
143 singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_LOCKED
144 } else {
145 singleValResp.Response.GetUniInfo().AdmState = extension.GetOnuUniInfoResponse_ADMSTATE_UNDEFINED
146 }
147 configIndMap := map[uint8]extension.GetOnuUniInfoResponse_ConfigurationInd{
148 0: 0,
149 1: extension.GetOnuUniInfoResponse_TEN_BASE_T_FDX,
150 2: extension.GetOnuUniInfoResponse_HUNDRED_BASE_T_FDX,
151 3: extension.GetOnuUniInfoResponse_GIGABIT_ETHERNET_FDX,
152 4: extension.GetOnuUniInfoResponse_TEN_G_ETHERNET_FDX,
153 17: extension.GetOnuUniInfoResponse_TEN_BASE_T_HDX,
154 18: extension.GetOnuUniInfoResponse_HUNDRED_BASE_T_HDX,
155 19: extension.GetOnuUniInfoResponse_GIGABIT_ETHERNET_HDX,
156 }
157 configInd := meAttributes[configInd].(uint8)
158 singleValResp.Response.GetUniInfo().ConfigInd = configIndMap[configInd]
159 return &singleValResp
160}
161
162func postUniStatusErrResponse(reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
163 return &extension.SingleGetValueResponse{
164 Response: &extension.GetValueResponse{
165 Status: extension.GetValueResponse_ERROR,
166 ErrReason: reason,
167 },
168 }
169}