blob: 34150839b935dd0a2785a9fea772f1f1dc93cd20 [file] [log] [blame]
Matteo Scandolo11006992019-08-28 11:29:46 -07001/*
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 Scandolo4747d292019-08-05 11:50:18 -070017package devices
18
19import (
Matteo Scandolo40e067f2019-10-16 16:59:41 -070020 "context"
Matteo Scandolo99f18462019-10-28 14:14:28 -070021 "errors"
Matteo Scandolo3bc73742019-08-20 14:04:04 -070022 "fmt"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010023 "net"
24
25 "time"
26
Matteo Scandolo40e067f2019-10-16 16:59:41 -070027 "github.com/cboling/omci"
Matteo Scandolo3bc73742019-08-20 14:04:04 -070028 "github.com/google/gopacket/layers"
Matteo Scandolo4747d292019-08-05 11:50:18 -070029 "github.com/looplab/fsm"
Matteo Scandolo075b1892019-10-07 12:11:07 -070030 "github.com/opencord/bbsim/internal/bbsim/packetHandlers"
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070031 "github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
32 "github.com/opencord/bbsim/internal/bbsim/responders/eapol"
Arjun E K57a7fcb2020-01-30 06:44:45 +000033 "github.com/opencord/bbsim/internal/bbsim/responders/igmp"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070034 "github.com/opencord/bbsim/internal/common"
35 omcilib "github.com/opencord/bbsim/internal/common/omci"
36 omcisim "github.com/opencord/omci-sim"
Matteo Scandolo3de9de02019-11-14 13:40:03 -080037 "github.com/opencord/voltha-protos/v2/go/openolt"
Matteo Scandolo4747d292019-08-05 11:50:18 -070038 log "github.com/sirupsen/logrus"
39)
40
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070041var onuLogger = log.WithFields(log.Fields{
42 "module": "ONU",
43})
44
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070045type Onu struct {
Matteo Scandoloe811ae92019-12-10 17:50:14 -080046 ID uint32
47 PonPortID uint32
48 PonPort PonPort
49 STag int
50 CTag int
51 Auth bool // automatically start EAPOL if set to true
52 Dhcp bool // automatically start DHCP if set to true
53 HwAddress net.HardwareAddr
54 InternalState *fsm.FSM
Pragya Arya2225f202020-01-29 18:05:01 +053055 DiscoveryRetryDelay time.Duration // this is the time between subsequent Discovery Indication
56 DiscoveryDelay time.Duration // this is the time to send the first Discovery Indication
Matteo Scandoloe811ae92019-12-10 17:50:14 -080057
58 // ONU State
Matteo Scandolo27428702019-10-11 16:21:16 -070059 // PortNo comes with flows and it's used when sending packetIndications,
60 // There is one PortNo per UNI Port, for now we're only storing the first one
61 // FIXME add support for multiple UNIs
Matteo Scandolo99f18462019-10-28 14:14:28 -070062 PortNo uint32
63 DhcpFlowReceived bool
64
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070065 OperState *fsm.FSM
66 SerialNumber *openolt.SerialNumber
67
68 Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -070069
70 // OMCI params
71 tid uint16
72 hpTid uint16
73 seqNumber uint16
74 HasGemPort bool
75
76 DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070077}
78
Matteo Scandolo99f18462019-10-28 14:14:28 -070079func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070080 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070081}
82
Pragya Arya2225f202020-01-29 18:05:01 +053083func CreateONU(olt *OltDevice, pon PonPort, id uint32, sTag int, cTag int, auth bool, dhcp bool, delay time.Duration, isMock bool) *Onu {
Matteo Scandolo4747d292019-08-05 11:50:18 -070084
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070085 o := Onu{
Pragya Arya2225f202020-01-29 18:05:01 +053086 ID: 0,
Matteo Scandoloe811ae92019-12-10 17:50:14 -080087 PonPortID: pon.ID,
88 PonPort: pon,
89 STag: sTag,
90 CTag: cTag,
91 Auth: auth,
92 Dhcp: dhcp,
93 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
94 PortNo: 0,
95 tid: 0x1,
96 hpTid: 0x8000,
97 seqNumber: 0,
98 DoneChannel: make(chan bool, 1),
99 DhcpFlowReceived: false,
100 DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
Pragya Arya2225f202020-01-29 18:05:01 +0530101 DiscoveryDelay: delay,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700102 }
Pragya Arya2225f202020-01-29 18:05:01 +0530103 o.SerialNumber = o.NewSN(olt.ID, pon.ID, id)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700104
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700105 // NOTE this state machine is used to track the operational
106 // state as requested by VOLTHA
107 o.OperState = getOperStateFSM(func(e *fsm.Event) {
108 onuLogger.WithFields(log.Fields{
109 "ID": o.ID,
110 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
111 })
112
113 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
114 o.InternalState = fsm.NewFSM(
115 "created",
116 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700117 // DEVICE Lifecycle
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100118 {Name: "initialize", Src: []string{"created", "disabled"}, Dst: "initialized"},
Pragya Arya6a708d62020-01-01 17:17:20 +0530119 {Name: "discover", Src: []string{"initialized", "pon_disabled"}, Dst: "discovered"},
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700120 {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700121 {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"},
122 {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100123 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
Pragya Arya2225f202020-01-29 18:05:01 +0530124 {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 Arya6a708d62020-01-01 17:17:20 +0530125 // ONU state when PON port is disabled but ONU is power ON(more states should be added in src?)
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800126 {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 Scandolo4b3fc7e2019-09-17 16:49:54 -0700127 // EAPOL
Shubham Sharmabd4b6572020-02-12 13:00:44 +0000128 {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 Scandolo4b3fc7e2019-09-17 16:49:54 -0700129 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
130 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
131 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
132 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
133 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
134 // DHCP
Shubham Sharmabd4b6572020-02-12 13:00:44 +0000135 {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 Scandolo4b3fc7e2019-09-17 16:49:54 -0700136 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
137 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
138 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
139 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700140 // BBR States
141 // TODO add start OMCI state
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100142 {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700143 {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"},
Arjun E K57a7fcb2020-01-30 06:44:45 +0000144 // IGMP
Shubham Sharmabd4b6572020-02-12 13:00:44 +0000145 {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 Kdd443f02020-02-07 15:24:01 +0000146 {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 Sharmabd4b6572020-02-12 13:00:44 +0000147 {Name: "igmp_join_error", Src: []string{"igmp_join_started"}, Dst: "igmp_join_error"},
148 {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 Scandolo4b3fc7e2019-09-17 16:49:54 -0700149 },
150 fsm.Callbacks{
151 "enter_state": func(e *fsm.Event) {
152 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700153 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100154 "enter_initialized": func(e *fsm.Event) {
155 // create new channel for ProcessOnuMessages Go routine
156 o.Channel = make(chan Message, 2048)
Pragya Arya1cbefa42020-01-13 12:15:29 +0530157 if !isMock {
158 // start ProcessOnuMessages Go routine
159 go o.ProcessOnuMessages(olt.enableContext, *olt.OpenoltStream, nil)
160 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100161 },
162 "enter_discovered": func(e *fsm.Event) {
163 msg := Message{
164 Type: OnuDiscIndication,
165 Data: OnuDiscIndicationMessage{
166 Onu: &o,
167 OperState: UP,
168 },
169 }
170 o.Channel <- msg
171 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700172 "enter_enabled": func(event *fsm.Event) {
173 msg := Message{
174 Type: OnuIndication,
175 Data: OnuIndicationMessage{
176 OnuSN: o.SerialNumber,
177 PonPortID: o.PonPortID,
178 OperState: UP,
179 },
180 }
181 o.Channel <- msg
182 },
183 "enter_disabled": func(event *fsm.Event) {
184 msg := Message{
185 Type: OnuIndication,
186 Data: OnuIndicationMessage{
187 OnuSN: o.SerialNumber,
188 PonPortID: o.PonPortID,
189 OperState: DOWN,
190 },
191 }
192 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100193 // terminate the ONU's ProcessOnuMessages Go routine
194 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700195 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700196 "enter_auth_started": func(e *fsm.Event) {
197 o.logStateChange(e.Src, e.Dst)
198 msg := Message{
199 Type: StartEAPOL,
200 Data: PacketMessage{
201 PonPortID: o.PonPortID,
202 OnuID: o.ID,
203 },
204 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700205 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700206 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700207 "enter_auth_failed": func(e *fsm.Event) {
208 onuLogger.WithFields(log.Fields{
209 "OnuId": o.ID,
210 "IntfId": o.PonPortID,
211 "OnuSn": o.Sn(),
212 }).Errorf("ONU failed to authenticate!")
213 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700214 "before_start_dhcp": func(e *fsm.Event) {
215 if o.DhcpFlowReceived == false {
216 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
217 }
218 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700219 "enter_dhcp_started": func(e *fsm.Event) {
220 msg := Message{
221 Type: StartDHCP,
222 Data: PacketMessage{
223 PonPortID: o.PonPortID,
224 OnuID: o.ID,
225 },
226 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700227 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700228 },
229 "enter_dhcp_failed": func(e *fsm.Event) {
230 onuLogger.WithFields(log.Fields{
231 "OnuId": o.ID,
232 "IntfId": o.PonPortID,
233 "OnuSn": o.Sn(),
234 }).Errorf("ONU failed to DHCP!")
235 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700236 "enter_eapol_flow_sent": func(e *fsm.Event) {
237 msg := Message{
238 Type: SendEapolFlow,
239 }
240 o.Channel <- msg
241 },
242 "enter_dhcp_flow_sent": func(e *fsm.Event) {
243 msg := Message{
244 Type: SendDhcpFlow,
245 }
246 o.Channel <- msg
247 },
Arjun E K57a7fcb2020-01-30 06:44:45 +0000248 "igmp_join_start": func(e *fsm.Event) {
249 msg := Message{
250 Type: IGMPMembershipReportV2,
251 }
252 o.Channel <- msg
253 },
254 "igmp_leave": func(e *fsm.Event) {
255 msg := Message{
256 Type: IGMPLeaveGroup}
257 o.Channel <- msg
258 },
Arjun E Kdd443f02020-02-07 15:24:01 +0000259 "igmp_join_startv3": func(e *fsm.Event) {
260 msg := Message{
261 Type: IGMPMembershipReportV3,
262 }
263 o.Channel <- msg
264 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700265 },
266 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100267
Matteo Scandolo27428702019-10-11 16:21:16 -0700268 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700269}
270
William Kurkian0418bc82019-11-06 12:16:24 -0500271func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700272 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700273 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700274 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700275 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700276 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
277}
278
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100279// ProcessOnuMessages starts indication channel for each ONU
David Bainbridge103cf022019-12-16 20:11:35 +0000280func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700281 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100282 "onuID": o.ID,
283 "onuSN": o.Sn(),
284 "ponPort": o.PonPortID,
285 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700286
David Bainbridge103cf022019-12-16 20:11:35 +0000287loop:
288 for {
289 select {
290 case <-ctx.Done():
291 onuLogger.WithFields(log.Fields{
292 "onuID": o.ID,
293 "onuSN": o.Sn(),
294 }).Tracef("ONU message handling canceled via context")
295 break loop
296 case message, ok := <-o.Channel:
297 if !ok || ctx.Err() != nil {
298 onuLogger.WithFields(log.Fields{
299 "onuID": o.ID,
300 "onuSN": o.Sn(),
301 }).Tracef("ONU message handling canceled via channel close")
302 break loop
Matteo Scandolo075b1892019-10-07 12:11:07 -0700303 }
David Bainbridge103cf022019-12-16 20:11:35 +0000304 onuLogger.WithFields(log.Fields{
305 "onuID": o.ID,
306 "onuSN": o.Sn(),
307 "messageType": message.Type,
308 }).Tracef("Received message on ONU Channel")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700309
David Bainbridge103cf022019-12-16 20:11:35 +0000310 switch message.Type {
311 case OnuDiscIndication:
312 msg, _ := message.Data.(OnuDiscIndicationMessage)
313 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
Pragya Arya2225f202020-01-29 18:05:01 +0530314 time.Sleep(o.DiscoveryDelay)
David Bainbridge103cf022019-12-16 20:11:35 +0000315 o.sendOnuDiscIndication(msg, stream)
316 case OnuIndication:
317 msg, _ := message.Data.(OnuIndicationMessage)
318 o.sendOnuIndication(msg, stream)
319 case OMCI:
320 msg, _ := message.Data.(OmciMessage)
321 o.handleOmciMessage(msg, stream)
322 case FlowUpdate:
323 msg, _ := message.Data.(OnuFlowUpdateMessage)
324 o.handleFlowUpdate(msg)
325 case StartEAPOL:
326 log.Infof("Receive StartEAPOL message on ONU Channel")
327 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
328 case StartDHCP:
329 log.Infof("Receive StartDHCP message on ONU Channel")
330 // FIXME use id, ponId as SendEapStart
331 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
332 case OnuPacketOut:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700333
David Bainbridge103cf022019-12-16 20:11:35 +0000334 msg, _ := message.Data.(OnuPacketMessage)
335
336 log.WithFields(log.Fields{
337 "IntfId": msg.IntfId,
338 "OnuId": msg.OnuId,
339 "pktType": msg.Type,
340 }).Trace("Received OnuPacketOut Message")
341
342 if msg.Type == packetHandlers.EAPOL {
343 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
344 } else if msg.Type == packetHandlers.DHCP {
345 // NOTE here we receive packets going from the DHCP Server to the ONU
346 // for now we expect them to be double-tagged, but ideally the should be single tagged
347 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
348 }
349 case OnuPacketIn:
350 // NOTE we only receive BBR packets here.
351 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
352 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
353 msg, _ := message.Data.(OnuPacketMessage)
354
355 log.WithFields(log.Fields{
356 "IntfId": msg.IntfId,
357 "OnuId": msg.OnuId,
358 "pktType": msg.Type,
359 }).Trace("Received OnuPacketIn Message")
360
361 if msg.Type == packetHandlers.EAPOL {
362 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
363 } else if msg.Type == packetHandlers.DHCP {
364 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
365 }
366 case DyingGaspIndication:
367 msg, _ := message.Data.(DyingGaspIndicationMessage)
368 o.sendDyingGaspInd(msg, stream)
369 case OmciIndication:
370 msg, _ := message.Data.(OmciIndicationMessage)
371 o.handleOmci(msg, client)
372 case SendEapolFlow:
373 o.sendEapolFlow(client)
374 case SendDhcpFlow:
375 o.sendDhcpFlow(client)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000376 case IGMPMembershipReportV2:
377 log.Infof("Recieved IGMPMembershipReportV2 message on ONU channel")
378 igmp.SendIGMPMembershipReportV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
379 case IGMPLeaveGroup:
380 log.Infof("Recieved IGMPLeaveGroupV2 message on ONU channel")
381 igmp.SendIGMPLeaveGroupV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
Arjun E Kdd443f02020-02-07 15:24:01 +0000382 case IGMPMembershipReportV3:
383 log.Infof("Recieved IGMPMembershipReportV3 message on ONU channel")
384 igmp.SendIGMPMembershipReportV3(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
David Bainbridge103cf022019-12-16 20:11:35 +0000385 default:
386 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700387 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700388 }
389 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100390 onuLogger.WithFields(log.Fields{
391 "onuID": o.ID,
392 "onuSN": o.Sn(),
393 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700394}
395
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800396func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400397 switch message.Type {
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800398 case omcisim.UniLinkUp, omcisim.UniLinkDown:
399 onuLogger.WithFields(log.Fields{
400 "OnuId": message.Data.OnuId,
401 "IntfId": message.Data.IntfId,
402 "Type": message.Type,
403 }).Infof("UNI Link Alarm")
404 // TODO send to OLT
405
406 omciInd := openolt.OmciIndication{
407 IntfId: message.Data.IntfId,
408 OnuId: message.Data.OnuId,
409 Pkt: message.Packet,
410 }
411
412 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
413 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
414 onuLogger.WithFields(log.Fields{
415 "IntfId": o.PonPortID,
416 "SerialNumber": o.Sn(),
417 "Type": message.Type,
418 "omciPacket": omciInd.Pkt,
419 }).Errorf("Failed to send UNI Link Alarm: %v", err)
420 return
421 }
422
423 onuLogger.WithFields(log.Fields{
424 "IntfId": o.PonPortID,
425 "SerialNumber": o.Sn(),
426 "Type": message.Type,
427 "omciPacket": omciInd.Pkt,
428 }).Info("UNI Link alarm sent")
429
William Kurkian9dadc5b2019-10-22 13:51:57 -0400430 case omcisim.GemPortAdded:
431 log.WithFields(log.Fields{
432 "OnuId": message.Data.OnuId,
433 "IntfId": message.Data.IntfId,
434 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700435
William Kurkian9dadc5b2019-10-22 13:51:57 -0400436 // NOTE if we receive the GemPort but we don't have EAPOL flows
437 // go an intermediate state, otherwise start auth
438 if o.InternalState.Is("enabled") {
439 if err := o.InternalState.Event("add_gem_port"); err != nil {
440 log.Errorf("Can't go to gem_port_added: %v", err)
441 }
442 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800443 if o.Auth == true {
444 if err := o.InternalState.Event("start_auth"); err != nil {
445 log.Warnf("Can't go to auth_started: %v", err)
446 }
447 } else {
448 onuLogger.WithFields(log.Fields{
449 "IntfId": o.PonPortID,
450 "OnuId": o.ID,
451 "SerialNumber": o.Sn(),
452 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700453 }
454 }
455 }
456}
457
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100458func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700459
460 sn := new(openolt.SerialNumber)
461
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700462 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700463 sn.VendorId = []byte("BBSM")
464 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
465
466 return sn
467}
468
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700469// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
470// send method should not change the ONU state
471
William Kurkian0418bc82019-11-06 12:16:24 -0500472func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700473 alarmData := &openolt.AlarmIndication_DyingGaspInd{
474 DyingGaspInd: &openolt.DyingGaspIndication{
475 IntfId: msg.PonPortID,
476 OnuId: msg.OnuID,
477 Status: "on",
478 },
479 }
480 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
481
482 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
483 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
484 return err
485 }
486 onuLogger.WithFields(log.Fields{
487 "IntfId": msg.PonPortID,
488 "OnuSn": o.Sn(),
489 "OnuId": msg.OnuID,
490 }).Info("sendDyingGaspInd")
491 return nil
492}
493
William Kurkian0418bc82019-11-06 12:16:24 -0500494func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700495 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700496 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700497 SerialNumber: msg.Onu.SerialNumber,
498 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700499
Matteo Scandolo4747d292019-08-05 11:50:18 -0700500 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700501 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700502 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700503 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700504
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700505 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700506 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700507 "OnuSn": msg.Onu.Sn(),
508 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700509 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800510
511 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
512 go func(delay time.Duration) {
Matteo Scandolo569e7172019-12-20 11:51:51 -0800513 time.Sleep(delay)
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800514 if o.InternalState.Current() == "discovered" {
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800515 o.sendOnuDiscIndication(msg, stream)
516 }
517 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700518}
519
William Kurkian0418bc82019-11-06 12:16:24 -0500520func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700521 // NOTE voltha returns an ID, but if we use that ID then it complains:
522 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
523 // so we're using the internal ID that is 1
524 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700525
526 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700527 IntfId: o.PonPortID,
528 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700529 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700530 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700531 SerialNumber: o.SerialNumber,
532 }}
533 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700534 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700535 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700536 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700537 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700538 "IntfId": o.PonPortID,
539 "OnuId": o.ID,
540 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700541 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700542 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700543 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700544
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700545}
546
William Kurkian0418bc82019-11-06 12:16:24 -0500547func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700548
549 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700550 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700551 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700552 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700553 }).Tracef("Received OMCI message")
554
555 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700556 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700557 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700558 onuLogger.WithFields(log.Fields{
559 "IntfId": o.PonPortID,
560 "SerialNumber": o.Sn(),
561 "omciPacket": omciInd.Pkt,
562 "msg": msg,
563 }).Errorf("Error handling OMCI message %v", msg)
564 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700565 }
566
567 omciInd.IntfId = o.PonPortID
568 omciInd.OnuId = o.ID
569 omciInd.Pkt = respPkt
570
571 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
572 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700573 onuLogger.WithFields(log.Fields{
574 "IntfId": o.PonPortID,
575 "SerialNumber": o.Sn(),
576 "omciPacket": omciInd.Pkt,
577 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700578 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700579 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700580 }
581 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700582 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700583 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700584 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700585 }).Tracef("Sent OMCI message")
586}
587
Matteo Scandolo27428702019-10-11 16:21:16 -0700588func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700589 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700590 // we need to add support for multiple UNIs
591 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700592 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700593 // - change the library so that it reports a single UNI and remove this workaroung
594 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700595 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700596 onuLogger.WithFields(log.Fields{
597 "IntfId": o.PonPortID,
598 "OnuId": o.ID,
599 "SerialNumber": o.Sn(),
600 "OnuPortNo": o.PortNo,
601 "FlowPortNo": portNo,
602 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700603 o.PortNo = portNo
604 }
605}
606
William Kurkian0418bc82019-11-06 12:16:24 -0500607func (o *Onu) SetID(id uint32) {
Matteo Scandolo583f17d2020-02-13 10:35:17 -0800608 onuLogger.WithFields(log.Fields{
609 "IntfId": o.PonPortID,
610 "OnuId": id,
611 "SerialNumber": o.Sn(),
612 }).Debug("Storing OnuId ")
William Kurkian0418bc82019-11-06 12:16:24 -0500613 o.ID = id
614}
615
Matteo Scandolo813402b2019-10-23 19:24:52 -0700616func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700617 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700618 "DstPort": msg.Flow.Classifier.DstPort,
619 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
620 "FlowId": msg.Flow.FlowId,
621 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700622 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700623 "IntfId": msg.Flow.AccessIntfId,
624 "IpProto": msg.Flow.Classifier.IpProto,
625 "OnuId": msg.Flow.OnuId,
626 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700627 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700628 "PortNo": msg.Flow.PortNo,
629 "SrcPort": msg.Flow.Classifier.SrcPort,
630 "UniID": msg.Flow.UniId,
631 }).Debug("ONU receives Flow")
632
Matteo Scandolo813402b2019-10-23 19:24:52 -0700633 if msg.Flow.UniId != 0 {
634 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
635 onuLogger.WithFields(log.Fields{
636 "IntfId": o.PonPortID,
637 "OnuId": o.ID,
638 "SerialNumber": o.Sn(),
639 }).Debug("Ignoring flow as it's not for the first UNI")
640 return
641 }
642
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700643 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700644 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700645 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700646
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700647 // NOTE if we receive the EAPOL flows but we don't have GemPorts
648 // go an intermediate state, otherwise start auth
649 if o.InternalState.Is("enabled") {
650 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700651 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700652 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700653 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700654
655 if o.Auth == true {
656 if err := o.InternalState.Event("start_auth"); err != nil {
657 log.Warnf("Can't go to auth_started: %v", err)
658 }
659 } else {
660 onuLogger.WithFields(log.Fields{
661 "IntfId": o.PonPortID,
662 "OnuId": o.ID,
663 "SerialNumber": o.Sn(),
664 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700665 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700666
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700667 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700668 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
669 msg.Flow.Classifier.SrcPort == uint32(68) &&
670 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700671
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100672 // keep track that we received the DHCP Flows so that we can transition the state to dhcp_started
Matteo Scandolo99f18462019-10-28 14:14:28 -0700673 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700674
675 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100676 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700677 if err := o.InternalState.Event("start_dhcp"); err != nil {
678 log.Errorf("Can't go to dhcp_started: %v", err)
679 }
680 } else {
681 onuLogger.WithFields(log.Fields{
682 "IntfId": o.PonPortID,
683 "OnuId": o.ID,
684 "SerialNumber": o.Sn(),
685 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700686 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700687 }
688}
689
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700690// HexDecode converts the hex encoding to binary
691func HexDecode(pkt []byte) []byte {
692 p := make([]byte, len(pkt)/2)
693 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
694 // Go figure this ;)
695 u := (pkt[i] & 15) + (pkt[i]>>6)*9
696 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
697 p[j] = u<<4 + l
698 }
699 onuLogger.Tracef("Omci decoded: %x.", p)
700 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700701}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700702
703// BBR methods
704
705func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
706 omciMsg := openolt.OmciMsg{
707 IntfId: intfId,
708 OnuId: onuId,
709 Pkt: pktBytes,
710 }
711
712 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
713 log.WithFields(log.Fields{
714 "IntfId": intfId,
715 "OnuId": onuId,
716 "SerialNumber": common.OnuSnToString(sn),
717 "Pkt": omciMsg.Pkt,
718 }).Fatalf("Failed to send MIB Reset")
719 }
720 log.WithFields(log.Fields{
721 "IntfId": intfId,
722 "OnuId": onuId,
723 "SerialNumber": common.OnuSnToString(sn),
724 "Pkt": omciMsg.Pkt,
725 }).Tracef("Sent OMCI message %s", msgType)
726}
727
728func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
729 var next uint16
730 if len(highPriority) > 0 && highPriority[0] {
731 next = onu.hpTid
732 onu.hpTid += 1
733 if onu.hpTid < 0x8000 {
734 onu.hpTid = 0x8000
735 }
736 } else {
737 next = onu.tid
738 onu.tid += 1
739 if onu.tid >= 0x8000 {
740 onu.tid = 1
741 }
742 }
743 return next
744}
745
746// TODO move this method in responders/omcisim
747func (o *Onu) StartOmci(client openolt.OpenoltClient) {
748 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
749 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
750}
751
752func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
753 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
754
755 log.WithFields(log.Fields{
756 "IntfId": msg.OmciInd.IntfId,
757 "OnuId": msg.OmciInd.OnuId,
758 "OnuSn": common.OnuSnToString(o.SerialNumber),
759 "Pkt": msg.OmciInd.Pkt,
760 "msgType": msgType,
761 }).Trace("ONU Receveives OMCI Msg")
762 switch msgType {
763 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700764 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,
770 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700771 case omci.MibResetResponseType:
772 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
773 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
774 case omci.MibUploadResponseType:
775 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
776 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
777 case omci.MibUploadNextResponseType:
778 o.seqNumber++
779
780 if o.seqNumber > 290 {
781 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
782 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
783 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
784 } else {
785 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
786 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
787 }
788 case omci.CreateResponseType:
789 // NOTE Creating a GemPort,
790 // BBsim actually doesn't care about the values, so we can do we want with the parameters
791 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
792 // but we need the GemPort to trigger the state change
793
794 if !o.HasGemPort {
795 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
796 // thus we send this request only once
797 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
798 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
799 o.HasGemPort = true
800 } else {
801 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
802 onuLogger.WithFields(log.Fields{
803 "OnuId": o.ID,
804 "IntfId": o.PonPortID,
805 "OnuSn": o.Sn(),
806 }).Errorf("Error while transitioning ONU State %v", err)
807 }
808 }
809
810 }
811}
812
813func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
814
815 classifierProto := openolt.Classifier{
816 EthType: uint32(layers.EthernetTypeEAPOL),
817 OVid: 4091,
818 }
819
820 actionProto := openolt.Action{}
821
822 downstreamFlow := openolt.Flow{
823 AccessIntfId: int32(o.PonPortID),
824 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700825 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700826 FlowId: uint32(o.ID),
827 FlowType: "downstream",
828 AllocId: int32(0),
829 NetworkIntfId: int32(0),
830 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
831 Classifier: &classifierProto,
832 Action: &actionProto,
833 Priority: int32(100),
834 Cookie: uint64(o.ID),
835 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
836 }
837
838 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
839 log.WithFields(log.Fields{
840 "IntfId": o.PonPortID,
841 "OnuId": o.ID,
842 "FlowId": downstreamFlow.FlowId,
843 "PortNo": downstreamFlow.PortNo,
844 "SerialNumber": common.OnuSnToString(o.SerialNumber),
845 }).Fatalf("Failed to EAPOL Flow")
846 }
847 log.WithFields(log.Fields{
848 "IntfId": o.PonPortID,
849 "OnuId": o.ID,
850 "FlowId": downstreamFlow.FlowId,
851 "PortNo": downstreamFlow.PortNo,
852 "SerialNumber": common.OnuSnToString(o.SerialNumber),
853 }).Info("Sent EAPOL Flow")
854}
855
856func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
857 classifierProto := openolt.Classifier{
858 EthType: uint32(layers.EthernetTypeIPv4),
859 SrcPort: uint32(68),
860 DstPort: uint32(67),
861 }
862
863 actionProto := openolt.Action{}
864
865 downstreamFlow := openolt.Flow{
866 AccessIntfId: int32(o.PonPortID),
867 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700868 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700869 FlowId: uint32(o.ID),
870 FlowType: "downstream",
871 AllocId: int32(0),
872 NetworkIntfId: int32(0),
873 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
874 Classifier: &classifierProto,
875 Action: &actionProto,
876 Priority: int32(100),
877 Cookie: uint64(o.ID),
878 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
879 }
880
881 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
882 log.WithFields(log.Fields{
883 "IntfId": o.PonPortID,
884 "OnuId": o.ID,
885 "FlowId": downstreamFlow.FlowId,
886 "PortNo": downstreamFlow.PortNo,
887 "SerialNumber": common.OnuSnToString(o.SerialNumber),
888 }).Fatalf("Failed to send DHCP Flow")
889 }
890 log.WithFields(log.Fields{
891 "IntfId": o.PonPortID,
892 "OnuId": o.ID,
893 "FlowId": downstreamFlow.FlowId,
894 "PortNo": downstreamFlow.PortNo,
895 "SerialNumber": common.OnuSnToString(o.SerialNumber),
896 }).Info("Sent DHCP Flow")
897}