blob: f5fc22456686348177dd2a88fa4945d031f5c5bb [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001/*
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 "errors"
23 "strconv"
24
25 //"sync"
26 //"time"
27
28 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
29 "github.com/opencord/voltha-lib-go/v3/pkg/log"
30 vc "github.com/opencord/voltha-protos/v3/go/common"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
32 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
33 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
34 //"github.com/opencord/voltha-protos/v3/go/voltha"
35)
36
37type UniPortType uint8
38
39const (
40 // Uni Interface type
41 UniPPTP UniPortType = 0 // relates to PPTP
42 UniVEIP UniPortType = 1 // relates to VEIP
43)
44
45//OntDeviceEntry structure holds information about the attached FSM'as and their communication
46type OnuUniPort struct {
47 enabled bool
48 name string
49 portNo uint32
50 portType UniPortType
51 ofpPortNo string
52 uniId uint16
53 macBpNo uint16
54 entityId uint16
55 adminState vc.AdminState_Types
56 operState vc.OperStatus_Types
57 pPort *voltha.Port
58}
59
60//NewOnuUniPort returns a new instance of a OnuUniPort
61func NewOnuUniPort(a_uniId uint16, a_portNo uint32, a_InstNo uint16,
62 a_portType UniPortType) *OnuUniPort {
63 logger.Infow("init-onuUniPort", log.Fields{"uniId": a_uniId,
64 "portNo": a_portNo, "InstNo": a_InstNo, "type": a_portType})
65 var onuUniPort OnuUniPort
66 onuUniPort.enabled = false
67 onuUniPort.name = "uni-" + strconv.FormatUint(uint64(a_portNo), 10)
68 onuUniPort.portNo = a_portNo
69 onuUniPort.portType = a_portType
70 // so far it seems as here ofpPortNo/Name ist the same as the original port name ...??
71 onuUniPort.ofpPortNo = onuUniPort.name
72 onuUniPort.uniId = a_uniId
73 onuUniPort.macBpNo = a_uniId + 1 //ensure >0 instanceNo
74 onuUniPort.entityId = a_InstNo
75 onuUniPort.adminState = vc.AdminState_ENABLED //enabled per create
76 onuUniPort.operState = vc.OperStatus_UNKNOWN
77 onuUniPort.pPort = nil // to be set on create
78 return &onuUniPort
79}
80
Holger Hildebrandt24d51952020-05-04 14:03:42 +000081//creates the Voltha port based on ONU UNI Port
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000082func (oo *OnuUniPort) CreateVolthaPort(a_pDeviceHandler *DeviceHandler) error {
83 logger.Debug("adding-uni-port")
84 pUniPort := &voltha.Port{
85 PortNo: oo.portNo,
86 Label: oo.name,
87 Type: voltha.Port_ETHERNET_UNI,
88 AdminState: oo.adminState,
89 OperStatus: oo.operState,
90 // obviously empty peer setting
91 }
92 if pUniPort != nil {
93 if err := a_pDeviceHandler.coreProxy.PortCreated(context.TODO(),
94 a_pDeviceHandler.deviceID, pUniPort); err != nil {
95 logger.Fatalf("adding-uni-port: create-VOLTHA-Port-failed-%s", err)
96 return err
97 }
98 logger.Infow("Voltha onuUniPort-added", log.Fields{"for PortNo": oo.portNo})
99 oo.pPort = pUniPort
100 oo.operState = vc.OperStatus_DISCOVERED
101 } else {
102 logger.Warnw("could not create Voltha UniPort - nil pointer",
103 log.Fields{"for PortNo": oo.portNo})
104 return errors.New("create Voltha UniPort failed")
105 }
106 return nil
107}
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000108
109//mofify OperState of the the UniPort
110func (oo *OnuUniPort) SetOperState(a_NewOperState vc.OperStatus_Types) {
111 oo.operState = a_NewOperState
112}