Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [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 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 20 | "context" |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 21 | "encoding/hex" |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 22 | "fmt" |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame^] | 23 | "sync" |
| 24 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 25 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
| 26 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 27 | "github.com/opencord/bbsim/internal/bbsim/responders/eapol" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 28 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 29 | pb "github.com/opencord/bbsim/api/bbsim" |
| 30 | "github.com/opencord/bbsim/internal/bbsim/alarmsim" |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 31 | |
| 32 | "net" |
| 33 | "strconv" |
| 34 | "time" |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 35 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 36 | bbsim "github.com/opencord/bbsim/internal/bbsim/types" |
| 37 | me "github.com/opencord/omci-lib-go/generated" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 38 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 39 | "github.com/google/gopacket/layers" |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 40 | "github.com/jpillora/backoff" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 41 | "github.com/looplab/fsm" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 42 | "github.com/opencord/bbsim/internal/common" |
| 43 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 44 | "github.com/opencord/omci-lib-go" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 45 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 46 | "github.com/opencord/voltha-protos/v4/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 47 | log "github.com/sirupsen/logrus" |
| 48 | ) |
| 49 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 50 | var onuLogger = log.WithFields(log.Fields{ |
| 51 | "module": "ONU", |
| 52 | }) |
| 53 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 54 | const ( |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 55 | maxOmciMsgCounter = 10 |
| 56 | ) |
| 57 | |
| 58 | const ( |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 59 | // ONU transitions |
| 60 | OnuTxInitialize = "initialize" |
| 61 | OnuTxDiscover = "discover" |
| 62 | OnuTxEnable = "enable" |
| 63 | OnuTxDisable = "disable" |
| 64 | OnuTxPonDisable = "pon_disable" |
| 65 | OnuTxStartImageDownload = "start_image_download" |
| 66 | OnuTxProgressImageDownload = "progress_image_download" |
| 67 | OnuTxCompleteImageDownload = "complete_image_download" |
| 68 | OnuTxFailImageDownload = "fail_image_download" |
| 69 | OnuTxActivateImage = "activate_image" |
| 70 | OnuTxCommitImage = "commit_image" |
| 71 | |
| 72 | // ONU States |
| 73 | OnuStateCreated = "created" |
| 74 | OnuStateInitialized = "initialized" |
| 75 | OnuStateDiscovered = "discovered" |
| 76 | OnuStateEnabled = "enabled" |
| 77 | OnuStateDisabled = "disabled" |
| 78 | OnuStatePonDisabled = "pon_disabled" |
| 79 | OnuStateImageDownloadStarted = "image_download_started" |
| 80 | OnuStateImageDownloadInProgress = "image_download_in_progress" |
| 81 | OnuStateImageDownloadComplete = "image_download_completed" |
| 82 | OnuStateImageDownloadError = "image_download_error" |
| 83 | OnuStateImageActivated = "software_image_activated" |
| 84 | OnuStateImageCommitted = "software_image_committed" |
| 85 | |
| 86 | // BBR ONU States and Transitions |
| 87 | BbrOnuTxSendEapolFlow = "send_eapol_flow" |
| 88 | BbrOnuStateEapolFlowSent = "eapol_flow_sent" |
| 89 | BbrOnuTxSendDhcpFlow = "send_dhcp_flow" |
| 90 | BbrOnuStateDhcpFlowSent = "dhcp_flow_sent" |
| 91 | ) |
| 92 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 93 | type FlowKey struct { |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 94 | ID uint64 |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 95 | Direction string |
| 96 | } |
| 97 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 98 | type Onu struct { |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 99 | ID uint32 |
| 100 | PonPortID uint32 |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 101 | PonPort *PonPort |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 102 | InternalState *fsm.FSM |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 103 | DiscoveryRetryDelay time.Duration // this is the time between subsequent Discovery Indication |
| 104 | DiscoveryDelay time.Duration // this is the time to send the first Discovery Indication |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 105 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 106 | Backoff *backoff.Backoff |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 107 | // ONU State |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 108 | UniPorts []UniPortIf |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 109 | Flows []FlowKey |
| 110 | FlowIds []uint64 // keep track of the flows we currently have in the ONU |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 111 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 112 | OperState *fsm.FSM |
| 113 | SerialNumber *openolt.SerialNumber |
| 114 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 115 | Channel chan bbsim.Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 116 | |
| 117 | // OMCI params |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 118 | MibDataSync uint8 |
| 119 | ImageSoftwareExpectedSections int |
| 120 | ImageSoftwareReceivedSections int |
| 121 | ActiveImageEntityId uint16 |
| 122 | CommittedImageEntityId uint16 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 123 | StandbyImageVersion string |
| 124 | ActiveImageVersion string |
| 125 | CommittedImageVersion string |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 126 | OmciResponseRate uint8 |
| 127 | OmciMsgCounter uint8 |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 128 | |
| 129 | // OMCI params (Used in BBR) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 130 | tid uint16 |
| 131 | hpTid uint16 |
| 132 | seqNumber uint16 |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 133 | MibDb *omcilib.MibDb |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 134 | |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 135 | DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR) |
| 136 | TrafficSchedulers *tech_profile.TrafficSchedulers |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 137 | onuAlarmsInfoLock sync.RWMutex |
| 138 | onuAlarmsInfo map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 141 | func (o *Onu) Sn() string { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 142 | return common.OnuSnToString(o.SerialNumber) |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 145 | func CreateONU(olt *OltDevice, pon *PonPort, id uint32, delay time.Duration, nextCtag map[string]int, nextStag map[string]int, isMock bool) *Onu { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 146 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 147 | o := Onu{ |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 148 | ID: id, |
| 149 | PonPortID: pon.ID, |
| 150 | PonPort: pon, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 151 | tid: 0x1, |
| 152 | hpTid: 0x8000, |
| 153 | seqNumber: 0, |
| 154 | DoneChannel: make(chan bool, 1), |
| 155 | DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received |
| 156 | Flows: []FlowKey{}, |
| 157 | DiscoveryDelay: delay, |
| 158 | MibDataSync: 0, |
| 159 | ImageSoftwareExpectedSections: 0, // populated during OMCI StartSoftwareDownloadRequest |
| 160 | ImageSoftwareReceivedSections: 0, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 161 | //TODO this needs reworking, it's always 0 or 1, possibly base all on the version |
| 162 | ActiveImageEntityId: 0, // when we start the SoftwareImage with ID 0 is active and committed |
| 163 | CommittedImageEntityId: 0, |
| 164 | StandbyImageVersion: "BBSM_IMG_00000", |
| 165 | ActiveImageVersion: "BBSM_IMG_00001", |
| 166 | CommittedImageVersion: "BBSM_IMG_00001", |
| 167 | OmciResponseRate: olt.OmciResponseRate, |
| 168 | OmciMsgCounter: 0, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 169 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 170 | o.SerialNumber = NewSN(olt.ID, pon.ID, id) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 171 | // NOTE this state machine is used to track the operational |
| 172 | // state as requested by VOLTHA |
| 173 | o.OperState = getOperStateFSM(func(e *fsm.Event) { |
| 174 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 175 | "OnuId": o.ID, |
| 176 | "IntfId": o.PonPortID, |
| 177 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 178 | }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst) |
| 179 | }) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 180 | o.onuAlarmsInfo = make(map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 181 | // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients |
| 182 | o.InternalState = fsm.NewFSM( |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 183 | OnuStateCreated, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 184 | fsm.Events{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 185 | // DEVICE Lifecycle |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 186 | {Name: OnuTxInitialize, Src: []string{OnuStateCreated, OnuStateDisabled, OnuStatePonDisabled}, Dst: OnuStateInitialized}, |
| 187 | {Name: OnuTxDiscover, Src: []string{OnuStateInitialized}, Dst: OnuStateDiscovered}, |
| 188 | {Name: OnuTxEnable, Src: []string{OnuStateDiscovered, OnuStatePonDisabled}, Dst: OnuStateEnabled}, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 189 | // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)? |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 190 | {Name: OnuTxDisable, Src: []string{OnuStateEnabled, OnuStatePonDisabled, OnuStateImageActivated, OnuStateImageDownloadError, OnuStateImageCommitted}, Dst: OnuStateDisabled}, |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 191 | // ONU state when PON port is disabled but ONU is power ON(more states should be added in src?) |
Matteo Scandolo | 9f4bf4f | 2021-06-22 09:41:02 +0200 | [diff] [blame] | 192 | {Name: OnuTxPonDisable, Src: []string{OnuStateEnabled, OnuStateImageActivated, OnuStateImageDownloadError, OnuStateImageCommitted, OnuStateImageDownloadComplete}, Dst: OnuStatePonDisabled}, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 193 | // Software Image Download related states |
Matteo Scandolo | 9f4bf4f | 2021-06-22 09:41:02 +0200 | [diff] [blame] | 194 | {Name: OnuTxStartImageDownload, Src: []string{OnuStateEnabled, OnuStateImageDownloadComplete, OnuStateImageDownloadError, OnuStateImageCommitted}, Dst: OnuStateImageDownloadStarted}, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 195 | {Name: OnuTxProgressImageDownload, Src: []string{OnuStateImageDownloadStarted}, Dst: OnuStateImageDownloadInProgress}, |
| 196 | {Name: OnuTxCompleteImageDownload, Src: []string{OnuStateImageDownloadInProgress}, Dst: OnuStateImageDownloadComplete}, |
| 197 | {Name: OnuTxFailImageDownload, Src: []string{OnuStateImageDownloadInProgress}, Dst: OnuStateImageDownloadError}, |
| 198 | {Name: OnuTxActivateImage, Src: []string{OnuStateImageDownloadComplete}, Dst: OnuStateImageActivated}, |
| 199 | {Name: OnuTxCommitImage, Src: []string{OnuStateEnabled}, Dst: OnuStateImageCommitted}, // the image is committed after a ONU reboot |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 200 | // BBR States |
| 201 | // TODO add start OMCI state |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 202 | {Name: BbrOnuTxSendEapolFlow, Src: []string{OnuStateInitialized}, Dst: BbrOnuStateEapolFlowSent}, |
| 203 | {Name: BbrOnuTxSendDhcpFlow, Src: []string{BbrOnuStateEapolFlowSent}, Dst: BbrOnuStateDhcpFlowSent}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 204 | }, |
| 205 | fsm.Callbacks{ |
| 206 | "enter_state": func(e *fsm.Event) { |
| 207 | o.logStateChange(e.Src, e.Dst) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 208 | }, |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 209 | fmt.Sprintf("enter_%s", OnuStateInitialized): func(e *fsm.Event) { |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 210 | // create new channel for ProcessOnuMessages Go routine |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 211 | o.Channel = make(chan bbsim.Message, 2048) |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 212 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 213 | if err := o.OperState.Event(OnuTxEnable); err != nil { |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 214 | onuLogger.WithFields(log.Fields{ |
| 215 | "OnuId": o.ID, |
| 216 | "IntfId": o.PonPortID, |
| 217 | "OnuSn": o.Sn(), |
| 218 | }).Errorf("Cannot change ONU OperState to up: %s", err.Error()) |
| 219 | } |
| 220 | |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 221 | if !isMock { |
| 222 | // start ProcessOnuMessages Go routine |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 223 | go o.ProcessOnuMessages(olt.enableContext, olt.OpenoltStream, nil) |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 224 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 225 | }, |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 226 | fmt.Sprintf("enter_%s", OnuStateDiscovered): func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 227 | msg := bbsim.Message{ |
| 228 | Type: bbsim.OnuDiscIndication, |
| 229 | Data: bbsim.OnuDiscIndicationMessage{ |
| 230 | OperState: bbsim.UP, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 231 | }, |
| 232 | } |
| 233 | o.Channel <- msg |
| 234 | }, |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 235 | fmt.Sprintf("enter_%s", OnuStateEnabled): func(event *fsm.Event) { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 236 | |
| 237 | if used, sn := o.PonPort.isOnuIdAllocated(o.ID); used { |
| 238 | onuLogger.WithFields(log.Fields{ |
| 239 | "IntfId": o.PonPortID, |
| 240 | "OnuId": o.ID, |
| 241 | "SerialNumber": o.Sn(), |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 242 | }).Errorf("onu-id-duplicated-with-%s", common.OnuSnToString(sn)) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 243 | return |
| 244 | } else { |
| 245 | o.PonPort.storeOnuId(o.ID, o.SerialNumber) |
| 246 | } |
| 247 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 248 | msg := bbsim.Message{ |
| 249 | Type: bbsim.OnuIndication, |
| 250 | Data: bbsim.OnuIndicationMessage{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 251 | OnuSN: o.SerialNumber, |
| 252 | PonPortID: o.PonPortID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 253 | OperState: bbsim.UP, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 254 | }, |
| 255 | } |
| 256 | o.Channel <- msg |
| 257 | }, |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 258 | fmt.Sprintf("enter_%s", OnuStateDisabled): func(event *fsm.Event) { |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 259 | |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 260 | o.cleanupOnuState() |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 261 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 262 | // set the OperState to disabled |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 263 | if err := o.OperState.Event("disable"); err != nil { |
| 264 | onuLogger.WithFields(log.Fields{ |
| 265 | "OnuId": o.ID, |
| 266 | "IntfId": o.PonPortID, |
| 267 | "OnuSn": o.Sn(), |
| 268 | }).Errorf("Cannot change ONU OperState to down: %s", err.Error()) |
| 269 | } |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 270 | // send the OnuIndication DOWN event |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 271 | msg := bbsim.Message{ |
| 272 | Type: bbsim.OnuIndication, |
| 273 | Data: bbsim.OnuIndicationMessage{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 274 | OnuSN: o.SerialNumber, |
| 275 | PonPortID: o.PonPortID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 276 | OperState: bbsim.DOWN, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 277 | }, |
| 278 | } |
| 279 | o.Channel <- msg |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 280 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 281 | // disable the UNI ports |
| 282 | for _, uni := range o.UniPorts { |
| 283 | _ = uni.Disable() |
| 284 | } |
| 285 | |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 286 | // verify all the flows removes are handled and |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 287 | // terminate the ONU's ProcessOnuMessages Go routine |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 288 | // NOTE may need to wait for the UNIs to be down too before shutting down the channel |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 289 | if len(o.FlowIds) == 0 { |
| 290 | close(o.Channel) |
| 291 | } |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 292 | }, |
| 293 | fmt.Sprintf("enter_%s", OnuStatePonDisabled): func(event *fsm.Event) { |
| 294 | o.cleanupOnuState() |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 295 | }, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 296 | // BBR states |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 297 | fmt.Sprintf("enter_%s", BbrOnuStateEapolFlowSent): func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 298 | msg := bbsim.Message{ |
| 299 | Type: bbsim.SendEapolFlow, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 300 | } |
| 301 | o.Channel <- msg |
| 302 | }, |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 303 | fmt.Sprintf("enter_%s", BbrOnuStateDhcpFlowSent): func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 304 | msg := bbsim.Message{ |
| 305 | Type: bbsim.SendDhcpFlow, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 306 | } |
| 307 | o.Channel <- msg |
| 308 | }, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 309 | }, |
| 310 | ) |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame^] | 311 | onuLogger.WithFields(log.Fields{ |
| 312 | "OnuId": o.ID, |
| 313 | "IntfId": o.PonPortID, |
| 314 | "OnuSn": o.Sn(), |
| 315 | "NumUni": olt.NumUni, |
| 316 | }).Debug("creating-uni-ports") |
| 317 | for i := 0; i < olt.NumUni; i++ { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 318 | uni, err := NewUniPort(uint32(i), &o, nextCtag, nextStag) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 319 | if err != nil { |
| 320 | onuLogger.WithFields(log.Fields{ |
| 321 | "OnuId": o.ID, |
| 322 | "IntfId": o.PonPortID, |
| 323 | "OnuSn": o.Sn(), |
| 324 | "Err": err, |
| 325 | }).Fatal("cannot-create-uni-port") |
| 326 | } |
| 327 | o.UniPorts = append(o.UniPorts, uni) |
| 328 | } |
| 329 | |
| 330 | mibDb, err := omcilib.GenerateMibDatabase(len(o.UniPorts)) |
| 331 | if err != nil { |
| 332 | onuLogger.WithFields(log.Fields{ |
| 333 | "OnuId": o.ID, |
| 334 | "IntfId": o.PonPortID, |
| 335 | "OnuSn": o.Sn(), |
| 336 | }).Fatal("cannot-generate-mibdb-for-onu") |
| 337 | } |
| 338 | o.MibDb = mibDb |
| 339 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 340 | return &o |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 341 | } |
| 342 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 343 | func (o *Onu) logStateChange(src string, dst string) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 344 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 345 | "OnuId": o.ID, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 346 | "IntfId": o.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 347 | "OnuSn": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 348 | }).Debugf("Changing ONU InternalState from %s to %s", src, dst) |
| 349 | } |
| 350 | |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 351 | // cleanupOnuState this method is to clean the local state when the ONU is disabled |
| 352 | func (o *Onu) cleanupOnuState() { |
| 353 | // clean the ONU state |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 354 | o.Flows = []FlowKey{} |
| 355 | o.PonPort.removeOnuId(o.ID) |
| 356 | o.PonPort.removeAllocId(o.SerialNumber) |
| 357 | o.PonPort.removeGemPortBySn(o.SerialNumber) |
| 358 | |
| 359 | o.onuAlarmsInfoLock.Lock() |
| 360 | o.onuAlarmsInfo = make(map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo) //Basically reset everything on onu disable |
| 361 | o.onuAlarmsInfoLock.Unlock() |
| 362 | } |
| 363 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 364 | // ProcessOnuMessages starts indication channel for each ONU |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 365 | func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 366 | onuLogger.WithFields(log.Fields{ |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 367 | "onuID": o.ID, |
| 368 | "onuSN": o.Sn(), |
| 369 | "ponPort": o.PonPortID, |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 370 | "stream": stream, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 371 | }).Debug("Starting ONU Indication Channel") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 372 | |
Matteo Scandolo | b307d8a | 2021-05-10 15:19:27 -0700 | [diff] [blame] | 373 | defer onuLogger.WithFields(log.Fields{ |
| 374 | "onuID": o.ID, |
| 375 | "onuSN": o.Sn(), |
| 376 | "stream": stream, |
| 377 | }).Debug("Stopped handling ONU Indication Channel") |
| 378 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 379 | loop: |
| 380 | for { |
| 381 | select { |
| 382 | case <-ctx.Done(): |
| 383 | onuLogger.WithFields(log.Fields{ |
| 384 | "onuID": o.ID, |
| 385 | "onuSN": o.Sn(), |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 386 | }).Debug("ONU message handling canceled via context") |
| 387 | break loop |
| 388 | case <-stream.Context().Done(): |
| 389 | onuLogger.WithFields(log.Fields{ |
| 390 | "onuID": o.ID, |
| 391 | "onuSN": o.Sn(), |
| 392 | }).Debug("ONU message handling canceled via stream context") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 393 | break loop |
| 394 | case message, ok := <-o.Channel: |
| 395 | if !ok || ctx.Err() != nil { |
| 396 | onuLogger.WithFields(log.Fields{ |
| 397 | "onuID": o.ID, |
| 398 | "onuSN": o.Sn(), |
Matteo Scandolo | 9ddb3a9 | 2021-04-14 16:16:20 -0700 | [diff] [blame] | 399 | }).Debug("ONU message handling canceled via channel close") |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 400 | break loop |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 401 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 402 | onuLogger.WithFields(log.Fields{ |
| 403 | "onuID": o.ID, |
| 404 | "onuSN": o.Sn(), |
| 405 | "messageType": message.Type, |
| 406 | }).Tracef("Received message on ONU Channel") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 407 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 408 | switch message.Type { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 409 | case bbsim.OnuDiscIndication: |
| 410 | msg, _ := message.Data.(bbsim.OnuDiscIndicationMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 411 | // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 412 | time.Sleep(o.DiscoveryDelay) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 413 | o.sendOnuDiscIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 414 | case bbsim.OnuIndication: |
| 415 | msg, _ := message.Data.(bbsim.OnuIndicationMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 416 | o.sendOnuIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 417 | case bbsim.OMCI: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 418 | // these are OMCI messages received by the ONU |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 419 | msg, _ := message.Data.(bbsim.OmciMessage) |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 420 | _ = o.handleOmciRequest(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 421 | case bbsim.UniStatusAlarm: |
| 422 | msg, _ := message.Data.(bbsim.UniStatusAlarmMessage) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 423 | onuAlarmMapKey := omcilib.OnuAlarmInfoMapKey{ |
| 424 | MeInstance: msg.EntityID, |
| 425 | MeClassID: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 426 | } |
| 427 | seqNo := o.IncrementAlarmSequenceNumber(onuAlarmMapKey) |
| 428 | o.onuAlarmsInfoLock.Lock() |
| 429 | var alarmInfo = o.onuAlarmsInfo[onuAlarmMapKey] |
| 430 | pkt, alarmBitMap := omcilib.CreateUniStatusAlarm(msg.RaiseOMCIAlarm, msg.EntityID, seqNo) |
| 431 | if pkt != nil { //pkt will be nil if we are unable to create the alarm |
| 432 | if err := o.sendOmciIndication(pkt, 0, stream); err != nil { |
| 433 | onuLogger.WithFields(log.Fields{ |
| 434 | "IntfId": o.PonPortID, |
| 435 | "SerialNumber": o.Sn(), |
| 436 | "omciPacket": pkt, |
| 437 | "adminState": msg.AdminState, |
| 438 | "entityID": msg.EntityID, |
| 439 | }).Errorf("failed-to-send-UNI-Link-Alarm: %v", err) |
| 440 | alarmInfo.SequenceNo-- |
| 441 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 442 | onuLogger.WithFields(log.Fields{ |
| 443 | "IntfId": o.PonPortID, |
| 444 | "SerialNumber": o.Sn(), |
| 445 | "omciPacket": pkt, |
| 446 | "adminState": msg.AdminState, |
| 447 | "entityID": msg.EntityID, |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 448 | }).Trace("UNI-Link-alarm-sent") |
| 449 | if alarmBitMap == [28]byte{0} { |
| 450 | delete(o.onuAlarmsInfo, onuAlarmMapKey) |
| 451 | } else { |
| 452 | alarmInfo.AlarmBitMap = alarmBitMap |
| 453 | o.onuAlarmsInfo[onuAlarmMapKey] = alarmInfo |
| 454 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 455 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 456 | o.onuAlarmsInfoLock.Unlock() |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 457 | case bbsim.FlowAdd: |
| 458 | msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 459 | o.handleFlowAdd(msg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 460 | case bbsim.FlowRemoved: |
| 461 | msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 462 | o.handleFlowRemove(msg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 463 | case bbsim.OnuPacketOut: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 464 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 465 | msg, _ := message.Data.(bbsim.OnuPacketMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 466 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 467 | onuLogger.WithFields(log.Fields{ |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 468 | "IntfId": msg.IntfId, |
| 469 | "OnuId": msg.OnuId, |
| 470 | "pktType": msg.Type, |
| 471 | }).Trace("Received OnuPacketOut Message") |
| 472 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 473 | uni, err := o.findUniByPortNo(msg.PortNo) |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 474 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 475 | if err != nil { |
| 476 | onuLogger.WithFields(log.Fields{ |
| 477 | "IntfId": msg.IntfId, |
| 478 | "OnuId": msg.OnuId, |
| 479 | "pktType": msg.Type, |
| 480 | "portNo": msg.PortNo, |
| 481 | "MacAddress": msg.MacAddress, |
| 482 | "Pkt": hex.EncodeToString(msg.Packet.Data()), |
| 483 | "OnuSn": o.Sn(), |
| 484 | }).Error("Cannot find Uni associated with packet") |
| 485 | return |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 486 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 487 | uni.PacketCh <- msg |
| 488 | // BBR specific messages |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 489 | case bbsim.OnuPacketIn: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 490 | // NOTE we only receive BBR packets here. |
| 491 | // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same |
| 492 | // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 493 | msg, _ := message.Data.(bbsim.OnuPacketMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 494 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 495 | onuLogger.WithFields(log.Fields{ |
| 496 | "IntfId": msg.IntfId, |
| 497 | "OnuId": msg.OnuId, |
| 498 | "PortNo": msg.PortNo, |
| 499 | "GemPortId": msg.GemPortId, |
| 500 | "pktType": msg.Type, |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 501 | }).Trace("Received OnuPacketIn Message") |
| 502 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 503 | uni, err := o.findUniByPortNo(msg.PortNo) |
| 504 | if err != nil { |
| 505 | onuLogger.WithFields(log.Fields{ |
| 506 | "IntfId": msg.IntfId, |
| 507 | "OnuId": msg.OnuId, |
| 508 | "PortNo": msg.PortNo, |
| 509 | "GemPortId": msg.GemPortId, |
| 510 | "pktType": msg.Type, |
| 511 | }).Error(err.Error()) |
| 512 | } |
| 513 | |
| 514 | // BBR has one service and one UNI |
| 515 | serviceId := uint32(0) |
| 516 | oltId := 0 |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 517 | if msg.Type == packetHandlers.EAPOL { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 518 | eapol.HandleNextPacket(msg.OnuId, msg.IntfId, msg.GemPortId, o.Sn(), msg.PortNo, uni.ID, serviceId, oltId, o.InternalState, msg.Packet, stream, client) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 519 | } else if msg.Type == packetHandlers.DHCP { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 520 | _ = dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.DoneChannel, msg.Packet, client) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 521 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 522 | case bbsim.OmciIndication: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 523 | // these are OMCI messages received by BBR (VOLTHA emulator) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 524 | msg, _ := message.Data.(bbsim.OmciIndicationMessage) |
| 525 | o.handleOmciResponse(msg, client) |
| 526 | case bbsim.SendEapolFlow: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 527 | o.sendEapolFlow(client) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 528 | case bbsim.SendDhcpFlow: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 529 | o.sendDhcpFlow(client) |
| 530 | default: |
| 531 | onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 532 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 537 | func NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 538 | sn := new(openolt.SerialNumber) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 539 | sn.VendorId = []byte("BBSM") |
| 540 | sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)} |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 541 | return sn |
| 542 | } |
| 543 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 544 | func (o *Onu) sendOnuDiscIndication(msg bbsim.OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 545 | discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 546 | IntfId: o.PonPortID, |
| 547 | SerialNumber: o.SerialNumber, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 548 | }} |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 549 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 550 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 551 | log.Errorf("Failed to send Indication_OnuDiscInd: %v", err) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 552 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 553 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 554 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 555 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 556 | "IntfId": o.PonPortID, |
| 557 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 558 | "OnuId": o.ID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 559 | }).Debug("Sent Indication_OnuDiscInd") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 560 | publishEvent("ONU-discovery-indication-sent", int32(o.PonPortID), int32(o.ID), o.Sn()) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 561 | |
| 562 | // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication |
| 563 | go func(delay time.Duration) { |
Matteo Scandolo | 569e717 | 2019-12-20 11:51:51 -0800 | [diff] [blame] | 564 | time.Sleep(delay) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 565 | if o.InternalState.Current() == OnuStateDiscovered { |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 566 | o.sendOnuDiscIndication(msg, stream) |
| 567 | } |
| 568 | }(o.DiscoveryRetryDelay) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 571 | func (o *Onu) sendOnuIndication(msg bbsim.OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 572 | // NOTE the ONU ID is set by VOLTHA in the ActivateOnu call (via openolt.proto) |
| 573 | // and stored in the Onu struct via onu.SetID |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 574 | |
| 575 | indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 576 | IntfId: o.PonPortID, |
| 577 | OnuId: o.ID, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 578 | OperState: msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 579 | AdminState: o.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 580 | SerialNumber: o.SerialNumber, |
| 581 | }} |
| 582 | if err := stream.Send(&openolt.Indication{Data: indData}); err != nil { |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 583 | // NOTE do we need to transition to a broken state? |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 584 | log.Errorf("Failed to send Indication_OnuInd: %v", err) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 585 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 586 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 587 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 588 | "IntfId": o.PonPortID, |
| 589 | "OnuId": o.ID, |
| 590 | "VolthaOnuId": msg.OnuID, |
| 591 | "OperState": msg.OperState.String(), |
| 592 | "AdminState": msg.OperState.String(), |
| 593 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 594 | }).Debug("Sent Indication_OnuInd") |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 595 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 598 | func (o *Onu) HandleShutdownONU() error { |
| 599 | |
| 600 | dyingGasp := pb.ONUAlarmRequest{ |
| 601 | AlarmType: "DYING_GASP", |
| 602 | SerialNumber: o.Sn(), |
| 603 | Status: "on", |
| 604 | } |
| 605 | |
| 606 | if err := alarmsim.SimulateOnuAlarm(&dyingGasp, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil { |
| 607 | onuLogger.WithFields(log.Fields{ |
| 608 | "OnuId": o.ID, |
| 609 | "IntfId": o.PonPortID, |
| 610 | "OnuSn": o.Sn(), |
| 611 | }).Errorf("Cannot send Dying Gasp: %s", err.Error()) |
| 612 | return err |
| 613 | } |
| 614 | |
| 615 | losReq := pb.ONUAlarmRequest{ |
| 616 | AlarmType: "ONU_ALARM_LOS", |
| 617 | SerialNumber: o.Sn(), |
| 618 | Status: "on", |
| 619 | } |
| 620 | |
| 621 | if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil { |
| 622 | onuLogger.WithFields(log.Fields{ |
| 623 | "OnuId": o.ID, |
| 624 | "IntfId": o.PonPortID, |
| 625 | "OnuSn": o.Sn(), |
| 626 | }).Errorf("Cannot send LOS: %s", err.Error()) |
| 627 | |
| 628 | return err |
| 629 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 630 | o.SendOMCIAlarmNotificationMsg(true, losReq.AlarmType) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 631 | // TODO if it's the last ONU on the PON, then send a PON LOS |
| 632 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 633 | if err := o.InternalState.Event(OnuTxDisable); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 634 | onuLogger.WithFields(log.Fields{ |
| 635 | "OnuId": o.ID, |
| 636 | "IntfId": o.PonPortID, |
| 637 | "OnuSn": o.Sn(), |
| 638 | }).Errorf("Cannot shutdown ONU: %s", err.Error()) |
| 639 | return err |
| 640 | } |
| 641 | |
| 642 | return nil |
| 643 | } |
| 644 | |
| 645 | func (o *Onu) HandlePowerOnONU() error { |
| 646 | intitalState := o.InternalState.Current() |
| 647 | |
| 648 | // initialize the ONU |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 649 | if intitalState == OnuStateCreated || intitalState == OnuStateDisabled { |
| 650 | if err := o.InternalState.Event(OnuTxInitialize); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 651 | onuLogger.WithFields(log.Fields{ |
| 652 | "OnuId": o.ID, |
| 653 | "IntfId": o.PonPortID, |
| 654 | "OnuSn": o.Sn(), |
| 655 | }).Errorf("Cannot poweron ONU: %s", err.Error()) |
| 656 | return err |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | // turn off the LOS Alarm |
| 661 | losReq := pb.ONUAlarmRequest{ |
| 662 | AlarmType: "ONU_ALARM_LOS", |
| 663 | SerialNumber: o.Sn(), |
| 664 | Status: "off", |
| 665 | } |
| 666 | |
| 667 | if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil { |
| 668 | onuLogger.WithFields(log.Fields{ |
| 669 | "OnuId": o.ID, |
| 670 | "IntfId": o.PonPortID, |
| 671 | "OnuSn": o.Sn(), |
| 672 | }).Errorf("Cannot send LOS: %s", err.Error()) |
| 673 | return err |
| 674 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 675 | o.SendOMCIAlarmNotificationMsg(false, losReq.AlarmType) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 676 | |
| 677 | // Send a ONU Discovery indication |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 678 | if err := o.InternalState.Event(OnuTxDiscover); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 679 | onuLogger.WithFields(log.Fields{ |
| 680 | "OnuId": o.ID, |
| 681 | "IntfId": o.PonPortID, |
| 682 | "OnuSn": o.Sn(), |
| 683 | }).Errorf("Cannot poweron ONU: %s", err.Error()) |
| 684 | return err |
| 685 | } |
| 686 | |
| 687 | // move o directly to enable state only when its a powercycle case |
| 688 | // in case of first time o poweron o will be moved to enable on |
| 689 | // receiving ActivateOnu request from openolt adapter |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 690 | if intitalState == OnuStateDisabled { |
| 691 | if err := o.InternalState.Event(OnuTxEnable); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 692 | onuLogger.WithFields(log.Fields{ |
| 693 | "OnuId": o.ID, |
| 694 | "IntfId": o.PonPortID, |
| 695 | "OnuSn": o.Sn(), |
| 696 | }).Errorf("Cannot enable ONU: %s", err.Error()) |
| 697 | return err |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | return nil |
| 702 | } |
| 703 | |
| 704 | func (o *Onu) SetAlarm(alarmType string, status string) error { |
| 705 | alarmReq := pb.ONUAlarmRequest{ |
| 706 | AlarmType: alarmType, |
| 707 | SerialNumber: o.Sn(), |
| 708 | Status: status, |
| 709 | } |
| 710 | |
| 711 | err := alarmsim.SimulateOnuAlarm(&alarmReq, o.ID, o.PonPortID, o.PonPort.Olt.channel) |
| 712 | if err != nil { |
| 713 | return err |
| 714 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 715 | raiseAlarm := false |
| 716 | if alarmReq.Status == "on" { |
| 717 | raiseAlarm = true |
| 718 | } |
| 719 | o.SendOMCIAlarmNotificationMsg(raiseAlarm, alarmReq.AlarmType) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 720 | return nil |
| 721 | } |
| 722 | |
| 723 | func (o *Onu) publishOmciEvent(msg bbsim.OmciMessage) { |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 724 | if olt.PublishEvents { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 725 | _, omciMsg, err := omcilib.ParseOpenOltOmciPacket(msg.OmciPkt.Data()) |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 726 | if err != nil { |
| 727 | log.Errorf("error in getting msgType %v", err) |
| 728 | return |
| 729 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 730 | if omciMsg.MessageType == omci.MibUploadRequestType { |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 731 | o.seqNumber = 0 |
| 732 | publishEvent("MIB-upload-received", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber)) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 733 | } else if omciMsg.MessageType == omci.MibUploadNextRequestType { |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 734 | o.seqNumber++ |
| 735 | if o.seqNumber > 290 { |
| 736 | publishEvent("MIB-upload-done", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber)) |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 742 | // handleOmciRequest is responsible to parse the OMCI packets received from the openolt adapter |
| 743 | // and generate the appropriate response to it |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 744 | func (o *Onu) handleOmciRequest(msg bbsim.OmciMessage, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 745 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 746 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 747 | "omciMsgType": msg.OmciMsg.MessageType, |
| 748 | "transCorrId": strconv.FormatInt(int64(msg.OmciMsg.TransactionID), 16), |
| 749 | "DeviceIdent": msg.OmciMsg.DeviceIdentifier, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 750 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 751 | "SerialNumber": o.Sn(), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 752 | }).Trace("omci-message-decoded") |
| 753 | |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 754 | if o.OmciMsgCounter < maxOmciMsgCounter { |
| 755 | o.OmciMsgCounter++ |
| 756 | } else { |
| 757 | o.OmciMsgCounter = 1 |
| 758 | } |
| 759 | if o.OmciMsgCounter > o.OmciResponseRate { |
| 760 | onuLogger.WithFields(log.Fields{ |
| 761 | "OmciMsgCounter": o.OmciMsgCounter, |
| 762 | "OmciResponseRate": o.OmciResponseRate, |
| 763 | "omciMsgType": msg.OmciMsg.MessageType, |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 764 | }).Debug("skipping-omci-msg-response") |
| 765 | return fmt.Errorf("skipping-omci-msg-response-because-of-response-rate-%d", o.OmciResponseRate) |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 766 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 767 | var responsePkt []byte |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 768 | var errResp error |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 769 | switch msg.OmciMsg.MessageType { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 770 | case omci.MibResetRequestType: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 771 | onuLogger.WithFields(log.Fields{ |
| 772 | "IntfId": o.PonPortID, |
| 773 | "OnuId": o.ID, |
| 774 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 2fdc3b8 | 2021-04-23 15:27:21 -0700 | [diff] [blame] | 775 | }).Debug("received-mib-reset-request") |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 776 | if responsePkt, errResp = omcilib.CreateMibResetResponse(msg.OmciMsg.TransactionID); errResp == nil { |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 777 | o.MibDataSync = 0 |
Matteo Scandolo | 2fdc3b8 | 2021-04-23 15:27:21 -0700 | [diff] [blame] | 778 | |
| 779 | // if the MIB reset is successful then remove all the stored AllocIds and GemPorts |
| 780 | o.PonPort.removeAllocId(o.SerialNumber) |
| 781 | o.PonPort.removeGemPortBySn(o.SerialNumber) |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 782 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 783 | case omci.MibUploadRequestType: |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 784 | responsePkt, _ = omcilib.CreateMibUploadResponse(msg.OmciMsg.TransactionID, o.MibDb.NumberOfCommands) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 785 | case omci.MibUploadNextRequestType: |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 786 | responsePkt, _ = omcilib.CreateMibUploadNextResponse(msg.OmciPkt, msg.OmciMsg, o.MibDataSync, o.MibDb) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 787 | case omci.GetRequestType: |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 788 | onuDown := o.OperState.Current() == "down" |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 789 | responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId, |
| 790 | o.CommittedImageEntityId, o.StandbyImageVersion, o.ActiveImageVersion, o.CommittedImageVersion, onuDown) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 791 | case omci.SetRequestType: |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 792 | success := true |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 793 | msgObj, _ := omcilib.ParseSetRequest(msg.OmciPkt) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 794 | switch msgObj.EntityClass { |
| 795 | case me.PhysicalPathTerminationPointEthernetUniClassID: |
| 796 | // if we're Setting a PPTP state |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 797 | // we need to send the appropriate alarm (handled in the UNI struct) |
| 798 | uni, err := o.FindUniByEntityId(msgObj.EntityInstance) |
| 799 | if err != nil { |
| 800 | onuLogger.Error(err) |
| 801 | success = false |
| 802 | } else { |
| 803 | // 1 locks the UNI, 0 unlocks it |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 804 | adminState := msgObj.Attributes["AdministrativeState"].(uint8) |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 805 | var err error |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 806 | if adminState == 1 { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 807 | err = uni.Disable() |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 808 | } else { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 809 | err = uni.Enable() |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 810 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 811 | if err != nil { |
| 812 | onuLogger.WithFields(log.Fields{ |
| 813 | "IntfId": o.PonPortID, |
| 814 | "OnuId": o.ID, |
| 815 | "UniMeId": uni.MeId, |
| 816 | "UniId": uni.ID, |
| 817 | "SerialNumber": o.Sn(), |
| 818 | "Err": err.Error(), |
| 819 | }).Warn("cannot-change-uni-status") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 820 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 821 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 822 | case me.TContClassID: |
| 823 | allocId := msgObj.Attributes["AllocId"].(uint16) |
| 824 | |
| 825 | // if the AllocId is 255 (0xFF) or 65535 (0xFFFF) it means we are removing it, |
| 826 | // otherwise we are adding it |
| 827 | if allocId == 255 || allocId == 65535 { |
| 828 | onuLogger.WithFields(log.Fields{ |
| 829 | "IntfId": o.PonPortID, |
| 830 | "OnuId": o.ID, |
| 831 | "TContId": msgObj.EntityInstance, |
| 832 | "AllocId": allocId, |
| 833 | "SerialNumber": o.Sn(), |
| 834 | }).Trace("freeing-alloc-id-via-omci") |
| 835 | o.PonPort.removeAllocId(o.SerialNumber) |
| 836 | } else { |
| 837 | if used, sn := o.PonPort.isAllocIdAllocated(allocId); used { |
| 838 | onuLogger.WithFields(log.Fields{ |
| 839 | "IntfId": o.PonPortID, |
| 840 | "OnuId": o.ID, |
| 841 | "AllocId": allocId, |
| 842 | "SerialNumber": o.Sn(), |
| 843 | }).Errorf("allocid-already-allocated-to-onu-with-sn-%s", common.OnuSnToString(sn)) |
| 844 | success = false |
| 845 | } else { |
| 846 | onuLogger.WithFields(log.Fields{ |
| 847 | "IntfId": o.PonPortID, |
| 848 | "OnuId": o.ID, |
| 849 | "TContId": msgObj.EntityInstance, |
| 850 | "AllocId": allocId, |
| 851 | "SerialNumber": o.Sn(), |
| 852 | }).Trace("storing-alloc-id-via-omci") |
| 853 | o.PonPort.storeAllocId(allocId, o.SerialNumber) |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | } |
| 858 | |
| 859 | if success { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 860 | if responsePkt, errResp = omcilib.CreateSetResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 861 | o.MibDataSync++ |
| 862 | } |
| 863 | } else { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 864 | responsePkt, _ = omcilib.CreateSetResponse(msg.OmciPkt, msg.OmciMsg, me.AttributeFailure) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 865 | } |
| 866 | case omci.CreateRequestType: |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 867 | // check for GemPortNetworkCtp and make sure there are no duplicates on the same PON |
| 868 | var used bool |
| 869 | var sn *openolt.SerialNumber |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 870 | msgObj, err := omcilib.ParseCreateRequest(msg.OmciPkt) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 871 | if err == nil { |
| 872 | if msgObj.EntityClass == me.GemPortNetworkCtpClassID { |
Matteo Scandolo | 973b018 | 2021-04-08 11:24:42 -0700 | [diff] [blame] | 873 | // GemPort 4069 is reserved for multicast and shared across ONUs |
| 874 | if msgObj.EntityInstance != 4069 { |
| 875 | if used, sn = o.PonPort.isGemPortAllocated(msgObj.EntityInstance); used { |
| 876 | onuLogger.WithFields(log.Fields{ |
| 877 | "IntfId": o.PonPortID, |
| 878 | "OnuId": o.ID, |
| 879 | "GemPortId": msgObj.EntityInstance, |
| 880 | "SerialNumber": o.Sn(), |
| 881 | }).Errorf("gemport-already-allocated-to-onu-with-sn-%s", common.OnuSnToString(sn)) |
| 882 | } else { |
| 883 | onuLogger.WithFields(log.Fields{ |
| 884 | "IntfId": o.PonPortID, |
| 885 | "OnuId": o.ID, |
| 886 | "GemPortId": msgObj.EntityInstance, |
| 887 | "SerialNumber": o.Sn(), |
| 888 | }).Trace("storing-gem-port-id-via-omci") |
| 889 | o.PonPort.storeGemPort(msgObj.EntityInstance, o.SerialNumber) |
| 890 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | // if the gemPort is valid then increment the MDS and return a successful response |
| 896 | // otherwise fail the request |
| 897 | // for now the CreateRequeste for the gemPort is the only one that can fail, if we start supporting multiple |
| 898 | // validation this check will need to be rewritten |
| 899 | if !used { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 900 | if responsePkt, errResp = omcilib.CreateCreateResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 901 | o.MibDataSync++ |
| 902 | } |
| 903 | } else { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 904 | responsePkt, _ = omcilib.CreateCreateResponse(msg.OmciPkt, msg.OmciMsg, me.ProcessingError) |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 905 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 906 | case omci.DeleteRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 907 | msgObj, err := omcilib.ParseDeleteRequest(msg.OmciPkt) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 908 | if err == nil { |
| 909 | if msgObj.EntityClass == me.GemPortNetworkCtpClassID { |
| 910 | onuLogger.WithFields(log.Fields{ |
| 911 | "IntfId": o.PonPortID, |
| 912 | "OnuId": o.ID, |
| 913 | "GemPortId": msgObj.EntityInstance, |
| 914 | "SerialNumber": o.Sn(), |
| 915 | }).Trace("freeing-gem-port-id-via-omci") |
| 916 | o.PonPort.removeGemPort(msgObj.EntityInstance) |
| 917 | } |
| 918 | } |
| 919 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 920 | if responsePkt, errResp = omcilib.CreateDeleteResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 921 | o.MibDataSync++ |
| 922 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 923 | case omci.RebootRequestType: |
| 924 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 925 | responsePkt, _ = omcilib.CreateRebootResponse(msg.OmciPkt, msg.OmciMsg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 926 | |
| 927 | // powercycle the ONU |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 928 | // we run this in a separate goroutine so that |
| 929 | // the RebootRequestResponse is sent to VOLTHA |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 930 | go func() { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 931 | if err := o.Reboot(10 * time.Second); err != nil { |
| 932 | log.WithFields(log.Fields{ |
| 933 | "IntfId": o.PonPortID, |
| 934 | "OnuId": o.ID, |
| 935 | "SerialNumber": o.Sn(), |
| 936 | "err": err, |
| 937 | }).Error("cannot-reboot-onu-after-omci-reboot-request") |
| 938 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 939 | }() |
| 940 | case omci.TestRequestType: |
Girish Gowdra | 161d27a | 2021-05-05 12:01:44 -0700 | [diff] [blame] | 941 | var classID me.ClassID |
| 942 | var omciResult me.Results |
| 943 | var instID uint16 |
| 944 | responsePkt, errResp, classID, instID, omciResult = omcilib.CreateTestResponse(msg.OmciPkt, msg.OmciMsg) |
| 945 | // Send TestResult only in case the TestResponse omci result code is me.Success |
| 946 | if responsePkt != nil && errResp == nil && omciResult == me.Success { |
| 947 | if testResultPkt, err := omcilib.CreateTestResult(classID, instID, msg.OmciMsg.TransactionID); err == nil { |
| 948 | // send test results asynchronously |
| 949 | go func() { |
| 950 | // Send test results after a second to emulate async behavior |
| 951 | time.Sleep(1 * time.Second) |
| 952 | if testResultPkt != nil { |
| 953 | if err := o.sendOmciIndication(testResultPkt, msg.OmciMsg.TransactionID, stream); err != nil { |
| 954 | onuLogger.WithFields(log.Fields{ |
| 955 | "IntfId": o.PonPortID, |
| 956 | "SerialNumber": o.Sn(), |
| 957 | "omciPacket": testResultPkt, |
| 958 | "msg.OmciMsgType": msg.OmciMsg.MessageType, |
| 959 | "transCorrId": msg.OmciMsg.TransactionID, |
| 960 | }).Errorf("failed-to-send-omci-message: %v", err) |
| 961 | } |
| 962 | } |
| 963 | }() |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 964 | } |
| 965 | } |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 966 | case omci.SynchronizeTimeRequestType: |
| 967 | // MDS counter increment is not required for this message type |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 968 | responsePkt, _ = omcilib.CreateSyncTimeResponse(msg.OmciPkt, msg.OmciMsg) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 969 | case omci.StartSoftwareDownloadRequestType: |
| 970 | |
| 971 | o.ImageSoftwareReceivedSections = 0 |
| 972 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 973 | o.ImageSoftwareExpectedSections = omcilib.ComputeDownloadSectionsCount(msg.OmciPkt) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 974 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 975 | if responsePkt, errResp = omcilib.CreateStartSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 976 | o.MibDataSync++ |
| 977 | if err := o.InternalState.Event(OnuTxStartImageDownload); err != nil { |
| 978 | onuLogger.WithFields(log.Fields{ |
| 979 | "OnuId": o.ID, |
| 980 | "IntfId": o.PonPortID, |
| 981 | "OnuSn": o.Sn(), |
| 982 | "Err": err.Error(), |
| 983 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadStarted) |
| 984 | } |
| 985 | } else { |
| 986 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 987 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 988 | "TransCorrId": msg.OmciMsg.TransactionID, |
| 989 | "Err": errResp.Error(), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 990 | "IntfId": o.PonPortID, |
| 991 | "SerialNumber": o.Sn(), |
| 992 | }).Error("error-while-processing-start-software-download-request") |
| 993 | } |
| 994 | case omci.DownloadSectionRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 995 | if msgObj, err := omcilib.ParseDownloadSectionRequest(msg.OmciPkt); err == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 996 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 997 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 998 | "TransCorrId": msg.OmciMsg.TransactionID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 999 | "EntityInstance": msgObj.EntityInstance, |
| 1000 | "SectionNumber": msgObj.SectionNumber, |
| 1001 | "SectionData": msgObj.SectionData, |
| 1002 | }).Trace("received-download-section-request") |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 1003 | //Extracting the first 14 bytes to use as a version for this image. |
| 1004 | if o.ImageSoftwareReceivedSections == 0 { |
| 1005 | o.StandbyImageVersion = string(msgObj.SectionData[0:14]) |
| 1006 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1007 | o.ImageSoftwareReceivedSections++ |
| 1008 | if o.InternalState.Current() != OnuStateImageDownloadInProgress { |
| 1009 | if err := o.InternalState.Event(OnuTxProgressImageDownload); err != nil { |
| 1010 | onuLogger.WithFields(log.Fields{ |
| 1011 | "OnuId": o.ID, |
| 1012 | "IntfId": o.PonPortID, |
| 1013 | "OnuSn": o.Sn(), |
| 1014 | "Err": err.Error(), |
| 1015 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadInProgress) |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| 1019 | case omci.DownloadSectionRequestWithResponseType: |
| 1020 | // NOTE we only need to respond if an ACK is requested |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1021 | responsePkt, errResp = omcilib.CreateDownloadSectionResponse(msg.OmciPkt, msg.OmciMsg) |
| 1022 | if errResp != nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1023 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1024 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 1025 | "TransCorrId": msg.OmciMsg.TransactionID, |
| 1026 | "Err": errResp.Error(), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1027 | "IntfId": o.PonPortID, |
| 1028 | "SerialNumber": o.Sn(), |
| 1029 | }).Error("error-while-processing-create-download-section-response") |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 1030 | return fmt.Errorf("error-while-processing-create-download-section-response: %s", errResp.Error()) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1031 | } |
| 1032 | o.ImageSoftwareReceivedSections++ |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1033 | case omci.EndSoftwareDownloadRequestType: |
| 1034 | |
| 1035 | // In the startSoftwareDownload we get the image size and the window size. |
| 1036 | // We calculate how many DownloadSection we should receive and validate |
| 1037 | // that we got the correct amount when we receive this message |
| 1038 | success := true |
| 1039 | if o.ImageSoftwareExpectedSections != o.ImageSoftwareReceivedSections { |
| 1040 | onuLogger.WithFields(log.Fields{ |
| 1041 | "OnuId": o.ID, |
| 1042 | "IntfId": o.PonPortID, |
| 1043 | "OnuSn": o.Sn(), |
| 1044 | "ExpectedSections": o.ImageSoftwareExpectedSections, |
| 1045 | "ReceivedSections": o.ImageSoftwareReceivedSections, |
| 1046 | }).Errorf("onu-did-not-receive-all-image-sections") |
| 1047 | success = false |
| 1048 | } |
| 1049 | |
| 1050 | if success { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1051 | if responsePkt, errResp = omcilib.CreateEndSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1052 | o.MibDataSync++ |
| 1053 | if err := o.InternalState.Event(OnuTxCompleteImageDownload); err != nil { |
| 1054 | onuLogger.WithFields(log.Fields{ |
| 1055 | "OnuId": o.ID, |
| 1056 | "IntfId": o.PonPortID, |
| 1057 | "OnuSn": o.Sn(), |
| 1058 | "Err": err.Error(), |
| 1059 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadComplete) |
| 1060 | } |
| 1061 | } else { |
| 1062 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1063 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 1064 | "TransCorrId": msg.OmciMsg.TransactionID, |
| 1065 | "Err": errResp.Error(), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1066 | "IntfId": o.PonPortID, |
| 1067 | "SerialNumber": o.Sn(), |
| 1068 | }).Error("error-while-processing-end-software-download-request") |
| 1069 | } |
| 1070 | } else { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1071 | if responsePkt, errResp = omcilib.CreateEndSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg, me.ProcessingError); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1072 | if err := o.InternalState.Event(OnuTxFailImageDownload); err != nil { |
| 1073 | onuLogger.WithFields(log.Fields{ |
| 1074 | "OnuId": o.ID, |
| 1075 | "IntfId": o.PonPortID, |
| 1076 | "OnuSn": o.Sn(), |
| 1077 | "Err": err.Error(), |
| 1078 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadError) |
| 1079 | } |
| 1080 | } |
| 1081 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1082 | case omci.ActivateSoftwareRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1083 | if responsePkt, errResp = omcilib.CreateActivateSoftwareResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1084 | o.MibDataSync++ |
| 1085 | if err := o.InternalState.Event(OnuTxActivateImage); err != nil { |
| 1086 | onuLogger.WithFields(log.Fields{ |
| 1087 | "OnuId": o.ID, |
| 1088 | "IntfId": o.PonPortID, |
| 1089 | "OnuSn": o.Sn(), |
| 1090 | "Err": err.Error(), |
| 1091 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageActivated) |
| 1092 | } |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1093 | if msgObj, err := omcilib.ParseActivateSoftwareRequest(msg.OmciPkt); err == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1094 | o.ActiveImageEntityId = msgObj.EntityInstance |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 1095 | previousActiveImage := o.ActiveImageVersion |
| 1096 | o.ActiveImageVersion = o.StandbyImageVersion |
| 1097 | o.StandbyImageVersion = previousActiveImage |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1098 | } else { |
| 1099 | onuLogger.Errorf("something-went-wrong-while-activating: %s", err) |
| 1100 | } |
| 1101 | onuLogger.WithFields(log.Fields{ |
| 1102 | "OnuId": o.ID, |
| 1103 | "IntfId": o.PonPortID, |
| 1104 | "OnuSn": o.Sn(), |
| 1105 | "ActiveImageEntityId": o.ActiveImageEntityId, |
| 1106 | "CommittedImageEntityId": o.CommittedImageEntityId, |
| 1107 | }).Info("onu-software-image-activated") |
| 1108 | |
| 1109 | // powercycle the ONU |
| 1110 | // we run this in a separate goroutine so that |
| 1111 | // the ActivateSoftwareResponse is sent to VOLTHA |
| 1112 | // NOTE do we need to wait before rebooting? |
| 1113 | go func() { |
| 1114 | if err := o.Reboot(10 * time.Second); err != nil { |
| 1115 | log.WithFields(log.Fields{ |
| 1116 | "IntfId": o.PonPortID, |
| 1117 | "OnuId": o.ID, |
| 1118 | "SerialNumber": o.Sn(), |
| 1119 | "err": err, |
| 1120 | }).Error("cannot-reboot-onu-after-omci-activate-software-request") |
| 1121 | } |
| 1122 | }() |
| 1123 | } |
| 1124 | case omci.CommitSoftwareRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1125 | if responsePkt, errResp = omcilib.CreateCommitSoftwareResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1126 | o.MibDataSync++ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1127 | if msgObj, err := omcilib.ParseCommitSoftwareRequest(msg.OmciPkt); err == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1128 | // TODO validate that the image to commit is: |
| 1129 | // - active |
| 1130 | // - not already committed |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 1131 | o.ActiveImageEntityId = msgObj.EntityInstance |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1132 | o.CommittedImageEntityId = msgObj.EntityInstance |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 1133 | //committed becomes standby |
| 1134 | o.StandbyImageVersion = o.CommittedImageVersion |
| 1135 | o.CommittedImageVersion = o.ActiveImageVersion |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1136 | } else { |
| 1137 | onuLogger.Errorf("something-went-wrong-while-committing: %s", err) |
| 1138 | } |
| 1139 | if err := o.InternalState.Event(OnuTxCommitImage); err != nil { |
| 1140 | onuLogger.WithFields(log.Fields{ |
| 1141 | "OnuId": o.ID, |
| 1142 | "IntfId": o.PonPortID, |
| 1143 | "OnuSn": o.Sn(), |
| 1144 | "Err": err.Error(), |
| 1145 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageCommitted) |
| 1146 | } |
| 1147 | onuLogger.WithFields(log.Fields{ |
| 1148 | "OnuId": o.ID, |
| 1149 | "IntfId": o.PonPortID, |
| 1150 | "OnuSn": o.Sn(), |
| 1151 | "ActiveImageEntityId": o.ActiveImageEntityId, |
| 1152 | "CommittedImageEntityId": o.CommittedImageEntityId, |
| 1153 | }).Info("onu-software-image-committed") |
| 1154 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1155 | case omci.GetAllAlarmsRequestType: |
| 1156 | // Reset the alarm sequence number on receiving get all alarms request. |
| 1157 | o.onuAlarmsInfoLock.Lock() |
| 1158 | for key, alarmInfo := range o.onuAlarmsInfo { |
| 1159 | // reset the alarm sequence no |
| 1160 | alarmInfo.SequenceNo = 0 |
| 1161 | o.onuAlarmsInfo[key] = alarmInfo |
| 1162 | } |
| 1163 | o.onuAlarmsInfoLock.Unlock() |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1164 | responsePkt, _ = omcilib.CreateGetAllAlarmsResponse(msg.OmciMsg.TransactionID, o.onuAlarmsInfo) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1165 | case omci.GetAllAlarmsNextRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1166 | if responsePkt, errResp = omcilib.CreateGetAllAlarmsNextResponse(msg.OmciPkt, msg.OmciMsg, o.onuAlarmsInfo); errResp != nil { |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1167 | responsePkt = nil //Do not send any response for error case |
| 1168 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1169 | default: |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1170 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1171 | "omciBytes": hex.EncodeToString(msg.OmciPkt.Data()), |
| 1172 | "omciPkt": msg.OmciPkt, |
| 1173 | "omciMsgType": msg.OmciMsg.MessageType, |
| 1174 | "transCorrId": msg.OmciMsg.TransactionID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1175 | "IntfId": o.PonPortID, |
| 1176 | "SerialNumber": o.Sn(), |
| 1177 | }).Warnf("OMCI-message-not-supported") |
| 1178 | } |
| 1179 | |
| 1180 | if responsePkt != nil { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1181 | if err := o.sendOmciIndication(responsePkt, msg.OmciMsg.TransactionID, stream); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1182 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame] | 1183 | "IntfId": o.PonPortID, |
| 1184 | "SerialNumber": o.Sn(), |
| 1185 | "omciPacket": responsePkt, |
| 1186 | "msg.OmciMsgType": msg.OmciMsg.MessageType, |
| 1187 | "transCorrId": msg.OmciMsg.TransactionID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1188 | }).Errorf("failed-to-send-omci-message: %v", err) |
| 1189 | } |
| 1190 | } |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1191 | |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1192 | o.publishOmciEvent(msg) |
Andrea Campanella | be1b7cf | 2021-04-30 09:53:40 +0200 | [diff] [blame] | 1193 | return nil |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1194 | } |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1195 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1196 | // sendOmciIndication takes an OMCI packet and sends it up to VOLTHA |
| 1197 | func (o *Onu) sendOmciIndication(responsePkt []byte, txId uint16, stream bbsim.Stream) error { |
| 1198 | indication := &openolt.Indication_OmciInd{ |
| 1199 | OmciInd: &openolt.OmciIndication{ |
| 1200 | IntfId: o.PonPortID, |
| 1201 | OnuId: o.ID, |
| 1202 | Pkt: responsePkt, |
| 1203 | }, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1204 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1205 | if err := stream.Send(&openolt.Indication{Data: indication}); err != nil { |
| 1206 | return fmt.Errorf("failed-to-send-omci-message: %v", err) |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1207 | } |
| 1208 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1209 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1210 | "SerialNumber": o.Sn(), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1211 | "omciPacket": indication.OmciInd.Pkt, |
| 1212 | "transCorrId": txId, |
| 1213 | }).Trace("omci-message-sent") |
| 1214 | return nil |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1217 | // FindUniById retrieves a UNI by ID |
| 1218 | func (o *Onu) FindUniById(uniID uint32) (*UniPort, error) { |
| 1219 | for _, u := range o.UniPorts { |
| 1220 | uni := u.(*UniPort) |
| 1221 | if uni.ID == uniID { |
| 1222 | return uni, nil |
| 1223 | } |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1224 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1225 | return nil, fmt.Errorf("cannot-find-uni-with-id-%d-on-onu-%s", uniID, o.Sn()) |
| 1226 | } |
| 1227 | |
| 1228 | // FindUniByEntityId retrieves a uni by MeID (the OMCI entity ID) |
| 1229 | func (o *Onu) FindUniByEntityId(meId uint16) (*UniPort, error) { |
| 1230 | entityId := omcilib.EntityID{}.FromUint16(meId) |
| 1231 | for _, u := range o.UniPorts { |
| 1232 | uni := u.(*UniPort) |
| 1233 | if uni.MeId.Equals(entityId) { |
| 1234 | return uni, nil |
| 1235 | } |
| 1236 | } |
| 1237 | return nil, fmt.Errorf("cannot-find-uni-with-meid-%s-on-onu-%s", entityId.ToString(), o.Sn()) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 1240 | func (o *Onu) SetID(id uint32) { |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 1241 | onuLogger.WithFields(log.Fields{ |
| 1242 | "IntfId": o.PonPortID, |
| 1243 | "OnuId": id, |
| 1244 | "SerialNumber": o.Sn(), |
| 1245 | }).Debug("Storing OnuId ") |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 1246 | o.ID = id |
| 1247 | } |
| 1248 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1249 | func (o *Onu) handleFlowAdd(msg bbsim.OnuFlowUpdateMessage) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1250 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1251 | "AllocId": msg.Flow.AllocId, |
Matteo Scandolo | edf30c7 | 2020-09-18 18:15:28 -0700 | [diff] [blame] | 1252 | "Cookie": msg.Flow.Cookie, |
| 1253 | "DstPort": msg.Flow.Classifier.DstPort, |
| 1254 | "FlowId": msg.Flow.FlowId, |
| 1255 | "FlowType": msg.Flow.FlowType, |
| 1256 | "GemportId": msg.Flow.GemportId, |
| 1257 | "InnerVlan": msg.Flow.Classifier.IVid, |
| 1258 | "IntfId": msg.Flow.AccessIntfId, |
| 1259 | "IpProto": msg.Flow.Classifier.IpProto, |
| 1260 | "OnuId": msg.Flow.OnuId, |
| 1261 | "OnuSn": o.Sn(), |
| 1262 | "OuterVlan": msg.Flow.Classifier.OVid, |
| 1263 | "PortNo": msg.Flow.PortNo, |
| 1264 | "SrcPort": msg.Flow.Classifier.SrcPort, |
| 1265 | "UniID": msg.Flow.UniId, |
| 1266 | "ClassifierEthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType), |
| 1267 | "ClassifierOPbits": msg.Flow.Classifier.OPbits, |
| 1268 | "ClassifierIVid": msg.Flow.Classifier.IVid, |
| 1269 | "ClassifierOVid": msg.Flow.Classifier.OVid, |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1270 | "ReplicateFlow": msg.Flow.ReplicateFlow, |
| 1271 | "PbitToGemport": msg.Flow.PbitToGemport, |
Matteo Scandolo | edf30c7 | 2020-09-18 18:15:28 -0700 | [diff] [blame] | 1272 | }).Debug("OLT receives FlowAdd for ONU") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1273 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1274 | o.FlowIds = append(o.FlowIds, msg.Flow.FlowId) |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1275 | |
| 1276 | var gemPortId uint32 |
| 1277 | if msg.Flow.ReplicateFlow { |
| 1278 | // This means that the OLT should replicate the flow for each PBIT, for BBSim it's enough to use the |
| 1279 | // first available gemport (we only need to send one packet) |
| 1280 | // NOTE different TP may create different mapping between PBits and GemPorts, this may require some changes |
| 1281 | gemPortId = msg.Flow.PbitToGemport[0] |
| 1282 | } else { |
| 1283 | // if replicateFlows is false, then the flow is carrying the correct GemPortId |
| 1284 | gemPortId = uint32(msg.Flow.GemportId) |
| 1285 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1286 | |
| 1287 | uni, err := o.FindUniById(uint32(msg.Flow.UniId)) |
| 1288 | if err != nil { |
| 1289 | onuLogger.WithFields(log.Fields{ |
| 1290 | "IntfId": o.PonPortID, |
| 1291 | "OnuId": o.ID, |
| 1292 | "UniId": msg.Flow.UniId, |
| 1293 | "PortNo": msg.Flow.PortNo, |
| 1294 | "SerialNumber": o.Sn(), |
| 1295 | "FlowId": msg.Flow.FlowId, |
| 1296 | "FlowType": msg.Flow.FlowType, |
| 1297 | }).Error("cannot-find-uni-port-for-flow") |
| 1298 | } |
| 1299 | |
| 1300 | uni.addGemPortToService(gemPortId, msg.Flow.Classifier.EthType, msg.Flow.Classifier.OVid, msg.Flow.Classifier.IVid) |
| 1301 | uni.StorePortNo(msg.Flow.PortNo) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1302 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1303 | if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1304 | uni.HandleAuth() |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1305 | } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) && |
| 1306 | msg.Flow.Classifier.SrcPort == uint32(68) && |
Matteo Scandolo | bd875b3 | 2020-09-18 17:46:31 -0700 | [diff] [blame] | 1307 | msg.Flow.Classifier.DstPort == uint32(67) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1308 | uni.HandleDhcp(uint8(msg.Flow.Classifier.OPbits), int(msg.Flow.Classifier.OVid)) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1312 | func (o *Onu) handleFlowRemove(msg bbsim.OnuFlowUpdateMessage) { |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1313 | onuLogger.WithFields(log.Fields{ |
| 1314 | "IntfId": o.PonPortID, |
| 1315 | "OnuId": o.ID, |
| 1316 | "SerialNumber": o.Sn(), |
| 1317 | "FlowId": msg.Flow.FlowId, |
| 1318 | "FlowType": msg.Flow.FlowType, |
| 1319 | }).Debug("ONU receives FlowRemove") |
| 1320 | |
| 1321 | for idx, flow := range o.FlowIds { |
| 1322 | // If the gemport is found, delete it from local cache. |
| 1323 | if flow == msg.Flow.FlowId { |
| 1324 | o.FlowIds = append(o.FlowIds[:idx], o.FlowIds[idx+1:]...) |
| 1325 | break |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | if len(o.FlowIds) == 0 { |
| 1330 | onuLogger.WithFields(log.Fields{ |
| 1331 | "IntfId": o.PonPortID, |
| 1332 | "OnuId": o.ID, |
| 1333 | "SerialNumber": o.Sn(), |
| 1334 | }).Info("Resetting GemPort") |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1335 | |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1336 | // check if ONU delete is performed and |
| 1337 | // terminate the ONU's ProcessOnuMessages Go routine |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1338 | if o.InternalState.Current() == OnuStateDisabled { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1339 | close(o.Channel) |
| 1340 | } |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1344 | func (o *Onu) Reboot(timeout time.Duration) error { |
| 1345 | onuLogger.WithFields(log.Fields{ |
| 1346 | "IntfId": o.PonPortID, |
| 1347 | "OnuId": o.ID, |
| 1348 | "SerialNumber": o.Sn(), |
| 1349 | }).Debug("shutting-down-onu") |
| 1350 | if err := o.HandleShutdownONU(); err != nil { |
| 1351 | return err |
| 1352 | } |
| 1353 | time.Sleep(timeout) |
| 1354 | onuLogger.WithFields(log.Fields{ |
| 1355 | "IntfId": o.PonPortID, |
| 1356 | "OnuId": o.ID, |
| 1357 | "SerialNumber": o.Sn(), |
| 1358 | }).Debug("power-on-onu") |
| 1359 | if err := o.HandlePowerOnONU(); err != nil { |
| 1360 | return err |
| 1361 | } |
| 1362 | return nil |
| 1363 | } |
| 1364 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1365 | // BBR methods |
| 1366 | |
| 1367 | func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) { |
| 1368 | omciMsg := openolt.OmciMsg{ |
| 1369 | IntfId: intfId, |
| 1370 | OnuId: onuId, |
| 1371 | Pkt: pktBytes, |
| 1372 | } |
| 1373 | |
| 1374 | if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil { |
| 1375 | log.WithFields(log.Fields{ |
| 1376 | "IntfId": intfId, |
| 1377 | "OnuId": onuId, |
| 1378 | "SerialNumber": common.OnuSnToString(sn), |
| 1379 | "Pkt": omciMsg.Pkt, |
| 1380 | }).Fatalf("Failed to send MIB Reset") |
| 1381 | } |
| 1382 | log.WithFields(log.Fields{ |
| 1383 | "IntfId": intfId, |
| 1384 | "OnuId": onuId, |
| 1385 | "SerialNumber": common.OnuSnToString(sn), |
| 1386 | "Pkt": omciMsg.Pkt, |
| 1387 | }).Tracef("Sent OMCI message %s", msgType) |
| 1388 | } |
| 1389 | |
| 1390 | func (onu *Onu) getNextTid(highPriority ...bool) uint16 { |
| 1391 | var next uint16 |
| 1392 | if len(highPriority) > 0 && highPriority[0] { |
| 1393 | next = onu.hpTid |
| 1394 | onu.hpTid += 1 |
| 1395 | if onu.hpTid < 0x8000 { |
| 1396 | onu.hpTid = 0x8000 |
| 1397 | } |
| 1398 | } else { |
| 1399 | next = onu.tid |
| 1400 | onu.tid += 1 |
| 1401 | if onu.tid >= 0x8000 { |
| 1402 | onu.tid = 1 |
| 1403 | } |
| 1404 | } |
| 1405 | return next |
| 1406 | } |
| 1407 | |
| 1408 | // TODO move this method in responders/omcisim |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1409 | // StartOmci is called in BBR to start the OMCI state machine |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1410 | func (o *Onu) StartOmci(client openolt.OpenoltClient) { |
| 1411 | mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false)) |
| 1412 | sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client) |
| 1413 | } |
| 1414 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1415 | // handleOmciResponse is used in BBR to generate the OMCI packets the openolt-adapter would send to the device |
| 1416 | func (o *Onu) handleOmciResponse(msg bbsim.OmciIndicationMessage, client openolt.OpenoltClient) { |
| 1417 | |
| 1418 | // we need to encode the packet in HEX |
| 1419 | pkt := make([]byte, len(msg.OmciInd.Pkt)*2) |
| 1420 | hex.Encode(pkt, msg.OmciInd.Pkt) |
| 1421 | packet, omciMsg, err := omcilib.ParseOpenOltOmciPacket(pkt) |
| 1422 | if err != nil { |
| 1423 | log.WithFields(log.Fields{ |
| 1424 | "IntfId": o.PonPortID, |
| 1425 | "SerialNumber": o.Sn(), |
| 1426 | "omciPacket": msg.OmciInd.Pkt, |
| 1427 | }).Error("BBR Cannot parse OMCI packet") |
| 1428 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1429 | |
| 1430 | log.WithFields(log.Fields{ |
| 1431 | "IntfId": msg.OmciInd.IntfId, |
| 1432 | "OnuId": msg.OmciInd.OnuId, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1433 | "OnuSn": o.Sn(), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1434 | "Pkt": msg.OmciInd.Pkt, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1435 | "msgType": omciMsg.MessageType, |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1436 | }).Trace("ONU Receives OMCI Msg") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1437 | switch omciMsg.MessageType { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1438 | default: |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1439 | log.WithFields(log.Fields{ |
| 1440 | "IntfId": msg.OmciInd.IntfId, |
| 1441 | "OnuId": msg.OmciInd.OnuId, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1442 | "OnuSn": o.Sn(), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1443 | "Pkt": msg.OmciInd.Pkt, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1444 | "msgType": omciMsg.MessageType, |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1445 | }).Fatalf("unexpected frame: %v", packet) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1446 | case omci.MibResetResponseType: |
| 1447 | mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false)) |
| 1448 | sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client) |
| 1449 | case omci.MibUploadResponseType: |
| 1450 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 1451 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 1452 | case omci.MibUploadNextResponseType: |
| 1453 | o.seqNumber++ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1454 | // once the mibUpload is complete send a SetRequest for the PPTP to enable the UNI |
| 1455 | // NOTE that in BBR we only enable the first UNI |
| 1456 | if o.seqNumber == o.MibDb.NumberOfCommands { |
| 1457 | meId := omcilib.GenerateUniPortEntityId(1) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1458 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1459 | meParams := me.ParamData{ |
| 1460 | EntityID: meId.ToUint16(), |
| 1461 | Attributes: me.AttributeValueMap{"AdministrativeState": 0}, |
| 1462 | } |
| 1463 | managedEntity, omciError := me.NewPhysicalPathTerminationPointEthernetUni(meParams) |
| 1464 | if omciError.GetError() != nil { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1465 | onuLogger.WithFields(log.Fields{ |
| 1466 | "OnuId": o.ID, |
| 1467 | "IntfId": o.PonPortID, |
| 1468 | "OnuSn": o.Sn(), |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1469 | }).Fatal(omciError.GetError()) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1470 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1471 | |
| 1472 | setPPtp, _ := omcilib.CreateSetRequest(managedEntity, 1) |
| 1473 | sendOmciMsg(setPPtp, o.PonPortID, o.ID, o.SerialNumber, "setRquest", client) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1474 | } else { |
| 1475 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 1476 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1477 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1478 | case omci.SetResponseType: |
| 1479 | // once we set the PPTP to active we can start sending flows |
| 1480 | |
| 1481 | if err := o.InternalState.Event(BbrOnuTxSendEapolFlow); err != nil { |
| 1482 | onuLogger.WithFields(log.Fields{ |
| 1483 | "OnuId": o.ID, |
| 1484 | "IntfId": o.PonPortID, |
| 1485 | "OnuSn": o.Sn(), |
| 1486 | }).Errorf("Error while transitioning ONU State %v", err) |
| 1487 | } |
| 1488 | case omci.AlarmNotificationType: |
| 1489 | log.Info("bbr-received-alarm") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) { |
| 1494 | |
| 1495 | classifierProto := openolt.Classifier{ |
| 1496 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 1497 | OVid: 4091, |
| 1498 | } |
| 1499 | |
| 1500 | actionProto := openolt.Action{} |
| 1501 | |
| 1502 | downstreamFlow := openolt.Flow{ |
| 1503 | AccessIntfId: int32(o.PonPortID), |
| 1504 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1505 | UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1506 | FlowId: uint64(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1507 | FlowType: "downstream", |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1508 | NetworkIntfId: int32(0), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1509 | Classifier: &classifierProto, |
| 1510 | Action: &actionProto, |
| 1511 | Priority: int32(100), |
| 1512 | Cookie: uint64(o.ID), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1513 | PortNo: o.ID, // NOTE we are using this to map an incoming packetIndication to an ONU |
| 1514 | // AllocId and GemPorts need to be unique per PON |
| 1515 | // for now use the ONU-ID, will need to change once we support multiple UNIs |
| 1516 | AllocId: int32(o.ID), |
| 1517 | GemportId: int32(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 1521 | log.WithFields(log.Fields{ |
| 1522 | "IntfId": o.PonPortID, |
| 1523 | "OnuId": o.ID, |
| 1524 | "FlowId": downstreamFlow.FlowId, |
| 1525 | "PortNo": downstreamFlow.PortNo, |
| 1526 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1527 | "Err": err, |
Matteo Scandolo | b0e3e62 | 2020-04-23 17:00:29 -0700 | [diff] [blame] | 1528 | }).Fatalf("Failed to add EAPOL Flow") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1529 | } |
| 1530 | log.WithFields(log.Fields{ |
| 1531 | "IntfId": o.PonPortID, |
| 1532 | "OnuId": o.ID, |
| 1533 | "FlowId": downstreamFlow.FlowId, |
| 1534 | "PortNo": downstreamFlow.PortNo, |
| 1535 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 1536 | }).Info("Sent EAPOL Flow") |
| 1537 | } |
| 1538 | |
| 1539 | func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1540 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1541 | // BBR only works with a single UNI and a single service (ATT HSIA) |
| 1542 | hsia := o.UniPorts[0].(*UniPort).Services[0].(*Service) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1543 | classifierProto := openolt.Classifier{ |
| 1544 | EthType: uint32(layers.EthernetTypeIPv4), |
| 1545 | SrcPort: uint32(68), |
| 1546 | DstPort: uint32(67), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1547 | OVid: uint32(hsia.CTag), |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1548 | OPbits: 255, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | actionProto := openolt.Action{} |
| 1552 | |
| 1553 | downstreamFlow := openolt.Flow{ |
| 1554 | AccessIntfId: int32(o.PonPortID), |
| 1555 | OnuId: int32(o.ID), |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1556 | UniId: int32(0), // BBR only supports a single UNI |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1557 | FlowId: uint64(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1558 | FlowType: "downstream", |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1559 | NetworkIntfId: int32(0), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1560 | Classifier: &classifierProto, |
| 1561 | Action: &actionProto, |
| 1562 | Priority: int32(100), |
| 1563 | Cookie: uint64(o.ID), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1564 | PortNo: o.ID, // NOTE we are using this to map an incoming packetIndication to an ONU |
| 1565 | // AllocId and GemPorts need to be unique per PON |
| 1566 | // for now use the ONU-ID, will need to change once we support multiple UNIs |
| 1567 | AllocId: int32(o.ID), |
| 1568 | GemportId: int32(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 1572 | log.WithFields(log.Fields{ |
| 1573 | "IntfId": o.PonPortID, |
| 1574 | "OnuId": o.ID, |
| 1575 | "FlowId": downstreamFlow.FlowId, |
| 1576 | "PortNo": downstreamFlow.PortNo, |
| 1577 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1578 | "Err": err, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1579 | }).Fatalf("Failed to send DHCP Flow") |
| 1580 | } |
| 1581 | log.WithFields(log.Fields{ |
| 1582 | "IntfId": o.PonPortID, |
| 1583 | "OnuId": o.ID, |
| 1584 | "FlowId": downstreamFlow.FlowId, |
| 1585 | "PortNo": downstreamFlow.PortNo, |
| 1586 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 1587 | }).Info("Sent DHCP Flow") |
| 1588 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1589 | |
| 1590 | // DeleteFlow method search and delete flowKey from the onu flows slice |
| 1591 | func (onu *Onu) DeleteFlow(key FlowKey) { |
| 1592 | for pos, flowKey := range onu.Flows { |
| 1593 | if flowKey == key { |
| 1594 | // delete the flowKey by shifting all flowKeys by one |
| 1595 | onu.Flows = append(onu.Flows[:pos], onu.Flows[pos+1:]...) |
| 1596 | t := make([]FlowKey, len(onu.Flows)) |
| 1597 | copy(t, onu.Flows) |
| 1598 | onu.Flows = t |
| 1599 | break |
| 1600 | } |
| 1601 | } |
| 1602 | } |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1603 | |
| 1604 | func (onu *Onu) ReDiscoverOnu() { |
| 1605 | // Wait for few seconds to be sure of the cleanup |
| 1606 | time.Sleep(5 * time.Second) |
| 1607 | |
| 1608 | onuLogger.WithFields(log.Fields{ |
| 1609 | "IntfId": onu.PonPortID, |
| 1610 | "OnuId": onu.ID, |
| 1611 | "OnuSn": onu.Sn(), |
| 1612 | }).Debug("Send ONU Re-Discovery") |
| 1613 | |
| 1614 | // ONU Re-Discovery |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1615 | if err := onu.InternalState.Event(OnuTxInitialize); err != nil { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1616 | log.WithFields(log.Fields{ |
| 1617 | "IntfId": onu.PonPortID, |
| 1618 | "OnuSn": onu.Sn(), |
| 1619 | "OnuId": onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1620 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateInitialized, err.Error()) |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1621 | } |
| 1622 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1623 | if err := onu.InternalState.Event(OnuTxDiscover); err != nil { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1624 | log.WithFields(log.Fields{ |
| 1625 | "IntfId": onu.PonPortID, |
| 1626 | "OnuSn": onu.Sn(), |
| 1627 | "OnuId": onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1628 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateDiscovered, err.Error()) |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1629 | } |
| 1630 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1631 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1632 | // deprecated, delegate this to the uniPort |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1633 | func (onu *Onu) findServiceByMacAddress(macAddress net.HardwareAddr) (*Service, error) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1634 | // FIXME is there a better way to avoid this loop? |
| 1635 | for _, u := range onu.UniPorts { |
| 1636 | uni := u.(*UniPort) |
| 1637 | for _, s := range uni.Services { |
| 1638 | service := s.(*Service) |
| 1639 | if service.HwAddress.String() == macAddress.String() { |
| 1640 | return service, nil |
| 1641 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | return nil, fmt.Errorf("cannot-find-service-with-mac-address-%s", macAddress.String()) |
| 1645 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1646 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 1647 | func (onu *Onu) findUniByPortNo(portNo uint32) (*UniPort, error) { |
| 1648 | for _, u := range onu.UniPorts { |
| 1649 | uni := u.(*UniPort) |
| 1650 | if uni.PortNo == portNo { |
| 1651 | return uni, nil |
| 1652 | } |
| 1653 | } |
| 1654 | return nil, fmt.Errorf("cannot-find-uni-with-port-no-%d", portNo) |
| 1655 | } |
| 1656 | |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1657 | func (o *Onu) SendOMCIAlarmNotificationMsg(raiseOMCIAlarm bool, alarmType string) { |
| 1658 | switch alarmType { |
| 1659 | case "ONU_ALARM_LOS": |
| 1660 | msg := bbsim.Message{ |
| 1661 | Type: bbsim.UniStatusAlarm, |
| 1662 | Data: bbsim.UniStatusAlarmMessage{ |
| 1663 | OnuSN: o.SerialNumber, |
| 1664 | OnuID: o.ID, |
| 1665 | EntityID: 257, |
| 1666 | RaiseOMCIAlarm: raiseOMCIAlarm, |
| 1667 | }, |
| 1668 | } |
| 1669 | o.Channel <- msg |
| 1670 | } |
| 1671 | |
| 1672 | } |
| 1673 | |
| 1674 | func (o *Onu) IncrementAlarmSequenceNumber(key omcilib.OnuAlarmInfoMapKey) uint8 { |
| 1675 | o.onuAlarmsInfoLock.Lock() |
| 1676 | defer o.onuAlarmsInfoLock.Unlock() |
| 1677 | if alarmInfo, ok := o.onuAlarmsInfo[key]; ok { |
| 1678 | if alarmInfo.SequenceNo == 255 { |
| 1679 | alarmInfo.SequenceNo = 1 |
| 1680 | } else { |
| 1681 | alarmInfo.SequenceNo++ |
| 1682 | } |
| 1683 | o.onuAlarmsInfo[key] = alarmInfo |
| 1684 | return alarmInfo.SequenceNo |
| 1685 | } else { |
| 1686 | // This is the first time alarm notification message is being sent |
| 1687 | o.onuAlarmsInfo[key] = omcilib.OnuAlarmInfo{ |
| 1688 | SequenceNo: 1, |
| 1689 | } |
| 1690 | return 1 |
| 1691 | } |
| 1692 | } |