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