blob: ec7ce86139863ce47f594430bd0f55f75ba43f3e [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()
45
46 chassis := (*phyChassisMap)[clli]
47 if chassis != nil {
48 return &AddChassisReturn{DeviceID: chassis.CLLI}, nil
49 }
50 abstractChassis := abstract.GenerateChassis(clli)
51 phyChassis := physical.Chassis{CLLI: clli}
52 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 }
57 (*phyChassisMap)[clli] = &phyChassis
58 (*absChassisMap)[clli] = abstractChassis
59 return &AddChassisReturn{DeviceID: clli}, nil
60}
61
62/*
63AddOLTChassis adds an OLT chassis/line card to the Physical chassis
64*/
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())}
74 sOlt := physical.SimpleOLT{CLLI: clli, Hostname: in.GetHostname(), Address: address}
75
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 {
98 physChassis.Linecards = append(physChassis.Linecards, olt)
99
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 }
108
109 //should probably worry about error at some point
110 return nil
111}