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