blob: f4b7826a4793a99dd0a9cc5701dd8c5f4a7d9be0 [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 main
18
19import (
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040020 "context"
21 "flag"
22 "fmt"
Author Namea594e632018-08-10 11:33:58 -040023 "log"
Author Namea594e632018-08-10 11:33:58 -040024 "runtime/debug"
donNewtonAlphab3279ea2018-09-18 15:55:32 -040025 "strings"
Author Namea594e632018-08-10 11:33:58 -040026
27 "gerrit.opencord.org/abstract-olt/api"
Author Namea594e632018-08-10 11:33:58 -040028 "google.golang.org/grpc"
29 "google.golang.org/grpc/credentials"
30)
31
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040032func main() {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040033 /* COMMAND FLAGS */
donNewtonAlphab3279ea2018-09-18 15:55:32 -040034 echo := flag.Bool("e", false, "echo")
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040035 create := flag.Bool("c", false, "create?")
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040036 update := flag.Bool("u", false, "update?")
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040037 addOlt := flag.Bool("s", false, "addOlt?")
38 provOnt := flag.Bool("o", false, "provisionOnt?")
Don Newton281e0252018-10-22 14:38:50 -040039 provOntFull := flag.Bool("f", false, "provsionOntFull?")
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040040 deleteOnt := flag.Bool("d", false, "deleteOnt")
Don Newton281e0252018-10-22 14:38:50 -040041 output := flag.Bool("output", false, "dump output")
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040042 /* END COMMAND FLAGS */
43
44 /* CREATE CHASSIS FLAGS */
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040045 xosUser := flag.String("xos_user", "", "xos_user")
46 xosPassword := flag.String("xos_password", "", "xos_password")
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040047 xosAddress := flag.String("xos_address", "", "xos address")
48 xosPort := flag.Uint("xos_port", 0, "xos port")
49 rack := flag.Uint("rack", 1, "rack number for chassis")
50 shelf := flag.Uint("shelf", 1, "shelf number for chassis")
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040051 /* END CREATE CHASSIS FLAGS */
52
53 /* ADD OLT FLAGS */
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040054 oltAddress := flag.String("olt_address", "", "ip address for olt chassis")
55 oltPort := flag.Uint("olt_port", 0, "listen port for olt chassis")
56 name := flag.String("name", "", "friendly name for olt chassis")
57 driver := flag.String("driver", "", "driver to use with olt chassis")
58 oltType := flag.String("type", "", "olt chassis type")
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040059 /* END ADD OLT FLAGS */
60
61 /* PROVISION / DELETE ONT FLAGS */
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040062 slot := flag.Uint("slot", 1, "slot number 1-16 to provision ont to")
63 port := flag.Uint("port", 1, "port number 1-16 to provision ont to")
64 ont := flag.Uint("ont", 1, "ont number 1-64")
65 serial := flag.String("serial", "", "serial number of ont")
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040066 /* END PROVISION / DELETE ONT FLAGS */
67
Don Newton281e0252018-10-22 14:38:50 -040068 /*PROVISION ONT FULL EXTRA FLAGS*/
69 stag := flag.Uint("stag", 0, "s-tag for ont")
70 ctag := flag.Uint("ctag", 0, "c-tag for ont")
71 nasPort := flag.String("nas_port", "", "NasPortID for ont")
72 circuitID := flag.String("circuit_id", "", "CircuitID for ont")
73 /*END PROVISION ONT FULL EXTRA FLAGS*/
74
75 /* ECHO FLAGS */
76 message := flag.String("message", "ping", "message to be echoed back")
77 /*END ECHO FLAGS*/
78
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040079 /*GENERIC FLAGS */
80 clli := flag.String("clli", "", "clli of abstract chassis")
donNewtonAlphab3279ea2018-09-18 15:55:32 -040081 useSsl := flag.Bool("ssl", false, "use ssl")
82 useAuth := flag.Bool("auth", false, "use auth")
83 crtFile := flag.String("cert", "cert/server.crt", "Public cert for server to establish tls session")
84 serverAddressPort := flag.String("server", "localhost:7777", "address and port of AbstractOLT server")
85 fqdn := flag.String("fqdn", "", "FQDN of the service to match what is in server.crt")
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040086 /*GENERIC FLAGS */
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040087
88 flag.Parse()
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040089
donNewtonAlphab3279ea2018-09-18 15:55:32 -040090 if *useSsl {
91 if *fqdn == "" {
92 fqdn = &(strings.Split(*serverAddressPort, ":")[0])
93 fmt.Printf("using %s as the FQDN for the AbstractOLT server", *fqdn)
94 }
95 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040096
Don Newton281e0252018-10-22 14:38:50 -040097 cmdFlags := []*bool{echo, addOlt, update, create, provOnt, provOntFull, deleteOnt, output}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040098 cmdCount := 0
99 for _, flag := range cmdFlags {
100 if *flag {
101 cmdCount++
102 }
103 }
104 if cmdCount > 1 {
105 fmt.Println("CMD You can only call one method at a time")
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400106 usage()
107 return
108 }
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400109 if cmdCount < 1 {
110 fmt.Println("CMD You didn't specify an operation to perform")
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400111 usage()
112 return
113 }
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400114
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400115 var conn *grpc.ClientConn
donNewtonAlphab3279ea2018-09-18 15:55:32 -0400116 var err error
117
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400118 // Setup the login/pass
119 auth := Authentication{
120 Login: "john",
121 Password: "doe",
122 }
donNewtonAlphab3279ea2018-09-18 15:55:32 -0400123 if *useSsl && *useAuth {
124
125 creds, err := credentials.NewClientTLSFromFile(*crtFile, *fqdn)
126 conn, err = grpc.Dial(*serverAddressPort, grpc.WithTransportCredentials(creds), grpc.WithPerRPCCredentials(&auth))
127 if err != nil {
128 log.Fatalf("could not load tls cert: %s", err)
129 }
130 } else if *useSsl {
131 creds, err := credentials.NewClientTLSFromFile("cert/server.crt", *fqdn)
132 conn, err = grpc.Dial(*serverAddressPort, grpc.WithTransportCredentials(creds))
133 if err != nil {
134 log.Fatalf("could not load tls cert: %s", err)
135 }
136 } else if *useAuth {
137 conn, err = grpc.Dial(*serverAddressPort, grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
138 } else {
139 conn, err = grpc.Dial(*serverAddressPort, grpc.WithInsecure())
140 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400141 if err != nil {
142 log.Fatalf("did not connect: %s", err)
143 }
144 defer conn.Close()
145
146 c := api.NewAbstractOLTClient(conn)
147 if *create {
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400148 createChassis(c, clli, xosUser, xosPassword, xosAddress, xosPort, rack, shelf)
149 } else if *update {
150 updateXOSUserPassword(c, clli, xosUser, xosPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400151 } else if *addOlt {
152 addOltChassis(c, clli, oltAddress, oltPort, name, driver, oltType)
153 } else if *provOnt {
154 provisionONT(c, clli, slot, port, ont, serial)
Don Newton281e0252018-10-22 14:38:50 -0400155 } else if *provOntFull {
156 provisionONTFull(c, clli, slot, port, ont, serial, stag, ctag, nasPort, circuitID)
donNewtonAlphab3279ea2018-09-18 15:55:32 -0400157 } else if *echo {
158 ping(c, *message)
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400159 } else if *output {
160 Output(c)
161 } else if *deleteOnt {
162 deleteONT(c, clli, slot, port, ont, serial)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400163 }
164
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400165}
166
Author Namea594e632018-08-10 11:33:58 -0400167// Authentication holds the login/password
168type Authentication struct {
169 Login string
170 Password string
171}
172
173// GetRequestMetadata gets the current request metadata
174func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
175 return map[string]string{
176 "login": a.Login,
177 "password": a.Password,
178 }, nil
179}
180
181// RequireTransportSecurity indicates whether the credentials requires transport security
182func (a *Authentication) RequireTransportSecurity() bool {
183 return true
184}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400185func Output(c api.AbstractOLTClient) error {
186 response, err := c.Output(context.Background(), &api.OutputMessage{Something: "wtf"})
187 if err != nil {
188 fmt.Printf("Error when calling Echo: %s", err)
189 return err
190 }
191 log.Printf("Response from server: %v", response.GetSuccess())
192
193 return nil
194}
195
donNewtonAlphab3279ea2018-09-18 15:55:32 -0400196func ping(c api.AbstractOLTClient, message string) error {
197 response, err := c.Echo(context.Background(), &api.EchoMessage{Ping: message})
198 if err != nil {
199 fmt.Printf("Error when calling Echo: %s", err)
200 return err
201 }
202 log.Printf("Response from server: %s", response.GetPong())
203 return nil
204}
Author Namea594e632018-08-10 11:33:58 -0400205
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400206func createChassis(c api.AbstractOLTClient, clli *string, xosUser *string, xosPassword *string, xosAddress *string, xosPort *uint, rack *uint, shelf *uint) error {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400207 fmt.Println("Calling Create Chassis")
208 fmt.Println("clli", *clli)
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400209 fmt.Println("xos_user", *xosUser)
210 fmt.Println("xos_password", *xosPassword)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400211 fmt.Println("xos_address", *xosAddress)
212 fmt.Println("xos_port", *xosPort)
213 fmt.Println("rack", *rack)
214 fmt.Println("shelf", *shelf)
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400215 response, err := c.CreateChassis(context.Background(), &api.AddChassisMessage{CLLI: *clli, XOSUser: *xosUser, XOSPassword: *xosPassword,
216 XOSIP: *xosAddress, XOSPort: int32(*xosPort), Rack: int32(*rack), Shelf: int32(*shelf)})
Author Namea594e632018-08-10 11:33:58 -0400217 if err != nil {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400218 fmt.Printf("Error when calling CreateChassis: %s", err)
219 return err
Author Namea594e632018-08-10 11:33:58 -0400220 }
221 log.Printf("Response from server: %s", response.GetDeviceID())
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400222 return nil
223}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400224func updateXOSUserPassword(c api.AbstractOLTClient, clli *string, xosUser *string, xosPassword *string) error {
225 fmt.Println("Calling Update XOS USER/PASSWORD")
226 fmt.Println("clli", *clli)
227 fmt.Println("xos_user", *xosUser)
228 fmt.Println("xos_password", *xosPassword)
229 response, err := c.ChangeXOSUserPassword(context.Background(), &api.ChangeXOSUserPasswordMessage{CLLI: *clli, XOSUser: *xosUser, XOSPassword: *xosPassword})
230 if err != nil {
231 fmt.Printf("Error when calling UpdateXOSUserPassword: %s", err)
232 return err
233 }
donNewtonAlphab1466392018-10-02 10:42:05 -0400234 log.Printf("Response from server: %t", response.GetSuccess())
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400235 return nil
236}
237
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400238func addOltChassis(c api.AbstractOLTClient, clli *string, oltAddress *string, oltPort *uint, name *string, driver *string, oltType *string) error {
239 fmt.Println("clli", *clli)
240 fmt.Println("olt_address", *oltAddress)
241 fmt.Println("olt_port", *oltPort)
242 fmt.Println("name", *name)
243 fmt.Println("driver", *driver)
244 fmt.Println("type", *oltType)
245 var driverType api.AddOLTChassisMessage_OltDriver
246 var chassisType api.AddOLTChassisMessage_OltType
247 switch *oltType {
248 case "edgecore":
249 chassisType = api.AddOLTChassisMessage_edgecore
250 }
251 switch *driver {
252 case "openolt":
253 driverType = api.AddOLTChassisMessage_openoltDriver
254
255 }
256
257 res, err := c.CreateOLTChassis(context.Background(), &api.AddOLTChassisMessage{CLLI: *clli, SlotIP: *oltAddress, SlotPort: uint32(*oltPort), Hostname: *name, Type: chassisType, Driver: driverType})
Author Namea594e632018-08-10 11:33:58 -0400258 if err != nil {
259 debug.PrintStack()
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400260 fmt.Printf("Error when calling CreateOLTChassis: %s", err)
261 return err
Author Namea594e632018-08-10 11:33:58 -0400262 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400263 log.Printf("Response from server: %s", res.GetDeviceID())
264 return nil
265}
266func provisionONT(c api.AbstractOLTClient, clli *string, slot *uint, port *uint, ont *uint, serial *string) error {
267 fmt.Println("clli", *clli)
268 fmt.Println("slot", *slot)
269 fmt.Println("port", *port)
270 fmt.Println("ont", *ont)
271 fmt.Println("serial", *serial)
272 res, err := c.ProvisionOnt(context.Background(), &api.AddOntMessage{CLLI: *clli, SlotNumber: int32(*slot), PortNumber: int32(*port), OntNumber: int32(*ont), SerialNumber: *serial})
273 if err != nil {
274 debug.PrintStack()
275 fmt.Printf("Error when calling ProvsionOnt %s", err)
276 return err
277 }
278 log.Printf("Response from server: %t", res.GetSuccess())
279 return nil
Don Newton281e0252018-10-22 14:38:50 -0400280}
281func provisionONTFull(c api.AbstractOLTClient, clli *string, slot *uint, port *uint, ont *uint, serial *string, stag *uint, ctag *uint, nasPort *string, circuitID *string) error {
282 fmt.Println("clli", *clli)
283 fmt.Println("slot", *slot)
284 fmt.Println("port", *port)
285 fmt.Println("ont", *ont)
286 fmt.Println("serial", *serial)
287 fmt.Println("stag", *stag)
288 fmt.Println("ctag", *ctag)
289 fmt.Println("nasPort", *nasPort)
290 fmt.Println("circuitID", *circuitID)
291 res, err := c.ProvisionOntFull(context.Background(), &api.AddOntFullMessage{CLLI: *clli, SlotNumber: int32(*slot), PortNumber: int32(*port), OntNumber: int32(*ont), SerialNumber: *serial, STag: uint32(*stag), CTag: uint32(*ctag), NasPortID: *nasPort, CircuitID: *circuitID})
292 if err != nil {
293 debug.PrintStack()
294 fmt.Printf("Error when calling ProvsionOnt %s", err)
295 return err
296 }
297 log.Printf("Response from server: %t", res.GetSuccess())
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400298 return nil
299}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400300func deleteONT(c api.AbstractOLTClient, clli *string, slot *uint, port *uint, ont *uint, serial *string) error {
301 fmt.Println("clli", *clli)
302 fmt.Println("slot", *slot)
303 fmt.Println("port", *port)
304 fmt.Println("ont", *ont)
305 fmt.Println("serial", *serial)
306 res, err := c.DeleteOnt(context.Background(), &api.DeleteOntMessage{CLLI: *clli, SlotNumber: int32(*slot), PortNumber: int32(*port), OntNumber: int32(*ont), SerialNumber: *serial})
307 if err != nil {
308 debug.PrintStack()
309 fmt.Printf("Error when calling ProvsionOnt %s", err)
310 return err
311 }
312 log.Printf("Response from server: %t", res.GetSuccess())
313 return nil
314}
315
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400316func usage() {
317 var output = `
donNewtonAlphab3279ea2018-09-18 15:55:32 -0400318 Usage ./client -server=[serverAddress:port] -[methodFlag] params
319 ./client -ssl -fqdn=FQDN_OF_ABSTRACT_OLT_SERVER.CRT -cert PATH_TO_SERVER.CRT -server=[serverAddress:port] -[methodFlag] params : use ssl
320 ./client -auth -server=[serverAddress:port] -[methodFlag] params : Authenticate session
321
322 methodFlags:
323 -e echo # used to test connectivity to server NOOP
324 params:
325 -message string to be echoed back from the server
326 e.g. ./client -server=localhost:7777 -e -message MESSAGE_TO_BE_ECHOED
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400327 -c create chassis
328 params:
329 -clli CLLI_NAME
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400330 -xos_user XOS_USER
331 -xos_password XOS_PASSWORD
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400332 -xos_address XOS_TOSCA_IP
333 -xos_port XOS_TOSCA_LISTEN_PORT
334 -rack [optional default 1]
335 -shelf [optional default 1]
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400336 e.g. ./client -server=localhost:7777 -c -clli MY_CLLI -xos_user foundry -xos_password password -xos_address 192.168.0.1 -xos_port 30007 -rack 1 -shelf 1
337 -u update xos user/password
338 -clli CLLI_NAME
339 -xos_user XOS_USER
340 -xos_password XOS_PASSWORD
341 e.g. ./client -server=localhost:7777 -u -clli MY_CLLI -xos_user NEW_USER -xos_password NEW_PASSWORD
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400342 -s add physical olt chassis to chassis
343 params:
344 -clli CLLI_NAME - identifies abstract chassis to assign olt chassis to
345 -olt_address - OLT_CHASSIS_IP_ADDRESS
346 -olt_port - OLT_CHASSIS_LISTEN_PORT
347 -name - OLT_NAME internal human readable name to identify OLT_CHASSIS
348 -driver [openolt,asfvolt16,adtran,tibits] - used to tell XOS which driver should be used to manange chassis
349 -type [edgecore,adtran,tibit] - used to tell AbstractOLT how many ports are available on olt chassis
donNewtonAlphab3279ea2018-09-18 15:55:32 -0400350 e.g. ./client -server abstractOltHost:7777 -s -clli MY_CLLI -olt_address 192.168.1.100 -olt_port=9191 -name=slot1 -driver=openolt -type=adtran
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400351 -o provision ont - adds ont to whitelist in XOS on a specific port on a specific olt chassis based on abstract -> phyisical mapping
352 params:
353 -clli CLLI_NAME
354 -slot SLOT_NUMBER [1-16]
355 -port OLT_PORT_NUMBER [1-16]
356 -ont ONT_NUMBER [1-64]
357 -serial ONT_SERIAL_NUM
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400358 e.g. ./client -server=localhost:7777 -o -clli=MY_CLLI -slot=1 -port=1 -ont=22 -serial=aer900jasdf
Don Newton281e0252018-10-22 14:38:50 -0400359 -f provision ont full - same as -o above but allows explicit set of s/c vlans , NasPortID and CircuitID
360 params:
361 -clli CLLI_NAME
362 -slot SLOT_NUMBER [1-16]
363 -port OLT_PORT_NUMBER [1-16]
364 -ont ONT_NUMBER [1-64]
365 -serial ONT_SERIAL_NUM
366 -stag S_TAG
367 -ctag C_TAG
368 -nas_port NAS_PORT_ID
369 -circuit_id CIRCUIT_ID
370 e.g. ./client -server=localhost:7777 -f -clli=MY_CLLI -slot=1 -port=1 -ont=22 -serial=aer900jasdf -stag=33 -ctag=104 -nas_port="pon 1/1/1/3:1.1" -circuit_id="CLLI 1/1/1/13:1.1"
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400371 -d delete ont - removes ont from service
372 params:
373 -clli CLLI_NAME
374 -slot SLOT_NUMBER [1-16]
375 -port OLT_PORT_NUMBER [1-16]
376 -ont ONT_NUMBER [1-64]
377 -serial ONT_SERIAL_NUM
378 e.g. ./client -server=localhost:7777 -d -clli=MY_CLLI -slot=1 -port=1 -ont=22 -serial=aer900jasdf
379 -output (TEMPORARY) causes AbstractOLT to serialize all chassis to JSON file in $WorkingDirectory/backups
380 e.g. ./client -server=localhost:7777 -output
381 `
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400382
383 fmt.Println(output)
Author Namea594e632018-08-10 11:33:58 -0400384}