Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 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 | |
| 229 | /////////////////////////////////////////////////////////// |
| 230 | |
| 231 | type 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 |
| 239 | type OmciDeviceFsms map[string]activityDescr |
| 240 | |
| 241 | // AdapterFsm - Adapter FSM details including channel, event and device |
| 242 | type 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) |
| 252 | const CErrWaitAborted = "waitResponse aborted" |
| 253 | |
| 254 | /////////////////////////////////////////////////////////// |
| 255 | |
| 256 | // UniPortType holds possible UNI port types |
| 257 | type UniPortType uint8 |
| 258 | |
| 259 | // UniPPTP Interface type - re-use values from G.988 (Chapter 9.3.4) TP type definition (directly used in OMCI!) |
| 260 | const ( |
| 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 |
| 270 | type 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 |
| 285 | type OnuUniPortMap map[uint32]*OnuUniPort |
| 286 | |
| 287 | /////////////////////////////////////////////////////////// |
| 288 | |
| 289 | const ( |
| 290 | tpIDStart = 64 |
| 291 | tpIDEnd = 256 |
| 292 | tpRange = tpIDEnd - tpIDStart |
| 293 | maxUni = 256 |
| 294 | ) |
| 295 | |
| 296 | // TODO |
| 297 | const ( |
| 298 | IeeMaperServiceProfileBaseEID = uint16(0x1001) |
| 299 | MacBridgePortAniBaseEID = uint16(0x1001) |
| 300 | MacBridgePortUniBaseEID = uint16(0x201) |
| 301 | MacBridgePortAniMcastBaseEID = uint16(0xA01) |
ozgecanetsia | 0e3111f | 2021-10-19 18:04:15 +0300 | [diff] [blame] | 302 | VoipUniBaseEID = uint16(0x2001) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 303 | GalEthernetEID = uint16(1) |
| 304 | MacBridgeServiceProfileEID = uint16(0x201) |
| 305 | ) |
| 306 | |
| 307 | // UniVlanRuleParams - TODO: add comment |
| 308 | type 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 |
| 318 | type UniVlanFlowParams struct { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 319 | 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /////////////////////////////////////////////////////////// |
| 326 | |
| 327 | //definitions as per G.988 |
| 328 | const ( |
| 329 | OnuDataMeID = 0 |
| 330 | Onu2gMeID = 0 |
| 331 | OnugMeID = 0 |
| 332 | IPHostConfigDataMeID = 1 |
| 333 | OnugSerialNumberLen = 8 |
| 334 | OmciMacAddressLen = 6 |
| 335 | ) |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 336 | |
| 337 | /////////////////////////////////////////////////////////// |
| 338 | |
| 339 | // CBasePathOnuKVStore - kv store path of ONU specific data |
| 340 | const CBasePathOnuKVStore = "%s/openonu" |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 341 | |
| 342 | /////////////////////////////////////////////////////////// |
| 343 | |
| 344 | //WaitGroupWithTimeOut definitions to have waitGroup functionality with timeout |
| 345 | type WaitGroupWithTimeOut struct { |
| 346 | sync.WaitGroup |
| 347 | } |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 348 | |
| 349 | /////////////////////////////////////////////////////////// |
| 350 | |
| 351 | // event notifications |
| 352 | const ( |
| 353 | OnuMibAuditFailureMds = "ONU_MIB_AUDIT_FAILURE_MDS" |
| 354 | OnuMibAuditFailureMdsDesc = "MIB audit failed due to MDS value mismatch between ONU and adapter" |
| 355 | |
| 356 | OnuOmciCommunicationFailureConfig = "ONU_OMCI_COMMUNICATION_FAILURE_CONFIG" |
| 357 | OnuOmciCommunicationFailureConfigDesc = "OMCI communication during ONU configuration failed" |
| 358 | |
| 359 | OnuOmciCommunicationFailureSwUpgrade = "ONU_OMCI_COMMUNICATION_FAILURE_SW_UPGRADE" |
| 360 | OnuOmciCommunicationFailureSwUpgradeDesc = "OMCI communication during ONU SW upgrade failed" |
| 361 | ) |