blob: 0c164e91c216af1bf6d56139ba3258fc0e7b418b [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 physical
18
donNewtonAlpha5234b132018-08-16 14:12:28 -040019import (
20 "fmt"
donNewtonAlphaaf229742018-09-19 13:22:00 -040021 "log"
donNewtonAlpha5234b132018-08-16 14:12:28 -040022 "net"
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040023 "net/http"
24 "strings"
25
donNewtonAlphaaf229742018-09-19 13:22:00 -040026 "gerrit.opencord.org/abstract-olt/internal/pkg/settings"
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040027 "gerrit.opencord.org/abstract-olt/models/tosca"
donNewtonAlpha5234b132018-08-16 14:12:28 -040028)
Author Namea594e632018-08-10 11:33:58 -040029
30/*
31Chassis is a model that takes up to 16 discreet OLT chassis as if it is a 16 slot OLT chassis
32*/
33type Chassis struct {
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040034 CLLI string
35 XOSAddress net.TCPAddr
36 XOSUser string
37 XOSPassword string
38 Linecards []SimpleOLT
39 Rack int
40 Shelf int
Author Namea594e632018-08-10 11:33:58 -040041}
donNewtonAlpha8205a4d2018-08-16 18:27:20 -040042type UnprovisionedSlotError struct {
43 CLLI string
44 SlotNumber int
45}
46
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040047func (c *Chassis) Output() {
48 for _, olt := range c.Linecards {
49 olt.Output()
50 }
51}
52
donNewtonAlpha8205a4d2018-08-16 18:27:20 -040053func (e *UnprovisionedSlotError) Error() string {
54 return fmt.Sprintf("SlotNumber %d in Chassis %s is currently unprovsioned", e.SlotNumber, e.CLLI)
55}
donNewtonAlpha5234b132018-08-16 14:12:28 -040056
57/*
58AddOLTChassis - adds a reference to a new olt chassis
59*/
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040060func (chassis *Chassis) AddOLTChassis(olt SimpleOLT) {
61 olt.SetNumber((len(chassis.Linecards) + 1))
donNewtonAlpha5234b132018-08-16 14:12:28 -040062 chassis.Linecards = append(chassis.Linecards, olt)
63 //TODO - api call to add olt i.e. preprovision_olt
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040064 //S>103 func NewOltProvision(name string, deviceType string, host string, port int) OltProvsion {
65 ipString := olt.GetAddress().IP.String()
66 webServerPort := olt.GetAddress().Port
67 oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), "openolt", ipString, webServerPort)
68 yaml, _ := oltStruct.ToYaml()
donNewtonAlphaaf229742018-09-19 13:22:00 -040069 if settings.GetDummy() {
70 log.Printf("yaml:%s\n", yaml)
71 log.Println("YAML IS NOT BEING SET TO XOS")
72 return
73 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040074 client := &http.Client{}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040075 requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040076 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040077 req.Header.Add("xos-username", chassis.XOSUser)
78 req.Header.Add("xos-password", chassis.XOSPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040079 resp, err := client.Do(req)
80 if err != nil {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040081 //TODO
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040082 // handle error
83 }
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040084 log.Printf("Server response was %v\n", resp)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040085
donNewtonAlpha5234b132018-08-16 14:12:28 -040086}
87func (chassis *Chassis) provisionONT(ont Ont) {
88 //TODO - api call to provison s/c vlans and ont serial number etc
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040089 log.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040090 ponPort := ont.Parent
91 slot := ponPort.Parent
92
93 //func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
94 ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number)
95 yaml, _ := ontStruct.ToYaml()
96
donNewtonAlphaaf229742018-09-19 13:22:00 -040097 if settings.GetDummy() {
98 log.Printf("yaml:%s\n", yaml)
99 log.Println("YAML IS NOT BEING SET TO XOS")
100 return
101 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400102 client := &http.Client{}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400103 requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400104 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400105 req.Header.Add("xos-username", chassis.XOSUser)
106 req.Header.Add("xos-password", chassis.XOSPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400107 resp, err := client.Do(req)
108 if err != nil {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400109 log.Printf("ERROR :) %v\n", err)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400110 // handle error
111 }
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400112 log.Printf("Response is %v\n", resp)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400113 rgName := fmt.Sprintf("%s_%d_%d_%d_RG", chassis.CLLI, slot.Number, ponPort.Number, ont.Number)
114 subStruct := tosca.NewSubscriberProvision(rgName, ont.Cvlan, ont.Svlan, ont.SerialNumber, ont.NasPortID, ont.CircuitID, chassis.CLLI)
115 yaml, _ = subStruct.ToYaml()
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400116 log.Printf("yaml:%s\n", yaml)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400117 req, err = http.NewRequest("POST", requestList, strings.NewReader(yaml))
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400118 req.Header.Add("xos-username", chassis.XOSUser)
119 req.Header.Add("xos-password", chassis.XOSPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400120 resp, err = client.Do(req)
121 if err != nil {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400122 log.Printf("ERROR :) %v\n", err)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400123 // handle error
124 }
donNewtonAlpha5234b132018-08-16 14:12:28 -0400125}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400126func (chassis *Chassis) deleteONT(ont Ont) {
127 //TODO - api call to provison s/c vlans and ont serial number etc
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400128 log.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
donNewtonAlpha8205a4d2018-08-16 18:27:20 -0400129}