blob: d0135aabced029691ad445890b7b7e4507fded6a [file] [log] [blame]
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001/*
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
17//Package common provides global definitions
18package common
19
20import (
21 "context"
mpagenko101ac942021-11-16 15:01:29 +000022 "sync"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000023 "time"
24
25 gp "github.com/google/gopacket"
26 "github.com/looplab/fsm"
mpagenko836a1fd2021-11-01 16:12:42 +000027 "github.com/opencord/omci-lib-go/v2"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000028 vc "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo42dcdfd2021-10-19 17:34:12 -040029 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000030 "github.com/opencord/voltha-protos/v5/go/voltha"
31)
32
33// MessageType - Message Protocol Type
34type MessageType uint8
35
36const (
37 // TestMsg - Message type for non OMCI messages
38 TestMsg MessageType = iota
39 //OMCI - OMCI protocol type msg
40 OMCI
41)
42
43// String - Return the text representation of the message type based on integer
44func (m MessageType) String() string {
45 names := [...]string{
46 "TestMsg",
47 "OMCI",
48 }
49 return names[m]
50}
51
52// Message - message type and data(OMCI)
53type Message struct {
54 Type MessageType
55 Data interface{}
56}
57
58//TestMessageType - message data for various events
59type TestMessageType uint8
60
61const (
62 // LoadMibTemplateOk - message data for getting mib template successfully
63 LoadMibTemplateOk TestMessageType = iota + 1
64 // LoadMibTemplateFailed - message data for failure for getting mib template
65 LoadMibTemplateFailed
66 // TimeOutOccurred - message data for timeout
67 TimeOutOccurred
68 // AbortMessageProcessing - message data for aborting running message
69 AbortMessageProcessing
70)
71
72//TestMessage - Struct to hold the message data
73//TODO: place holder to have a second interface variant - to be replaced by real variant later on
74type TestMessage struct {
75 TestMessageVal TestMessageType
76}
77
78//OmciMessage - OMCI protocol messages for managing and monitoring ONUs
79type OmciMessage struct {
80 //OnuSN *openolt.SerialNumber
81 //OnuID uint32
82 OmciMsg *omci.OMCI
83 OmciPacket *gp.Packet
84}
85
86///////////////////////////////////////////////////////////
87
88// device reasons
89const (
90 DrUnset = 0
91 DrActivatingOnu = 1
92 DrStartingOpenomci = 2
93 DrDiscoveryMibsyncComplete = 3
94 DrInitialMibDownloaded = 4
95 DrTechProfileConfigDownloadSuccess = 5
96 DrOmciFlowsPushed = 6
97 DrOmciAdminLock = 7
98 DrOnuReenabled = 8
99 DrStoppingOpenomci = 9
100 DrRebooting = 10
101 DrOmciFlowsDeleted = 11
102 DrTechProfileConfigDeleteSuccess = 12
103 DrReconcileFailed = 13
104 DrReconcileMaxTimeout = 14
105 DrReconcileCanceled = 15
106 DrTechProfileConfigDownloadFailed = 16
107)
108
109// DeviceReasonMap holds device reason strings
110var DeviceReasonMap = map[uint8]string{
111 DrUnset: "unset",
112 DrActivatingOnu: "activating-onu",
113 DrStartingOpenomci: "starting-openomci",
114 DrDiscoveryMibsyncComplete: "discovery-mibsync-complete",
115 DrInitialMibDownloaded: "initial-mib-downloaded",
116 DrTechProfileConfigDownloadSuccess: "tech-profile-config-download-success",
117 DrTechProfileConfigDownloadFailed: "tech-profile-config-download-failed",
118 DrOmciFlowsPushed: "omci-flows-pushed",
119 DrOmciAdminLock: "omci-admin-lock",
120 DrOnuReenabled: "onu-reenabled",
121 DrStoppingOpenomci: "stopping-openomci",
122 DrRebooting: "rebooting",
123 DrOmciFlowsDeleted: "omci-flows-deleted",
124 DrTechProfileConfigDeleteSuccess: "tech-profile-config-delete-success",
125 DrReconcileFailed: "reconcile-failed",
126 DrReconcileMaxTimeout: "reconcile-max-timeout",
127 DrReconcileCanceled: "reconciling-canceled",
128}
129
130// UsedOmciConfigFsms type for FSMs dealing with OMCI messages
131type UsedOmciConfigFsms int
132
133// FSMs dealing with OMCI messages
134const (
135 CUploadFsm UsedOmciConfigFsms = iota
136 CDownloadFsm
137 CUniLockFsm
138 CUniUnLockFsm
139 CAniConfigFsm
140 CUniVlanConfigFsm
141 CL2PmFsm
142 COnuUpgradeFsm
143)
144
145// OnuDeviceEvent - TODO: add comment
146type OnuDeviceEvent int
147
148// Events of interest to Device Adapters and OpenOMCI State Machines
149const (
150 // DeviceStatusInit - default start state
151 DeviceStatusInit OnuDeviceEvent = iota
152 // MibDatabaseSync - MIB database sync (upload done)
153 MibDatabaseSync
154 // OmciCapabilitiesDone - OMCI ME and message type capabilities known
155 OmciCapabilitiesDone
156 // MibDownloadDone - // MIB download done
157 MibDownloadDone
158 // UniLockStateDone - Uni ports admin set to lock
159 UniLockStateDone
160 // UniUnlockStateDone - Uni ports admin set to unlock
161 UniUnlockStateDone
162 // UniDisableStateDone - Uni ports admin set to lock based on device disable
163 UniDisableStateDone
164 // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable
165 UniEnableStateDone
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700166 // UniEnableStateFailed - Uni ports admin set to unlock failure based on device re-enable
167 UniEnableStateFailed
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000168 // PortLinkUp - Port link state change
169 PortLinkUp
170 // PortLinkDw - Port link state change
171 PortLinkDw
172 // OmciAniConfigDone - AniSide config according to TechProfile done
173 OmciAniConfigDone
174 // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed
175 OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone!
176 // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add with request to write kvStore
177 OmciVlanFilterAddDone
178 // OmciVlanFilterAddDoneNoKvStore - Omci Vlan config done according to flow-add without writing kvStore
179 OmciVlanFilterAddDoneNoKvStore // needs to be the successor of OmciVlanFilterAddDone!
180 // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove with request to write kvStore
181 OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDoneNoKvStore!
182 // OmciVlanFilterRemDoneNoKvStore - Omci Vlan config done according to flow-remove without writing kvStore
183 OmciVlanFilterRemDoneNoKvStore // needs to be the successor of OmciVlanFilterRemDone!
184 // OmciOnuSwUpgradeDone - SoftwareUpgrade to ONU finished
185 OmciOnuSwUpgradeDone
186 // Add other events here as needed (alarms separate???)
187)
188
189///////////////////////////////////////////////////////////
190
191//definitions as per G.988 softwareImage::valid ME IDs
192const (
193 FirstSwImageMeID = 0
194 SecondSwImageMeID = 1
195)
196
197//definitions as per G.988 softwareImage::IsCommitted
198const (
199 SwIsUncommitted = 0
200 SwIsCommitted = 1
201)
202
203//definitions as per G.988 softwareImage::IsActive
204const (
205 SwIsInactive = 0
206 SwIsActive = 1
207)
208
209//definitions as per G.988 softwareImage::IsValid
210const (
211 SwIsInvalid = 0
212 SwIsValid = 1
213)
214
215// SEntrySwImageIndication - TODO: add comment
216type SEntrySwImageIndication struct {
217 Valid bool
218 EntityID uint16
219 Version string
220 IsCommitted uint8
221}
222
223// SswImageIndications - TODO: add comment
224type SswImageIndications struct {
225 ActiveEntityEntry SEntrySwImageIndication
226 InActiveEntityEntry SEntrySwImageIndication
227}
228
229///////////////////////////////////////////////////////////
230
231type activityDescr struct {
232 DatabaseClass func(context.Context) error
233 //advertiseEvents bool
234 AuditInterval time.Duration
235 //tasks map[string]func() error
236}
237
238// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
239type OmciDeviceFsms map[string]activityDescr
240
241// AdapterFsm - Adapter FSM details including channel, event and device
242type AdapterFsm struct {
243 fsmName string
244 deviceID string
245 CommChan chan Message
246 PFsm *fsm.FSM
247}
248
249//CErrWaitAborted - AdapterFsm related error string
250//error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log
251// but not used that way so far (permit error log even for wanted cancellation)
252const CErrWaitAborted = "waitResponse aborted"
253
254///////////////////////////////////////////////////////////
255
256// UniPortType holds possible UNI port types
257type UniPortType uint8
258
259// UniPPTP Interface type - re-use values from G.988 (Chapter 9.3.4) TP type definition (directly used in OMCI!)
260const (
261 // UniPPTP relates to PPTP
262 UniPPTP UniPortType = 1 // relates to PPTP
263 // UniVEIP relates to VEIP
264 UniVEIP UniPortType = 11 // relates to VEIP
265 // UniPPTPPots relates to PPTP POTS
266 UniPPTPPots UniPortType = 4 // relates to IP host config data (for Voice Services)
267)
268
269//OnuUniPort structure holds information about the ONU attached Uni Ports
270type OnuUniPort struct {
271 Enabled bool
272 Name string
273 PortNo uint32
274 PortType UniPortType
275 OfpPortNo string
276 UniID uint8
277 MacBpNo uint8
278 EntityID uint16
279 AdminState vc.AdminState_Types
280 OperState vc.OperStatus_Types
281 PPort *voltha.Port
282}
283
284// OnuUniPortMap - TODO: add comment
285type OnuUniPortMap map[uint32]*OnuUniPort
286
287///////////////////////////////////////////////////////////
288
289const (
290 tpIDStart = 64
291 tpIDEnd = 256
292 tpRange = tpIDEnd - tpIDStart
293 maxUni = 256
294)
295
296// TODO
297const (
298 IeeMaperServiceProfileBaseEID = uint16(0x1001)
299 MacBridgePortAniBaseEID = uint16(0x1001)
300 MacBridgePortUniBaseEID = uint16(0x201)
301 MacBridgePortAniMcastBaseEID = uint16(0xA01)
ozgecanetsia0e3111f2021-10-19 18:04:15 +0300302 VoipUniBaseEID = uint16(0x2001)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000303 GalEthernetEID = uint16(1)
304 MacBridgeServiceProfileEID = uint16(0x201)
305)
306
307// UniVlanRuleParams - TODO: add comment
308type UniVlanRuleParams struct {
309 TpID uint8 `json:"tp_id"`
310 MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting
311 MatchPcp uint32 `json:"match_pcp"`
312 TagsToRemove uint32 `json:"tags_to_remove"`
313 SetVid uint32 `json:"set_vid"`
314 SetPcp uint32 `json:"set_pcp"`
315}
316
317// UniVlanFlowParams - TODO: add comment
318type UniVlanFlowParams struct {
khenaidoo42dcdfd2021-10-19 17:34:12 -0400319 CookieSlice []uint64 `json:"cookie_slice"`
320 VlanRuleParams UniVlanRuleParams `json:"vlan_rule_params"`
321 Meter *ofp.OfpMeterConfig `json:"flow_meter"`
322 RespChan *chan error `json:"-"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000323}
324
325///////////////////////////////////////////////////////////
326
327//definitions as per G.988
328const (
329 OnuDataMeID = 0
330 Onu2gMeID = 0
331 OnugMeID = 0
332 IPHostConfigDataMeID = 1
333 OnugSerialNumberLen = 8
334 OmciMacAddressLen = 6
335)
Holger Hildebrandt60652202021-11-02 11:09:36 +0000336
337///////////////////////////////////////////////////////////
338
339// CBasePathOnuKVStore - kv store path of ONU specific data
340const CBasePathOnuKVStore = "%s/openonu"
mpagenko101ac942021-11-16 15:01:29 +0000341
342///////////////////////////////////////////////////////////
343
344//WaitGroupWithTimeOut definitions to have waitGroup functionality with timeout
345type WaitGroupWithTimeOut struct {
346 sync.WaitGroup
347}