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