blob: 2f98c96a9dacd76f8b49a289e8c2f6e3427d0a0c [file] [log] [blame]
Zack Williams41513bf2018-07-07 20:08:35 -07001/*
2 * Copyright 2017-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 */
Stephane Barbarie35595062018-02-08 08:34:39 -050016package sbi
17
18import (
19 "context"
20 "github.com/google/uuid"
21 "github.com/opencord/voltha/ponsim/v2/common"
22 "github.com/opencord/voltha/ponsim/v2/core"
23 "github.com/opencord/voltha/protos/go/ponsim"
24 "github.com/sirupsen/logrus"
25)
26
27type PonSimOltHandler struct {
28 olt *core.PonSimOltDevice
29}
30
31func NewPonSimOltHandler(olt *core.PonSimOltDevice) *PonSimOltHandler {
32 var handler *PonSimOltHandler
33
34 handler = &PonSimOltHandler{olt: olt}
35
36 return handler
37}
38
39func (h *PonSimOltHandler) Register(
40 ctx context.Context,
41 request *ponsim.RegistrationRequest,
42) (*ponsim.RegistrationReply, error) {
43 common.Logger().WithFields(logrus.Fields{
44 "handler": h,
45 }).Info("Registering device")
46
47 onu := &core.PonSimOnuDevice{
48 PonSimDevice: core.PonSimDevice{
49 Address: request.Address, Port: request.Port, //GrpcSecurity: h.olt.GrpcSecurity,
50 }}
Andy Bavierea82b462018-07-27 16:48:13 -070051 onu.SerialNumber = request.SerialNumber
Stephane Barbarie35595062018-02-08 08:34:39 -050052
53 if assignedPort, err := h.olt.AddOnu(onu); assignedPort == -1 || err != nil {
54 return &ponsim.RegistrationReply{
55 Id: uuid.New().String(),
56 Status: ponsim.RegistrationReply_FAILED,
57 StatusMessage: "Failed to register ONU",
58 ParentAddress: common.GetInterfaceIP(h.olt.ExternalIf),
59 ParentPort: h.olt.Port,
60 AssignedPort: assignedPort,
61 }, err
62 } else {
63 common.Logger().WithFields(logrus.Fields{
64 "handler": h,
65 "onus": h.olt.GetOnus(),
66 }).Debug("ONU Added")
67
68 return &ponsim.RegistrationReply{
69 Id: uuid.New().String(),
70 Status: ponsim.RegistrationReply_REGISTERED,
71 StatusMessage: "Successfully registered ONU",
72 ParentAddress: common.GetInterfaceIP(h.olt.ExternalIf),
73 ParentPort: h.olt.Port,
74 AssignedPort: assignedPort,
75 }, nil
76
77 }
78}