blob: 6beba76fcbcd94a6be006cf8dccf9c10474580d8 [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 (
20 "fmt"
21 "log"
22 "net"
23 "strings"
24
25 "gerrit.opencord.org/abstract-olt/internal/pkg/settings"
26 "gerrit.opencord.org/abstract-olt/models"
27 "gerrit.opencord.org/abstract-olt/models/abstract"
28 "gerrit.opencord.org/abstract-olt/models/physical"
29 context "golang.org/x/net/context"
30)
31
32/*
33Server instance of the grpc server
34*/
35type Server struct {
36}
37
38/*
39CreateChassis - allocates a new Chassis struct and stores it in chassisMap
40*/
41func (s *Server) CreateChassis(ctx context.Context, in *AddChassisMessage) (*AddChassisReturn, error) {
42 phyChassisMap := models.GetPhyChassisMap()
43 absChassisMap := models.GetAbstractChassisMap()
44 clli := in.GetCLLI()
Author Namea594e632018-08-10 11:33:58 -040045 chassis := (*phyChassisMap)[clli]
46 if chassis != nil {
47 return &AddChassisReturn{DeviceID: chassis.CLLI}, nil
48 }
49 abstractChassis := abstract.GenerateChassis(clli)
donNewtonAlpha5234b132018-08-16 14:12:28 -040050 phyChassis := &physical.Chassis{CLLI: clli, VCoreAddress: net.TCPAddr{IP: net.ParseIP(in.GetVCoreIP()), Port: int(in.GetVCorePort())}}
Author Namea594e632018-08-10 11:33:58 -040051 if settings.GetDebug() {
52 output := fmt.Sprintf("%v", abstractChassis)
53 formatted := strings.Replace(output, "{", "\n{", -1)
54 log.Printf("new chassis %s\n", formatted)
55 }
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040056 (*phyChassisMap)[clli] = phyChassis
57 fmt.Printf("phy %v, abs %v\n", phyChassisMap, absChassisMap)
Author Namea594e632018-08-10 11:33:58 -040058 (*absChassisMap)[clli] = abstractChassis
59 return &AddChassisReturn{DeviceID: clli}, nil
60}
61
62/*
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040063CreateOLTChassis adds an OLT chassis/line card to the Physical chassis
Author Namea594e632018-08-10 11:33:58 -040064*/
65func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
66 fmt.Printf(" CreateOLTChassis %v \n", *in)
67 phyChassisMap := models.GetPhyChassisMap()
68 clli := in.GetCLLI()
69 chassis := (*phyChassisMap)[clli]
70 if chassis == nil {
71 }
72 oltType := in.GetType()
73 address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
donNewtonAlpha5234b132018-08-16 14:12:28 -040074 sOlt := physical.SimpleOLT{CLLI: clli, Hostname: in.GetHostname(), Address: address, Parent: chassis}
Author Namea594e632018-08-10 11:33:58 -040075
76 var olt physical.OLT
77 switch oltType {
78 case AddOLTChassisMessage_edgecore:
79 olt = physical.CreateEdgecore(&sOlt)
80 case AddOLTChassisMessage_adtran:
81 case AddOLTChassisMessage_tibit:
82 }
83
84 err := AddCard(chassis, olt)
85 if err != nil {
86 //TODO do something
87 }
88
89 return &AddOLTChassisReturn{DeviceID: in.GetHostname(), ChassisDeviceID: clli}, nil
90
91}
92
93/*
94AddCard Adds an OLT card to an existing physical chassis, allocating ports
95in the physical card to those in the abstract model
96*/
97func AddCard(physChassis *physical.Chassis, olt physical.OLT) error {
donNewtonAlpha5234b132018-08-16 14:12:28 -040098 physChassis.AddOLTChassis(olt)
Author Namea594e632018-08-10 11:33:58 -040099
100 ports := olt.GetPorts()
101 absChassis := (*models.GetAbstractChassisMap())[physChassis.CLLI]
102
103 for i := 0; i < len(ports); i++ {
104 absPort, _ := absChassis.NextPort()
105 absPort.PhysPort = &ports[i]
106 //AssignTraits(&ports[i], absPort)
107 }
Author Namea594e632018-08-10 11:33:58 -0400108 //should probably worry about error at some point
109 return nil
110}
donNewtonAlpha5234b132018-08-16 14:12:28 -0400111
112/*
donNewtonAlpha5234b132018-08-16 14:12:28 -0400113ProvisionOnt provisions an ONT on a specific Chassis/LineCard/Port
114*/
115func (s *Server) ProvisionOnt(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
116 absChassisMap := models.GetAbstractChassisMap()
117 clli := in.GetCLLI()
118 chassis := (*absChassisMap)[clli]
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400119 err := chassis.ActivateONT(int(in.GetSlotNumber()), int(in.GetPortNumber()), int(in.GetOntNumber()), in.GetSerialNumber())
donNewtonAlpha5234b132018-08-16 14:12:28 -0400120
121 if err != nil {
122 return nil, err
123 }
124 return &AddOntReturn{Success: true}, nil
125}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400126
127/*
128DeleteOnt - deletes a previously provision ont
129*/
130func (s *Server) DeleteOnt(ctx context.Context, in *DeleteOntMessage) (*DeleteOntReturn, error) {
131 absChassisMap := models.GetAbstractChassisMap()
132 clli := in.GetCLLI()
133 chassis := (*absChassisMap)[clli]
134 err := chassis.DeleteONT(int(in.GetSlotNumber()), int(in.GetPortNumber()), int(in.GetOntNumber()), in.GetSerialNumber())
135 if err != nil {
136 return nil, err
137 }
138 return &DeleteOntReturn{Success: true}, nil
139}