blob: 3264bc3897f9fa00ff606946d8039a8fef2c5634 [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"
William Kurkian9dadc5b2019-10-22 13:51:57 -040032 omcisim "github.com/opencord/omci-sim"
Matteo Scandolo3de9de02019-11-14 13:40:03 -080033 "github.com/opencord/voltha-protos/v2/go/openolt"
34 "github.com/opencord/voltha-protos/v2/go/tech_profile"
Matteo Scandolo4747d292019-08-05 11:50:18 -070035 log "github.com/sirupsen/logrus"
36 "google.golang.org/grpc"
Zdravko Bozakov681364d2019-11-10 14:28:46 +010037 "google.golang.org/grpc/reflection"
Matteo Scandolo4747d292019-08-05 11:50:18 -070038)
39
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070040var oltLogger = log.WithFields(log.Fields{
Matteo Scandolo84f7d482019-08-08 19:00:47 -070041 "module": "OLT",
42})
43
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070044type OltDevice struct {
45 // BBSIM Internals
46 ID int
47 SerialNumber string
48 NumNni int
49 NumPon int
50 NumOnuPerPon int
51 InternalState *fsm.FSM
52 channel chan Message
Zdravko Bozakov681364d2019-11-10 14:28:46 +010053 nniPktInChannel chan *bbsim.PacketMsg // packets coming in from the NNI and going to VOLTHA
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070054
Matteo Scandoloe33447a2019-10-31 12:38:23 -070055 Delay int
56
Matteo Scandolo27428702019-10-11 16:21:16 -070057 Pons []*PonPort
58 Nnis []*NniPort
Matteo Scandolo86e8ce62019-10-11 12:03:10 -070059
60 // OLT Attributes
61 OperState *fsm.FSM
Matteo Scandolo4747d292019-08-05 11:50:18 -070062}
63
Matteo Scandolo27428702019-10-11 16:21:16 -070064var olt OltDevice
Zdravko Bozakov681364d2019-11-10 14:28:46 +010065var oltServer *grpc.Server
Matteo Scandolo84f7d482019-08-08 19:00:47 -070066
Matteo Scandolo27428702019-10-11 16:21:16 -070067func GetOLT() *OltDevice {
68 return &olt
Matteo Scandolo84f7d482019-08-08 19:00:47 -070069}
70
Zdravko Bozakov681364d2019-11-10 14:28:46 +010071func 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 -070072 oltLogger.WithFields(log.Fields{
Matteo Scandolo40e067f2019-10-16 16:59:41 -070073 "ID": oltId,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070074 "NumNni": nni,
75 "NumPon": pon,
76 "NumOnuPerPon": onuPerPon,
Matteo Scandolo4747d292019-08-05 11:50:18 -070077 }).Debug("CreateOLT")
78
Matteo Scandolo84f7d482019-08-08 19:00:47 -070079 olt = OltDevice{
Matteo Scandolo40e067f2019-10-16 16:59:41 -070080 ID: oltId,
81 SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", oltId),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070082 OperState: getOperStateFSM(func(e *fsm.Event) {
83 oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst)
84 }),
Zdravko Bozakov681364d2019-11-10 14:28:46 +010085 NumNni: nni,
86 NumPon: pon,
87 NumOnuPerPon: onuPerPon,
88 Pons: []*PonPort{},
89 Nnis: []*NniPort{},
90 Delay: delay,
Matteo Scandolo4747d292019-08-05 11:50:18 -070091 }
92
93 // OLT State machine
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070094 // NOTE do we need 2 state machines for the OLT? (InternalState and OperState)
Matteo Scandolo4747d292019-08-05 11:50:18 -070095 olt.InternalState = fsm.NewFSM(
96 "created",
97 fsm.Events{
Zdravko Bozakov681364d2019-11-10 14:28:46 +010098 {Name: "initialize", Src: []string{"disabled", "created"}, Dst: "initialized"},
99 {Name: "enable", Src: []string{"initialized", "disabled"}, Dst: "enabled"},
Matteo Scandolo4747d292019-08-05 11:50:18 -0700100 {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"},
101 },
102 fsm.Callbacks{
103 "enter_state": func(e *fsm.Event) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700104 oltLogger.Debugf("Changing OLT InternalState from %s to %s", e.Src, e.Dst)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700105 },
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100106 "enter_disabled": func(e *fsm.Event) { olt.disableOlt() },
107 "enter_initialized": func(e *fsm.Event) { olt.InitOlt() },
Matteo Scandolo4747d292019-08-05 11:50:18 -0700108 },
109 )
110
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700111 if isMock != true {
112 // create NNI Port
113 nniPort, err := CreateNNI(&olt)
114 if err != nil {
115 oltLogger.Fatalf("Couldn't create NNI Port: %v", err)
116 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700117
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700118 olt.Nnis = append(olt.Nnis, &nniPort)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700119 }
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700120
Matteo Scandolo4747d292019-08-05 11:50:18 -0700121 // create PON ports
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700122 availableCTag := cTagInit
Matteo Scandolo4747d292019-08-05 11:50:18 -0700123 for i := 0; i < pon; i++ {
124 p := PonPort{
125 NumOnu: olt.NumOnuPerPon,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700126 ID: uint32(i),
127 Type: "pon",
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700128 Olt: olt,
Matteo Scandolo27428702019-10-11 16:21:16 -0700129 Onus: []*Onu{},
Matteo Scandolo4747d292019-08-05 11:50:18 -0700130 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700131 p.OperState = getOperStateFSM(func(e *fsm.Event) {
132 oltLogger.WithFields(log.Fields{
133 "ID": p.ID,
134 }).Debugf("Changing PON Port OperState from %s to %s", e.Src, e.Dst)
135 })
Matteo Scandolo4747d292019-08-05 11:50:18 -0700136
137 // create ONU devices
138 for j := 0; j < onuPerPon; j++ {
Matteo Scandoloc1147092019-10-29 09:38:33 -0700139 o := CreateONU(olt, p, uint32(j+1), sTag, availableCTag, auth, dhcp)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700140 p.Onus = append(p.Onus, o)
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700141 availableCTag = availableCTag + 1
Matteo Scandolo4747d292019-08-05 11:50:18 -0700142 }
143
Matteo Scandolo27428702019-10-11 16:21:16 -0700144 olt.Pons = append(olt.Pons, &p)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700145 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100146
147 if err := olt.InternalState.Event("initialize"); err != nil {
148 log.Errorf("Error initializing OLT: %v", err)
149 return nil
150 }
151
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700152 return &olt
153}
Matteo Scandolo4747d292019-08-05 11:50:18 -0700154
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100155func (o *OltDevice) InitOlt() error {
156
157 if oltServer == nil {
158 oltServer, _ = newOltServer()
159 } else {
160 oltLogger.Warn("OLT server already running.")
161 }
162
163 // create new channel for processOltMessages Go routine
164 o.channel = make(chan Message)
165
166 o.nniPktInChannel = make(chan *bbsim.PacketMsg, 1024)
167 // FIXME we are assuming we have only one NNI
168 if o.Nnis[0] != nil {
169 ch, err := o.Nnis[0].NewVethChan()
170 if err == nil {
171 o.nniPktInChannel = ch
172 } else {
173 log.Errorf("Error getting NNI channel: %v", err)
174 }
175 }
176
177 for i := range olt.Pons {
178 for _, onu := range olt.Pons[i].Onus {
179 if err := onu.InternalState.Event("initialize"); err != nil {
180 log.Errorf("Error initializing ONU: %v", err)
181 return err
182 }
183 }
184 }
185
186 return nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700187}
188
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100189// callback for disable state entry
190func (o *OltDevice) disableOlt() error {
191
192 // disable all onus
193 for i := range o.Pons {
194 for _, onu := range o.Pons[i].Onus {
195 // NOTE order of these is important.
196 onu.OperState.Event("disable")
197 onu.InternalState.Event("disable")
198 }
199 }
200
201 // TODO handle hard poweroff (i.e. no indications sent to Voltha) vs soft poweroff
202 if err := StopOltServer(); err != nil {
203 return err
204 }
205
206 // terminate the OLT's processOltMessages go routine
207 close(o.channel)
208 // terminate the OLT's processNniPacketIns go routine
209 close(o.nniPktInChannel)
210 return nil
211}
212
213func (o *OltDevice) RestartOLT() error {
214 oltLogger.Infof("Simulating OLT restart... (%ds)", OltRebootDelay)
215
216 // transition internal state to disable
217 if !o.InternalState.Is("disabled") {
218 if err := o.InternalState.Event("disable"); err != nil {
219 log.Errorf("Error disabling OLT: %v", err)
220 return err
221 }
222 }
223
224 time.Sleep(OltRebootDelay * time.Second)
225
226 if err := o.InternalState.Event("initialize"); err != nil {
227 log.Errorf("Error initializing OLT: %v", err)
228 return err
229 }
230 oltLogger.Info("OLT restart completed")
231 return nil
232}
233
234// newOltServer launches a new grpc server for OpenOLT
235func newOltServer() (*grpc.Server, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700236 // TODO make configurable
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700237 address := "0.0.0.0:50060"
Matteo Scandolo4747d292019-08-05 11:50:18 -0700238 lis, err := net.Listen("tcp", address)
239 if err != nil {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700240 oltLogger.Fatalf("OLT failed to listen: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700241 }
242 grpcServer := grpc.NewServer()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100243
244 o := GetOLT()
Matteo Scandolo4747d292019-08-05 11:50:18 -0700245 openolt.RegisterOpenoltServer(grpcServer, o)
246
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100247 reflection.Register(grpcServer)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700248
Matteo Scandolo4747d292019-08-05 11:50:18 -0700249 go grpcServer.Serve(lis)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700250 oltLogger.Debugf("OLT Listening on: %v", address)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700251
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100252 return grpcServer, nil
253}
254
255// StopOltServer stops the OpenOLT grpc server
256func StopOltServer() error {
257 // TODO handle poweroff vs graceful shutdown
258 if oltServer != nil {
259 log.Warnf("Stopping OLT gRPC server")
260 oltServer.Stop()
261 oltServer = nil
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700262 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700263 return nil
264}
265
266// Device Methods
267
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100268// Enable implements the OpenOLT EnableIndicationServer functionality
269func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700270 oltLogger.Debug("Enable OLT called")
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700271
Matteo Scandolo4747d292019-08-05 11:50:18 -0700272 wg := sync.WaitGroup{}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700273 wg.Add(2)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700274
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100275 // create Go routine to process all OLT events
276 go o.processOltMessages(stream, &wg)
277 go o.processNniPacketIns(stream, &wg)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700278
279 // enable the OLT
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100280 oltMsg := Message{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700281 Type: OltIndication,
282 Data: OltIndicationMessage{
283 OperState: UP,
284 },
285 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100286 o.channel <- oltMsg
Matteo Scandolo4747d292019-08-05 11:50:18 -0700287
288 // send NNI Port Indications
289 for _, nni := range o.Nnis {
290 msg := Message{
291 Type: NniIndication,
292 Data: NniIndicationMessage{
293 OperState: UP,
294 NniPortID: nni.ID,
295 },
296 }
297 o.channel <- msg
298 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100299
William Kurkian9dadc5b2019-10-22 13:51:57 -0400300 go o.processOmciMessages()
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100301
Matteo Scandolo4747d292019-08-05 11:50:18 -0700302 // send PON Port indications
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100303 for i, pon := range o.Pons {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700304 msg := Message{
305 Type: PonIndication,
306 Data: PonIndicationMessage{
307 OperState: UP,
308 PonPortID: pon.ID,
309 },
310 }
311 o.channel <- msg
312
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100313 for _, onu := range o.Pons[i].Onus {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700314 go onu.ProcessOnuMessages(stream, nil)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100315 if err := onu.InternalState.Event("discover"); err != nil {
316 log.Errorf("Error discover ONU: %v", err)
317 return err
Matteo Scandolo4747d292019-08-05 11:50:18 -0700318 }
Matteo Scandolo4747d292019-08-05 11:50:18 -0700319 }
320 }
321
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100322 oltLogger.Warn("Enable OLT Done")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700323 wg.Wait()
324 return nil
325}
326
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100327func (o *OltDevice) processOmciMessages() {
William Kurkian9dadc5b2019-10-22 13:51:57 -0400328 ch := omcisim.GetChannel()
329
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100330 oltLogger.Debug("Starting OMCI Indication Channel")
William Kurkian9dadc5b2019-10-22 13:51:57 -0400331
332 for message := range ch {
333 onuId := message.Data.OnuId
334 intfId := message.Data.IntfId
335 onu, err := o.FindOnuById(intfId, onuId)
336 if err != nil {
337 oltLogger.Errorf("Failed to find onu: %v", err)
338 }
339 go onu.processOmciMessage(message)
340 }
341}
342
Matteo Scandolo4747d292019-08-05 11:50:18 -0700343// Helpers method
344
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700345func (o OltDevice) GetPonById(id uint32) (*PonPort, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700346 for _, pon := range o.Pons {
347 if pon.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -0700348 return pon, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700349 }
350 }
351 return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID))
352}
353
354func (o OltDevice) getNniById(id uint32) (*NniPort, error) {
355 for _, nni := range o.Nnis {
356 if nni.ID == id {
Matteo Scandolo27428702019-10-11 16:21:16 -0700357 return nni, nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700358 }
359 }
360 return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID))
361}
362
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100363func (o *OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700364 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}}
365 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700366 oltLogger.Errorf("Failed to send Indication_OltInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700367 }
368
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700369 oltLogger.WithFields(log.Fields{
Matteo Scandolo4747d292019-08-05 11:50:18 -0700370 "OperState": msg.OperState,
371 }).Debug("Sent Indication_OltInd")
372}
373
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100374func (o *OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700375 nni, _ := o.getNniById(msg.NniPortID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700376 nni.OperState.Event("enable")
377 // NOTE Operstate may need to be an integer
Matteo Scandolo4747d292019-08-05 11:50:18 -0700378 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700379 Type: nni.Type,
380 IntfId: nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700381 OperState: nni.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700382 }}
383
384 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700385 oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700386 }
387
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700388 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700389 "Type": nni.Type,
390 "IntfId": nni.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700391 "OperState": nni.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700392 }).Debug("Sent Indication_IntfOperInd for NNI")
393}
394
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100395func (o *OltDevice) sendPonIndication(msg PonIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700396 pon, _ := o.GetPonById(msg.PonPortID)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700397 pon.OperState.Event("enable")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700398 discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700399 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700400 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700401 }}
402
403 if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700404 oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700405 }
406
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700407 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700408 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700409 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700410 }).Debug("Sent Indication_IntfInd")
411
412 operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700413 Type: pon.Type,
414 IntfId: pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700415 OperState: pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700416 }}
417
418 if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
Matteo Scandolo11006992019-08-28 11:29:46 -0700419 oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700420 }
421
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700422 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700423 "Type": pon.Type,
424 "IntfId": pon.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700425 "OperState": pon.OperState.Current(),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700426 }).Debug("Sent Indication_IntfOperInd for PON")
427}
428
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100429// processOltMessages handles messages received over the OpenOLT interface
430func (o *OltDevice) processOltMessages(stream openolt.Openolt_EnableIndicationServer, wg *sync.WaitGroup) {
431 oltLogger.Debug("Starting OLT Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700432 for message := range o.channel {
433
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700434 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700435 "oltId": o.ID,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700436 "messageType": message.Type,
437 }).Trace("Received message")
438
439 switch message.Type {
440 case OltIndication:
441 msg, _ := message.Data.(OltIndicationMessage)
442 if msg.OperState == UP {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700443 o.InternalState.Event("enable")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700444 o.OperState.Event("enable")
445 } else if msg.OperState == DOWN {
446 o.InternalState.Event("disable")
447 o.OperState.Event("disable")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700448 }
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700449 o.sendOltIndication(msg, stream)
450 case NniIndication:
451 msg, _ := message.Data.(NniIndicationMessage)
452 o.sendNniIndication(msg, stream)
453 case PonIndication:
454 msg, _ := message.Data.(PonIndicationMessage)
455 o.sendPonIndication(msg, stream)
456 default:
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700457 oltLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700458 }
459
460 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100461 wg.Done()
462 oltLogger.Warn("Stopped handling OLT Indication Channel")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700463}
464
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100465// processNniPacketIns handles messages received over the NNI interface
466func (o *OltDevice) processNniPacketIns(stream openolt.Openolt_EnableIndicationServer, wg *sync.WaitGroup) {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700467 oltLogger.WithFields(log.Fields{
468 "nniChannel": o.nniPktInChannel,
469 }).Debug("Started NNI Channel")
470 nniId := o.Nnis[0].ID // FIXME we are assuming we have only one NNI
471 for message := range o.nniPktInChannel {
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700472 oltLogger.Tracef("Received packets on NNI Channel")
473
474 onuMac, err := packetHandlers.GetDstMacAddressFromPacket(message.Pkt)
475
476 if err != nil {
477 log.WithFields(log.Fields{
478 "IntfType": "nni",
479 "IntfId": nniId,
480 "Pkt": message.Pkt.Data(),
Matteo Scandolo27428702019-10-11 16:21:16 -0700481 }).Error("Can't find Dst MacAddress in packet")
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700482 return
483 }
484
485 onu, err := o.FindOnuByMacAddress(onuMac)
486 if err != nil {
487 log.WithFields(log.Fields{
488 "IntfType": "nni",
489 "IntfId": nniId,
490 "Pkt": message.Pkt.Data(),
491 "MacAddress": onuMac.String(),
Matteo Scandolo27428702019-10-11 16:21:16 -0700492 }).Error("Can't find ONU with MacAddress")
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700493 return
494 }
495
496 doubleTaggedPkt, err := packetHandlers.PushDoubleTag(onu.STag, onu.CTag, message.Pkt)
497 if err != nil {
498 log.Error("Fail to add double tag to packet")
499 }
500
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700501 data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{
502 IntfType: "nni",
503 IntfId: nniId,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700504 Pkt: doubleTaggedPkt.Data()}}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700505 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
506 oltLogger.WithFields(log.Fields{
507 "IntfType": data.PktInd.IntfType,
508 "IntfId": nniId,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700509 "Pkt": doubleTaggedPkt.Data(),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700510 }).Errorf("Fail to send PktInd indication: %v", err)
511 }
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700512 oltLogger.WithFields(log.Fields{
513 "IntfType": data.PktInd.IntfType,
514 "IntfId": nniId,
515 "Pkt": doubleTaggedPkt.Data(),
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700516 "OnuSn": onu.Sn(),
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700517 }).Tracef("Sent PktInd indication")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700518 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100519 wg.Done()
520 oltLogger.WithFields(log.Fields{
521 "nniChannel": o.nniPktInChannel,
522 }).Warn("Stopped handling NNI Channel")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700523}
524
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700525// returns an ONU with a given Serial Number
526func (o OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200527 // TODO this function can be a performance bottleneck when we have many ONUs,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700528 // memoizing it will remove the bottleneck
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700529 for _, pon := range o.Pons {
530 for _, onu := range pon.Onus {
531 if onu.Sn() == serialNumber {
Matteo Scandolo27428702019-10-11 16:21:16 -0700532 return onu, nil
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700533 }
534 }
535 }
536
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700537 return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-serial-number-%s", serialNumber))
538}
539
William Kurkian9dadc5b2019-10-22 13:51:57 -0400540// returns an ONU with a given interface/Onu Id
541func (o OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200542 // TODO this function can be a performance bottleneck when we have many ONUs,
William Kurkian9dadc5b2019-10-22 13:51:57 -0400543 // memoizing it will remove the bottleneck
544 for _, pon := range o.Pons {
545 if pon.ID == intfId {
546 for _, onu := range pon.Onus {
547 if onu.ID == onuId {
548 return onu, nil
549 }
550 }
551 }
552 }
553 return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-id-%v-%v", intfId, onuId))
554}
555
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700556// returns an ONU with a given Mac Address
557func (o OltDevice) FindOnuByMacAddress(mac net.HardwareAddr) (*Onu, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200558 // TODO this function can be a performance bottleneck when we have many ONUs,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700559 // memoizing it will remove the bottleneck
560 for _, pon := range o.Pons {
561 for _, onu := range pon.Onus {
562 if onu.HwAddress.String() == mac.String() {
Matteo Scandolo27428702019-10-11 16:21:16 -0700563 return onu, nil
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700564 }
565 }
566 }
567
568 return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-mac-address-%s", mac))
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700569}
570
Matteo Scandolo4747d292019-08-05 11:50:18 -0700571// GRPC Endpoints
572
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700573func (o OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700574 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700575 "OnuSn": onuSnToString(onu.SerialNumber),
Matteo Scandolo4747d292019-08-05 11:50:18 -0700576 }).Info("Received ActivateOnu call from VOLTHA")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700577
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700578 pon, _ := o.GetPonById(onu.IntfId)
579 _onu, _ := pon.GetOnuBySn(onu.SerialNumber)
William Kurkian0418bc82019-11-06 12:16:24 -0500580 _onu.SetID(onu.OnuId)
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700581
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700582 if err := _onu.OperState.Event("enable"); err != nil {
583 oltLogger.WithFields(log.Fields{
584 "IntfId": _onu.PonPortID,
585 "OnuSn": _onu.Sn(),
586 "OnuId": _onu.ID,
587 }).Infof("Failed to transition ONU.OperState to enabled state: %s", err.Error())
Matteo Scandolo4747d292019-08-05 11:50:18 -0700588 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700589 if err := _onu.InternalState.Event("enable"); err != nil {
590 oltLogger.WithFields(log.Fields{
591 "IntfId": _onu.PonPortID,
592 "OnuSn": _onu.Sn(),
593 "OnuId": _onu.ID,
594 }).Infof("Failed to transition ONU to enabled state: %s", err.Error())
595 }
596
597 // NOTE we need to immediately activate the ONU or the OMCI state machine won't start
598
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700599 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700600}
601
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700602func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700603 oltLogger.Error("DeactivateOnu not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700604 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700605}
606
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700607func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700608 oltLogger.Error("DeleteOnu not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700609 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700610}
611
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700612func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700613 // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether?
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100614 oltMsg := Message{
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700615 Type: OltIndication,
616 Data: OltIndicationMessage{
617 OperState: DOWN,
618 },
619 }
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100620 o.channel <- oltMsg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700621 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700622}
623
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700624func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700625 oltLogger.Error("DisablePonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700626 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700627}
628
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100629func (o *OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700630 oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700631 o.Enable(stream)
632 return nil
633}
634
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700635func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700636 oltLogger.Error("EnablePonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700637 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700638}
639
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700640func (o OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700641 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700642 "IntfId": flow.AccessIntfId,
643 "OnuId": flow.OnuId,
644 "EthType": fmt.Sprintf("%x", flow.Classifier.EthType),
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700645 "InnerVlan": flow.Classifier.IVid,
646 "OuterVlan": flow.Classifier.OVid,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700647 "FlowType": flow.FlowType,
648 "FlowId": flow.FlowId,
649 "UniID": flow.UniId,
650 "PortNo": flow.PortNo,
651 }).Tracef("OLT receives Flow")
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700652 // TODO optionally store flows somewhere
653
654 if flow.AccessIntfId == -1 {
655 oltLogger.WithFields(log.Fields{
656 "FlowId": flow.FlowId,
657 }).Debugf("This is an OLT flow")
658 } else {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700659 pon, err := o.GetPonById(uint32(flow.AccessIntfId))
Matteo Scandolo27428702019-10-11 16:21:16 -0700660 if err != nil {
661 oltLogger.WithFields(log.Fields{
662 "OnuId": flow.OnuId,
663 "IntfId": flow.AccessIntfId,
664 "err": err,
665 }).Error("Can't find PonPort")
666 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700667 onu, err := pon.GetOnuById(uint32(flow.OnuId))
Matteo Scandolo27428702019-10-11 16:21:16 -0700668 if err != nil {
669 oltLogger.WithFields(log.Fields{
670 "OnuId": flow.OnuId,
671 "IntfId": flow.AccessIntfId,
672 "err": err,
673 }).Error("Can't find Onu")
674 }
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700675
676 msg := Message{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700677 Type: FlowUpdate,
678 Data: OnuFlowUpdateMessage{
679 PonPortID: pon.ID,
680 OnuID: onu.ID,
681 Flow: flow,
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700682 },
683 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700684 onu.Channel <- msg
Matteo Scandolo3bc73742019-08-20 14:04:04 -0700685 }
686
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700687 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700688}
689
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700690func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error) {
691 oltLogger.Tracef("received FlowRemove")
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700692 // TODO store flows somewhere
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700693 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700694}
695
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700696func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700697 oltLogger.Error("HeartbeatCheck not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700698 return new(openolt.Heartbeat), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700699}
700
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700701func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) {
Matteo Scandolo4747d292019-08-05 11:50:18 -0700702
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700703 oltLogger.WithFields(log.Fields{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700704 "oltId": o.ID,
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700705 "PonPorts": o.NumPon,
706 }).Info("OLT receives GetDeviceInfo call from VOLTHA")
Matteo Scandolo4747d292019-08-05 11:50:18 -0700707 devinfo := new(openolt.DeviceInfo)
708 devinfo.Vendor = "BBSim"
709 devinfo.Model = "asfvolt16"
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700710 devinfo.HardwareVersion = "emulated"
Matteo Scandolo4747d292019-08-05 11:50:18 -0700711 devinfo.FirmwareVersion = ""
712 devinfo.Technology = "xgspon"
Matteo Scandoloda9cbe22019-08-19 16:05:10 -0700713 devinfo.PonPorts = uint32(o.NumPon)
Matteo Scandolo4747d292019-08-05 11:50:18 -0700714 devinfo.OnuIdStart = 1
715 devinfo.OnuIdEnd = 255
716 devinfo.AllocIdStart = 1024
717 devinfo.AllocIdEnd = 16383
718 devinfo.GemportIdStart = 1024
719 devinfo.GemportIdEnd = 65535
720 devinfo.FlowIdStart = 1
721 devinfo.FlowIdEnd = 16383
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700722 devinfo.DeviceSerialNumber = o.SerialNumber
Matteo Scandolo3f5d7f22019-10-16 14:21:13 -0700723 devinfo.DeviceId = net.HardwareAddr{0xA, 0xA, 0xA, 0xA, 0xA, byte(o.ID)}.String()
Matteo Scandolo4747d292019-08-05 11:50:18 -0700724
725 return devinfo, nil
726}
727
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700728func (o OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700729 pon, _ := o.GetPonById(omci_msg.IntfId)
730 onu, _ := pon.GetOnuById(omci_msg.OnuId)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700731 oltLogger.WithFields(log.Fields{
732 "IntfId": onu.PonPortID,
733 "OnuId": onu.ID,
734 "OnuSn": onu.Sn(),
735 }).Tracef("Received OmciMsgOut")
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700736 msg := Message{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700737 Type: OMCI,
738 Data: OmciMessage{
739 OnuSN: onu.SerialNumber,
740 OnuID: onu.ID,
741 omciMsg: omci_msg,
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700742 },
743 }
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700744 onu.Channel <- msg
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700745 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700746}
747
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700748func (o OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700749 pon, err := o.GetPonById(onuPkt.IntfId)
Matteo Scandolo27428702019-10-11 16:21:16 -0700750 if err != nil {
751 oltLogger.WithFields(log.Fields{
752 "OnuId": onuPkt.OnuId,
753 "IntfId": onuPkt.IntfId,
754 "err": err,
755 }).Error("Can't find PonPort")
756 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700757 onu, err := pon.GetOnuById(onuPkt.OnuId)
Matteo Scandolo27428702019-10-11 16:21:16 -0700758 if err != nil {
759 oltLogger.WithFields(log.Fields{
760 "OnuId": onuPkt.OnuId,
761 "IntfId": onuPkt.IntfId,
762 "err": err,
763 }).Error("Can't find Onu")
764 }
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700765
Matteo Scandolo075b1892019-10-07 12:11:07 -0700766 oltLogger.WithFields(log.Fields{
767 "IntfId": onu.PonPortID,
768 "OnuId": onu.ID,
769 "OnuSn": onu.Sn(),
770 }).Tracef("Received OnuPacketOut")
771
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700772 rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700773 pktType, err := packetHandlers.IsEapolOrDhcp(rawpkt)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700774
Matteo Scandolo075b1892019-10-07 12:11:07 -0700775 msg := Message{
776 Type: OnuPacketOut,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700777 Data: OnuPacketMessage{
Matteo Scandolo075b1892019-10-07 12:11:07 -0700778 IntfId: onuPkt.IntfId,
779 OnuId: onuPkt.OnuId,
780 Packet: rawpkt,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700781 Type: pktType,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700782 },
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700783 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700784 onu.Channel <- msg
785
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700786 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700787}
788
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700789func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100790 oltLogger.Info("Shutting down")
791 o.RestartOLT()
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700792 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700793}
794
795func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700796 oltLogger.Error("ReenableOlt not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700797 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700798}
799
800func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700801 pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
802
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100803 o.Nnis[0].sendNniPacket(pkt) // FIXME we are assuming we have only one NNI
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700804 // NOTE should we return an error if sendNniPakcet fails?
805 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700806}
807
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700808func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700809 oltLogger.Error("CollectStatistics not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700810 return new(openolt.Empty), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700811}
812
Matteo Scandolo4747d292019-08-05 11:50:18 -0700813func (o OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700814 oltLogger.Error("GetOnuInfo not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700815 return new(openolt.OnuIndication), nil
Matteo Scandolo4747d292019-08-05 11:50:18 -0700816}
817
818func (o OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700819 oltLogger.Error("GetPonIf not implemented")
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700820 return new(openolt.IntfIndication), nil
Matteo Scandolod54283a2019-08-13 16:22:31 -0700821}
822
823func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700824 oltLogger.Info("received CreateTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700825 return new(openolt.Empty), nil
826}
827
828func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700829 oltLogger.Info("received RemoveTrafficQueues")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700830 return new(openolt.Empty), nil
831}
832
833func (s OltDevice) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700834 oltLogger.Info("received CreateTrafficSchedulers")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700835 return new(openolt.Empty), nil
836}
837
838func (s OltDevice) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
Matteo Scandoloc559ef12019-08-20 13:24:21 -0700839 oltLogger.Info("received RemoveTrafficSchedulers")
Matteo Scandolod54283a2019-08-13 16:22:31 -0700840 return new(openolt.Empty), nil
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700841}