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