blob: a264532afdde95242847f7c0b7ece9c04a055fb4 [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 }}
51
52 if assignedPort, err := h.olt.AddOnu(onu); assignedPort == -1 || err != nil {
53 return &ponsim.RegistrationReply{
54 Id: uuid.New().String(),
55 Status: ponsim.RegistrationReply_FAILED,
56 StatusMessage: "Failed to register ONU",
57 ParentAddress: common.GetInterfaceIP(h.olt.ExternalIf),
58 ParentPort: h.olt.Port,
59 AssignedPort: assignedPort,
60 }, err
61 } else {
62 common.Logger().WithFields(logrus.Fields{
63 "handler": h,
64 "onus": h.olt.GetOnus(),
65 }).Debug("ONU Added")
66
67 return &ponsim.RegistrationReply{
68 Id: uuid.New().String(),
69 Status: ponsim.RegistrationReply_REGISTERED,
70 StatusMessage: "Successfully registered ONU",
71 ParentAddress: common.GetInterfaceIP(h.olt.ExternalIf),
72 ParentPort: h.olt.Port,
73 AssignedPort: assignedPort,
74 }, nil
75
76 }
77}