blob: bb058ca3463b1daaff7c70fff845f11187608cfd [file] [log] [blame]
Stephane Barbarie35595062018-02-08 08:34:39 -05001package sbi
2
3import (
4 "context"
5 "github.com/google/uuid"
6 "github.com/opencord/voltha/ponsim/v2/common"
7 "github.com/opencord/voltha/ponsim/v2/core"
8 "github.com/opencord/voltha/protos/go/ponsim"
9 "github.com/sirupsen/logrus"
10)
11
12type PonSimOltHandler struct {
13 olt *core.PonSimOltDevice
14}
15
16func NewPonSimOltHandler(olt *core.PonSimOltDevice) *PonSimOltHandler {
17 var handler *PonSimOltHandler
18
19 handler = &PonSimOltHandler{olt: olt}
20
21 return handler
22}
23
24func (h *PonSimOltHandler) Register(
25 ctx context.Context,
26 request *ponsim.RegistrationRequest,
27) (*ponsim.RegistrationReply, error) {
28 common.Logger().WithFields(logrus.Fields{
29 "handler": h,
30 }).Info("Registering device")
31
32 onu := &core.PonSimOnuDevice{
33 PonSimDevice: core.PonSimDevice{
34 Address: request.Address, Port: request.Port, //GrpcSecurity: h.olt.GrpcSecurity,
35 }}
36
37 if assignedPort, err := h.olt.AddOnu(onu); assignedPort == -1 || err != nil {
38 return &ponsim.RegistrationReply{
39 Id: uuid.New().String(),
40 Status: ponsim.RegistrationReply_FAILED,
41 StatusMessage: "Failed to register ONU",
42 ParentAddress: common.GetInterfaceIP(h.olt.ExternalIf),
43 ParentPort: h.olt.Port,
44 AssignedPort: assignedPort,
45 }, err
46 } else {
47 common.Logger().WithFields(logrus.Fields{
48 "handler": h,
49 "onus": h.olt.GetOnus(),
50 }).Debug("ONU Added")
51
52 return &ponsim.RegistrationReply{
53 Id: uuid.New().String(),
54 Status: ponsim.RegistrationReply_REGISTERED,
55 StatusMessage: "Successfully registered ONU",
56 ParentAddress: common.GetInterfaceIP(h.olt.ExternalIf),
57 ParentPort: h.olt.Port,
58 AssignedPort: assignedPort,
59 }, nil
60
61 }
62}