blob: 6ce09a1d8f33d16c5d8ec786e801570f4af91ba1 [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 (
20 "context"
21 "errors"
22 "fmt"
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070023 bbsim "github.com/opencord/bbsim/internal/bbsim/types"
24 "github.com/google/gopacket"
25 "github.com/google/gopacket/layers"
Matteo Scandolo4747d292019-08-05 11:50:18 -070026 "github.com/looplab/fsm"
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070027 "github.com/opencord/voltha-protos/go/openolt"
Matteo Scandolod54283a2019-08-13 16:22:31 -070028 "github.com/opencord/voltha-protos/go/tech_profile"
Matteo Scandolo4747d292019-08-05 11:50:18 -070029 log "github.com/sirupsen/logrus"
30 "google.golang.org/grpc"
31 "net"
32 "sync"
33)
34
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070035var oltLogger = log.WithFields(log.Fields{
Matteo Scandolo84f7d482019-08-08 19:00:47 -070036 "module": "OLT",
37})
38
Matteo Scandolo4747d292019-08-05 11:50:18 -070039func init() {
40 //log.SetReportCaller(true)
41 log.SetLevel(log.DebugLevel)
42}
43
Matteo Scandolo84f7d482019-08-08 19:00:47 -070044var olt = OltDevice{}
45
46func GetOLT() OltDevice {
47 return olt
48}
49
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070050func CreateOLT(seq int, nni int, pon int, onuPerPon int, oltDoneChannel *chan bool, apiDoneChannel *chan bool, group *sync.WaitGroup) OltDevice {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070051 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -070052 "ID": seq,
53 "NumNni":nni,
54 "NumPon":pon,
55 "NumOnuPerPon":onuPerPon,
56 }).Debug("CreateOLT")
57
Matteo Scandolo84f7d482019-08-08 19:00:47 -070058 olt = OltDevice{
Matteo Scandolo4747d292019-08-05 11:50:18 -070059 ID: seq,
Matteo Scandolo8df63df2019-09-12 10:34:32 -070060 SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", seq),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070061 OperState: getOperStateFSM(func(e *fsm.Event) {
62 oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst)
63 }),
Matteo Scandolo4747d292019-08-05 11:50:18 -070064 NumNni:nni,
65 NumPon:pon,
66 NumOnuPerPon:onuPerPon,
67 Pons: []PonPort{},
68 Nnis: []NniPort{},
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070069 channel: make(chan Message),
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070070 oltDoneChannel: oltDoneChannel,
71 apiDoneChannel: apiDoneChannel,
Matteo Scandolo4747d292019-08-05 11:50:18 -070072 }
73
74 // OLT State machine
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070075 // NOTE do we need 2 state machines for the OLT? (InternalState and OperState)
Matteo Scandolo4747d292019-08-05 11:50:18 -070076 olt.InternalState = fsm.NewFSM(
77 "created",
78 fsm.Events{
79 {Name: "enable", Src: []string{"created"}, Dst: "enabled"},
80 {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"},
81 },
82 fsm.Callbacks{
83 "enter_state": func(e *fsm.Event) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070084 oltLogger.Debugf("Changing OLT InternalState from %s to %s", e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -070085 },
86 },
87 )
88
89 // create NNI Port
90 nniPort := NniPort{
91 ID: uint32(0),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070092 OperState: getOperStateFSM(func(e *fsm.Event) {
93 oltLogger.Debugf("Changing NNI OperState from %s to %s", e.Src, e.Dst)
94 }),
Matteo Scandolo4747d292019-08-05 11:50:18 -070095 Type: "nni",
96 }
97 olt.Nnis = append(olt.Nnis, nniPort)
98
99 // create PON ports
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700100 //onuId := 1
Matteo Scandolo4747d292019-08-05 11:50:18 -0700101 for i := 0; i < pon; i++ {
102 p := PonPort{
103 NumOnu: olt.NumOnuPerPon,
104 ID: uint32(i),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700105 Type: "pon",
106 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700107 p.OperState = getOperStateFSM(func(e *fsm.Event) {
108 oltLogger.WithFields(log.Fields{
109 "ID": p.ID,
110 }).Debugf("Changing PON Port OperState from %s to %s", e.Src, e.Dst)
111 })
Matteo Scandolo4747d292019-08-05 11:50:18 -0700112
113 // create ONU devices
114 for j := 0; j < onuPerPon; j++ {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700115 //o := CreateONU(olt, p, uint32(onuId))
116 o := CreateONU(olt, p, uint32(j + 1))
Matteo Scandolo4747d292019-08-05 11:50:18 -0700117 p.Onus = append(p.Onus, o)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700118 //onuId = onuId + 1
Matteo Scandolo4747d292019-08-05 11:50:18 -0700119 }
120
121 olt.Pons = append(olt.Pons, p)
122 }
123
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700124 newOltServer(olt)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700125
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700126 group.Done()
Matteo Scandolo4747d292019-08-05 11:50:18 -0700127 return olt
128}
129
130func newOltServer(o OltDevice) error {
131 // TODO make configurable
132 address := "0.0.0.0:50060"
Matteo Scandolo4747d292019-08-05 11:50:18 -0700133 lis, err := net.Listen("tcp", address)
134 if err != nil {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700135 oltLogger.Fatalf("OLT failed to listen: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700136 }
137 grpcServer := grpc.NewServer()
138 openolt.RegisterOpenoltServer(grpcServer, o)
139
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700140 wg := sync.WaitGroup{}
141 wg.Add(1)
142
Matteo Scandolo4747d292019-08-05 11:50:18 -0700143 go grpcServer.Serve(lis)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700144 oltLogger.Debugf("OLT Listening on: %v", address)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700145
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700146 for {
147 _, ok := <- *o.oltDoneChannel
148 if !ok {
149 // if the olt channel is closed, stop the gRPC server
150 log.Warnf("Stopping OLT gRPC server")
151 grpcServer.Stop()
152 wg.Done()
153 break
154 }
155 }
156
157 wg.Wait()
158
Matteo Scandolo4747d292019-08-05 11:50:18 -0700159 return nil
160}
161
162// Device Methods
163
164func (o OltDevice) Enable (stream openolt.Openolt_EnableIndicationServer) error {
165
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700166 oltLogger.Debug("Enable OLT called")
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700167
Matteo Scandolo4747d292019-08-05 11:50:18 -0700168 wg := sync.WaitGroup{}
169 wg.Add(1)
170
171 // create a channel for all the OLT events
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700172 go o.processOltMessages(stream)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700173
174 // enable the OLT
175 olt_msg := Message{
176 Type: OltIndication,
177 Data: OltIndicationMessage{
178 OperState: UP,
179 },
180 }
181 o.channel <- olt_msg
182
183 // send NNI Port Indications
184 for _, nni := range o.Nnis {
185 msg := Message{
186 Type: NniIndication,
187 Data: NniIndicationMessage{
188 OperState: UP,
189 NniPortID: nni.ID,
190 },
191 }
192 o.channel <- msg
193 }
194
195 // send PON Port indications
196 for _, pon := range o.Pons {
197 msg := Message{
198 Type: PonIndication,
199 Data: PonIndicationMessage{
200 OperState: UP,
201 PonPortID: pon.ID,
202 },
203 }
204 o.channel <- msg
205
206 for _, onu := range pon.Onus {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700207 go onu.processOnuMessages(stream)
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700208 go onu.processOmciMessages(stream)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700209 msg := Message{
210 Type: OnuDiscIndication,
211 Data: OnuDiscIndicationMessage{
212 Onu: onu,
213 OperState: UP,
214 },
215 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700216 onu.channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700217 }
218 }
219
220 wg.Wait()
221 return nil
222}
223
224// Helpers method
225
226func (o OltDevice) getPonById(id uint32) (*PonPort, error) {
227 for _, pon := range o.Pons {
228 if pon.ID == id {
229 return &pon, nil
230 }
231 }
232 return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID))
233}
234
235func (o OltDevice) getNniById(id uint32) (*NniPort, error) {
236 for _, nni := range o.Nnis {
237 if nni.ID == id {
238 return &nni, nil
239 }
240 }
241 return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID))
242}
243
Matteo Scandolo4747d292019-08-05 11:50:18 -0700244func (o OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
245 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}}
246 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700247 oltLogger.Errorf("Failed to send Indication_OltInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700248 }
249
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700250 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700251 "OperState": msg.OperState,
252 }).Debug("Sent Indication_OltInd")
253}
254
255func (o OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
256 nni, _ := o.getNniById(msg.NniPortID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700257 nni.OperState.Event("enable")
258 // NOTE Operstate may need to be an integer
Matteo Scandolo4747d292019-08-05 11:50:18 -0700259 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
260 Type: nni.Type,
261 IntfId: nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700262 OperState: nni.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700263 }}
264
265 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700266 oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700267 }
268
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700269 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700270 "Type": nni.Type,
271 "IntfId": nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700272 "OperState": nni.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700273 }).Debug("Sent Indication_IntfOperInd for NNI")
274}
275
276func (o OltDevice) sendPonIndication(msg PonIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
277 pon, _ := o.getPonById(msg.PonPortID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700278 pon.OperState.Event("enable")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700279 discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{
280 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700281 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700282 }}
283
284 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700285 oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700286 }
287
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700288 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700289 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700290 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700291 }).Debug("Sent Indication_IntfInd")
292
293 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
294 Type: pon.Type,
295 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700296 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700297 }}
298
299 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700300 oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700301 }
302
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700303 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700304 "Type": pon.Type,
305 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700306 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700307 }).Debug("Sent Indication_IntfOperInd for PON")
308}
309
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700310func (o OltDevice) processOltMessages(stream openolt.Openolt_EnableIndicationServer) {
311 oltLogger.Debug("Started OLT Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700312 for message := range o.channel {
313
Matteo Scandolo4747d292019-08-05 11:50:18 -0700314
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700315 oltLogger.WithFields(log.Fields{
316 "oltId": o.ID,
317 "messageType": message.Type,
318 }).Trace("Received message")
319
320 switch message.Type {
321 case OltIndication:
322 msg, _ := message.Data.(OltIndicationMessage)
323 if msg.OperState == UP {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700324 o.InternalState.Event("enable")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700325 o.OperState.Event("enable")
326 } else if msg.OperState == DOWN {
327 o.InternalState.Event("disable")
328 o.OperState.Event("disable")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700329 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700330 o.sendOltIndication(msg, stream)
331 case NniIndication:
332 msg, _ := message.Data.(NniIndicationMessage)
333 o.sendNniIndication(msg, stream)
334 case PonIndication:
335 msg, _ := message.Data.(PonIndicationMessage)
336 o.sendPonIndication(msg, stream)
337 default:
338 oltLogger.Warnf("Received unknown message data %v for type %v in OLT channel", message.Data, message.Type)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700339 }
340
341 }
342}
343
344// GRPC Endpoints
345
346func (o OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700347 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700348 "onuSerialNumber": onu.SerialNumber,
349 }).Info("Received ActivateOnu call from VOLTHA")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700350
351 pon, _ := o.getPonById(onu.IntfId)
352 _onu, _ := pon.getOnuBySn(onu.SerialNumber)
353
354 // NOTE we need to immediately activate the ONU or the OMCI state machine won't start
Matteo Scandolo4747d292019-08-05 11:50:18 -0700355 msg := Message{
356 Type: OnuIndication,
357 Data: OnuIndicationMessage{
358 OnuSN: onu.SerialNumber,
359 PonPortID: onu.IntfId,
360 OperState: UP,
361 },
362 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700363 _onu.channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700364 return new(openolt.Empty) , nil
365}
366
367func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700368 oltLogger.Error("DeactivateOnu not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700369 return new(openolt.Empty) , nil
370}
371
372func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700373 oltLogger.Error("DeleteOnu not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700374 return new(openolt.Empty) , nil
375}
376
377func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700378 // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether?
379 olt_msg := Message{
380 Type: OltIndication,
381 Data: OltIndicationMessage{
382 OperState: DOWN,
383 },
384 }
385 o.channel <- olt_msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700386 return new(openolt.Empty) , nil
387}
388
389func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700390 oltLogger.Error("DisablePonIf not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700391 return new(openolt.Empty) , nil
392}
393
394func (o OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700395 oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700396 o.Enable(stream)
397 return nil
398}
399
400func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700401 oltLogger.Error("EnablePonIf not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700402 return new(openolt.Empty) , nil
403}
404
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700405func (o OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
406 oltLogger.WithFields(log.Fields{
407 "IntfId": flow.AccessIntfId,
408 "OnuId": flow.OnuId,
409 "EthType": fmt.Sprintf("%x", flow.Classifier.EthType),
410 "InnerVlan": flow.Classifier.IVid,
411 "OuterVlan": flow.Classifier.OVid,
412 "FlowType": flow.FlowType,
413 "FlowId": flow.FlowId,
414 "UniID": flow.UniId,
415 "PortNo": flow.PortNo,
416 }).Infof("OLT receives Flow")
417 // TODO optionally store flows somewhere
418
419 if flow.AccessIntfId == -1 {
420 oltLogger.WithFields(log.Fields{
421 "FlowId": flow.FlowId,
422 }).Debugf("This is an OLT flow")
423 } else {
424 pon, _ := o.getPonById(uint32(flow.AccessIntfId))
425 onu, _ := pon.getOnuById(uint32(flow.OnuId))
426
427 msg := Message{
428 Type: FlowUpdate,
429 Data: OnuFlowUpdateMessage{
430 PonPortID: pon.ID,
431 OnuID: onu.ID,
432 Flow: flow,
433 },
434 }
435 onu.channel <- msg
436 }
437
Matteo Scandolo4747d292019-08-05 11:50:18 -0700438 return new(openolt.Empty) , nil
439}
440
441func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700442 oltLogger.Info("received FlowRemove")
443 // TODO store flows somewhere
Matteo Scandolo4747d292019-08-05 11:50:18 -0700444 return new(openolt.Empty) , nil
445}
446
447func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700448 oltLogger.Error("HeartbeatCheck not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700449 return new(openolt.Heartbeat) , nil
450}
451
452func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) {
453
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700454 oltLogger.WithFields(log.Fields{
455 "oltId": o.ID,
456 "PonPorts": o.NumPon,
457 }).Info("OLT receives GetDeviceInfo call from VOLTHA")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700458 devinfo := new(openolt.DeviceInfo)
459 devinfo.Vendor = "BBSim"
460 devinfo.Model = "asfvolt16"
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700461 devinfo.HardwareVersion = "emulated"
Matteo Scandolo4747d292019-08-05 11:50:18 -0700462 devinfo.FirmwareVersion = ""
463 devinfo.Technology = "xgspon"
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700464 devinfo.PonPorts = uint32(o.NumPon)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700465 devinfo.OnuIdStart = 1
466 devinfo.OnuIdEnd = 255
467 devinfo.AllocIdStart = 1024
468 devinfo.AllocIdEnd = 16383
469 devinfo.GemportIdStart = 1024
470 devinfo.GemportIdEnd = 65535
471 devinfo.FlowIdStart = 1
472 devinfo.FlowIdEnd = 16383
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700473 devinfo.DeviceSerialNumber = o.SerialNumber
Matteo Scandolo4747d292019-08-05 11:50:18 -0700474
475 return devinfo, nil
476}
477
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700478func (o OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700479 pon, _ := o.getPonById(omci_msg.IntfId)
480 onu, _ := pon.getOnuById(omci_msg.OnuId)
481 msg := Message{
482 Type: OMCI,
483 Data: OmciMessage{
484 OnuSN: onu.SerialNumber,
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700485 OnuID: onu.ID,
486 omciMsg: omci_msg,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700487 },
488 }
489 onu.channel <- msg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700490 return new(openolt.Empty) , nil
491}
492
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700493func (o OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
494 pon, _ := o.getPonById(onuPkt.IntfId)
495 onu, _ := pon.getOnuById(onuPkt.OnuId)
496
497 rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default)
498
499 // NOTE is this the best way to the to the ethertype?
500 etherType := rawpkt.Layer(layers.LayerTypeEthernet).(*layers.Ethernet).EthernetType
501
502 if etherType == layers.EthernetTypeEAPOL {
503 eapolPkt := bbsim.ByteMsg{IntfId: onuPkt.IntfId, OnuId: onuPkt.OnuId, Bytes: rawpkt.Data()}
504 onu.eapolPktOutCh <- &eapolPkt
505 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700506 return new(openolt.Empty) , nil
507}
508
509func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700510 oltLogger.Info("Shutting Down")
511 close(*o.oltDoneChannel)
512 close(*o.apiDoneChannel)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700513 return new(openolt.Empty) , nil
514}
515
516func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700517 oltLogger.Error("ReenableOlt not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700518 return new(openolt.Empty) , nil
519}
520
521func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700522 oltLogger.Warn("UplinkPacketOut not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700523 return new(openolt.Empty) , nil
524}
525
526func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700527 oltLogger.Error("CollectStatistics not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700528 return new(openolt.Empty) , nil
529}
530
Matteo Scandolo4747d292019-08-05 11:50:18 -0700531func (o OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700532 oltLogger.Error("GetOnuInfo not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700533 return new(openolt.OnuIndication) , nil
534}
535
536func (o OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700537 oltLogger.Error("GetPonIf not implemented")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700538 return new(openolt.IntfIndication) , nil
Matteo Scandolod54283a2019-08-13 16:22:31 -0700539}
540
541func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700542 oltLogger.Info("received CreateTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700543 return new(openolt.Empty), nil
544}
545
546func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700547 oltLogger.Info("received RemoveTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700548 return new(openolt.Empty), nil
549}
550
551func (s OltDevice) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700552 oltLogger.Info("received CreateTrafficSchedulers")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700553 return new(openolt.Empty), nil
554}
555
556func (s OltDevice) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700557 oltLogger.Info("received RemoveTrafficSchedulers")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700558 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700559}