Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package physical |
| 18 | |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 19 | import ( |
| 20 | "fmt" |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 21 | "log" |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 22 | "net" |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 23 | "net/http" |
| 24 | "strings" |
| 25 | |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 26 | "gerrit.opencord.org/abstract-olt/internal/pkg/settings" |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 27 | "gerrit.opencord.org/abstract-olt/models/tosca" |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 28 | ) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | Chassis is a model that takes up to 16 discreet OLT chassis as if it is a 16 slot OLT chassis |
| 32 | */ |
| 33 | type Chassis struct { |
donNewtonAlpha | 57aa2ff | 2018-10-01 16:45:32 -0400 | [diff] [blame] | 34 | CLLI string |
| 35 | XOSAddress net.TCPAddr |
| 36 | XOSUser string |
| 37 | XOSPassword string |
| 38 | Linecards []SimpleOLT |
| 39 | Rack int |
| 40 | Shelf int |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 41 | } |
donNewtonAlpha | 8205a4d | 2018-08-16 18:27:20 -0400 | [diff] [blame] | 42 | type UnprovisionedSlotError struct { |
| 43 | CLLI string |
| 44 | SlotNumber int |
| 45 | } |
| 46 | |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 47 | func (c *Chassis) Output() { |
| 48 | for _, olt := range c.Linecards { |
| 49 | olt.Output() |
| 50 | } |
| 51 | } |
| 52 | |
donNewtonAlpha | 8205a4d | 2018-08-16 18:27:20 -0400 | [diff] [blame] | 53 | func (e *UnprovisionedSlotError) Error() string { |
| 54 | return fmt.Sprintf("SlotNumber %d in Chassis %s is currently unprovsioned", e.SlotNumber, e.CLLI) |
| 55 | } |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | AddOLTChassis - adds a reference to a new olt chassis |
| 59 | */ |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 60 | func (chassis *Chassis) AddOLTChassis(olt SimpleOLT) { |
| 61 | olt.SetNumber((len(chassis.Linecards) + 1)) |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 62 | chassis.Linecards = append(chassis.Linecards, olt) |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 63 | chassis.SendOltTosca(olt) |
| 64 | |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | SendOltTosca - Broke above method apart to support Reflow |
| 69 | */ |
| 70 | func (chassis *Chassis) SendOltTosca(olt SimpleOLT) { |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 71 | 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() |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 75 | if settings.GetDummy() { |
| 76 | log.Printf("yaml:%s\n", yaml) |
| 77 | log.Println("YAML IS NOT BEING SET TO XOS") |
| 78 | return |
| 79 | } |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 80 | client := &http.Client{} |
donNewtonAlpha | 57aa2ff | 2018-10-01 16:45:32 -0400 | [diff] [blame] | 81 | requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 82 | req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml)) |
donNewtonAlpha | 57aa2ff | 2018-10-01 16:45:32 -0400 | [diff] [blame] | 83 | req.Header.Add("xos-username", chassis.XOSUser) |
| 84 | req.Header.Add("xos-password", chassis.XOSPassword) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 85 | resp, err := client.Do(req) |
| 86 | if err != nil { |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 87 | //TODO |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 88 | // handle error |
| 89 | } |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 90 | log.Printf("Server response was %v\n", resp) |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 91 | } |
| 92 | func (chassis *Chassis) provisionONT(ont Ont) { |
| 93 | //TODO - api call to provison s/c vlans and ont serial number etc |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 94 | log.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan) |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 95 | chassis.SendOntTosca(ont) |
| 96 | chassis.SendSubscriberTosca(ont) |
| 97 | } |
| 98 | func (chassis *Chassis) SendOntTosca(ont Ont) { |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 99 | ponPort := ont.Parent |
| 100 | slot := ponPort.Parent |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 101 | ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number) |
| 102 | yaml, _ := ontStruct.ToYaml() |
| 103 | |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 104 | if settings.GetDummy() { |
| 105 | log.Printf("yaml:%s\n", yaml) |
| 106 | log.Println("YAML IS NOT BEING SET TO XOS") |
| 107 | return |
| 108 | } |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 109 | client := &http.Client{} |
donNewtonAlpha | 57aa2ff | 2018-10-01 16:45:32 -0400 | [diff] [blame] | 110 | requestList := fmt.Sprintf("http://%s:%d/run", chassis.XOSAddress.IP.String(), chassis.XOSAddress.Port) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 111 | req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml)) |
donNewtonAlpha | 57aa2ff | 2018-10-01 16:45:32 -0400 | [diff] [blame] | 112 | req.Header.Add("xos-username", chassis.XOSUser) |
| 113 | req.Header.Add("xos-password", chassis.XOSPassword) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 114 | resp, err := client.Do(req) |
| 115 | if err != nil { |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 116 | log.Printf("ERROR :) %v\n", err) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 117 | // handle error |
| 118 | } |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 119 | log.Printf("Response is %v\n", resp) |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 120 | } |
| 121 | func (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) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 125 | 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 Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 127 | 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 | |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 143 | } |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 144 | } |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 145 | func (chassis *Chassis) deleteONT(ont Ont) { |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 146 | log.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan) |
donNewtonAlpha | b8f3075 | 2018-10-04 11:57:41 -0400 | [diff] [blame] | 147 | 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 | } |
donNewtonAlpha | 8205a4d | 2018-08-16 18:27:20 -0400 | [diff] [blame] | 195 | } |