blob: 4aeae1363b331ebc1dbf3910460ae9c0a769da9e [file] [log] [blame]
Author Namea594e632018-08-10 11:33:58 -04001/*
2 Copyright 2017 the original author or authors.
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
17package api
18
19import (
donNewtonAlpha5234b132018-08-16 14:12:28 -040020 "errors"
Author Namea594e632018-08-10 11:33:58 -040021 "fmt"
22 "log"
23 "net"
24 "strings"
25
26 "gerrit.opencord.org/abstract-olt/internal/pkg/settings"
27 "gerrit.opencord.org/abstract-olt/models"
28 "gerrit.opencord.org/abstract-olt/models/abstract"
29 "gerrit.opencord.org/abstract-olt/models/physical"
30 context "golang.org/x/net/context"
31)
32
33/*
34Server instance of the grpc server
35*/
36type Server struct {
37}
38
39/*
40CreateChassis - allocates a new Chassis struct and stores it in chassisMap
41*/
42func (s *Server) CreateChassis(ctx context.Context, in *AddChassisMessage) (*AddChassisReturn, error) {
43 phyChassisMap := models.GetPhyChassisMap()
44 absChassisMap := models.GetAbstractChassisMap()
45 clli := in.GetCLLI()
Author Namea594e632018-08-10 11:33:58 -040046 chassis := (*phyChassisMap)[clli]
47 if chassis != nil {
48 return &AddChassisReturn{DeviceID: chassis.CLLI}, nil
49 }
50 abstractChassis := abstract.GenerateChassis(clli)
donNewtonAlpha5234b132018-08-16 14:12:28 -040051 phyChassis := &physical.Chassis{CLLI: clli, VCoreAddress: net.TCPAddr{IP: net.ParseIP(in.GetVCoreIP()), Port: int(in.GetVCorePort())}}
Author Namea594e632018-08-10 11:33:58 -040052 if settings.GetDebug() {
53 output := fmt.Sprintf("%v", abstractChassis)
54 formatted := strings.Replace(output, "{", "\n{", -1)
55 log.Printf("new chassis %s\n", formatted)
56 }
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040057 (*phyChassisMap)[clli] = phyChassis
58 fmt.Printf("phy %v, abs %v\n", phyChassisMap, absChassisMap)
Author Namea594e632018-08-10 11:33:58 -040059 (*absChassisMap)[clli] = abstractChassis
60 return &AddChassisReturn{DeviceID: clli}, nil
61}
62
63/*
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040064CreateOLTChassis adds an OLT chassis/line card to the Physical chassis
Author Namea594e632018-08-10 11:33:58 -040065*/
66func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
67 fmt.Printf(" CreateOLTChassis %v \n", *in)
68 phyChassisMap := models.GetPhyChassisMap()
69 clli := in.GetCLLI()
70 chassis := (*phyChassisMap)[clli]
71 if chassis == nil {
72 }
73 oltType := in.GetType()
74 address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
donNewtonAlpha5234b132018-08-16 14:12:28 -040075 sOlt := physical.SimpleOLT{CLLI: clli, Hostname: in.GetHostname(), Address: address, Parent: chassis}
Author Namea594e632018-08-10 11:33:58 -040076
77 var olt physical.OLT
78 switch oltType {
79 case AddOLTChassisMessage_edgecore:
80 olt = physical.CreateEdgecore(&sOlt)
81 case AddOLTChassisMessage_adtran:
82 case AddOLTChassisMessage_tibit:
83 }
84
85 err := AddCard(chassis, olt)
86 if err != nil {
87 //TODO do something
88 }
89
90 return &AddOLTChassisReturn{DeviceID: in.GetHostname(), ChassisDeviceID: clli}, nil
91
92}
93
94/*
95AddCard Adds an OLT card to an existing physical chassis, allocating ports
96in the physical card to those in the abstract model
97*/
98func AddCard(physChassis *physical.Chassis, olt physical.OLT) error {
donNewtonAlpha5234b132018-08-16 14:12:28 -040099 physChassis.AddOLTChassis(olt)
Author Namea594e632018-08-10 11:33:58 -0400100
101 ports := olt.GetPorts()
102 absChassis := (*models.GetAbstractChassisMap())[physChassis.CLLI]
103
104 for i := 0; i < len(ports); i++ {
105 absPort, _ := absChassis.NextPort()
106 absPort.PhysPort = &ports[i]
107 //AssignTraits(&ports[i], absPort)
108 }
Author Namea594e632018-08-10 11:33:58 -0400109 //should probably worry about error at some point
110 return nil
111}
donNewtonAlpha5234b132018-08-16 14:12:28 -0400112
113/*
114EnableSlot - activates an OLT Chassis
115*/
116func (s *Server) EnableSlot(ctx context.Context, in *ActivateSlotMessage) (*ActivateSlotReturn, error) {
117 return nil, errors.New("garbage error")
118}
119
120/*
121ProvisionOnt provisions an ONT on a specific Chassis/LineCard/Port
122*/
123func (s *Server) ProvisionOnt(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
124 absChassisMap := models.GetAbstractChassisMap()
125 clli := in.GetCLLI()
126 chassis := (*absChassisMap)[clli]
127 err := chassis.ActivateONT(int(in.GetSlotNumber()), int(in.GetPortNumber()), int(in.GetPortNumber()), in.GetSerialNumber())
128
129 if err != nil {
130 return nil, err
131 }
132 return &AddOntReturn{Success: true}, nil
133}