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