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 | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 21 | "fmt" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 22 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
| 23 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 24 | "github.com/opencord/bbsim/internal/bbsim/responders/eapol" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 25 | "net" |
| 26 | |
| 27 | "time" |
| 28 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 29 | "github.com/cboling/omci" |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 30 | "github.com/google/gopacket/layers" |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 31 | "github.com/jpillora/backoff" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 32 | "github.com/looplab/fsm" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 33 | "github.com/opencord/bbsim/internal/common" |
| 34 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
| 35 | omcisim "github.com/opencord/omci-sim" |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v2/go/openolt" |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v2/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 38 | log "github.com/sirupsen/logrus" |
| 39 | ) |
| 40 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 41 | var onuLogger = log.WithFields(log.Fields{ |
| 42 | "module": "ONU", |
| 43 | }) |
| 44 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 45 | type FlowKey struct { |
| 46 | ID uint32 |
| 47 | Direction string |
| 48 | } |
| 49 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 50 | type Onu struct { |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 51 | ID uint32 |
| 52 | PonPortID uint32 |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 53 | PonPort *PonPort |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 54 | InternalState *fsm.FSM |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 55 | DiscoveryRetryDelay time.Duration // this is the time between subsequent Discovery Indication |
| 56 | 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^] | 57 | |
| 58 | Services []ServiceIf |
| 59 | |
| 60 | Backoff *backoff.Backoff |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 61 | // ONU State |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 62 | // PortNo comes with flows and it's used when sending packetIndications, |
| 63 | // There is one PortNo per UNI Port, for now we're only storing the first one |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 64 | // FIXME add support for multiple UNIs (each UNI has a different PortNo) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 65 | PortNo uint32 |
| 66 | GemPortAdded bool |
| 67 | Flows []FlowKey |
| 68 | FlowIds []uint32 // keep track of the flows we currently have in the ONU |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 69 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 70 | OperState *fsm.FSM |
| 71 | SerialNumber *openolt.SerialNumber |
| 72 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 73 | Channel chan 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] | 74 | |
| 75 | // OMCI params |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 76 | tid uint16 |
| 77 | hpTid uint16 |
| 78 | seqNumber uint16 |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 79 | |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 80 | DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR) |
| 81 | TrafficSchedulers *tech_profile.TrafficSchedulers |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 84 | func (o *Onu) Sn() string { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 85 | return common.OnuSnToString(o.SerialNumber) |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 88 | func CreateONU(olt *OltDevice, pon *PonPort, id uint32, delay time.Duration, isMock bool) *Onu { |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 89 | b := &backoff.Backoff{ |
| 90 | //These are the defaults |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 91 | Min: 5 * time.Second, |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 92 | Max: 35 * time.Second, |
| 93 | Factor: 1.5, |
| 94 | Jitter: false, |
| 95 | } |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 96 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 97 | o := Onu{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 98 | ID: id, |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 99 | PonPortID: pon.ID, |
| 100 | PonPort: pon, |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 101 | PortNo: 0, |
| 102 | tid: 0x1, |
| 103 | hpTid: 0x8000, |
| 104 | seqNumber: 0, |
| 105 | DoneChannel: make(chan bool, 1), |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 106 | GemPortAdded: false, |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 107 | DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 108 | Flows: []FlowKey{}, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 109 | DiscoveryDelay: delay, |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 110 | Backoff: b, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 111 | } |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 112 | o.SerialNumber = o.NewSN(olt.ID, pon.ID, id) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 113 | // NOTE this state machine is used to track the operational |
| 114 | // state as requested by VOLTHA |
| 115 | o.OperState = getOperStateFSM(func(e *fsm.Event) { |
| 116 | onuLogger.WithFields(log.Fields{ |
| 117 | "ID": o.ID, |
| 118 | }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst) |
| 119 | }) |
| 120 | |
| 121 | // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients |
| 122 | o.InternalState = fsm.NewFSM( |
| 123 | "created", |
| 124 | fsm.Events{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 125 | // DEVICE Lifecycle |
Hardik Windlass | ad790cb | 2020-06-17 21:26:22 +0530 | [diff] [blame] | 126 | {Name: "initialize", Src: []string{"created", "disabled", "pon_disabled"}, Dst: "initialized"}, |
| 127 | {Name: "discover", Src: []string{"initialized"}, Dst: "discovered"}, |
| 128 | {Name: "enable", Src: []string{"discovered", "pon_disabled"}, Dst: "enabled"}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 129 | {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"}, |
| 130 | {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"}, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 131 | // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)? |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 132 | {Name: "disable", Src: []string{"enabled", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed", "pon_disabled"}, Dst: "disabled"}, |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 133 | // ONU state when PON port is disabled but ONU is power ON(more states should be added in src?) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 134 | {Name: "pon_disabled", Src: []string{"enabled", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed"}, Dst: "pon_disabled"}, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 135 | // BBR States |
| 136 | // TODO add start OMCI state |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 137 | {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"}, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 138 | {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 139 | }, |
| 140 | fsm.Callbacks{ |
| 141 | "enter_state": func(e *fsm.Event) { |
| 142 | o.logStateChange(e.Src, e.Dst) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 143 | }, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 144 | "enter_initialized": func(e *fsm.Event) { |
| 145 | // create new channel for ProcessOnuMessages Go routine |
| 146 | o.Channel = make(chan Message, 2048) |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 147 | |
| 148 | if err := o.OperState.Event("enable"); err != nil { |
| 149 | onuLogger.WithFields(log.Fields{ |
| 150 | "OnuId": o.ID, |
| 151 | "IntfId": o.PonPortID, |
| 152 | "OnuSn": o.Sn(), |
| 153 | }).Errorf("Cannot change ONU OperState to up: %s", err.Error()) |
| 154 | } |
| 155 | |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 156 | if !isMock { |
| 157 | // start ProcessOnuMessages Go routine |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 158 | go o.ProcessOnuMessages(olt.enableContext, olt.OpenoltStream, nil) |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 159 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 160 | }, |
| 161 | "enter_discovered": func(e *fsm.Event) { |
| 162 | msg := Message{ |
| 163 | Type: OnuDiscIndication, |
| 164 | Data: OnuDiscIndicationMessage{ |
| 165 | Onu: &o, |
| 166 | OperState: UP, |
| 167 | }, |
| 168 | } |
| 169 | o.Channel <- msg |
| 170 | }, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 171 | "enter_enabled": func(event *fsm.Event) { |
| 172 | msg := Message{ |
| 173 | Type: OnuIndication, |
| 174 | Data: OnuIndicationMessage{ |
| 175 | OnuSN: o.SerialNumber, |
| 176 | PonPortID: o.PonPortID, |
| 177 | OperState: UP, |
| 178 | }, |
| 179 | } |
| 180 | o.Channel <- msg |
| 181 | }, |
| 182 | "enter_disabled": func(event *fsm.Event) { |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 183 | |
| 184 | // clean the ONU state |
Matteo Scandolo | 328c5f0 | 2020-06-26 14:16:39 -0700 | [diff] [blame] | 185 | o.GemPortAdded = false |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 186 | o.PortNo = 0 |
| 187 | o.Flows = []FlowKey{} |
| 188 | |
| 189 | // set the OpenState to disabled |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 190 | if err := o.OperState.Event("disable"); err != nil { |
| 191 | onuLogger.WithFields(log.Fields{ |
| 192 | "OnuId": o.ID, |
| 193 | "IntfId": o.PonPortID, |
| 194 | "OnuSn": o.Sn(), |
| 195 | }).Errorf("Cannot change ONU OperState to down: %s", err.Error()) |
| 196 | } |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 197 | |
| 198 | // send the OnuIndication DOWN event |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 199 | msg := Message{ |
| 200 | Type: OnuIndication, |
| 201 | Data: OnuIndicationMessage{ |
| 202 | OnuSN: o.SerialNumber, |
| 203 | PonPortID: o.PonPortID, |
| 204 | OperState: DOWN, |
| 205 | }, |
| 206 | } |
| 207 | o.Channel <- msg |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 208 | |
| 209 | // verify all the flows removes are handled and |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 210 | // terminate the ONU's ProcessOnuMessages Go routine |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 211 | if len(o.FlowIds) == 0 { |
| 212 | close(o.Channel) |
| 213 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 214 | }, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 215 | // BBR states |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 216 | "enter_eapol_flow_sent": func(e *fsm.Event) { |
| 217 | msg := Message{ |
| 218 | Type: SendEapolFlow, |
| 219 | } |
| 220 | o.Channel <- msg |
| 221 | }, |
| 222 | "enter_dhcp_flow_sent": func(e *fsm.Event) { |
| 223 | msg := Message{ |
| 224 | Type: SendDhcpFlow, |
| 225 | } |
| 226 | o.Channel <- msg |
| 227 | }, |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 228 | "igmp_join_start": func(e *fsm.Event) { |
| 229 | msg := Message{ |
| 230 | Type: IGMPMembershipReportV2, |
| 231 | } |
| 232 | o.Channel <- msg |
| 233 | }, |
| 234 | "igmp_leave": func(e *fsm.Event) { |
| 235 | msg := Message{ |
| 236 | Type: IGMPLeaveGroup} |
| 237 | o.Channel <- msg |
| 238 | }, |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 239 | "igmp_join_startv3": func(e *fsm.Event) { |
| 240 | msg := Message{ |
| 241 | Type: IGMPMembershipReportV3, |
| 242 | } |
| 243 | o.Channel <- msg |
| 244 | }, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 245 | }, |
| 246 | ) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 247 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 248 | return &o |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 249 | } |
| 250 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 251 | func (o *Onu) logStateChange(src string, dst string) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 252 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 253 | "OnuId": o.ID, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 254 | "IntfId": o.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 255 | "OnuSn": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 256 | }).Debugf("Changing ONU InternalState from %s to %s", src, dst) |
| 257 | } |
| 258 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 259 | // ProcessOnuMessages starts indication channel for each ONU |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 260 | 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] | 261 | onuLogger.WithFields(log.Fields{ |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 262 | "onuID": o.ID, |
| 263 | "onuSN": o.Sn(), |
| 264 | "ponPort": o.PonPortID, |
| 265 | }).Debug("Starting ONU Indication Channel") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 266 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 267 | loop: |
| 268 | for { |
| 269 | select { |
| 270 | case <-ctx.Done(): |
| 271 | onuLogger.WithFields(log.Fields{ |
| 272 | "onuID": o.ID, |
| 273 | "onuSN": o.Sn(), |
| 274 | }).Tracef("ONU message handling canceled via context") |
| 275 | break loop |
| 276 | case message, ok := <-o.Channel: |
| 277 | if !ok || ctx.Err() != nil { |
| 278 | onuLogger.WithFields(log.Fields{ |
| 279 | "onuID": o.ID, |
| 280 | "onuSN": o.Sn(), |
| 281 | }).Tracef("ONU message handling canceled via channel close") |
| 282 | break loop |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 283 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 284 | onuLogger.WithFields(log.Fields{ |
| 285 | "onuID": o.ID, |
| 286 | "onuSN": o.Sn(), |
| 287 | "messageType": message.Type, |
| 288 | }).Tracef("Received message on ONU Channel") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 289 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 290 | switch message.Type { |
| 291 | case OnuDiscIndication: |
| 292 | msg, _ := message.Data.(OnuDiscIndicationMessage) |
| 293 | // 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] | 294 | time.Sleep(o.DiscoveryDelay) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 295 | o.sendOnuDiscIndication(msg, stream) |
| 296 | case OnuIndication: |
| 297 | msg, _ := message.Data.(OnuIndicationMessage) |
| 298 | o.sendOnuIndication(msg, stream) |
| 299 | case OMCI: |
| 300 | msg, _ := message.Data.(OmciMessage) |
| 301 | o.handleOmciMessage(msg, stream) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 302 | case FlowAdd: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 303 | msg, _ := message.Data.(OnuFlowUpdateMessage) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 304 | o.handleFlowAdd(msg) |
| 305 | case FlowRemoved: |
| 306 | msg, _ := message.Data.(OnuFlowUpdateMessage) |
| 307 | o.handleFlowRemove(msg) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 308 | case OnuPacketOut: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 309 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 310 | msg, _ := message.Data.(OnuPacketMessage) |
| 311 | |
| 312 | log.WithFields(log.Fields{ |
| 313 | "IntfId": msg.IntfId, |
| 314 | "OnuId": msg.OnuId, |
| 315 | "pktType": msg.Type, |
| 316 | }).Trace("Received OnuPacketOut Message") |
| 317 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 318 | service, err := o.findServiceByMacAddress(msg.MacAddress) |
| 319 | if err != nil { |
| 320 | onuLogger.WithFields(log.Fields{ |
| 321 | "IntfId": msg.IntfId, |
| 322 | "OnuId": msg.OnuId, |
| 323 | "pktType": msg.Type, |
| 324 | "MacAddress": msg.MacAddress, |
| 325 | "OnuSn": o.Sn(), |
| 326 | }).Error("Cannot find Service associated with packet") |
| 327 | return |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 328 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 329 | |
| 330 | service.PacketCh <- msg |
| 331 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 332 | case OnuPacketIn: |
| 333 | // NOTE we only receive BBR packets here. |
| 334 | // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same |
| 335 | // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket |
| 336 | msg, _ := message.Data.(OnuPacketMessage) |
| 337 | |
| 338 | log.WithFields(log.Fields{ |
| 339 | "IntfId": msg.IntfId, |
| 340 | "OnuId": msg.OnuId, |
| 341 | "pktType": msg.Type, |
| 342 | }).Trace("Received OnuPacketIn Message") |
| 343 | |
| 344 | if msg.Type == packetHandlers.EAPOL { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 345 | eapol.HandleNextPacket(msg.OnuId, msg.IntfId, msg.GemPortId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 346 | } else if msg.Type == packetHandlers.DHCP { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 347 | _ = 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] | 348 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 349 | case OmciIndication: |
| 350 | msg, _ := message.Data.(OmciIndicationMessage) |
| 351 | o.handleOmci(msg, client) |
| 352 | case SendEapolFlow: |
| 353 | o.sendEapolFlow(client) |
| 354 | case SendDhcpFlow: |
| 355 | o.sendDhcpFlow(client) |
| 356 | default: |
| 357 | 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] | 358 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 361 | onuLogger.WithFields(log.Fields{ |
| 362 | "onuID": o.ID, |
| 363 | "onuSN": o.Sn(), |
| 364 | }).Debug("Stopped handling ONU Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Matteo Scandolo | df3f85d | 2020-01-15 12:50:48 -0800 | [diff] [blame] | 367 | func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) { |
William Kurkian | 9dadc5b | 2019-10-22 13:51:57 -0400 | [diff] [blame] | 368 | switch message.Type { |
Matteo Scandolo | df3f85d | 2020-01-15 12:50:48 -0800 | [diff] [blame] | 369 | case omcisim.UniLinkUp, omcisim.UniLinkDown: |
| 370 | onuLogger.WithFields(log.Fields{ |
| 371 | "OnuId": message.Data.OnuId, |
| 372 | "IntfId": message.Data.IntfId, |
| 373 | "Type": message.Type, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 374 | }).Debug("UNI Link Alarm") |
Matteo Scandolo | df3f85d | 2020-01-15 12:50:48 -0800 | [diff] [blame] | 375 | // TODO send to OLT |
| 376 | |
| 377 | omciInd := openolt.OmciIndication{ |
| 378 | IntfId: message.Data.IntfId, |
| 379 | OnuId: message.Data.OnuId, |
| 380 | Pkt: message.Packet, |
| 381 | } |
| 382 | |
| 383 | omci := &openolt.Indication_OmciInd{OmciInd: &omciInd} |
| 384 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
| 385 | onuLogger.WithFields(log.Fields{ |
| 386 | "IntfId": o.PonPortID, |
| 387 | "SerialNumber": o.Sn(), |
| 388 | "Type": message.Type, |
| 389 | "omciPacket": omciInd.Pkt, |
| 390 | }).Errorf("Failed to send UNI Link Alarm: %v", err) |
| 391 | return |
| 392 | } |
| 393 | |
| 394 | onuLogger.WithFields(log.Fields{ |
| 395 | "IntfId": o.PonPortID, |
| 396 | "SerialNumber": o.Sn(), |
| 397 | "Type": message.Type, |
| 398 | "omciPacket": omciInd.Pkt, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 399 | }).Debug("UNI Link alarm sent") |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 403 | func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 404 | |
| 405 | sn := new(openolt.SerialNumber) |
| 406 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 407 | //sn = new(openolt.SerialNumber) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 408 | sn.VendorId = []byte("BBSM") |
| 409 | sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)} |
| 410 | |
| 411 | return sn |
| 412 | } |
| 413 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 414 | func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 415 | discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 416 | IntfId: msg.Onu.PonPortID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 417 | SerialNumber: msg.Onu.SerialNumber, |
| 418 | }} |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 419 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 420 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 421 | log.Errorf("Failed to send Indication_OnuDiscInd: %v", err) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 422 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 423 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 424 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 425 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 426 | "IntfId": msg.Onu.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 427 | "OnuSn": msg.Onu.Sn(), |
| 428 | "OnuId": o.ID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 429 | }).Debug("Sent Indication_OnuDiscInd") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 430 | publishEvent("ONU-discovery-indication-sent", int32(msg.Onu.PonPortID), int32(o.ID), msg.Onu.Sn()) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 431 | |
| 432 | // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication |
| 433 | go func(delay time.Duration) { |
Matteo Scandolo | 569e717 | 2019-12-20 11:51:51 -0800 | [diff] [blame] | 434 | time.Sleep(delay) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 435 | if o.InternalState.Current() == "discovered" { |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 436 | o.sendOnuDiscIndication(msg, stream) |
| 437 | } |
| 438 | }(o.DiscoveryRetryDelay) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 439 | } |
| 440 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 441 | func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 442 | // NOTE voltha returns an ID, but if we use that ID then it complains: |
| 443 | // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted |
| 444 | // so we're using the internal ID that is 1 |
| 445 | // o.ID = msg.OnuID |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 446 | |
| 447 | indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 448 | IntfId: o.PonPortID, |
| 449 | OnuId: o.ID, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 450 | OperState: msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 451 | AdminState: o.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 452 | SerialNumber: o.SerialNumber, |
| 453 | }} |
| 454 | if err := stream.Send(&openolt.Indication{Data: indData}); err != nil { |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 455 | // NOTE do we need to transition to a broken state? |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 456 | log.Errorf("Failed to send Indication_OnuInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 457 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 458 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 459 | "IntfId": o.PonPortID, |
| 460 | "OnuId": o.ID, |
| 461 | "OperState": msg.OperState.String(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 462 | "AdminState": msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 463 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 464 | }).Debug("Sent Indication_OnuInd") |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 465 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 466 | for _, s := range o.Services { |
| 467 | go s.HandlePackets(stream) |
| 468 | } |
| 469 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 472 | func (o *Onu) publishOmciEvent(msg OmciMessage) { |
| 473 | if olt.PublishEvents { |
| 474 | _, _, msgType, _, _, _, err := omcisim.ParsePkt(HexDecode(msg.omciMsg.Pkt)) |
| 475 | if err != nil { |
| 476 | log.Errorf("error in getting msgType %v", err) |
| 477 | return |
| 478 | } |
| 479 | if msgType == omcisim.MibUpload { |
| 480 | o.seqNumber = 0 |
| 481 | publishEvent("MIB-upload-received", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber)) |
| 482 | } else if msgType == omcisim.MibUploadNext { |
| 483 | o.seqNumber++ |
| 484 | if o.seqNumber > 290 { |
| 485 | publishEvent("MIB-upload-done", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber)) |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 491 | // Create a TestResponse packet and send it |
| 492 | func (o *Onu) sendTestResult(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) error { |
| 493 | resp, err := omcilib.BuildTestResult(HexDecode(msg.omciMsg.Pkt)) |
| 494 | if err != nil { |
| 495 | return err |
| 496 | } |
| 497 | |
| 498 | var omciInd openolt.OmciIndication |
| 499 | omciInd.IntfId = o.PonPortID |
| 500 | omciInd.OnuId = o.ID |
| 501 | omciInd.Pkt = resp |
| 502 | |
| 503 | omci := &openolt.Indication_OmciInd{OmciInd: &omciInd} |
| 504 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
| 505 | onuLogger.WithFields(log.Fields{ |
| 506 | "IntfId": o.PonPortID, |
| 507 | "SerialNumber": o.Sn(), |
| 508 | "omciPacket": omciInd.Pkt, |
| 509 | "msg": msg, |
| 510 | }).Errorf("send TestResult omcisim indication failed: %v", err) |
| 511 | return err |
| 512 | } |
| 513 | onuLogger.WithFields(log.Fields{ |
| 514 | "IntfId": o.PonPortID, |
| 515 | "SerialNumber": o.Sn(), |
| 516 | "omciPacket": omciInd.Pkt, |
| 517 | }).Tracef("Sent TestResult OMCI message") |
| 518 | |
| 519 | return nil |
| 520 | } |
| 521 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 522 | func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 523 | |
| 524 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 525 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 526 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 527 | "omciPacket": msg.omciMsg.Pkt, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 528 | }).Tracef("Received OMCI message") |
| 529 | |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 530 | o.publishOmciEvent(msg) |
| 531 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 532 | var omciInd openolt.OmciIndication |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 533 | respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt)) |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 534 | if err != nil { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 535 | onuLogger.WithFields(log.Fields{ |
| 536 | "IntfId": o.PonPortID, |
| 537 | "SerialNumber": o.Sn(), |
| 538 | "omciPacket": omciInd.Pkt, |
| 539 | "msg": msg, |
| 540 | }).Errorf("Error handling OMCI message %v", msg) |
| 541 | return |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | omciInd.IntfId = o.PonPortID |
| 545 | omciInd.OnuId = o.ID |
| 546 | omciInd.Pkt = respPkt |
| 547 | |
| 548 | omci := &openolt.Indication_OmciInd{OmciInd: &omciInd} |
| 549 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 550 | onuLogger.WithFields(log.Fields{ |
| 551 | "IntfId": o.PonPortID, |
| 552 | "SerialNumber": o.Sn(), |
| 553 | "omciPacket": omciInd.Pkt, |
| 554 | "msg": msg, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 555 | }).Errorf("send omcisim indication failed: %v", err) |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 556 | return |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 557 | } |
| 558 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 559 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 560 | "SerialNumber": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 561 | "omciPacket": omciInd.Pkt, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 562 | }).Tracef("Sent OMCI message") |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 563 | |
| 564 | // Test message is special, it requires sending two packets: |
| 565 | // first packet: TestResponse, says whether test was started successully, handled by omci-sim |
| 566 | // second packet, TestResult, reports the result of running the self-test |
| 567 | // TestResult can come some time after a TestResponse |
| 568 | // TODO: Implement some delay between the TestResponse and the TestResult |
| 569 | isTest, err := omcilib.IsTestRequest(HexDecode(msg.omciMsg.Pkt)) |
| 570 | if (err == nil) && (isTest) { |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 571 | _ = o.sendTestResult(msg, stream) |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 572 | } |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 575 | func (o *Onu) storePortNumber(portNo uint32) { |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 576 | // NOTE this needed only as long as we don't support multiple UNIs |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 577 | // we need to add support for multiple UNIs |
| 578 | // the action plan is: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 579 | // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 580 | // - change the library so that it reports a single UNI and remove this workaroung |
| 581 | // - add support for multiple UNIs in BBSim |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 582 | if o.PortNo == 0 || portNo < o.PortNo { |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 583 | onuLogger.WithFields(log.Fields{ |
| 584 | "IntfId": o.PonPortID, |
| 585 | "OnuId": o.ID, |
| 586 | "SerialNumber": o.Sn(), |
| 587 | "OnuPortNo": o.PortNo, |
| 588 | "FlowPortNo": portNo, |
| 589 | }).Debug("Storing ONU portNo") |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 590 | o.PortNo = portNo |
| 591 | } |
| 592 | } |
| 593 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 594 | func (o *Onu) SetID(id uint32) { |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 595 | onuLogger.WithFields(log.Fields{ |
| 596 | "IntfId": o.PonPortID, |
| 597 | "OnuId": id, |
| 598 | "SerialNumber": o.Sn(), |
| 599 | }).Debug("Storing OnuId ") |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 600 | o.ID = id |
| 601 | } |
| 602 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 603 | func (o *Onu) handleFlowAdd(msg OnuFlowUpdateMessage) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 604 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 605 | "DstPort": msg.Flow.Classifier.DstPort, |
| 606 | "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType), |
| 607 | "FlowId": msg.Flow.FlowId, |
| 608 | "FlowType": msg.Flow.FlowType, |
| 609 | "GemportId": msg.Flow.GemportId, |
| 610 | "InnerVlan": msg.Flow.Classifier.IVid, |
| 611 | "IntfId": msg.Flow.AccessIntfId, |
| 612 | "IpProto": msg.Flow.Classifier.IpProto, |
| 613 | "OnuId": msg.Flow.OnuId, |
| 614 | "OnuSn": o.Sn(), |
| 615 | "OuterVlan": msg.Flow.Classifier.OVid, |
| 616 | "PortNo": msg.Flow.PortNo, |
| 617 | "SrcPort": msg.Flow.Classifier.SrcPort, |
| 618 | "UniID": msg.Flow.UniId, |
Matteo Scandolo | 3ac5279 | 2020-03-05 14:21:08 -0800 | [diff] [blame] | 619 | "ClassifierOPbits": msg.Flow.Classifier.OPbits, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 620 | }).Debug("ONU receives FlowAdd") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 621 | |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 622 | if msg.Flow.UniId != 0 { |
| 623 | // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it |
| 624 | onuLogger.WithFields(log.Fields{ |
| 625 | "IntfId": o.PonPortID, |
| 626 | "OnuId": o.ID, |
| 627 | "SerialNumber": o.Sn(), |
| 628 | }).Debug("Ignoring flow as it's not for the first UNI") |
| 629 | return |
| 630 | } |
| 631 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 632 | o.FlowIds = append(o.FlowIds, msg.Flow.FlowId) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 633 | o.addGemPortToService(uint32(msg.Flow.GemportId), msg.Flow.Classifier.EthType, msg.Flow.Classifier.OVid, msg.Flow.Classifier.IVid) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 634 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 635 | if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 636 | // NOTE storing the PortNO, it's needed when sending PacketIndications |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 637 | o.storePortNumber(uint32(msg.Flow.PortNo)) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 638 | |
| 639 | for _, s := range o.Services { |
| 640 | s.HandleAuth(o.PonPort.Olt.OpenoltStream) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 641 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 642 | } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) && |
| 643 | msg.Flow.Classifier.SrcPort == uint32(68) && |
Matteo Scandolo | 3ac5279 | 2020-03-05 14:21:08 -0800 | [diff] [blame] | 644 | msg.Flow.Classifier.DstPort == uint32(67) && |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 645 | (msg.Flow.Classifier.OPbits == 0 || msg.Flow.Classifier.OPbits == 255) { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 646 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 647 | for _, s := range o.Services { |
| 648 | s.HandleDhcp(o.PonPort.Olt.OpenoltStream, int(msg.Flow.Classifier.OVid)) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 649 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 653 | func (o *Onu) handleFlowRemove(msg OnuFlowUpdateMessage) { |
| 654 | onuLogger.WithFields(log.Fields{ |
| 655 | "IntfId": o.PonPortID, |
| 656 | "OnuId": o.ID, |
| 657 | "SerialNumber": o.Sn(), |
| 658 | "FlowId": msg.Flow.FlowId, |
| 659 | "FlowType": msg.Flow.FlowType, |
| 660 | }).Debug("ONU receives FlowRemove") |
| 661 | |
| 662 | for idx, flow := range o.FlowIds { |
| 663 | // If the gemport is found, delete it from local cache. |
| 664 | if flow == msg.Flow.FlowId { |
| 665 | o.FlowIds = append(o.FlowIds[:idx], o.FlowIds[idx+1:]...) |
| 666 | break |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if len(o.FlowIds) == 0 { |
| 671 | onuLogger.WithFields(log.Fields{ |
| 672 | "IntfId": o.PonPortID, |
| 673 | "OnuId": o.ID, |
| 674 | "SerialNumber": o.Sn(), |
| 675 | }).Info("Resetting GemPort") |
| 676 | o.GemPortAdded = false |
| 677 | |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 678 | // check if ONU delete is performed and |
| 679 | // terminate the ONU's ProcessOnuMessages Go routine |
| 680 | if o.InternalState.Current() == "disabled" { |
| 681 | close(o.Channel) |
| 682 | } |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 686 | // HexDecode converts the hex encoding to binary |
| 687 | func HexDecode(pkt []byte) []byte { |
| 688 | p := make([]byte, len(pkt)/2) |
| 689 | for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 { |
| 690 | // Go figure this ;) |
| 691 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 692 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 693 | p[j] = u<<4 + l |
| 694 | } |
| 695 | onuLogger.Tracef("Omci decoded: %x.", p) |
| 696 | return p |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 697 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 698 | |
| 699 | // BBR methods |
| 700 | |
| 701 | func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) { |
| 702 | omciMsg := openolt.OmciMsg{ |
| 703 | IntfId: intfId, |
| 704 | OnuId: onuId, |
| 705 | Pkt: pktBytes, |
| 706 | } |
| 707 | |
| 708 | if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil { |
| 709 | log.WithFields(log.Fields{ |
| 710 | "IntfId": intfId, |
| 711 | "OnuId": onuId, |
| 712 | "SerialNumber": common.OnuSnToString(sn), |
| 713 | "Pkt": omciMsg.Pkt, |
| 714 | }).Fatalf("Failed to send MIB Reset") |
| 715 | } |
| 716 | log.WithFields(log.Fields{ |
| 717 | "IntfId": intfId, |
| 718 | "OnuId": onuId, |
| 719 | "SerialNumber": common.OnuSnToString(sn), |
| 720 | "Pkt": omciMsg.Pkt, |
| 721 | }).Tracef("Sent OMCI message %s", msgType) |
| 722 | } |
| 723 | |
| 724 | func (onu *Onu) getNextTid(highPriority ...bool) uint16 { |
| 725 | var next uint16 |
| 726 | if len(highPriority) > 0 && highPriority[0] { |
| 727 | next = onu.hpTid |
| 728 | onu.hpTid += 1 |
| 729 | if onu.hpTid < 0x8000 { |
| 730 | onu.hpTid = 0x8000 |
| 731 | } |
| 732 | } else { |
| 733 | next = onu.tid |
| 734 | onu.tid += 1 |
| 735 | if onu.tid >= 0x8000 { |
| 736 | onu.tid = 1 |
| 737 | } |
| 738 | } |
| 739 | return next |
| 740 | } |
| 741 | |
| 742 | // TODO move this method in responders/omcisim |
| 743 | func (o *Onu) StartOmci(client openolt.OpenoltClient) { |
| 744 | mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false)) |
| 745 | sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client) |
| 746 | } |
| 747 | |
| 748 | func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) { |
| 749 | msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt) |
| 750 | |
| 751 | log.WithFields(log.Fields{ |
| 752 | "IntfId": msg.OmciInd.IntfId, |
| 753 | "OnuId": msg.OmciInd.OnuId, |
| 754 | "OnuSn": common.OnuSnToString(o.SerialNumber), |
| 755 | "Pkt": msg.OmciInd.Pkt, |
| 756 | "msgType": msgType, |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 757 | }).Trace("ONU Receives OMCI Msg") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 758 | switch msgType { |
| 759 | default: |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 760 | log.WithFields(log.Fields{ |
| 761 | "IntfId": msg.OmciInd.IntfId, |
| 762 | "OnuId": msg.OmciInd.OnuId, |
| 763 | "OnuSn": common.OnuSnToString(o.SerialNumber), |
| 764 | "Pkt": msg.OmciInd.Pkt, |
| 765 | "msgType": msgType, |
| 766 | }).Fatalf("unexpected frame: %v", packet) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 767 | case omci.MibResetResponseType: |
| 768 | mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false)) |
| 769 | sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client) |
| 770 | case omci.MibUploadResponseType: |
| 771 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 772 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 773 | case omci.MibUploadNextResponseType: |
| 774 | o.seqNumber++ |
| 775 | |
| 776 | if o.seqNumber > 290 { |
| 777 | // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to) |
| 778 | galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false)) |
| 779 | sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client) |
| 780 | } else { |
| 781 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 782 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 783 | } |
| 784 | case omci.CreateResponseType: |
| 785 | // NOTE Creating a GemPort, |
| 786 | // BBsim actually doesn't care about the values, so we can do we want with the parameters |
| 787 | // In the same way we can create a GemPort even without setting up UNIs/TConts/... |
| 788 | // but we need the GemPort to trigger the state change |
| 789 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 790 | if !o.GemPortAdded { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 791 | // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType |
| 792 | // thus we send this request only once |
| 793 | gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false)) |
| 794 | sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 795 | o.GemPortAdded = true |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 796 | } else { |
| 797 | if err := o.InternalState.Event("send_eapol_flow"); err != nil { |
| 798 | onuLogger.WithFields(log.Fields{ |
| 799 | "OnuId": o.ID, |
| 800 | "IntfId": o.PonPortID, |
| 801 | "OnuSn": o.Sn(), |
| 802 | }).Errorf("Error while transitioning ONU State %v", err) |
| 803 | } |
| 804 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
| 808 | func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) { |
| 809 | |
| 810 | classifierProto := openolt.Classifier{ |
| 811 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 812 | OVid: 4091, |
| 813 | } |
| 814 | |
| 815 | actionProto := openolt.Action{} |
| 816 | |
| 817 | downstreamFlow := openolt.Flow{ |
| 818 | AccessIntfId: int32(o.PonPortID), |
| 819 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 820 | UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 821 | FlowId: uint32(o.ID), |
| 822 | FlowType: "downstream", |
| 823 | AllocId: int32(0), |
| 824 | NetworkIntfId: int32(0), |
| 825 | GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode |
| 826 | Classifier: &classifierProto, |
| 827 | Action: &actionProto, |
| 828 | Priority: int32(100), |
| 829 | Cookie: uint64(o.ID), |
| 830 | PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 831 | } |
| 832 | |
| 833 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 834 | log.WithFields(log.Fields{ |
| 835 | "IntfId": o.PonPortID, |
| 836 | "OnuId": o.ID, |
| 837 | "FlowId": downstreamFlow.FlowId, |
| 838 | "PortNo": downstreamFlow.PortNo, |
| 839 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
Matteo Scandolo | b0e3e62 | 2020-04-23 17:00:29 -0700 | [diff] [blame] | 840 | }).Fatalf("Failed to add EAPOL Flow") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 841 | } |
| 842 | log.WithFields(log.Fields{ |
| 843 | "IntfId": o.PonPortID, |
| 844 | "OnuId": o.ID, |
| 845 | "FlowId": downstreamFlow.FlowId, |
| 846 | "PortNo": downstreamFlow.PortNo, |
| 847 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 848 | }).Info("Sent EAPOL Flow") |
| 849 | } |
| 850 | |
| 851 | func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 852 | |
| 853 | // BBR only works with a single service (ATT HSIA) |
| 854 | hsia := o.Services[0].(*Service) |
| 855 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 856 | classifierProto := openolt.Classifier{ |
| 857 | EthType: uint32(layers.EthernetTypeIPv4), |
| 858 | SrcPort: uint32(68), |
| 859 | DstPort: uint32(67), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 860 | OVid: uint32(hsia.CTag), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | actionProto := openolt.Action{} |
| 864 | |
| 865 | downstreamFlow := openolt.Flow{ |
| 866 | AccessIntfId: int32(o.PonPortID), |
| 867 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 868 | UniId: int32(0), // FIXME do not hardcode this |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 869 | FlowId: uint32(o.ID), |
| 870 | FlowType: "downstream", |
| 871 | AllocId: int32(0), |
| 872 | NetworkIntfId: int32(0), |
| 873 | GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode |
| 874 | Classifier: &classifierProto, |
| 875 | Action: &actionProto, |
| 876 | Priority: int32(100), |
| 877 | Cookie: uint64(o.ID), |
| 878 | PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 879 | } |
| 880 | |
| 881 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 882 | log.WithFields(log.Fields{ |
| 883 | "IntfId": o.PonPortID, |
| 884 | "OnuId": o.ID, |
| 885 | "FlowId": downstreamFlow.FlowId, |
| 886 | "PortNo": downstreamFlow.PortNo, |
| 887 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 888 | }).Fatalf("Failed to send DHCP Flow") |
| 889 | } |
| 890 | log.WithFields(log.Fields{ |
| 891 | "IntfId": o.PonPortID, |
| 892 | "OnuId": o.ID, |
| 893 | "FlowId": downstreamFlow.FlowId, |
| 894 | "PortNo": downstreamFlow.PortNo, |
| 895 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 896 | }).Info("Sent DHCP Flow") |
| 897 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 898 | |
| 899 | // DeleteFlow method search and delete flowKey from the onu flows slice |
| 900 | func (onu *Onu) DeleteFlow(key FlowKey) { |
| 901 | for pos, flowKey := range onu.Flows { |
| 902 | if flowKey == key { |
| 903 | // delete the flowKey by shifting all flowKeys by one |
| 904 | onu.Flows = append(onu.Flows[:pos], onu.Flows[pos+1:]...) |
| 905 | t := make([]FlowKey, len(onu.Flows)) |
| 906 | copy(t, onu.Flows) |
| 907 | onu.Flows = t |
| 908 | break |
| 909 | } |
| 910 | } |
| 911 | } |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 912 | |
| 913 | func (onu *Onu) ReDiscoverOnu() { |
| 914 | // Wait for few seconds to be sure of the cleanup |
| 915 | time.Sleep(5 * time.Second) |
| 916 | |
| 917 | onuLogger.WithFields(log.Fields{ |
| 918 | "IntfId": onu.PonPortID, |
| 919 | "OnuId": onu.ID, |
| 920 | "OnuSn": onu.Sn(), |
| 921 | }).Debug("Send ONU Re-Discovery") |
| 922 | |
| 923 | // ONU Re-Discovery |
| 924 | if err := onu.InternalState.Event("initialize"); err != nil { |
| 925 | log.WithFields(log.Fields{ |
| 926 | "IntfId": onu.PonPortID, |
| 927 | "OnuSn": onu.Sn(), |
| 928 | "OnuId": onu.ID, |
| 929 | }).Infof("Failed to transition ONU to initialized state: %s", err.Error()) |
| 930 | } |
| 931 | |
| 932 | if err := onu.InternalState.Event("discover"); err != nil { |
| 933 | log.WithFields(log.Fields{ |
| 934 | "IntfId": onu.PonPortID, |
| 935 | "OnuSn": onu.Sn(), |
| 936 | "OnuId": onu.ID, |
| 937 | }).Infof("Failed to transition ONU to discovered state: %s", err.Error()) |
| 938 | } |
| 939 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 940 | |
| 941 | func (onu *Onu) addGemPortToService(gemport uint32, ethType uint32, oVlan uint32, iVlan uint32) { |
| 942 | for _, s := range onu.Services { |
| 943 | if service, ok := s.(*Service); ok { |
| 944 | // EAPOL is a strange case, as packets are untagged |
| 945 | // but we assume we will have a single service requiring EAPOL |
| 946 | if ethType == uint32(layers.EthernetTypeEAPOL) && service.NeedsEapol { |
| 947 | service.GemPort = gemport |
| 948 | } |
| 949 | |
| 950 | // For DHCP services we single tag the outgoing packets, |
| 951 | // thus the flow only contains the CTag and we can use that to match the service |
| 952 | if ethType == uint32(layers.EthernetTypeIPv4) && service.NeedsDhcp && service.CTag == int(oVlan) { |
| 953 | service.GemPort = gemport |
| 954 | } |
| 955 | |
| 956 | // for dataplane services match both C and S tags |
| 957 | if service.CTag == int(iVlan) && service.STag == int(oVlan) { |
| 958 | service.GemPort = gemport |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | func (onu *Onu) findServiceByMacAddress(macAddress net.HardwareAddr) (*Service, error) { |
| 965 | for _, s := range onu.Services { |
| 966 | service := s.(*Service) |
| 967 | if service.HwAddress.String() == macAddress.String() { |
| 968 | return service, nil |
| 969 | } |
| 970 | } |
| 971 | return nil, fmt.Errorf("cannot-find-service-with-mac-address-%s", macAddress.String()) |
| 972 | } |