blob: a93843395a1d4dfd0ee9dbda338d254bab4746ab [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 Scandolo27428702019-10-11 16:21:16 -070045 ID uint32
46 PonPortID uint32
47 PonPort PonPort
48 STag int
49 CTag int
Matteo Scandoloc1147092019-10-29 09:38:33 -070050 Auth bool // automatically start EAPOL if set to true
51 Dhcp bool // automatically start DHCP if set to true
Matteo Scandolo27428702019-10-11 16:21:16 -070052 // PortNo comes with flows and it's used when sending packetIndications,
53 // There is one PortNo per UNI Port, for now we're only storing the first one
54 // FIXME add support for multiple UNIs
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070055 HwAddress net.HardwareAddr
56 InternalState *fsm.FSM
57
Matteo Scandolo99f18462019-10-28 14:14:28 -070058 // ONU State
59 PortNo uint32
60 DhcpFlowReceived bool
61
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070062 OperState *fsm.FSM
63 SerialNumber *openolt.SerialNumber
64
65 Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
Matteo Scandolo40e067f2019-10-16 16:59:41 -070066
67 // OMCI params
68 tid uint16
69 hpTid uint16
70 seqNumber uint16
71 HasGemPort bool
72
73 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 -070074}
75
Matteo Scandolo99f18462019-10-28 14:14:28 -070076func (o *Onu) Sn() string {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070077 return common.OnuSnToString(o.SerialNumber)
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070078}
79
Matteo Scandoloc1147092019-10-29 09:38:33 -070080func CreateONU(olt OltDevice, pon PonPort, id uint32, sTag int, cTag int, auth bool, dhcp bool) *Onu {
Matteo Scandolo4747d292019-08-05 11:50:18 -070081
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070082 o := Onu{
Matteo Scandolo99f18462019-10-28 14:14:28 -070083 ID: id,
84 PonPortID: pon.ID,
85 PonPort: pon,
86 STag: sTag,
87 CTag: cTag,
Matteo Scandoloc1147092019-10-29 09:38:33 -070088 Auth: auth,
89 Dhcp: dhcp,
Matteo Scandolo99f18462019-10-28 14:14:28 -070090 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
91 PortNo: 0,
Matteo Scandolo99f18462019-10-28 14:14:28 -070092 tid: 0x1,
93 hpTid: 0x8000,
94 seqNumber: 0,
95 DoneChannel: make(chan bool, 1),
96 DhcpFlowReceived: false,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070097 }
98 o.SerialNumber = o.NewSN(olt.ID, pon.ID, o.ID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070099
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700100 // NOTE this state machine is used to track the operational
101 // state as requested by VOLTHA
102 o.OperState = getOperStateFSM(func(e *fsm.Event) {
103 onuLogger.WithFields(log.Fields{
104 "ID": o.ID,
105 }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst)
106 })
107
108 // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients
109 o.InternalState = fsm.NewFSM(
110 "created",
111 fsm.Events{
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700112 // DEVICE Lifecycle
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100113 {Name: "initialize", Src: []string{"created", "disabled"}, Dst: "initialized"},
114 {Name: "discover", Src: []string{"initialized"}, Dst: "discovered"},
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700115 {Name: "enable", Src: []string{"discovered", "disabled"}, Dst: "enabled"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700116 {Name: "receive_eapol_flow", Src: []string{"enabled", "gem_port_added"}, Dst: "eapol_flow_received"},
117 {Name: "add_gem_port", Src: []string{"enabled", "eapol_flow_received"}, Dst: "gem_port_added"},
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100118 // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)?
119 {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 -0700120 // EAPOL
Matteo Scandolo5e081b52019-11-21 14:34:25 -0800121 {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 -0700122 {Name: "eap_start_sent", Src: []string{"auth_started"}, Dst: "eap_start_sent"},
123 {Name: "eap_response_identity_sent", Src: []string{"eap_start_sent"}, Dst: "eap_response_identity_sent"},
124 {Name: "eap_response_challenge_sent", Src: []string{"eap_response_identity_sent"}, Dst: "eap_response_challenge_sent"},
125 {Name: "eap_response_success_received", Src: []string{"eap_response_challenge_sent"}, Dst: "eap_response_success_received"},
126 {Name: "auth_failed", Src: []string{"auth_started", "eap_start_sent", "eap_response_identity_sent", "eap_response_challenge_sent"}, Dst: "auth_failed"},
127 // DHCP
Matteo Scandolofe9ac252019-10-25 11:40:17 -0700128 {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 -0700129 {Name: "dhcp_discovery_sent", Src: []string{"dhcp_started"}, Dst: "dhcp_discovery_sent"},
130 {Name: "dhcp_request_sent", Src: []string{"dhcp_discovery_sent"}, Dst: "dhcp_request_sent"},
131 {Name: "dhcp_ack_received", Src: []string{"dhcp_request_sent"}, Dst: "dhcp_ack_received"},
132 {Name: "dhcp_failed", Src: []string{"dhcp_started", "dhcp_discovery_sent", "dhcp_request_sent"}, Dst: "dhcp_failed"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700133 // BBR States
134 // TODO add start OMCI state
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100135 {Name: "send_eapol_flow", Src: []string{"initialized"}, Dst: "eapol_flow_sent"},
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700136 {Name: "send_dhcp_flow", Src: []string{"eapol_flow_sent"}, Dst: "dhcp_flow_sent"},
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700137 },
138 fsm.Callbacks{
139 "enter_state": func(e *fsm.Event) {
140 o.logStateChange(e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700141 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100142 "enter_initialized": func(e *fsm.Event) {
143 // create new channel for ProcessOnuMessages Go routine
144 o.Channel = make(chan Message, 2048)
145 },
146 "enter_discovered": func(e *fsm.Event) {
147 msg := Message{
148 Type: OnuDiscIndication,
149 Data: OnuDiscIndicationMessage{
150 Onu: &o,
151 OperState: UP,
152 },
153 }
154 o.Channel <- msg
155 },
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700156 "enter_enabled": func(event *fsm.Event) {
157 msg := Message{
158 Type: OnuIndication,
159 Data: OnuIndicationMessage{
160 OnuSN: o.SerialNumber,
161 PonPortID: o.PonPortID,
162 OperState: UP,
163 },
164 }
165 o.Channel <- msg
166 },
167 "enter_disabled": func(event *fsm.Event) {
168 msg := Message{
169 Type: OnuIndication,
170 Data: OnuIndicationMessage{
171 OnuSN: o.SerialNumber,
172 PonPortID: o.PonPortID,
173 OperState: DOWN,
174 },
175 }
176 o.Channel <- msg
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100177 // terminate the ONU's ProcessOnuMessages Go routine
178 close(o.Channel)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700179 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700180 "enter_auth_started": func(e *fsm.Event) {
181 o.logStateChange(e.Src, e.Dst)
182 msg := Message{
183 Type: StartEAPOL,
184 Data: PacketMessage{
185 PonPortID: o.PonPortID,
186 OnuID: o.ID,
187 },
188 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700189 o.Channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700190 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700191 "enter_auth_failed": func(e *fsm.Event) {
192 onuLogger.WithFields(log.Fields{
193 "OnuId": o.ID,
194 "IntfId": o.PonPortID,
195 "OnuSn": o.Sn(),
196 }).Errorf("ONU failed to authenticate!")
197 },
Matteo Scandolo99f18462019-10-28 14:14:28 -0700198 "before_start_dhcp": func(e *fsm.Event) {
199 if o.DhcpFlowReceived == false {
200 e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
201 }
202 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700203 "enter_dhcp_started": func(e *fsm.Event) {
204 msg := Message{
205 Type: StartDHCP,
206 Data: PacketMessage{
207 PonPortID: o.PonPortID,
208 OnuID: o.ID,
209 },
210 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700211 o.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700212 },
213 "enter_dhcp_failed": func(e *fsm.Event) {
214 onuLogger.WithFields(log.Fields{
215 "OnuId": o.ID,
216 "IntfId": o.PonPortID,
217 "OnuSn": o.Sn(),
218 }).Errorf("ONU failed to DHCP!")
219 },
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700220 "enter_eapol_flow_sent": func(e *fsm.Event) {
221 msg := Message{
222 Type: SendEapolFlow,
223 }
224 o.Channel <- msg
225 },
226 "enter_dhcp_flow_sent": func(e *fsm.Event) {
227 msg := Message{
228 Type: SendDhcpFlow,
229 }
230 o.Channel <- msg
231 },
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700232 },
233 )
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100234
Matteo Scandolo27428702019-10-11 16:21:16 -0700235 return &o
Matteo Scandolo4747d292019-08-05 11:50:18 -0700236}
237
William Kurkian0418bc82019-11-06 12:16:24 -0500238func (o *Onu) logStateChange(src string, dst string) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700239 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700240 "OnuId": o.ID,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700241 "IntfId": o.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700242 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700243 }).Debugf("Changing ONU InternalState from %s to %s", src, dst)
244}
245
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100246// ProcessOnuMessages starts indication channel for each ONU
Matteo Scandolo99f18462019-10-28 14:14:28 -0700247func (o *Onu) ProcessOnuMessages(stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700248 onuLogger.WithFields(log.Fields{
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100249 "onuID": o.ID,
250 "onuSN": o.Sn(),
251 "ponPort": o.PonPortID,
252 }).Debug("Starting ONU Indication Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700253
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700254 for message := range o.Channel {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700255 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700256 "onuID": o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700257 "onuSN": o.Sn(),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700258 "messageType": message.Type,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700259 }).Tracef("Received message on ONU Channel")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700260
261 switch message.Type {
262 case OnuDiscIndication:
263 msg, _ := message.Data.(OnuDiscIndicationMessage)
Matteo Scandoloe33447a2019-10-31 12:38:23 -0700264 // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
265 time.Sleep(time.Duration(int(o.ID)*o.PonPort.Olt.Delay) * time.Millisecond)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700266 o.sendOnuDiscIndication(msg, stream)
267 case OnuIndication:
268 msg, _ := message.Data.(OnuIndicationMessage)
269 o.sendOnuIndication(msg, stream)
270 case OMCI:
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700271 msg, _ := message.Data.(OmciMessage)
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700272 o.handleOmciMessage(msg, stream)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700273 case FlowUpdate:
274 msg, _ := message.Data.(OnuFlowUpdateMessage)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700275 o.handleFlowUpdate(msg)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700276 case StartEAPOL:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700277 log.Infof("Receive StartEAPOL message on ONU Channel")
Matteo Scandolo27428702019-10-11 16:21:16 -0700278 eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700279 case StartDHCP:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700280 log.Infof("Receive StartDHCP message on ONU Channel")
Matteo Scandolo27428702019-10-11 16:21:16 -0700281 // FIXME use id, ponId as SendEapStart
282 dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700283 case OnuPacketOut:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700284
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700285 msg, _ := message.Data.(OnuPacketMessage)
286
287 log.WithFields(log.Fields{
288 "IntfId": msg.IntfId,
289 "OnuId": msg.OnuId,
290 "pktType": msg.Type,
291 }).Trace("Received OnuPacketOut Message")
292
293 if msg.Type == packetHandlers.EAPOL {
294 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
295 } else if msg.Type == packetHandlers.DHCP {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700296 // NOTE here we receive packets going from the DHCP Server to the ONU
297 // for now we expect them to be double-tagged, but ideally the should be single tagged
Matteo Scandolo27428702019-10-11 16:21:16 -0700298 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 -0700299 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700300 case OnuPacketIn:
301 // NOTE we only receive BBR packets here.
302 // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
303 // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
304 msg, _ := message.Data.(OnuPacketMessage)
305
306 log.WithFields(log.Fields{
307 "IntfId": msg.IntfId,
308 "OnuId": msg.OnuId,
309 "pktType": msg.Type,
310 }).Trace("Received OnuPacketIn Message")
311
312 if msg.Type == packetHandlers.EAPOL {
313 eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
314 } else if msg.Type == packetHandlers.DHCP {
315 dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
316 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700317 case DyingGaspIndication:
318 msg, _ := message.Data.(DyingGaspIndicationMessage)
319 o.sendDyingGaspInd(msg, stream)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700320 case OmciIndication:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700321 msg, _ := message.Data.(OmciIndicationMessage)
322 o.handleOmci(msg, client)
323 case SendEapolFlow:
324 o.sendEapolFlow(client)
325 case SendDhcpFlow:
326 o.sendDhcpFlow(client)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700327 default:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700328 onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700329 }
330 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100331 onuLogger.WithFields(log.Fields{
332 "onuID": o.ID,
333 "onuSN": o.Sn(),
334 }).Debug("Stopped handling ONU Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700335}
336
William Kurkian0418bc82019-11-06 12:16:24 -0500337func (o *Onu) processOmciMessage(message omcisim.OmciChMessage) {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400338 switch message.Type {
339 case omcisim.GemPortAdded:
340 log.WithFields(log.Fields{
341 "OnuId": message.Data.OnuId,
342 "IntfId": message.Data.IntfId,
343 }).Infof("GemPort Added")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700344
William Kurkian9dadc5b2019-10-22 13:51:57 -0400345 // NOTE if we receive the GemPort but we don't have EAPOL flows
346 // go an intermediate state, otherwise start auth
347 if o.InternalState.Is("enabled") {
348 if err := o.InternalState.Event("add_gem_port"); err != nil {
349 log.Errorf("Can't go to gem_port_added: %v", err)
350 }
351 } else if o.InternalState.Is("eapol_flow_received") {
Matteo Scandolo3c656a12019-12-10 09:54:51 -0800352 if o.Auth == true {
353 if err := o.InternalState.Event("start_auth"); err != nil {
354 log.Warnf("Can't go to auth_started: %v", err)
355 }
356 } else {
357 onuLogger.WithFields(log.Fields{
358 "IntfId": o.PonPortID,
359 "OnuId": o.ID,
360 "SerialNumber": o.Sn(),
361 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700362 }
363 }
364 }
365}
366
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100367func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700368
369 sn := new(openolt.SerialNumber)
370
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700371 //sn = new(openolt.SerialNumber)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700372 sn.VendorId = []byte("BBSM")
373 sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
374
375 return sn
376}
377
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700378// NOTE handle_/process methods can change the ONU internal state as they are receiving messages
379// send method should not change the ONU state
380
William Kurkian0418bc82019-11-06 12:16:24 -0500381func (o *Onu) sendDyingGaspInd(msg DyingGaspIndicationMessage, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700382 alarmData := &openolt.AlarmIndication_DyingGaspInd{
383 DyingGaspInd: &openolt.DyingGaspIndication{
384 IntfId: msg.PonPortID,
385 OnuId: msg.OnuID,
386 Status: "on",
387 },
388 }
389 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
390
391 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
392 onuLogger.Errorf("Failed to send DyingGaspInd : %v", err)
393 return err
394 }
395 onuLogger.WithFields(log.Fields{
396 "IntfId": msg.PonPortID,
397 "OnuSn": o.Sn(),
398 "OnuId": msg.OnuID,
399 }).Info("sendDyingGaspInd")
400 return nil
401}
402
William Kurkian0418bc82019-11-06 12:16:24 -0500403func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700404 discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700405 IntfId: msg.Onu.PonPortID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700406 SerialNumber: msg.Onu.SerialNumber,
407 }}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700408
Matteo Scandolo4747d292019-08-05 11:50:18 -0700409 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700410 log.Errorf("Failed to send Indication_OnuDiscInd: %v", err)
Matteo Scandolo99f18462019-10-28 14:14:28 -0700411 return
Matteo Scandolo4747d292019-08-05 11:50:18 -0700412 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700413
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700414 onuLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700415 "IntfId": msg.Onu.PonPortID,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700416 "OnuSn": msg.Onu.Sn(),
417 "OnuId": o.ID,
Matteo Scandolo4747d292019-08-05 11:50:18 -0700418 }).Debug("Sent Indication_OnuDiscInd")
419}
420
William Kurkian0418bc82019-11-06 12:16:24 -0500421func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700422 // NOTE voltha returns an ID, but if we use that ID then it complains:
423 // expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
424 // so we're using the internal ID that is 1
425 // o.ID = msg.OnuID
Matteo Scandolo4747d292019-08-05 11:50:18 -0700426
427 indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700428 IntfId: o.PonPortID,
429 OnuId: o.ID,
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700430 OperState: msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700431 AdminState: o.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700432 SerialNumber: o.SerialNumber,
433 }}
434 if err := stream.Send(&openolt.Indication{Data: indData}); err != nil {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700435 // TODO do we need to transition to a broken state?
Matteo Scandolo11006992019-08-28 11:29:46 -0700436 log.Errorf("Failed to send Indication_OnuInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700437 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700438 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700439 "IntfId": o.PonPortID,
440 "OnuId": o.ID,
441 "OperState": msg.OperState.String(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700442 "AdminState": msg.OperState.String(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700443 "OnuSn": o.Sn(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700444 }).Debug("Sent Indication_OnuInd")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700445
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700446}
447
William Kurkian0418bc82019-11-06 12:16:24 -0500448func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700449
450 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700451 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700452 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700453 "omciPacket": msg.omciMsg.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700454 }).Tracef("Received OMCI message")
455
456 var omciInd openolt.OmciIndication
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700457 respPkt, err := omcisim.OmciSim(o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700458 if err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700459 onuLogger.WithFields(log.Fields{
460 "IntfId": o.PonPortID,
461 "SerialNumber": o.Sn(),
462 "omciPacket": omciInd.Pkt,
463 "msg": msg,
464 }).Errorf("Error handling OMCI message %v", msg)
465 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700466 }
467
468 omciInd.IntfId = o.PonPortID
469 omciInd.OnuId = o.ID
470 omciInd.Pkt = respPkt
471
472 omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
473 if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
Matteo Scandolo27428702019-10-11 16:21:16 -0700474 onuLogger.WithFields(log.Fields{
475 "IntfId": o.PonPortID,
476 "SerialNumber": o.Sn(),
477 "omciPacket": omciInd.Pkt,
478 "msg": msg,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700479 }).Errorf("send omcisim indication failed: %v", err)
Matteo Scandolo27428702019-10-11 16:21:16 -0700480 return
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700481 }
482 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700483 "IntfId": o.PonPortID,
Matteo Scandolo27428702019-10-11 16:21:16 -0700484 "SerialNumber": o.Sn(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700485 "omciPacket": omciInd.Pkt,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700486 }).Tracef("Sent OMCI message")
487}
488
Matteo Scandolo27428702019-10-11 16:21:16 -0700489func (o *Onu) storePortNumber(portNo uint32) {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700490 // NOTE this needed only as long as we don't support multiple UNIs
Matteo Scandolo27428702019-10-11 16:21:16 -0700491 // we need to add support for multiple UNIs
492 // the action plan is:
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700493 // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages
Matteo Scandolo27428702019-10-11 16:21:16 -0700494 // - change the library so that it reports a single UNI and remove this workaroung
495 // - add support for multiple UNIs in BBSim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700496 if o.PortNo == 0 || portNo < o.PortNo {
Matteo Scandolo813402b2019-10-23 19:24:52 -0700497 onuLogger.WithFields(log.Fields{
498 "IntfId": o.PonPortID,
499 "OnuId": o.ID,
500 "SerialNumber": o.Sn(),
501 "OnuPortNo": o.PortNo,
502 "FlowPortNo": portNo,
503 }).Debug("Storing ONU portNo")
Matteo Scandolo27428702019-10-11 16:21:16 -0700504 o.PortNo = portNo
505 }
506}
507
William Kurkian0418bc82019-11-06 12:16:24 -0500508func (o *Onu) SetID(id uint32) {
509 o.ID = id
510}
511
Matteo Scandolo813402b2019-10-23 19:24:52 -0700512func (o *Onu) handleFlowUpdate(msg OnuFlowUpdateMessage) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700513 onuLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700514 "DstPort": msg.Flow.Classifier.DstPort,
515 "EthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType),
516 "FlowId": msg.Flow.FlowId,
517 "FlowType": msg.Flow.FlowType,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700518 "InnerVlan": msg.Flow.Classifier.IVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700519 "IntfId": msg.Flow.AccessIntfId,
520 "IpProto": msg.Flow.Classifier.IpProto,
521 "OnuId": msg.Flow.OnuId,
522 "OnuSn": o.Sn(),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700523 "OuterVlan": msg.Flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700524 "PortNo": msg.Flow.PortNo,
525 "SrcPort": msg.Flow.Classifier.SrcPort,
526 "UniID": msg.Flow.UniId,
527 }).Debug("ONU receives Flow")
528
Matteo Scandolo813402b2019-10-23 19:24:52 -0700529 if msg.Flow.UniId != 0 {
530 // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it
531 onuLogger.WithFields(log.Fields{
532 "IntfId": o.PonPortID,
533 "OnuId": o.ID,
534 "SerialNumber": o.Sn(),
535 }).Debug("Ignoring flow as it's not for the first UNI")
536 return
537 }
538
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700539 if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 {
Matteo Scandolo27428702019-10-11 16:21:16 -0700540 // NOTE storing the PortNO, it's needed when sending PacketIndications
Matteo Scandolo813402b2019-10-23 19:24:52 -0700541 o.storePortNumber(uint32(msg.Flow.PortNo))
Matteo Scandolo27428702019-10-11 16:21:16 -0700542
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700543 // NOTE if we receive the EAPOL flows but we don't have GemPorts
544 // go an intermediate state, otherwise start auth
545 if o.InternalState.Is("enabled") {
546 if err := o.InternalState.Event("receive_eapol_flow"); err != nil {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700547 log.Warnf("Can't go to eapol_flow_received: %v", err)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700548 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700549 } else if o.InternalState.Is("gem_port_added") {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700550
551 if o.Auth == true {
552 if err := o.InternalState.Event("start_auth"); err != nil {
553 log.Warnf("Can't go to auth_started: %v", err)
554 }
555 } else {
556 onuLogger.WithFields(log.Fields{
557 "IntfId": o.PonPortID,
558 "OnuId": o.ID,
559 "SerialNumber": o.Sn(),
560 }).Warn("Not starting authentication as Auth bit is not set in CLI parameters")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700561 }
Matteo Scandoloc1147092019-10-29 09:38:33 -0700562
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700563 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700564 } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) &&
565 msg.Flow.Classifier.SrcPort == uint32(68) &&
566 msg.Flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700567
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100568 // 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 -0700569 o.DhcpFlowReceived = true
Matteo Scandoloc1147092019-10-29 09:38:33 -0700570
571 if o.Dhcp == true {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100572 // NOTE we are receiving multiple DHCP flows but we shouldn't call the transition multiple times
Matteo Scandoloc1147092019-10-29 09:38:33 -0700573 if err := o.InternalState.Event("start_dhcp"); err != nil {
574 log.Errorf("Can't go to dhcp_started: %v", err)
575 }
576 } else {
577 onuLogger.WithFields(log.Fields{
578 "IntfId": o.PonPortID,
579 "OnuId": o.ID,
580 "SerialNumber": o.Sn(),
581 }).Warn("Not starting DHCP as Dhcp bit is not set in CLI parameters")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700582 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700583 }
584}
585
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700586// HexDecode converts the hex encoding to binary
587func HexDecode(pkt []byte) []byte {
588 p := make([]byte, len(pkt)/2)
589 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
590 // Go figure this ;)
591 u := (pkt[i] & 15) + (pkt[i]>>6)*9
592 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
593 p[j] = u<<4 + l
594 }
595 onuLogger.Tracef("Omci decoded: %x.", p)
596 return p
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700597}
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700598
599// BBR methods
600
601func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
602 omciMsg := openolt.OmciMsg{
603 IntfId: intfId,
604 OnuId: onuId,
605 Pkt: pktBytes,
606 }
607
608 if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil {
609 log.WithFields(log.Fields{
610 "IntfId": intfId,
611 "OnuId": onuId,
612 "SerialNumber": common.OnuSnToString(sn),
613 "Pkt": omciMsg.Pkt,
614 }).Fatalf("Failed to send MIB Reset")
615 }
616 log.WithFields(log.Fields{
617 "IntfId": intfId,
618 "OnuId": onuId,
619 "SerialNumber": common.OnuSnToString(sn),
620 "Pkt": omciMsg.Pkt,
621 }).Tracef("Sent OMCI message %s", msgType)
622}
623
624func (onu *Onu) getNextTid(highPriority ...bool) uint16 {
625 var next uint16
626 if len(highPriority) > 0 && highPriority[0] {
627 next = onu.hpTid
628 onu.hpTid += 1
629 if onu.hpTid < 0x8000 {
630 onu.hpTid = 0x8000
631 }
632 } else {
633 next = onu.tid
634 onu.tid += 1
635 if onu.tid >= 0x8000 {
636 onu.tid = 1
637 }
638 }
639 return next
640}
641
642// TODO move this method in responders/omcisim
643func (o *Onu) StartOmci(client openolt.OpenoltClient) {
644 mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false))
645 sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
646}
647
648func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
649 msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
650
651 log.WithFields(log.Fields{
652 "IntfId": msg.OmciInd.IntfId,
653 "OnuId": msg.OmciInd.OnuId,
654 "OnuSn": common.OnuSnToString(o.SerialNumber),
655 "Pkt": msg.OmciInd.Pkt,
656 "msgType": msgType,
657 }).Trace("ONU Receveives OMCI Msg")
658 switch msgType {
659 default:
Matteo Scandolo813402b2019-10-23 19:24:52 -0700660 log.WithFields(log.Fields{
661 "IntfId": msg.OmciInd.IntfId,
662 "OnuId": msg.OmciInd.OnuId,
663 "OnuSn": common.OnuSnToString(o.SerialNumber),
664 "Pkt": msg.OmciInd.Pkt,
665 "msgType": msgType,
666 }).Fatalf("unexpected frame: %v", packet)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700667 case omci.MibResetResponseType:
668 mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
669 sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client)
670 case omci.MibUploadResponseType:
671 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
672 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
673 case omci.MibUploadNextResponseType:
674 o.seqNumber++
675
676 if o.seqNumber > 290 {
677 // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to)
678 galEnet, _ := omcilib.CreateGalEnetRequest(o.getNextTid(false))
679 sendOmciMsg(galEnet, o.PonPortID, o.ID, o.SerialNumber, "CreateGalEnetRequest", client)
680 } else {
681 mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber)
682 sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client)
683 }
684 case omci.CreateResponseType:
685 // NOTE Creating a GemPort,
686 // BBsim actually doesn't care about the values, so we can do we want with the parameters
687 // In the same way we can create a GemPort even without setting up UNIs/TConts/...
688 // but we need the GemPort to trigger the state change
689
690 if !o.HasGemPort {
691 // NOTE this sends a CreateRequestType and BBSim replies with a CreateResponseType
692 // thus we send this request only once
693 gemReq, _ := omcilib.CreateGemPortRequest(o.getNextTid(false))
694 sendOmciMsg(gemReq, o.PonPortID, o.ID, o.SerialNumber, "CreateGemPortRequest", client)
695 o.HasGemPort = true
696 } else {
697 if err := o.InternalState.Event("send_eapol_flow"); err != nil {
698 onuLogger.WithFields(log.Fields{
699 "OnuId": o.ID,
700 "IntfId": o.PonPortID,
701 "OnuSn": o.Sn(),
702 }).Errorf("Error while transitioning ONU State %v", err)
703 }
704 }
705
706 }
707}
708
709func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) {
710
711 classifierProto := openolt.Classifier{
712 EthType: uint32(layers.EthernetTypeEAPOL),
713 OVid: 4091,
714 }
715
716 actionProto := openolt.Action{}
717
718 downstreamFlow := openolt.Flow{
719 AccessIntfId: int32(o.PonPortID),
720 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700721 UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700722 FlowId: uint32(o.ID),
723 FlowType: "downstream",
724 AllocId: int32(0),
725 NetworkIntfId: int32(0),
726 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
727 Classifier: &classifierProto,
728 Action: &actionProto,
729 Priority: int32(100),
730 Cookie: uint64(o.ID),
731 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
732 }
733
734 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
735 log.WithFields(log.Fields{
736 "IntfId": o.PonPortID,
737 "OnuId": o.ID,
738 "FlowId": downstreamFlow.FlowId,
739 "PortNo": downstreamFlow.PortNo,
740 "SerialNumber": common.OnuSnToString(o.SerialNumber),
741 }).Fatalf("Failed to EAPOL Flow")
742 }
743 log.WithFields(log.Fields{
744 "IntfId": o.PonPortID,
745 "OnuId": o.ID,
746 "FlowId": downstreamFlow.FlowId,
747 "PortNo": downstreamFlow.PortNo,
748 "SerialNumber": common.OnuSnToString(o.SerialNumber),
749 }).Info("Sent EAPOL Flow")
750}
751
752func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) {
753 classifierProto := openolt.Classifier{
754 EthType: uint32(layers.EthernetTypeIPv4),
755 SrcPort: uint32(68),
756 DstPort: uint32(67),
757 }
758
759 actionProto := openolt.Action{}
760
761 downstreamFlow := openolt.Flow{
762 AccessIntfId: int32(o.PonPortID),
763 OnuId: int32(o.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700764 UniId: int32(0), // FIXME do not hardcode this
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700765 FlowId: uint32(o.ID),
766 FlowType: "downstream",
767 AllocId: int32(0),
768 NetworkIntfId: int32(0),
769 GemportId: int32(1), // FIXME use the same value as CreateGemPortRequest PortID, do not hardcode
770 Classifier: &classifierProto,
771 Action: &actionProto,
772 Priority: int32(100),
773 Cookie: uint64(o.ID),
774 PortNo: uint32(o.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
775 }
776
777 if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil {
778 log.WithFields(log.Fields{
779 "IntfId": o.PonPortID,
780 "OnuId": o.ID,
781 "FlowId": downstreamFlow.FlowId,
782 "PortNo": downstreamFlow.PortNo,
783 "SerialNumber": common.OnuSnToString(o.SerialNumber),
784 }).Fatalf("Failed to send DHCP Flow")
785 }
786 log.WithFields(log.Fields{
787 "IntfId": o.PonPortID,
788 "OnuId": o.ID,
789 "FlowId": downstreamFlow.FlowId,
790 "PortNo": downstreamFlow.PortNo,
791 "SerialNumber": common.OnuSnToString(o.SerialNumber),
792 }).Info("Sent DHCP Flow")
793}