blob: 59c87b703b8c5ea826b330912a6adf6598166ed7 [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)
Don Newtone973d342018-10-26 16:44:12 -040063 chassis.SendOltTosca(olt)
64
65}
66
67/*
68SendOltTosca - Broke above method apart to support Reflow
69*/
70func (chassis *Chassis) SendOltTosca(olt SimpleOLT) {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040071 ipString := olt.GetAddress().IP.String()
72 webServerPort := olt.GetAddress().Port
73 oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), "openolt", ipString, webServerPort)
74 yaml, _ := oltStruct.ToYaml()
donNewtonAlphaaf229742018-09-19 13:22:00 -040075 if settings.GetDummy() {
76 log.Printf("yaml:%s\n", yaml)
77 log.Println("YAML IS NOT BEING SET TO XOS")
78 return
79 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040080 client := &http.Client{}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040081 requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040082 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040083 req.Header.Add("xos-username", chassis.XOSUser)
84 req.Header.Add("xos-password", chassis.XOSPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040085 resp, err := client.Do(req)
86 if err != nil {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040087 //TODO
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040088 // handle error
89 }
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040090 log.Printf("Server response was %v\n", resp)
donNewtonAlpha5234b132018-08-16 14:12:28 -040091}
92func (chassis *Chassis) provisionONT(ont Ont) {
93 //TODO - api call to provison s/c vlans and ont serial number etc
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040094 log.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
Don Newtone973d342018-10-26 16:44:12 -040095 chassis.SendOntTosca(ont)
96 chassis.SendSubscriberTosca(ont)
97}
98func (chassis *Chassis) SendOntTosca(ont Ont) {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040099 ponPort := ont.Parent
100 slot := ponPort.Parent
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400101 ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number)
102 yaml, _ := ontStruct.ToYaml()
103
donNewtonAlphaaf229742018-09-19 13:22:00 -0400104 if settings.GetDummy() {
105 log.Printf("yaml:%s\n", yaml)
106 log.Println("YAML IS NOT BEING SET TO XOS")
107 return
108 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400109 client := &http.Client{}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400110 requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400111 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400112 req.Header.Add("xos-username", chassis.XOSUser)
113 req.Header.Add("xos-password", chassis.XOSPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400114 resp, err := client.Do(req)
115 if err != nil {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400116 log.Printf("ERROR :) %v\n", err)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400117 // handle error
118 }
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400119 log.Printf("Response is %v\n", resp)
Don Newtone973d342018-10-26 16:44:12 -0400120}
121func (chassis *Chassis) SendSubscriberTosca(ont Ont) {
122 ponPort := ont.Parent
123 slot := ponPort.Parent
124 requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400125 rgName := fmt.Sprintf("%s_%d_%d_%d_RG", chassis.CLLI, slot.Number, ponPort.Number, ont.Number)
126 subStruct := tosca.NewSubscriberProvision(rgName, ont.Cvlan, ont.Svlan, ont.SerialNumber, ont.NasPortID, ont.CircuitID, chassis.CLLI)
Don Newtone973d342018-10-26 16:44:12 -0400127 yaml, _ := subStruct.ToYaml()
128 if settings.GetDummy() {
129 log.Printf("yaml:%s\n", yaml)
130 log.Println("YAML IS NOT BEING SET TO XOS")
131 } else {
132 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
133 req.Header.Add("xos-username", chassis.XOSUser)
134 req.Header.Add("xos-password", chassis.XOSPassword)
135 client := &http.Client{}
136 resp, err := client.Do(req)
137 if err != nil {
138 log.Printf("ERROR :) %v\n", err)
139 // handle error
140 }
141 log.Printf("Response is %v\n", resp)
142
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400143 }
donNewtonAlpha5234b132018-08-16 14:12:28 -0400144}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400145func (chassis *Chassis) deleteONT(ont Ont) {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400146 log.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
donNewtonAlphab8f30752018-10-04 11:57:41 -0400147 ponPort := ont.Parent
148 slot := ponPort.Parent
149
150 //func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
151 ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number)
152 yaml, _ := ontStruct.ToYaml()
153 fmt.Println(yaml)
154
155 requestList := fmt.Sprintf("http://%s:%d/delete", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port)
156 client := &http.Client{}
157 if settings.GetDummy() {
158 log.Printf("yaml:%s\n", yaml)
159 log.Println("YAML IS NOT BEING SET TO XOS")
160 } else {
161
162 log.Println(requestList)
163 log.Println(yaml)
164 if settings.GetDummy() {
165 return
166 }
167 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
168 req.Header.Add("xos-username", chassis.XOSUser)
169 req.Header.Add("xos-password", chassis.XOSPassword)
170 resp, err := client.Do(req)
171 if err != nil {
172 log.Printf("ERROR :) %v\n", err)
173 // handle error
174 }
175 log.Printf("Response is %v\n", resp)
176 }
177 deleteOntStruct := tosca.NewOntDelete(ont.SerialNumber)
178 yaml, _ = deleteOntStruct.ToYaml()
179 fmt.Println(yaml)
180 if settings.GetDummy() {
181 log.Printf("yaml:%s\n", yaml)
182 log.Println("YAML IS NOT BEING SET TO XOS")
183 return
184 } else {
185 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
186 req.Header.Add("xos-username", chassis.XOSUser)
187 req.Header.Add("xos-password", chassis.XOSPassword)
188 resp, err := client.Do(req)
189 if err != nil {
190 log.Printf("ERROR :) %v\n", err)
191 // handle error
192 }
193 log.Printf("Response is %v\n", resp)
194 }
donNewtonAlpha8205a4d2018-08-16 18:27:20 -0400195}