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