blob: 5fb9a94dab9791f5462287796b4d6311d7c20212 [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 {
34 CLLI string
35 VCoreAddress net.TCPAddr
36 Dataswitch DataSwitch
37 Linecards []OLT
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040038 Rack int
39 Shelf int
Author Namea594e632018-08-10 11:33:58 -040040}
donNewtonAlpha8205a4d2018-08-16 18:27:20 -040041type UnprovisionedSlotError struct {
42 CLLI string
43 SlotNumber int
44}
45
46func (e *UnprovisionedSlotError) Error() string {
47 return fmt.Sprintf("SlotNumber %d in Chassis %s is currently unprovsioned", e.SlotNumber, e.CLLI)
48}
donNewtonAlpha5234b132018-08-16 14:12:28 -040049
50/*
51AddOLTChassis - adds a reference to a new olt chassis
52*/
53func (chassis *Chassis) AddOLTChassis(olt OLT) {
54 chassis.Linecards = append(chassis.Linecards, olt)
55 //TODO - api call to add olt i.e. preprovision_olt
56 fmt.Printf("chassis.AddOLTChassis(%s)\n", olt.GetHostname())
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040057 //S>103 func NewOltProvision(name string, deviceType string, host string, port int) OltProvsion {
58 ipString := olt.GetAddress().IP.String()
59 webServerPort := olt.GetAddress().Port
60 oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), "openolt", ipString, webServerPort)
61 yaml, _ := oltStruct.ToYaml()
donNewtonAlphaaf229742018-09-19 13:22:00 -040062 if settings.GetDummy() {
63 log.Printf("yaml:%s\n", yaml)
64 log.Println("YAML IS NOT BEING SET TO XOS")
65 return
66 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040067 client := &http.Client{}
68 requestList := fmt.Sprintf("http://%s:%d/run", chassis.VCoreAddress.IP.String(), chassis.VCoreAddress.Port)
69 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
70 req.Header.Add("xos-username", "admin@opencord.org")
71 req.Header.Add("xos-password", "letmein")
72 resp, err := client.Do(req)
73 if err != nil {
74 fmt.Printf("ERROR :) %v\n", err)
75 // handle error
76 }
77 fmt.Printf("Response is %v\n", resp)
78
donNewtonAlpha5234b132018-08-16 14:12:28 -040079}
80func (chassis *Chassis) provisionONT(ont Ont) {
81 //TODO - api call to provison s/c vlans and ont serial number etc
82 fmt.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040083 ponPort := ont.Parent
84 slot := ponPort.Parent
85
86 //func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
87 ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number)
88 yaml, _ := ontStruct.ToYaml()
89
donNewtonAlphaaf229742018-09-19 13:22:00 -040090 if settings.GetDummy() {
91 log.Printf("yaml:%s\n", yaml)
92 log.Println("YAML IS NOT BEING SET TO XOS")
93 return
94 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040095 client := &http.Client{}
96 requestList := fmt.Sprintf("http://%s:%d/run", chassis.VCoreAddress.IP.String(), chassis.VCoreAddress.Port)
97 req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
98 req.Header.Add("xos-username", "admin@opencord.org")
99 req.Header.Add("xos-password", "letmein")
100 resp, err := client.Do(req)
101 if err != nil {
102 fmt.Printf("ERROR :) %v\n", err)
103 // handle error
104 }
105 fmt.Printf("Response is %v\n", resp)
106 rgName := fmt.Sprintf("%s_%d_%d_%d_RG", chassis.CLLI, slot.Number, ponPort.Number, ont.Number)
107 subStruct := tosca.NewSubscriberProvision(rgName, ont.Cvlan, ont.Svlan, ont.SerialNumber, ont.NasPortID, ont.CircuitID, chassis.CLLI)
108 yaml, _ = subStruct.ToYaml()
109 fmt.Printf("yaml:%s\n", yaml)
110 req, err = http.NewRequest("POST", requestList, strings.NewReader(yaml))
111 req.Header.Add("xos-username", "admin@opencord.org")
112 req.Header.Add("xos-password", "letmein")
113 resp, err = client.Do(req)
114 if err != nil {
115 fmt.Printf("ERROR :) %v\n", err)
116 // handle error
117 }
donNewtonAlpha5234b132018-08-16 14:12:28 -0400118}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400119func (chassis *Chassis) deleteONT(ont Ont) {
120 //TODO - api call to provison s/c vlans and ont serial number etc
121 fmt.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
122}
donNewtonAlpha8205a4d2018-08-16 18:27:20 -0400123func (chassis *Chassis) ActivateSlot(slotNumber int) error {
124 // AT&T backend systems start at 1 and not 0 :P
125 if chassis.Linecards[slotNumber-1] == nil {
126 return &UnprovisionedSlotError{CLLI: chassis.CLLI, SlotNumber: slotNumber}
127 }
128 return chassis.Linecards[slotNumber-1].activate()
129}