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" |
| 22 | "time" |
| 23 | |
| 24 | gp "github.com/google/gopacket" |
| 25 | "github.com/looplab/fsm" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 26 | "github.com/opencord/omci-lib-go/v2" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 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 |
| 32 | type MessageType uint8 |
| 33 | |
| 34 | const ( |
| 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 |
| 42 | func (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) |
| 51 | type Message struct { |
| 52 | Type MessageType |
| 53 | Data interface{} |
| 54 | } |
| 55 | |
| 56 | //TestMessageType - message data for various events |
| 57 | type TestMessageType uint8 |
| 58 | |
| 59 | const ( |
| 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 |
| 72 | type TestMessage struct { |
| 73 | TestMessageVal TestMessageType |
| 74 | } |
| 75 | |
| 76 | //OmciMessage - OMCI protocol messages for managing and monitoring ONUs |
| 77 | type OmciMessage struct { |
| 78 | //OnuSN *openolt.SerialNumber |
| 79 | //OnuID uint32 |
| 80 | OmciMsg *omci.OMCI |
| 81 | OmciPacket *gp.Packet |
| 82 | } |
| 83 | |
| 84 | /////////////////////////////////////////////////////////// |
| 85 | |
| 86 | // device reasons |
| 87 | const ( |
| 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 |
| 108 | var 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 |
| 129 | type UsedOmciConfigFsms int |
| 130 | |
| 131 | // FSMs dealing with OMCI messages |
| 132 | const ( |
| 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 |
| 144 | type OnuDeviceEvent int |
| 145 | |
| 146 | // Events of interest to Device Adapters and OpenOMCI State Machines |
| 147 | const ( |
| 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 |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 164 | // UniEnableStateFailed - Uni ports admin set to unlock failure based on device re-enable |
| 165 | UniEnableStateFailed |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 166 | // PortLinkUp - Port link state change |
| 167 | PortLinkUp |
| 168 | // PortLinkDw - Port link state change |
| 169 | PortLinkDw |
| 170 | // OmciAniConfigDone - AniSide config according to TechProfile done |
| 171 | OmciAniConfigDone |
| 172 | // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed |
| 173 | OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone! |
| 174 | // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add with request to write kvStore |
| 175 | OmciVlanFilterAddDone |
| 176 | // OmciVlanFilterAddDoneNoKvStore - Omci Vlan config done according to flow-add without writing kvStore |
| 177 | OmciVlanFilterAddDoneNoKvStore // needs to be the successor of OmciVlanFilterAddDone! |
| 178 | // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove with request to write kvStore |
| 179 | OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDoneNoKvStore! |
| 180 | // OmciVlanFilterRemDoneNoKvStore - Omci Vlan config done according to flow-remove without writing kvStore |
| 181 | OmciVlanFilterRemDoneNoKvStore // needs to be the successor of OmciVlanFilterRemDone! |
| 182 | // OmciOnuSwUpgradeDone - SoftwareUpgrade to ONU finished |
| 183 | OmciOnuSwUpgradeDone |
| 184 | // Add other events here as needed (alarms separate???) |
| 185 | ) |
| 186 | |
| 187 | /////////////////////////////////////////////////////////// |
| 188 | |
| 189 | //definitions as per G.988 softwareImage::valid ME IDs |
| 190 | const ( |
| 191 | FirstSwImageMeID = 0 |
| 192 | SecondSwImageMeID = 1 |
| 193 | ) |
| 194 | |
| 195 | //definitions as per G.988 softwareImage::IsCommitted |
| 196 | const ( |
| 197 | SwIsUncommitted = 0 |
| 198 | SwIsCommitted = 1 |
| 199 | ) |
| 200 | |
| 201 | //definitions as per G.988 softwareImage::IsActive |
| 202 | const ( |
| 203 | SwIsInactive = 0 |
| 204 | SwIsActive = 1 |
| 205 | ) |
| 206 | |
| 207 | //definitions as per G.988 softwareImage::IsValid |
| 208 | const ( |
| 209 | SwIsInvalid = 0 |
| 210 | SwIsValid = 1 |
| 211 | ) |
| 212 | |
| 213 | // SEntrySwImageIndication - TODO: add comment |
| 214 | type SEntrySwImageIndication struct { |
| 215 | Valid bool |
| 216 | EntityID uint16 |
| 217 | Version string |
| 218 | IsCommitted uint8 |
| 219 | } |
| 220 | |
| 221 | // SswImageIndications - TODO: add comment |
| 222 | type SswImageIndications struct { |
| 223 | ActiveEntityEntry SEntrySwImageIndication |
| 224 | InActiveEntityEntry SEntrySwImageIndication |
| 225 | } |
| 226 | |
| 227 | /////////////////////////////////////////////////////////// |
| 228 | |
| 229 | type activityDescr struct { |
| 230 | DatabaseClass func(context.Context) error |
| 231 | //advertiseEvents bool |
| 232 | AuditInterval time.Duration |
| 233 | //tasks map[string]func() error |
| 234 | } |
| 235 | |
| 236 | // OmciDeviceFsms - FSM event mapping to database class and time to wait between audits |
| 237 | type OmciDeviceFsms map[string]activityDescr |
| 238 | |
| 239 | // AdapterFsm - Adapter FSM details including channel, event and device |
| 240 | type AdapterFsm struct { |
| 241 | fsmName string |
| 242 | deviceID string |
| 243 | CommChan chan Message |
| 244 | PFsm *fsm.FSM |
| 245 | } |
| 246 | |
| 247 | //CErrWaitAborted - AdapterFsm related error string |
| 248 | //error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log |
| 249 | // but not used that way so far (permit error log even for wanted cancellation) |
| 250 | const CErrWaitAborted = "waitResponse aborted" |
| 251 | |
| 252 | /////////////////////////////////////////////////////////// |
| 253 | |
| 254 | // UniPortType holds possible UNI port types |
| 255 | type UniPortType uint8 |
| 256 | |
| 257 | // UniPPTP Interface type - re-use values from G.988 (Chapter 9.3.4) TP type definition (directly used in OMCI!) |
| 258 | const ( |
| 259 | // UniPPTP relates to PPTP |
| 260 | UniPPTP UniPortType = 1 // relates to PPTP |
| 261 | // UniVEIP relates to VEIP |
| 262 | UniVEIP UniPortType = 11 // relates to VEIP |
| 263 | // UniPPTPPots relates to PPTP POTS |
| 264 | UniPPTPPots UniPortType = 4 // relates to IP host config data (for Voice Services) |
| 265 | ) |
| 266 | |
| 267 | //OnuUniPort structure holds information about the ONU attached Uni Ports |
| 268 | type OnuUniPort struct { |
| 269 | Enabled bool |
| 270 | Name string |
| 271 | PortNo uint32 |
| 272 | PortType UniPortType |
| 273 | OfpPortNo string |
| 274 | UniID uint8 |
| 275 | MacBpNo uint8 |
| 276 | EntityID uint16 |
| 277 | AdminState vc.AdminState_Types |
| 278 | OperState vc.OperStatus_Types |
| 279 | PPort *voltha.Port |
| 280 | } |
| 281 | |
| 282 | // OnuUniPortMap - TODO: add comment |
| 283 | type OnuUniPortMap map[uint32]*OnuUniPort |
| 284 | |
| 285 | /////////////////////////////////////////////////////////// |
| 286 | |
| 287 | const ( |
| 288 | tpIDStart = 64 |
| 289 | tpIDEnd = 256 |
| 290 | tpRange = tpIDEnd - tpIDStart |
| 291 | maxUni = 256 |
| 292 | ) |
| 293 | |
| 294 | // TODO |
| 295 | const ( |
| 296 | IeeMaperServiceProfileBaseEID = uint16(0x1001) |
| 297 | MacBridgePortAniBaseEID = uint16(0x1001) |
| 298 | MacBridgePortUniBaseEID = uint16(0x201) |
| 299 | MacBridgePortAniMcastBaseEID = uint16(0xA01) |
ozgecanetsia | 0e3111f | 2021-10-19 18:04:15 +0300 | [diff] [blame] | 300 | VoipUniBaseEID = uint16(0x2001) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 301 | GalEthernetEID = uint16(1) |
| 302 | MacBridgeServiceProfileEID = uint16(0x201) |
| 303 | ) |
| 304 | |
| 305 | // UniVlanRuleParams - TODO: add comment |
| 306 | type UniVlanRuleParams struct { |
| 307 | TpID uint8 `json:"tp_id"` |
| 308 | MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting |
| 309 | MatchPcp uint32 `json:"match_pcp"` |
| 310 | TagsToRemove uint32 `json:"tags_to_remove"` |
| 311 | SetVid uint32 `json:"set_vid"` |
| 312 | SetPcp uint32 `json:"set_pcp"` |
| 313 | } |
| 314 | |
| 315 | // UniVlanFlowParams - TODO: add comment |
| 316 | type UniVlanFlowParams struct { |
| 317 | CookieSlice []uint64 `json:"cookie_slice"` |
| 318 | VlanRuleParams UniVlanRuleParams `json:"vlan_rule_params"` |
| 319 | Meter *voltha.OfpMeterConfig `json:"flow_meter"` |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 320 | RespChan *chan error `json:"-"` |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /////////////////////////////////////////////////////////// |
| 324 | |
| 325 | //definitions as per G.988 |
| 326 | const ( |
| 327 | OnuDataMeID = 0 |
| 328 | Onu2gMeID = 0 |
| 329 | OnugMeID = 0 |
| 330 | IPHostConfigDataMeID = 1 |
| 331 | OnugSerialNumberLen = 8 |
| 332 | OmciMacAddressLen = 6 |
| 333 | ) |