blob: 4fd18cfa9115b1538f1d6e44db44178b6318a4ac [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"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070033 "github.com/opencord/bbsim/internal/common"
34 omcilib "github.com/opencord/bbsim/internal/common/omci"
35 omcisim "github.com/opencord/omci-sim"
Matteo Scandolo3de9de02019-11-14 13:40:03 -080036 "github.com/opencord/voltha-protos/v2/go/openolt"
Matteo Scandolo4747d292019-08-05 11:50:18 -070037 log "github.com/sirupsen/logrus"
38)
39
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070040var onuLogger = log.WithFields(log.Fields{
41 "module": "ONU",
42})
43
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070044type Onu struct {
Matteo Scandoloe811ae92019-12-10 17:50:14 -080045 ID uint32
46 PonPortID uint32
47 PonPort PonPort
48 STag int
49 CTag int
50 Auth bool // automatically start EAPOL if set to true
51 Dhcp bool // automatically start DHCP if set to true
52 HwAddress net.HardwareAddr
53 InternalState *fsm.FSM
54 DiscoveryRetryDelay time.Duration
55
56 // ONU State
Matteo Scandolo27428702019-10-11 16:21:16 -070057 // PortNo comes with flows and it's used when sending packetIndications,
58 // There is one PortNo per UNI Port, for now we're only storing the first one
59 // FIXME add support for multiple UNIs
Matteo Scandolo99f18462019-10-28 14:14:28 -070060 PortNo uint32
61 DhcpFlowReceived bool
62
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070063 OperState *fsm.FSM
64 SerialNumber *openolt.SerialNumber
65
66 Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -070067
68 // OMCI params
69 tid uint16
70 hpTid uint16
71 seqNumber uint16
72 HasGemPort bool
73
74 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 -070075}
76
Matteo Scandolo99f18462019-10-28 14:14:28 -070077func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070078 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070079}
80
Matteo Scandoloc1147092019-10-29 09:38:33 -070081func CreateONU(olt OltDevice, pon PonPort, id uint32, sTag int, cTag int, auth bool, dhcp bool) *Onu {
Matteo Scandolo4747d292019-08-05 11:50:18 -070082
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070083 o := Onu{
Matteo Scandoloe811ae92019-12-10 17:50:14 -080084 ID: id,
85 PonPortID: pon.ID,
86 PonPort: pon,
87 STag: sTag,
88 CTag: cTag,
89 Auth: auth,
90 Dhcp: dhcp,
91 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
92 PortNo: 0,
93 tid: 0x1,
94 hpTid: 0x8000,
95 seqNumber: 0,
96 DoneChannel: make(chan bool, 1),
97 DhcpFlowReceived: false,
98 DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070099 }
100 o.SerialNumber = o.NewSN(olt.ID, pon.ID, o.ID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700101
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700102 // NOTE this state machine is used to track the operational
103 // state as requested by VOLTHA
104 o.OperState = getOperStateFSM(func(e *fsm.Event) {
105 onuLogger.WithFields(log.Fields{
106 "ID": o.ID,
107 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
108 })
109
110 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
111 o.InternalState = fsm.NewFSM(
112 "created",
113 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700114 // DEVICE Lifecycle
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100115 {Name: "initialize", Src: []string{"created", "disabled"}, Dst: "initialized"},
116 {Name: "discover", Src: []string{"initialized"}, Dst: "discovered"},
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700117 {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700118 {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"},
119 {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100120 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
121 {Name: "disable", Src: []string{"enabled", "eap_response_success_received", "auth_failed", "dhcp_ack_received", "dhcp_failed"}, Dst: "disabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700122 // EAPOL
Matteo Scandolo5e081b52019-11-21 14:34:25 -0800123 {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"}, Dst: "auth_started"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700124 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
125 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
126 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
127 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
128 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
129 // DHCP
Matteo Scandolofe9ac252019-10-25 11:40:17 -0700130 {Name: "start_dhcp", Src: []string{"eap_response_success_received", "dhcp_discovery_sent", "dhcp_request_sent", "dhcp_ack_received", "dhcp_failed"}, Dst: "dhcp_started"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700131 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
132 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
133 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
134 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700135 // BBR States
136 // TODO add start OMCI state
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100137 {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700138 {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700139 },
140 fsm.Callbacks{
141 "enter_state": func(e *fsm.Event) {
142 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700143 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100144 "enter_initialized": func(e *fsm.Event) {
145 // create new channel for ProcessOnuMessages Go routine
146 o.Channel = make(chan Message, 2048)
147 },
148 "enter_discovered": func(e *fsm.Event) {
149 msg := Message{
150 Type: OnuDiscIndication,
151 Data: OnuDiscIndicationMessage{
152 Onu: &o,
153 OperState: UP,
154 },
155 }
156 o.Channel <- msg
157 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700158 "enter_enabled": func(event *fsm.Event) {
159 msg := Message{
160 Type: OnuIndication,
161 Data: OnuIndicationMessage{
162 OnuSN: o.SerialNumber,
163 PonPortID: o.PonPortID,
164 OperState: UP,
165 },
166 }
167 o.Channel <- msg
168 },
169 "enter_disabled": func(event *fsm.Event) {
170 msg := Message{
171 Type: OnuIndication,
172 Data: OnuIndicationMessage{
173 OnuSN: o.SerialNumber,
174 PonPortID: o.PonPortID,
175 OperState: DOWN,
176 },
177 }
178 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100179 // terminate the ONU's ProcessOnuMessages Go routine
180 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700181 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700182 "enter_auth_started": func(e *fsm.Event) {
183 o.logStateChange(e.Src, e.Dst)
184 msg := Message{
185 Type: StartEAPOL,
186 Data: PacketMessage{
187 PonPortID: o.PonPortID,
188 OnuID: o.ID,
189 },
190 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700191 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700192 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700193 "enter_auth_failed": func(e *fsm.Event) {
194 onuLogger.WithFields(log.Fields{
195 "OnuId": o.ID,
196 "IntfId": o.PonPortID,
197 "OnuSn": o.Sn(),
198 }).Errorf("ONU failed to authenticate!")
199 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700200 "before_start_dhcp": func(e *fsm.Event) {
201 if o.DhcpFlowReceived == false {
202 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
203 }
204 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700205 "enter_dhcp_started": func(e *fsm.Event) {
206 msg := Message{
207 Type: StartDHCP,
208 Data: PacketMessage{
209 PonPortID: o.PonPortID,
210 OnuID: o.ID,
211 },
212 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700213 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700214 },
215 "enter_dhcp_failed": func(e *fsm.Event) {
216 onuLogger.WithFields(log.Fields{
217 "OnuId": o.ID,
218 "IntfId": o.PonPortID,
219 "OnuSn": o.Sn(),
220 }).Errorf("ONU failed to DHCP!")
221 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700222 "enter_eapol_flow_sent": func(e *fsm.Event) {
223 msg := Message{
224 Type: SendEapolFlow,
225 }
226 o.Channel <- msg
227 },
228 "enter_dhcp_flow_sent": func(e *fsm.Event) {
229 msg := Message{
230 Type: SendDhcpFlow,
231 }
232 o.Channel <- msg
233 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700234 },
235 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100236
Matteo Scandolo27428702019-10-11 16:21:16 -0700237 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700238}
239
William Kurkian0418bc82019-11-06 12:16:24 -0500240func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700241 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700242 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700243 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700244 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700245 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
246}
247
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100248// ProcessOnuMessages starts indication channel for each ONU
Matteo Scandolo99f18462019-10-28 14:14:28 -0700249func (o *Onu) ProcessOnuMessages(stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700250 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100251 "onuID": o.ID,
252 "onuSN": o.Sn(),
253 "ponPort": o.PonPortID,
254 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700255
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700256 for message := range o.Channel {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700257 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700258 "onuID": o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700259 "onuSN": o.Sn(),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700260 "messageType": message.Type,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700261 }).Tracef("Received message on ONU Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700262
263 switch message.Type {
264 case OnuDiscIndication:
265 msg, _ := message.Data.(OnuDiscIndicationMessage)
Matteo Scandoloe33447a2019-10-31 12:38:23 -0700266 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
267 time.Sleep(time.Duration(int(o.ID)*o.PonPort.Olt.Delay) * time.Millisecond)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700268 o.sendOnuDiscIndication(msg, stream)
269 case OnuIndication:
270 msg, _ := message.Data.(OnuIndicationMessage)
271 o.sendOnuIndication(msg, stream)
272 case OMCI:
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700273 msg, _ := message.Data.(OmciMessage)
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700274 o.handleOmciMessage(msg, stream)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700275 case FlowUpdate:
276 msg, _ := message.Data.(OnuFlowUpdateMessage)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700277 o.handleFlowUpdate(msg)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700278 case StartEAPOL:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700279 log.Infof("Receive StartEAPOL message on ONU Channel")
Matteo Scandolo27428702019-10-11 16:21:16 -0700280 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700281 case StartDHCP:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700282 log.Infof("Receive StartDHCP message on ONU Channel")
Matteo Scandolo27428702019-10-11 16:21:16 -0700283 // FIXME use id, ponId as SendEapStart
284 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700285 case OnuPacketOut:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700286
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700287 msg, _ := message.Data.(OnuPacketMessage)
288
289 log.WithFields(log.Fields{
290 "IntfId": msg.IntfId,
291 "OnuId": msg.OnuId,
292 "pktType": msg.Type,
293 }).Trace("Received OnuPacketOut Message")
294
295 if msg.Type == packetHandlers.EAPOL {
296 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
297 } else if msg.Type == packetHandlers.DHCP {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700298 // NOTE here we receive packets going from the DHCP Server to the ONU
299 // for now we expect them to be double-tagged, but ideally the should be single tagged
Matteo Scandolo27428702019-10-11 16:21:16 -0700300 dhcp.HandleNextPacket(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700301 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700302 case OnuPacketIn:
303 // NOTE we only receive BBR packets here.
304 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
305 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
306 msg, _ := message.Data.(OnuPacketMessage)
307
308 log.WithFields(log.Fields{
309 "IntfId": msg.IntfId,
310 "OnuId": msg.OnuId,
311 "pktType": msg.Type,
312 }).Trace("Received OnuPacketIn Message")
313
314 if msg.Type == packetHandlers.EAPOL {
315 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
316 } else if msg.Type == packetHandlers.DHCP {
317 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
318 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700319 case DyingGaspIndication:
320 msg, _ := message.Data.(DyingGaspIndicationMessage)
321 o.sendDyingGaspInd(msg, stream)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700322 case OmciIndication:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700323 msg, _ := message.Data.(OmciIndicationMessage)
324 o.handleOmci(msg, client)
325 case SendEapolFlow:
326 o.sendEapolFlow(client)
327 case SendDhcpFlow:
328 o.sendDhcpFlow(client)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700329 default:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700330 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700331 }
332 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100333 onuLogger.WithFields(log.Fields{
334 "onuID": o.ID,
335 "onuSN": o.Sn(),
336 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700337}
338
William Kurkian0418bc82019-11-06 12:16:24 -0500339func (o *Onu) processOmciMessage(message omcisim.OmciChMessage) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400340 switch message.Type {
341 case omcisim.GemPortAdded:
342 log.WithFields(log.Fields{
343 "OnuId": message.Data.OnuId,
344 "IntfId": message.Data.IntfId,
345 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700346
William Kurkian9dadc5b2019-10-22 13:51:57 -0400347 // NOTE if we receive the GemPort but we don't have EAPOL flows
348 // go an intermediate state, otherwise start auth
349 if o.InternalState.Is("enabled") {
350 if err := o.InternalState.Event("add_gem_port"); err != nil {
351 log.Errorf("Can't go to gem_port_added: %v", err)
352 }
353 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800354 if o.Auth == true {
355 if err := o.InternalState.Event("start_auth"); err != nil {
356 log.Warnf("Can't go to auth_started: %v", err)
357 }
358 } else {
359 onuLogger.WithFields(log.Fields{
360 "IntfId": o.PonPortID,
361 "OnuId": o.ID,
362 "SerialNumber": o.Sn(),
363 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700364 }
365 }
366 }
367}
368
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100369func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700370
371 sn := new(openolt.SerialNumber)
372
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700373 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700374 sn.VendorId = []byte("BBSM")
375 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
376
377 return sn
378}
379
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700380// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
381// send method should not change the ONU state
382
William Kurkian0418bc82019-11-06 12:16:24 -0500383func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700384 alarmData := &openolt.AlarmIndication_DyingGaspInd{
385 DyingGaspInd: &openolt.DyingGaspIndication{
386 IntfId: msg.PonPortID,
387 OnuId: msg.OnuID,
388 Status: "on",
389 },
390 }
391 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
392
393 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
394 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
395 return err
396 }
397 onuLogger.WithFields(log.Fields{
398 "IntfId": msg.PonPortID,
399 "OnuSn": o.Sn(),
400 "OnuId": msg.OnuID,
401 }).Info("sendDyingGaspInd")
402 return nil
403}
404
William Kurkian0418bc82019-11-06 12:16:24 -0500405func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700406 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700407 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700408 SerialNumber: msg.Onu.SerialNumber,
409 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700410
Matteo Scandolo4747d292019-08-05 11:50:18 -0700411 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700412 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700413 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700414 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700415
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700416 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700417 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700418 "OnuSn": msg.Onu.Sn(),
419 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700420 }).Debug("Sent Indication_OnuDiscInd")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800421
422 // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
423 go func(delay time.Duration) {
424 if o.InternalState.Current() == "discovered" {
425 time.Sleep(delay)
426 o.sendOnuDiscIndication(msg, stream)
427 }
428 }(o.DiscoveryRetryDelay)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700429}
430
William Kurkian0418bc82019-11-06 12:16:24 -0500431func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700432 // NOTE voltha returns an ID, but if we use that ID then it complains:
433 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
434 // so we're using the internal ID that is 1
435 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700436
437 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700438 IntfId: o.PonPortID,
439 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700440 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700441 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700442 SerialNumber: o.SerialNumber,
443 }}
444 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700445 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700446 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700447 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700448 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700449 "IntfId": o.PonPortID,
450 "OnuId": o.ID,
451 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700452 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700453 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700454 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700455
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700456}
457
William Kurkian0418bc82019-11-06 12:16:24 -0500458func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700459
460 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700461 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700462 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700463 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700464 }).Tracef("Received OMCI message")
465
466 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700467 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700468 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700469 onuLogger.WithFields(log.Fields{
470 "IntfId": o.PonPortID,
471 "SerialNumber": o.Sn(),
472 "omciPacket": omciInd.Pkt,
473 "msg": msg,
474 }).Errorf("Error handling OMCI message %v", msg)
475 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700476 }
477
478 omciInd.IntfId = o.PonPortID
479 omciInd.OnuId = o.ID
480 omciInd.Pkt = respPkt
481
482 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
483 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700484 onuLogger.WithFields(log.Fields{
485 "IntfId": o.PonPortID,
486 "SerialNumber": o.Sn(),
487 "omciPacket": omciInd.Pkt,
488 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700489 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700490 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700491 }
492 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700493 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700494 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700495 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700496 }).Tracef("Sent OMCI message")
497}
498
Matteo Scandolo27428702019-10-11 16:21:16 -0700499func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700500 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700501 // we need to add support for multiple UNIs
502 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700503 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700504 // - change the library so that it reports a single UNI and remove this workaroung
505 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700506 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700507 onuLogger.WithFields(log.Fields{
508 "IntfId": o.PonPortID,
509 "OnuId": o.ID,
510 "SerialNumber": o.Sn(),
511 "OnuPortNo": o.PortNo,
512 "FlowPortNo": portNo,
513 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700514 o.PortNo = portNo
515 }
516}
517
William Kurkian0418bc82019-11-06 12:16:24 -0500518func (o *Onu) SetID(id uint32) {
519 o.ID = id
520}
521
Matteo Scandolo813402b2019-10-23 19:24:52 -0700522func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700523 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700524 "DstPort": msg.Flow.Classifier.DstPort,
525 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
526 "FlowId": msg.Flow.FlowId,
527 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700528 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700529 "IntfId": msg.Flow.AccessIntfId,
530 "IpProto": msg.Flow.Classifier.IpProto,
531 "OnuId": msg.Flow.OnuId,
532 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700533 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700534 "PortNo": msg.Flow.PortNo,
535 "SrcPort": msg.Flow.Classifier.SrcPort,
536 "UniID": msg.Flow.UniId,
537 }).Debug("ONU receives Flow")
538
Matteo Scandolo813402b2019-10-23 19:24:52 -0700539 if msg.Flow.UniId != 0 {
540 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
541 onuLogger.WithFields(log.Fields{
542 "IntfId": o.PonPortID,
543 "OnuId": o.ID,
544 "SerialNumber": o.Sn(),
545 }).Debug("Ignoring flow as it's not for the first UNI")
546 return
547 }
548
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700549 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700550 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700551 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700552
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700553 // NOTE if we receive the EAPOL flows but we don't have GemPorts
554 // go an intermediate state, otherwise start auth
555 if o.InternalState.Is("enabled") {
556 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700557 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700558 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700559 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700560
561 if o.Auth == true {
562 if err := o.InternalState.Event("start_auth"); err != nil {
563 log.Warnf("Can't go to auth_started: %v", err)
564 }
565 } else {
566 onuLogger.WithFields(log.Fields{
567 "IntfId": o.PonPortID,
568 "OnuId": o.ID,
569 "SerialNumber": o.Sn(),
570 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700571 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700572
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700573 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700574 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
575 msg.Flow.Classifier.SrcPort == uint32(68) &&
576 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700577
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100578 // 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 -0700579 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700580
581 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100582 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700583 if err := o.InternalState.Event("start_dhcp"); err != nil {
584 log.Errorf("Can't go to dhcp_started: %v", err)
585 }
586 } else {
587 onuLogger.WithFields(log.Fields{
588 "IntfId": o.PonPortID,
589 "OnuId": o.ID,
590 "SerialNumber": o.Sn(),
591 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700592 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700593 }
594}
595
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700596// HexDecode converts the hex encoding to binary
597func HexDecode(pkt []byte) []byte {
598 p := make([]byte, len(pkt)/2)
599 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
600 // Go figure this ;)
601 u := (pkt[i] & 15) + (pkt[i]>>6)*9
602 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
603 p[j] = u<<4 + l
604 }
605 onuLogger.Tracef("Omci decoded: %x.", p)
606 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700607}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700608
609// BBR methods
610
611func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
612 omciMsg := openolt.OmciMsg{
613 IntfId: intfId,
614 OnuId: onuId,
615 Pkt: pktBytes,
616 }
617
618 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
619 log.WithFields(log.Fields{
620 "IntfId": intfId,
621 "OnuId": onuId,
622 "SerialNumber": common.OnuSnToString(sn),
623 "Pkt": omciMsg.Pkt,
624 }).Fatalf("Failed to send MIB Reset")
625 }
626 log.WithFields(log.Fields{
627 "IntfId": intfId,
628 "OnuId": onuId,
629 "SerialNumber": common.OnuSnToString(sn),
630 "Pkt": omciMsg.Pkt,
631 }).Tracef("Sent OMCI message %s", msgType)
632}
633
634func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
635 var next uint16
636 if len(highPriority) > 0 && highPriority[0] {
637 next = onu.hpTid
638 onu.hpTid += 1
639 if onu.hpTid < 0x8000 {
640 onu.hpTid = 0x8000
641 }
642 } else {
643 next = onu.tid
644 onu.tid += 1
645 if onu.tid >= 0x8000 {
646 onu.tid = 1
647 }
648 }
649 return next
650}
651
652// TODO move this method in responders/omcisim
653func (o *Onu) StartOmci(client openolt.OpenoltClient) {
654 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
655 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
656}
657
658func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
659 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
660
661 log.WithFields(log.Fields{
662 "IntfId": msg.OmciInd.IntfId,
663 "OnuId": msg.OmciInd.OnuId,
664 "OnuSn": common.OnuSnToString(o.SerialNumber),
665 "Pkt": msg.OmciInd.Pkt,
666 "msgType": msgType,
667 }).Trace("ONU Receveives OMCI Msg")
668 switch msgType {
669 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700670 log.WithFields(log.Fields{
671 "IntfId": msg.OmciInd.IntfId,
672 "OnuId": msg.OmciInd.OnuId,
673 "OnuSn": common.OnuSnToString(o.SerialNumber),
674 "Pkt": msg.OmciInd.Pkt,
675 "msgType": msgType,
676 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700677 case omci.MibResetResponseType:
678 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
679 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
680 case omci.MibUploadResponseType:
681 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
682 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
683 case omci.MibUploadNextResponseType:
684 o.seqNumber++
685
686 if o.seqNumber > 290 {
687 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
688 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
689 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
690 } else {
691 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
692 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
693 }
694 case omci.CreateResponseType:
695 // NOTE Creating a GemPort,
696 // BBsim actually doesn't care about the values, so we can do we want with the parameters
697 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
698 // but we need the GemPort to trigger the state change
699
700 if !o.HasGemPort {
701 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
702 // thus we send this request only once
703 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
704 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
705 o.HasGemPort = true
706 } else {
707 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
708 onuLogger.WithFields(log.Fields{
709 "OnuId": o.ID,
710 "IntfId": o.PonPortID,
711 "OnuSn": o.Sn(),
712 }).Errorf("Error while transitioning ONU State %v", err)
713 }
714 }
715
716 }
717}
718
719func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
720
721 classifierProto := openolt.Classifier{
722 EthType: uint32(layers.EthernetTypeEAPOL),
723 OVid: 4091,
724 }
725
726 actionProto := openolt.Action{}
727
728 downstreamFlow := openolt.Flow{
729 AccessIntfId: int32(o.PonPortID),
730 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700731 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700732 FlowId: uint32(o.ID),
733 FlowType: "downstream",
734 AllocId: int32(0),
735 NetworkIntfId: int32(0),
736 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
737 Classifier: &classifierProto,
738 Action: &actionProto,
739 Priority: int32(100),
740 Cookie: uint64(o.ID),
741 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
742 }
743
744 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
745 log.WithFields(log.Fields{
746 "IntfId": o.PonPortID,
747 "OnuId": o.ID,
748 "FlowId": downstreamFlow.FlowId,
749 "PortNo": downstreamFlow.PortNo,
750 "SerialNumber": common.OnuSnToString(o.SerialNumber),
751 }).Fatalf("Failed to EAPOL Flow")
752 }
753 log.WithFields(log.Fields{
754 "IntfId": o.PonPortID,
755 "OnuId": o.ID,
756 "FlowId": downstreamFlow.FlowId,
757 "PortNo": downstreamFlow.PortNo,
758 "SerialNumber": common.OnuSnToString(o.SerialNumber),
759 }).Info("Sent EAPOL Flow")
760}
761
762func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
763 classifierProto := openolt.Classifier{
764 EthType: uint32(layers.EthernetTypeIPv4),
765 SrcPort: uint32(68),
766 DstPort: uint32(67),
767 }
768
769 actionProto := openolt.Action{}
770
771 downstreamFlow := openolt.Flow{
772 AccessIntfId: int32(o.PonPortID),
773 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700774 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700775 FlowId: uint32(o.ID),
776 FlowType: "downstream",
777 AllocId: int32(0),
778 NetworkIntfId: int32(0),
779 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
780 Classifier: &classifierProto,
781 Action: &actionProto,
782 Priority: int32(100),
783 Cookie: uint64(o.ID),
784 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
785 }
786
787 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
788 log.WithFields(log.Fields{
789 "IntfId": o.PonPortID,
790 "OnuId": o.ID,
791 "FlowId": downstreamFlow.FlowId,
792 "PortNo": downstreamFlow.PortNo,
793 "SerialNumber": common.OnuSnToString(o.SerialNumber),
794 }).Fatalf("Failed to send DHCP Flow")
795 }
796 log.WithFields(log.Fields{
797 "IntfId": o.PonPortID,
798 "OnuId": o.ID,
799 "FlowId": downstreamFlow.FlowId,
800 "PortNo": downstreamFlow.PortNo,
801 "SerialNumber": common.OnuSnToString(o.SerialNumber),
802 }).Info("Sent DHCP Flow")
803}