Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 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 |
| 18 | package common |
| 19 | |
| 20 | import ( |
| 21 | "context" |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 22 | "sync" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 23 | "time" |
| 24 | |
| 25 | gp "github.com/google/gopacket" |
| 26 | "github.com/looplab/fsm" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 27 | "github.com/opencord/omci-lib-go/v2" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 28 | vc "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 29 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| 31 | ) |
| 32 | |
| 33 | // MessageType - Message Protocol Type |
| 34 | type MessageType uint8 |
| 35 | |
| 36 | const ( |
| 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 |
| 44 | func (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) |
| 53 | type Message struct { |
| 54 | Type MessageType |
| 55 | Data interface{} |
| 56 | } |
| 57 | |
| 58 | //TestMessageType - message data for various events |
| 59 | type TestMessageType uint8 |
| 60 | |
| 61 | const ( |
| 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 |
| 74 | type TestMessage struct { |
| 75 | TestMessageVal TestMessageType |
| 76 | } |
| 77 | |
| 78 | //OmciMessage - OMCI protocol messages for managing and monitoring ONUs |
| 79 | type OmciMessage struct { |
| 80 | //OnuSN *openolt.SerialNumber |
| 81 | //OnuID uint32 |
| 82 | OmciMsg *omci.OMCI |
| 83 | OmciPacket *gp.Packet |
| 84 | } |
| 85 | |
| 86 | /////////////////////////////////////////////////////////// |
| 87 | |
| 88 | // device reasons |
| 89 | const ( |
| 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 |
| 110 | var 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 |
| 131 | type UsedOmciConfigFsms int |
| 132 | |
| 133 | // FSMs dealing with OMCI messages |
| 134 | const ( |
| 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 |
| 146 | type OnuDeviceEvent int |
| 147 | |
| 148 | // Events of interest to Device Adapters and OpenOMCI State Machines |
| 149 | const ( |
| 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 Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 166 | // UniEnableStateFailed - Uni ports admin set to unlock failure based on device re-enable |
| 167 | UniEnableStateFailed |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 168 | // 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 |
| 192 | const ( |
| 193 | FirstSwImageMeID = 0 |
| 194 | SecondSwImageMeID = 1 |
| 195 | ) |
| 196 | |
| 197 | //definitions as per G.988 softwareImage::IsCommitted |
| 198 | const ( |
| 199 | SwIsUncommitted = 0 |
| 200 | SwIsCommitted = 1 |
| 201 | ) |
| 202 | |
| 203 | //definitions as per G.988 softwareImage::IsActive |
| 204 | const ( |
| 205 | SwIsInactive = 0 |
| 206 | SwIsActive = 1 |
| 207 | ) |
| 208 | |
| 209 | //definitions as per G.988 softwareImage::IsValid |
| 210 | const ( |
| 211 | SwIsInvalid = 0 |
| 212 | SwIsValid = 1 |
| 213 | ) |
| 214 | |
| 215 | // SEntrySwImageIndication - TODO: add comment |
| 216 | type SEntrySwImageIndication struct { |
| 217 | Valid bool |
| 218 | EntityID uint16 |
| 219 | Version string |
| 220 | IsCommitted uint8 |
| 221 | } |
| 222 | |
| 223 | // SswImageIndications - TODO: add comment |
| 224 | type SswImageIndications struct { |
| 225 | ActiveEntityEntry SEntrySwImageIndication |
| 226 | InActiveEntityEntry SEntrySwImageIndication |
| 227 | } |
| 228 | |
Holger Hildebrandt | 8998ed5 | 2022-03-23 09:52:37 +0000 | [diff] [blame] | 229 | // CGenericManagedEntityIDName - generic name string of attribute "ManagedEntityId" |
| 230 | const CGenericManagedEntityIDName = "ManagedEntityId" |
| 231 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 232 | /////////////////////////////////////////////////////////// |
| 233 | |
| 234 | type 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 |
| 242 | type OmciDeviceFsms map[string]activityDescr |
| 243 | |
| 244 | // AdapterFsm - Adapter FSM details including channel, event and device |
| 245 | type AdapterFsm struct { |
| 246 | fsmName string |
| 247 | deviceID string |
| 248 | CommChan chan Message |
| 249 | PFsm *fsm.FSM |
| 250 | } |
| 251 | |
| 252 | //CErrWaitAborted - AdapterFsm related error string |
| 253 | //error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log |
| 254 | // but not used that way so far (permit error log even for wanted cancellation) |
| 255 | const CErrWaitAborted = "waitResponse aborted" |
| 256 | |
| 257 | /////////////////////////////////////////////////////////// |
| 258 | |
| 259 | // UniPortType holds possible UNI port types |
| 260 | type UniPortType uint8 |
| 261 | |
| 262 | // UniPPTP Interface type - re-use values from G.988 (Chapter 9.3.4) TP type definition (directly used in OMCI!) |
| 263 | const ( |
| 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 | |
| 272 | //OnuUniPort structure holds information about the ONU attached Uni Ports |
| 273 | type 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 |
| 288 | type OnuUniPortMap map[uint32]*OnuUniPort |
| 289 | |
| 290 | /////////////////////////////////////////////////////////// |
| 291 | |
| 292 | const ( |
| 293 | tpIDStart = 64 |
| 294 | tpIDEnd = 256 |
| 295 | tpRange = tpIDEnd - tpIDStart |
| 296 | maxUni = 256 |
| 297 | ) |
| 298 | |
| 299 | // TODO |
| 300 | const ( |
| 301 | IeeMaperServiceProfileBaseEID = uint16(0x1001) |
| 302 | MacBridgePortAniBaseEID = uint16(0x1001) |
| 303 | MacBridgePortUniBaseEID = uint16(0x201) |
| 304 | MacBridgePortAniMcastBaseEID = uint16(0xA01) |
ozgecanetsia | 0e3111f | 2021-10-19 18:04:15 +0300 | [diff] [blame] | 305 | VoipUniBaseEID = uint16(0x2001) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 306 | GalEthernetEID = uint16(1) |
| 307 | MacBridgeServiceProfileEID = uint16(0x201) |
| 308 | ) |
| 309 | |
| 310 | // UniVlanRuleParams - TODO: add comment |
| 311 | type 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 Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 318 | InnerCvlan uint16 `json:"inner_cvlan"` |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | // UniVlanFlowParams - TODO: add comment |
| 322 | type UniVlanFlowParams struct { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 323 | 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /////////////////////////////////////////////////////////// |
| 330 | |
| 331 | //definitions as per G.988 |
| 332 | const ( |
| 333 | OnuDataMeID = 0 |
| 334 | Onu2gMeID = 0 |
| 335 | OnugMeID = 0 |
| 336 | IPHostConfigDataMeID = 1 |
| 337 | OnugSerialNumberLen = 8 |
| 338 | OmciMacAddressLen = 6 |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 339 | MdsDefaultMib = 0 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 340 | ) |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 341 | |
| 342 | /////////////////////////////////////////////////////////// |
| 343 | |
| 344 | // CBasePathOnuKVStore - kv store path of ONU specific data |
| 345 | const CBasePathOnuKVStore = "%s/openonu" |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 346 | |
| 347 | /////////////////////////////////////////////////////////// |
| 348 | |
| 349 | //WaitGroupWithTimeOut definitions to have waitGroup functionality with timeout |
| 350 | type WaitGroupWithTimeOut struct { |
| 351 | sync.WaitGroup |
| 352 | } |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 353 | |
| 354 | /////////////////////////////////////////////////////////// |
| 355 | |
| 356 | // event notifications |
| 357 | const ( |
| 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 Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 366 | |
Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 367 | OnuConfigFailureMissingTcont = "ONU_CONFIG_FAILURE_MISSING_TCONT" |
| 368 | OnuConfigFailureMissingTcontDesc = "ONU config failed - no further TCONT resources available at ONU" |
| 369 | |
| 370 | OnuConfigFailureMissingUsPriorityQueue = "ONU_CONFIG_FAILURE_MISSING_US_PRIORITY_QUEUE" |
| 371 | OnuConfigFailureMissingUsPriorityQueueDesc = "ONU config failed - no further upstream PriorityQueue resources available at ONU" |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 372 | ) |