blob: c7ebf269b506c1cf3c1dfa5a871f31d6f47cf7d2 [file] [log] [blame]
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003
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
Joey Armstrong89c812c2024-01-12 19:00:20 -050017// Package common provides global definitions
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package 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
Joey Armstrong89c812c2024-01-12 19:00:20 -050058// TestMessageType - message data for various events
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000059type 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
Joey Armstrong89c812c2024-01-12 19:00:20 -050072// 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
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000074type TestMessage struct {
75 TestMessageVal TestMessageType
76}
77
Joey Armstrong89c812c2024-01-12 19:00:20 -050078// OmciMessage - OMCI protocol messages for managing and monitoring ONUs
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000079type 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
Joey Armstrong89c812c2024-01-12 19:00:20 -0500191// definitions as per G.988 softwareImage::valid ME IDs
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000192const (
193 FirstSwImageMeID = 0
194 SecondSwImageMeID = 1
195)
196
Joey Armstrong89c812c2024-01-12 19:00:20 -0500197// definitions as per G.988 softwareImage::IsCommitted
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000198const (
199 SwIsUncommitted = 0
200 SwIsCommitted = 1
201)
202
Joey Armstrong89c812c2024-01-12 19:00:20 -0500203// definitions as per G.988 softwareImage::IsActive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000204const (
205 SwIsInactive = 0
206 SwIsActive = 1
207)
208
Joey Armstrong89c812c2024-01-12 19:00:20 -0500209// definitions as per G.988 softwareImage::IsValid
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000210const (
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
Holger Hildebrandt8998ed52022-03-23 09:52:37 +0000229// CGenericManagedEntityIDName - generic name string of attribute "ManagedEntityId"
230const CGenericManagedEntityIDName = "ManagedEntityId"
231
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000232///////////////////////////////////////////////////////////
233
234type activityDescr struct {
235 DatabaseClass func(context.Context) error
236 //advertiseEvents bool
237 AuditInterval time.Duration
238 //tasks map[string]func() error
239}
240
241// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
242type OmciDeviceFsms map[string]activityDescr
243
244// AdapterFsm - Adapter FSM details including channel, event and device
245type AdapterFsm struct {
246 fsmName string
247 deviceID string
248 CommChan chan Message
249 PFsm *fsm.FSM
250}
251
Joey Armstrong89c812c2024-01-12 19:00:20 -0500252// CErrWaitAborted - AdapterFsm related error string
253// error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000254// but not used that way so far (permit error log even for wanted cancellation)
255const CErrWaitAborted = "waitResponse aborted"
256
257///////////////////////////////////////////////////////////
258
259// UniPortType holds possible UNI port types
260type UniPortType uint8
261
262// UniPPTP Interface type - re-use values from G.988 (Chapter 9.3.4) TP type definition (directly used in OMCI!)
263const (
264 // UniPPTP relates to PPTP
265 UniPPTP UniPortType = 1 // relates to PPTP
266 // UniVEIP relates to VEIP
267 UniVEIP UniPortType = 11 // relates to VEIP
268 // UniPPTPPots relates to PPTP POTS
269 UniPPTPPots UniPortType = 4 // relates to IP host config data (for Voice Services)
270)
271
Joey Armstrong89c812c2024-01-12 19:00:20 -0500272// OnuUniPort structure holds information about the ONU attached Uni Ports
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000273type OnuUniPort struct {
274 Enabled bool
275 Name string
276 PortNo uint32
277 PortType UniPortType
278 OfpPortNo string
279 UniID uint8
280 MacBpNo uint8
281 EntityID uint16
282 AdminState vc.AdminState_Types
283 OperState vc.OperStatus_Types
284 PPort *voltha.Port
285}
286
287// OnuUniPortMap - TODO: add comment
288type OnuUniPortMap map[uint32]*OnuUniPort
289
290///////////////////////////////////////////////////////////
291
292const (
293 tpIDStart = 64
294 tpIDEnd = 256
295 tpRange = tpIDEnd - tpIDStart
296 maxUni = 256
297)
298
299// TODO
300const (
301 IeeMaperServiceProfileBaseEID = uint16(0x1001)
302 MacBridgePortAniBaseEID = uint16(0x1001)
303 MacBridgePortUniBaseEID = uint16(0x201)
304 MacBridgePortAniMcastBaseEID = uint16(0xA01)
ozgecanetsia0e3111f2021-10-19 18:04:15 +0300305 VoipUniBaseEID = uint16(0x2001)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000306 GalEthernetEID = uint16(1)
307 MacBridgeServiceProfileEID = uint16(0x201)
308)
309
310// UniVlanRuleParams - TODO: add comment
311type UniVlanRuleParams struct {
312 TpID uint8 `json:"tp_id"`
313 MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting
314 MatchPcp uint32 `json:"match_pcp"`
315 TagsToRemove uint32 `json:"tags_to_remove"`
316 SetVid uint32 `json:"set_vid"`
317 SetPcp uint32 `json:"set_pcp"`
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530318 InnerCvlan uint16 `json:"inner_cvlan"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000319}
320
321// UniVlanFlowParams - TODO: add comment
322type UniVlanFlowParams struct {
khenaidoo42dcdfd2021-10-19 17:34:12 -0400323 CookieSlice []uint64 `json:"cookie_slice"`
324 VlanRuleParams UniVlanRuleParams `json:"vlan_rule_params"`
325 Meter *ofp.OfpMeterConfig `json:"flow_meter"`
326 RespChan *chan error `json:"-"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000327}
328
329///////////////////////////////////////////////////////////
330
Joey Armstrong89c812c2024-01-12 19:00:20 -0500331// definitions as per G.988
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000332const (
333 OnuDataMeID = 0
334 Onu2gMeID = 0
335 OnugMeID = 0
336 IPHostConfigDataMeID = 1
337 OnugSerialNumberLen = 8
338 OmciMacAddressLen = 6
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000339 MdsDefaultMib = 0
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000340)
Holger Hildebrandt60652202021-11-02 11:09:36 +0000341
342///////////////////////////////////////////////////////////
343
344// CBasePathOnuKVStore - kv store path of ONU specific data
345const CBasePathOnuKVStore = "%s/openonu"
mpagenko101ac942021-11-16 15:01:29 +0000346
347///////////////////////////////////////////////////////////
348
Joey Armstrong89c812c2024-01-12 19:00:20 -0500349// WaitGroupWithTimeOut definitions to have waitGroup functionality with timeout
mpagenko101ac942021-11-16 15:01:29 +0000350type WaitGroupWithTimeOut struct {
351 sync.WaitGroup
352}
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000353
354///////////////////////////////////////////////////////////
355
356// event notifications
357const (
358 OnuMibAuditFailureMds = "ONU_MIB_AUDIT_FAILURE_MDS"
359 OnuMibAuditFailureMdsDesc = "MIB audit failed due to MDS value mismatch between ONU and adapter"
360
361 OnuOmciCommunicationFailureConfig = "ONU_OMCI_COMMUNICATION_FAILURE_CONFIG"
362 OnuOmciCommunicationFailureConfigDesc = "OMCI communication during ONU configuration failed"
363
364 OnuOmciCommunicationFailureSwUpgrade = "ONU_OMCI_COMMUNICATION_FAILURE_SW_UPGRADE"
365 OnuOmciCommunicationFailureSwUpgradeDesc = "OMCI communication during ONU SW upgrade failed"
Holger Hildebrandt68854a82022-09-05 07:00:21 +0000366
Holger Hildebrandt7e138462023-03-29 12:12:14 +0000367 OnuConfigFailureResponseErr = "ONU_CONFIG_FAILURE_RESPONSE_ERROR"
368 OnuConfigFailureResponseErrDesc = "ONU config failed - response error: "
369
370 OnuConfigFailureTimeout = "ONU_CONFIG_FAILURE_TIMEOUT"
371 OnuConfigFailureTimeoutDesc = "ONU config failed - timeout, OMCI ME: "
372
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000373 OnuConfigFailureMissingTcont = "ONU_CONFIG_FAILURE_MISSING_TCONT"
374 OnuConfigFailureMissingTcontDesc = "ONU config failed - no further TCONT resources available at ONU"
375
376 OnuConfigFailureMissingUsPriorityQueue = "ONU_CONFIG_FAILURE_MISSING_US_PRIORITY_QUEUE"
377 OnuConfigFailureMissingUsPriorityQueueDesc = "ONU config failed - no further upstream PriorityQueue resources available at ONU"
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000378)