blob: f17ecd439d274f2ffee88c380116a4068ce908bd [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"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020023 "net"
24 "sync"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010025 "time"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020026
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070027 "github.com/google/gopacket"
28 "github.com/google/gopacket/layers"
Matteo Scandolo4747d292019-08-05 11:50:18 -070029 "github.com/looplab/fsm"
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070030 "github.com/opencord/bbsim/internal/bbsim/packetHandlers"
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070031 bbsim "github.com/opencord/bbsim/internal/bbsim/types"
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010032 "github.com/opencord/bbsim/internal/common"
William Kurkian9dadc5b2019-10-22 13:51:57 -040033 omcisim "github.com/opencord/omci-sim"
Matteo Scandolo3de9de02019-11-14 13:40:03 -080034 "github.com/opencord/voltha-protos/v2/go/openolt"
35 "github.com/opencord/voltha-protos/v2/go/tech_profile"
Matteo Scandolo4747d292019-08-05 11:50:18 -070036 log "github.com/sirupsen/logrus"
37 "google.golang.org/grpc"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010038 "google.golang.org/grpc/reflection"
Matteo Scandolo4747d292019-08-05 11:50:18 -070039)
40
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070041var oltLogger = log.WithFields(log.Fields{
Matteo Scandolo84f7d482019-08-08 19:00:47 -070042 "module": "OLT",
43})
44
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070045type OltDevice struct {
46 // BBSIM Internals
47 ID int
48 SerialNumber string
49 NumNni int
50 NumPon int
51 NumOnuPerPon int
52 InternalState *fsm.FSM
53 channel chan Message
Zdravko Bozakov681364d2019-11-10 14:28:46 +010054 nniPktInChannel chan *bbsim.PacketMsg // packets coming in from the NNI and going to VOLTHA
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070055
Matteo Scandoloe33447a2019-10-31 12:38:23 -070056 Delay int
57
Matteo Scandolo27428702019-10-11 16:21:16 -070058 Pons []*PonPort
59 Nnis []*NniPort
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070060
61 // OLT Attributes
62 OperState *fsm.FSM
Matteo Scandolo4747d292019-08-05 11:50:18 -070063}
64
Matteo Scandolo27428702019-10-11 16:21:16 -070065var olt OltDevice
Zdravko Bozakov681364d2019-11-10 14:28:46 +010066var oltServer *grpc.Server
Matteo Scandolo84f7d482019-08-08 19:00:47 -070067
Matteo Scandolo27428702019-10-11 16:21:16 -070068func GetOLT() *OltDevice {
69 return &olt
Matteo Scandolo84f7d482019-08-08 19:00:47 -070070}
71
Zdravko Bozakov681364d2019-11-10 14:28:46 +010072func CreateOLT(oltId int, nni int, pon int, onuPerPon int, sTag int, cTagInit int, auth bool, dhcp bool, delay int, isMock bool) *OltDevice {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070073 oltLogger.WithFields(log.Fields{
Matteo Scandolo40e067f2019-10-16 16:59:41 -070074 "ID": oltId,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070075 "NumNni": nni,
76 "NumPon": pon,
77 "NumOnuPerPon": onuPerPon,
Matteo Scandolo4747d292019-08-05 11:50:18 -070078 }).Debug("CreateOLT")
79
Matteo Scandolo84f7d482019-08-08 19:00:47 -070080 olt = OltDevice{
Matteo Scandolo40e067f2019-10-16 16:59:41 -070081 ID: oltId,
82 SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", oltId),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070083 OperState: getOperStateFSM(func(e *fsm.Event) {
84 oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst)
85 }),
Zdravko Bozakov681364d2019-11-10 14:28:46 +010086 NumNni: nni,
87 NumPon: pon,
88 NumOnuPerPon: onuPerPon,
89 Pons: []*PonPort{},
90 Nnis: []*NniPort{},
91 Delay: delay,
Matteo Scandolo4747d292019-08-05 11:50:18 -070092 }
93
94 // OLT State machine
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070095 // NOTE do we need 2 state machines for the OLT? (InternalState and OperState)
Matteo Scandolo4747d292019-08-05 11:50:18 -070096 olt.InternalState = fsm.NewFSM(
97 "created",
98 fsm.Events{
Zdravko Bozakov681364d2019-11-10 14:28:46 +010099 {Name: "initialize", Src: []string{"disabled", "created"}, Dst: "initialized"},
100 {Name: "enable", Src: []string{"initialized", "disabled"}, Dst: "enabled"},
Matteo Scandolo4747d292019-08-05 11:50:18 -0700101 {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"},
102 },
103 fsm.Callbacks{
104 "enter_state": func(e *fsm.Event) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700105 oltLogger.Debugf("Changing OLT InternalState from %s to %s", e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700106 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100107 "enter_disabled": func(e *fsm.Event) { olt.disableOlt() },
108 "enter_initialized": func(e *fsm.Event) { olt.InitOlt() },
Matteo Scandolo4747d292019-08-05 11:50:18 -0700109 },
110 )
111
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700112 if isMock != true {
113 // create NNI Port
114 nniPort, err := CreateNNI(&olt)
115 if err != nil {
116 oltLogger.Fatalf("Couldn't create NNI Port: %v", err)
117 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700118
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700119 olt.Nnis = append(olt.Nnis, &nniPort)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700120 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700121
Matteo Scandolo4747d292019-08-05 11:50:18 -0700122 // create PON ports
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700123 availableCTag := cTagInit
Matteo Scandolo4747d292019-08-05 11:50:18 -0700124 for i := 0; i < pon; i++ {
125 p := PonPort{
126 NumOnu: olt.NumOnuPerPon,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700127 ID: uint32(i),
128 Type: "pon",
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700129 Olt: olt,
Matteo Scandolo27428702019-10-11 16:21:16 -0700130 Onus: []*Onu{},
Matteo Scandolo4747d292019-08-05 11:50:18 -0700131 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700132 p.OperState = getOperStateFSM(func(e *fsm.Event) {
133 oltLogger.WithFields(log.Fields{
134 "ID": p.ID,
135 }).Debugf("Changing PON Port OperState from %s to %s", e.Src, e.Dst)
136 })
Matteo Scandolo4747d292019-08-05 11:50:18 -0700137
138 // create ONU devices
139 for j := 0; j < onuPerPon; j++ {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700140 o := CreateONU(olt, p, uint32(j+1), sTag, availableCTag, auth, dhcp)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700141 p.Onus = append(p.Onus, o)
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700142 availableCTag = availableCTag + 1
Matteo Scandolo4747d292019-08-05 11:50:18 -0700143 }
144
Matteo Scandolo27428702019-10-11 16:21:16 -0700145 olt.Pons = append(olt.Pons, &p)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700146 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100147
Matteo Scandolod32c3822019-11-26 15:57:46 -0700148 if isMock != true {
149 if err := olt.InternalState.Event("initialize"); err != nil {
150 log.Errorf("Error initializing OLT: %v", err)
151 return nil
152 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100153 }
154
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700155 return &olt
156}
Matteo Scandolo4747d292019-08-05 11:50:18 -0700157
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100158func (o *OltDevice) InitOlt() error {
159
160 if oltServer == nil {
161 oltServer, _ = newOltServer()
162 } else {
163 oltLogger.Warn("OLT server already running.")
164 }
165
166 // create new channel for processOltMessages Go routine
167 o.channel = make(chan Message)
168
169 o.nniPktInChannel = make(chan *bbsim.PacketMsg, 1024)
170 // FIXME we are assuming we have only one NNI
171 if o.Nnis[0] != nil {
172 ch, err := o.Nnis[0].NewVethChan()
173 if err == nil {
174 o.nniPktInChannel = ch
175 } else {
176 log.Errorf("Error getting NNI channel: %v", err)
177 }
178 }
179
180 for i := range olt.Pons {
181 for _, onu := range olt.Pons[i].Onus {
182 if err := onu.InternalState.Event("initialize"); err != nil {
183 log.Errorf("Error initializing ONU: %v", err)
184 return err
185 }
186 }
187 }
188
189 return nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700190}
191
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100192// callback for disable state entry
193func (o *OltDevice) disableOlt() error {
194
195 // disable all onus
196 for i := range o.Pons {
197 for _, onu := range o.Pons[i].Onus {
198 // NOTE order of these is important.
199 onu.OperState.Event("disable")
200 onu.InternalState.Event("disable")
201 }
202 }
203
204 // TODO handle hard poweroff (i.e. no indications sent to Voltha) vs soft poweroff
205 if err := StopOltServer(); err != nil {
206 return err
207 }
208
209 // terminate the OLT's processOltMessages go routine
210 close(o.channel)
211 // terminate the OLT's processNniPacketIns go routine
212 close(o.nniPktInChannel)
213 return nil
214}
215
216func (o *OltDevice) RestartOLT() error {
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +0100217 rebootDelay := common.Options.Olt.OltRebootDelay
218 oltLogger.Infof("Simulating OLT restart... (%ds)", rebootDelay)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100219
220 // transition internal state to disable
221 if !o.InternalState.Is("disabled") {
222 if err := o.InternalState.Event("disable"); err != nil {
223 log.Errorf("Error disabling OLT: %v", err)
224 return err
225 }
226 }
227
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +0100228 time.Sleep(time.Duration(rebootDelay) * time.Second)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100229
230 if err := o.InternalState.Event("initialize"); err != nil {
231 log.Errorf("Error initializing OLT: %v", err)
232 return err
233 }
234 oltLogger.Info("OLT restart completed")
235 return nil
236}
237
238// newOltServer launches a new grpc server for OpenOLT
239func newOltServer() (*grpc.Server, error) {
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +0100240 address := common.Options.BBSim.OpenOltAddress
Matteo Scandolo4747d292019-08-05 11:50:18 -0700241 lis, err := net.Listen("tcp", address)
242 if err != nil {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700243 oltLogger.Fatalf("OLT failed to listen: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700244 }
245 grpcServer := grpc.NewServer()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100246
247 o := GetOLT()
Matteo Scandolo4747d292019-08-05 11:50:18 -0700248 openolt.RegisterOpenoltServer(grpcServer, o)
249
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100250 reflection.Register(grpcServer)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700251
Matteo Scandolo4747d292019-08-05 11:50:18 -0700252 go grpcServer.Serve(lis)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700253 oltLogger.Debugf("OLT Listening on: %v", address)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700254
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100255 return grpcServer, nil
256}
257
258// StopOltServer stops the OpenOLT grpc server
259func StopOltServer() error {
260 // TODO handle poweroff vs graceful shutdown
261 if oltServer != nil {
262 log.Warnf("Stopping OLT gRPC server")
263 oltServer.Stop()
264 oltServer = nil
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700265 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700266 return nil
267}
268
269// Device Methods
270
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100271// Enable implements the OpenOLT EnableIndicationServer functionality
272func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700273 oltLogger.Debug("Enable OLT called")
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700274
Matteo Scandolo4747d292019-08-05 11:50:18 -0700275 wg := sync.WaitGroup{}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700276 wg.Add(2)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700277
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100278 // create Go routine to process all OLT events
279 go o.processOltMessages(stream, &wg)
280 go o.processNniPacketIns(stream, &wg)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700281
282 // enable the OLT
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100283 oltMsg := Message{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700284 Type: OltIndication,
285 Data: OltIndicationMessage{
286 OperState: UP,
287 },
288 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100289 o.channel <- oltMsg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700290
291 // send NNI Port Indications
292 for _, nni := range o.Nnis {
293 msg := Message{
294 Type: NniIndication,
295 Data: NniIndicationMessage{
296 OperState: UP,
297 NniPortID: nni.ID,
298 },
299 }
300 o.channel <- msg
301 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100302
William Kurkian9dadc5b2019-10-22 13:51:57 -0400303 go o.processOmciMessages()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100304
Matteo Scandolo4747d292019-08-05 11:50:18 -0700305 // send PON Port indications
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100306 for i, pon := range o.Pons {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700307 msg := Message{
308 Type: PonIndication,
309 Data: PonIndicationMessage{
310 OperState: UP,
311 PonPortID: pon.ID,
312 },
313 }
314 o.channel <- msg
315
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100316 for _, onu := range o.Pons[i].Onus {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700317 go onu.ProcessOnuMessages(stream, nil)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100318 if err := onu.InternalState.Event("discover"); err != nil {
319 log.Errorf("Error discover ONU: %v", err)
320 return err
Matteo Scandolo4747d292019-08-05 11:50:18 -0700321 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700322 }
323 }
324
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100325 oltLogger.Warn("Enable OLT Done")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700326 wg.Wait()
327 return nil
328}
329
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100330func (o *OltDevice) processOmciMessages() {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400331 ch := omcisim.GetChannel()
332
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100333 oltLogger.Debug("Starting OMCI Indication Channel")
William Kurkian9dadc5b2019-10-22 13:51:57 -0400334
335 for message := range ch {
336 onuId := message.Data.OnuId
337 intfId := message.Data.IntfId
338 onu, err := o.FindOnuById(intfId, onuId)
339 if err != nil {
340 oltLogger.Errorf("Failed to find onu: %v", err)
341 }
342 go onu.processOmciMessage(message)
343 }
344}
345
Matteo Scandolo4747d292019-08-05 11:50:18 -0700346// Helpers method
347
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700348func (o OltDevice) GetPonById(id uint32) (*PonPort, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700349 for _, pon := range o.Pons {
350 if pon.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -0700351 return pon, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700352 }
353 }
354 return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID))
355}
356
357func (o OltDevice) getNniById(id uint32) (*NniPort, error) {
358 for _, nni := range o.Nnis {
359 if nni.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -0700360 return nni, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700361 }
362 }
363 return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID))
364}
365
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100366func (o *OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700367 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}}
368 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700369 oltLogger.Errorf("Failed to send Indication_OltInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700370 }
371
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700372 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700373 "OperState": msg.OperState,
374 }).Debug("Sent Indication_OltInd")
375}
376
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100377func (o *OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700378 nni, _ := o.getNniById(msg.NniPortID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700379 nni.OperState.Event("enable")
380 // NOTE Operstate may need to be an integer
Matteo Scandolo4747d292019-08-05 11:50:18 -0700381 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700382 Type: nni.Type,
383 IntfId: nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700384 OperState: nni.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700385 }}
386
387 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700388 oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700389 }
390
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700391 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700392 "Type": nni.Type,
393 "IntfId": nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700394 "OperState": nni.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700395 }).Debug("Sent Indication_IntfOperInd for NNI")
396}
397
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100398func (o *OltDevice) sendPonIndication(msg PonIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700399 pon, _ := o.GetPonById(msg.PonPortID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700400 pon.OperState.Event("enable")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700401 discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700402 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700403 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700404 }}
405
406 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700407 oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700408 }
409
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700410 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700411 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700412 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700413 }).Debug("Sent Indication_IntfInd")
414
415 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700416 Type: pon.Type,
417 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700418 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700419 }}
420
421 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700422 oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700423 }
424
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700425 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700426 "Type": pon.Type,
427 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700428 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700429 }).Debug("Sent Indication_IntfOperInd for PON")
430}
431
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100432// processOltMessages handles messages received over the OpenOLT interface
433func (o *OltDevice) processOltMessages(stream openolt.Openolt_EnableIndicationServer, wg *sync.WaitGroup) {
434 oltLogger.Debug("Starting OLT Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700435 for message := range o.channel {
436
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700437 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700438 "oltId": o.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700439 "messageType": message.Type,
440 }).Trace("Received message")
441
442 switch message.Type {
443 case OltIndication:
444 msg, _ := message.Data.(OltIndicationMessage)
445 if msg.OperState == UP {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700446 o.InternalState.Event("enable")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700447 o.OperState.Event("enable")
448 } else if msg.OperState == DOWN {
449 o.InternalState.Event("disable")
450 o.OperState.Event("disable")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700451 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700452 o.sendOltIndication(msg, stream)
453 case NniIndication:
454 msg, _ := message.Data.(NniIndicationMessage)
455 o.sendNniIndication(msg, stream)
456 case PonIndication:
457 msg, _ := message.Data.(PonIndicationMessage)
458 o.sendPonIndication(msg, stream)
459 default:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700460 oltLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700461 }
462
463 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100464 wg.Done()
465 oltLogger.Warn("Stopped handling OLT Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700466}
467
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100468// processNniPacketIns handles messages received over the NNI interface
469func (o *OltDevice) processNniPacketIns(stream openolt.Openolt_EnableIndicationServer, wg *sync.WaitGroup) {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700470 oltLogger.WithFields(log.Fields{
471 "nniChannel": o.nniPktInChannel,
472 }).Debug("Started NNI Channel")
473 nniId := o.Nnis[0].ID // FIXME we are assuming we have only one NNI
474 for message := range o.nniPktInChannel {
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700475 oltLogger.Tracef("Received packets on NNI Channel")
476
477 onuMac, err := packetHandlers.GetDstMacAddressFromPacket(message.Pkt)
478
479 if err != nil {
480 log.WithFields(log.Fields{
481 "IntfType": "nni",
482 "IntfId": nniId,
483 "Pkt": message.Pkt.Data(),
Matteo Scandolo27428702019-10-11 16:21:16 -0700484 }).Error("Can't find Dst MacAddress in packet")
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700485 return
486 }
487
488 onu, err := o.FindOnuByMacAddress(onuMac)
489 if err != nil {
490 log.WithFields(log.Fields{
491 "IntfType": "nni",
492 "IntfId": nniId,
493 "Pkt": message.Pkt.Data(),
494 "MacAddress": onuMac.String(),
Matteo Scandolo27428702019-10-11 16:21:16 -0700495 }).Error("Can't find ONU with MacAddress")
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700496 return
497 }
498
499 doubleTaggedPkt, err := packetHandlers.PushDoubleTag(onu.STag, onu.CTag, message.Pkt)
500 if err != nil {
501 log.Error("Fail to add double tag to packet")
502 }
503
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700504 data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{
505 IntfType: "nni",
506 IntfId: nniId,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700507 Pkt: doubleTaggedPkt.Data()}}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700508 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
509 oltLogger.WithFields(log.Fields{
510 "IntfType": data.PktInd.IntfType,
511 "IntfId": nniId,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700512 "Pkt": doubleTaggedPkt.Data(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700513 }).Errorf("Fail to send PktInd indication: %v", err)
514 }
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700515 oltLogger.WithFields(log.Fields{
516 "IntfType": data.PktInd.IntfType,
517 "IntfId": nniId,
518 "Pkt": doubleTaggedPkt.Data(),
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700519 "OnuSn": onu.Sn(),
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700520 }).Tracef("Sent PktInd indication")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700521 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100522 wg.Done()
523 oltLogger.WithFields(log.Fields{
524 "nniChannel": o.nniPktInChannel,
525 }).Warn("Stopped handling NNI Channel")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700526}
527
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700528// returns an ONU with a given Serial Number
529func (o OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200530 // TODO this function can be a performance bottleneck when we have many ONUs,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700531 // memoizing it will remove the bottleneck
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700532 for _, pon := range o.Pons {
533 for _, onu := range pon.Onus {
534 if onu.Sn() == serialNumber {
Matteo Scandolo27428702019-10-11 16:21:16 -0700535 return onu, nil
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700536 }
537 }
538 }
539
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700540 return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-serial-number-%s", serialNumber))
541}
542
William Kurkian9dadc5b2019-10-22 13:51:57 -0400543// returns an ONU with a given interface/Onu Id
544func (o OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200545 // TODO this function can be a performance bottleneck when we have many ONUs,
William Kurkian9dadc5b2019-10-22 13:51:57 -0400546 // memoizing it will remove the bottleneck
547 for _, pon := range o.Pons {
548 if pon.ID == intfId {
549 for _, onu := range pon.Onus {
550 if onu.ID == onuId {
551 return onu, nil
552 }
553 }
554 }
555 }
556 return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-id-%v-%v", intfId, onuId))
557}
558
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700559// returns an ONU with a given Mac Address
560func (o OltDevice) FindOnuByMacAddress(mac net.HardwareAddr) (*Onu, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200561 // TODO this function can be a performance bottleneck when we have many ONUs,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700562 // memoizing it will remove the bottleneck
563 for _, pon := range o.Pons {
564 for _, onu := range pon.Onus {
565 if onu.HwAddress.String() == mac.String() {
Matteo Scandolo27428702019-10-11 16:21:16 -0700566 return onu, nil
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700567 }
568 }
569 }
570
571 return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-mac-address-%s", mac))
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700572}
573
Matteo Scandolo4747d292019-08-05 11:50:18 -0700574// GRPC Endpoints
575
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700576func (o OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700577 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700578 "OnuSn": onuSnToString(onu.SerialNumber),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700579 }).Info("Received ActivateOnu call from VOLTHA")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700580
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700581 pon, _ := o.GetPonById(onu.IntfId)
582 _onu, _ := pon.GetOnuBySn(onu.SerialNumber)
William Kurkian0418bc82019-11-06 12:16:24 -0500583 _onu.SetID(onu.OnuId)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700584
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700585 if err := _onu.OperState.Event("enable"); err != nil {
586 oltLogger.WithFields(log.Fields{
587 "IntfId": _onu.PonPortID,
588 "OnuSn": _onu.Sn(),
589 "OnuId": _onu.ID,
590 }).Infof("Failed to transition ONU.OperState to enabled state: %s", err.Error())
Matteo Scandolo4747d292019-08-05 11:50:18 -0700591 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700592 if err := _onu.InternalState.Event("enable"); err != nil {
593 oltLogger.WithFields(log.Fields{
594 "IntfId": _onu.PonPortID,
595 "OnuSn": _onu.Sn(),
596 "OnuId": _onu.ID,
597 }).Infof("Failed to transition ONU to enabled state: %s", err.Error())
598 }
599
600 // NOTE we need to immediately activate the ONU or the OMCI state machine won't start
601
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700602 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700603}
604
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700605func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700606 oltLogger.Error("DeactivateOnu not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700607 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700608}
609
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700610func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700611 oltLogger.Error("DeleteOnu not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700612 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700613}
614
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700615func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700616 // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether?
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100617 oltMsg := Message{
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700618 Type: OltIndication,
619 Data: OltIndicationMessage{
620 OperState: DOWN,
621 },
622 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100623 o.channel <- oltMsg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700624 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700625}
626
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700627func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700628 oltLogger.Error("DisablePonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700629 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700630}
631
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100632func (o *OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700633 oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700634 o.Enable(stream)
635 return nil
636}
637
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700638func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700639 oltLogger.Error("EnablePonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700640 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700641}
642
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700643func (o OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700644 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700645 "IntfId": flow.AccessIntfId,
646 "OnuId": flow.OnuId,
647 "EthType": fmt.Sprintf("%x", flow.Classifier.EthType),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700648 "InnerVlan": flow.Classifier.IVid,
649 "OuterVlan": flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700650 "FlowType": flow.FlowType,
651 "FlowId": flow.FlowId,
652 "UniID": flow.UniId,
653 "PortNo": flow.PortNo,
654 }).Tracef("OLT receives Flow")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700655 // TODO optionally store flows somewhere
656
657 if flow.AccessIntfId == -1 {
658 oltLogger.WithFields(log.Fields{
659 "FlowId": flow.FlowId,
660 }).Debugf("This is an OLT flow")
661 } else {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700662 pon, err := o.GetPonById(uint32(flow.AccessIntfId))
Matteo Scandolo27428702019-10-11 16:21:16 -0700663 if err != nil {
664 oltLogger.WithFields(log.Fields{
665 "OnuId": flow.OnuId,
666 "IntfId": flow.AccessIntfId,
667 "err": err,
668 }).Error("Can't find PonPort")
669 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700670 onu, err := pon.GetOnuById(uint32(flow.OnuId))
Matteo Scandolo27428702019-10-11 16:21:16 -0700671 if err != nil {
672 oltLogger.WithFields(log.Fields{
673 "OnuId": flow.OnuId,
674 "IntfId": flow.AccessIntfId,
675 "err": err,
676 }).Error("Can't find Onu")
677 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700678
679 msg := Message{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700680 Type: FlowUpdate,
681 Data: OnuFlowUpdateMessage{
682 PonPortID: pon.ID,
683 OnuID: onu.ID,
684 Flow: flow,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700685 },
686 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700687 onu.Channel <- msg
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700688 }
689
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700690 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700691}
692
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700693func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error) {
694 oltLogger.Tracef("received FlowRemove")
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700695 // TODO store flows somewhere
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700696 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700697}
698
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700699func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700700 oltLogger.Error("HeartbeatCheck not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700701 return new(openolt.Heartbeat), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700702}
703
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700704func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700705
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700706 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700707 "oltId": o.ID,
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700708 "PonPorts": o.NumPon,
709 }).Info("OLT receives GetDeviceInfo call from VOLTHA")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700710 devinfo := new(openolt.DeviceInfo)
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +0100711 devinfo.Vendor = common.Options.Olt.Vendor
712 devinfo.Model = common.Options.Olt.Model
713 devinfo.HardwareVersion = common.Options.Olt.HardwareVersion
714 devinfo.FirmwareVersion = common.Options.Olt.FirmwareVersion
715 devinfo.Technology = common.Options.Olt.Technology
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700716 devinfo.PonPorts = uint32(o.NumPon)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700717 devinfo.OnuIdStart = 1
718 devinfo.OnuIdEnd = 255
719 devinfo.AllocIdStart = 1024
720 devinfo.AllocIdEnd = 16383
721 devinfo.GemportIdStart = 1024
722 devinfo.GemportIdEnd = 65535
723 devinfo.FlowIdStart = 1
724 devinfo.FlowIdEnd = 16383
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700725 devinfo.DeviceSerialNumber = o.SerialNumber
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +0100726 devinfo.DeviceId = common.Options.Olt.DeviceId
Matteo Scandolo4747d292019-08-05 11:50:18 -0700727
728 return devinfo, nil
729}
730
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700731func (o OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700732 pon, _ := o.GetPonById(omci_msg.IntfId)
733 onu, _ := pon.GetOnuById(omci_msg.OnuId)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700734 oltLogger.WithFields(log.Fields{
735 "IntfId": onu.PonPortID,
736 "OnuId": onu.ID,
737 "OnuSn": onu.Sn(),
738 }).Tracef("Received OmciMsgOut")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700739 msg := Message{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700740 Type: OMCI,
741 Data: OmciMessage{
742 OnuSN: onu.SerialNumber,
743 OnuID: onu.ID,
744 omciMsg: omci_msg,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700745 },
746 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700747 onu.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700748 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700749}
750
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700751func (o OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700752 pon, err := o.GetPonById(onuPkt.IntfId)
Matteo Scandolo27428702019-10-11 16:21:16 -0700753 if err != nil {
754 oltLogger.WithFields(log.Fields{
755 "OnuId": onuPkt.OnuId,
756 "IntfId": onuPkt.IntfId,
757 "err": err,
758 }).Error("Can't find PonPort")
759 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700760 onu, err := pon.GetOnuById(onuPkt.OnuId)
Matteo Scandolo27428702019-10-11 16:21:16 -0700761 if err != nil {
762 oltLogger.WithFields(log.Fields{
763 "OnuId": onuPkt.OnuId,
764 "IntfId": onuPkt.IntfId,
765 "err": err,
766 }).Error("Can't find Onu")
767 }
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700768
Matteo Scandolo075b1892019-10-07 12:11:07 -0700769 oltLogger.WithFields(log.Fields{
770 "IntfId": onu.PonPortID,
771 "OnuId": onu.ID,
772 "OnuSn": onu.Sn(),
773 }).Tracef("Received OnuPacketOut")
774
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700775 rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700776 pktType, err := packetHandlers.IsEapolOrDhcp(rawpkt)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700777
Matteo Scandolo075b1892019-10-07 12:11:07 -0700778 msg := Message{
779 Type: OnuPacketOut,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700780 Data: OnuPacketMessage{
Matteo Scandolo075b1892019-10-07 12:11:07 -0700781 IntfId: onuPkt.IntfId,
782 OnuId: onuPkt.OnuId,
783 Packet: rawpkt,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700784 Type: pktType,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700785 },
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700786 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700787 onu.Channel <- msg
788
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700789 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700790}
791
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700792func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100793 oltLogger.Info("Shutting down")
794 o.RestartOLT()
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700795 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700796}
797
798func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700799 oltLogger.Error("ReenableOlt not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700800 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700801}
802
803func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700804 pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
805
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100806 o.Nnis[0].sendNniPacket(pkt) // FIXME we are assuming we have only one NNI
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700807 // NOTE should we return an error if sendNniPakcet fails?
808 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700809}
810
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700811func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700812 oltLogger.Error("CollectStatistics not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700813 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700814}
815
Matteo Scandolo4747d292019-08-05 11:50:18 -0700816func (o OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700817 oltLogger.Error("GetOnuInfo not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700818 return new(openolt.OnuIndication), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700819}
820
821func (o OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700822 oltLogger.Error("GetPonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700823 return new(openolt.IntfIndication), nil
Matteo Scandolod54283a2019-08-13 16:22:31 -0700824}
825
826func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700827 oltLogger.Info("received CreateTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700828 return new(openolt.Empty), nil
829}
830
831func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700832 oltLogger.Info("received RemoveTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700833 return new(openolt.Empty), nil
834}
835
836func (s OltDevice) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700837 oltLogger.Info("received CreateTrafficSchedulers")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700838 return new(openolt.Empty), nil
839}
840
841func (s OltDevice) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700842 oltLogger.Info("received RemoveTrafficSchedulers")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700843 return new(openolt.Empty), nil
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700844}