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