blob: 884274bb3fdbccaec4e6acfee8434f7070d37d64 [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"
25
26 "gerrit.opencord.org/abstract-olt/api"
Author Namea594e632018-08-10 11:33:58 -040027 "google.golang.org/grpc"
28 "google.golang.org/grpc/credentials"
29)
30
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040031func main() {
32 create := flag.Bool("c", false, "create?")
33 addOlt := flag.Bool("s", false, "addOlt?")
34 provOnt := flag.Bool("o", false, "provisionOnt?")
35 clli := flag.String("clli", "", "clli of abstract chassis")
36 xosAddress := flag.String("xos_address", "", "xos address")
37 xosPort := flag.Uint("xos_port", 0, "xos port")
38 rack := flag.Uint("rack", 1, "rack number for chassis")
39 shelf := flag.Uint("shelf", 1, "shelf number for chassis")
40 oltAddress := flag.String("olt_address", "", "ip address for olt chassis")
41 oltPort := flag.Uint("olt_port", 0, "listen port for olt chassis")
42 name := flag.String("name", "", "friendly name for olt chassis")
43 driver := flag.String("driver", "", "driver to use with olt chassis")
44 oltType := flag.String("type", "", "olt chassis type")
45 slot := flag.Uint("slot", 1, "slot number 1-16 to provision ont to")
46 port := flag.Uint("port", 1, "port number 1-16 to provision ont to")
47 ont := flag.Uint("ont", 1, "ont number 1-64")
48 serial := flag.String("serial", "", "serial number of ont")
49
50 flag.Parse()
51
52 if (*create && *addOlt) || (*create && *provOnt) || (*addOlt && *provOnt) {
53 fmt.Println("You can only call one method at a time")
54 usage()
55 return
56 }
57 if !(*create || *provOnt || *addOlt) {
58 fmt.Println("You didn't specify an operation to perform")
59 usage()
60 return
61 }
62 var conn *grpc.ClientConn
63 creds, err := credentials.NewClientTLSFromFile("cert/server.crt", "AbstractOLT.dev.atl.foundry.att.com")
64 if err != nil {
65 log.Fatalf("could not load tls cert: %s", err)
66 }
67 // Setup the login/pass
68 auth := Authentication{
69 Login: "john",
70 Password: "doe",
71 }
72 conn, err = grpc.Dial(":7777", grpc.WithTransportCredentials(creds), grpc.WithPerRPCCredentials(&auth))
73 if err != nil {
74 log.Fatalf("did not connect: %s", err)
75 }
76 defer conn.Close()
77
78 c := api.NewAbstractOLTClient(conn)
79 if *create {
80 createChassis(c, clli, xosAddress, xosPort, rack, shelf)
81 } else if *addOlt {
82 addOltChassis(c, clli, oltAddress, oltPort, name, driver, oltType)
83 } else if *provOnt {
84 provisionONT(c, clli, slot, port, ont, serial)
85 } else {
86 }
87
88 fmt.Println("TODO - Do something")
89}
90
Author Namea594e632018-08-10 11:33:58 -040091// Authentication holds the login/password
92type Authentication struct {
93 Login string
94 Password string
95}
96
97// GetRequestMetadata gets the current request metadata
98func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
99 return map[string]string{
100 "login": a.Login,
101 "password": a.Password,
102 }, nil
103}
104
105// RequireTransportSecurity indicates whether the credentials requires transport security
106func (a *Authentication) RequireTransportSecurity() bool {
107 return true
108}
109
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400110func createChassis(c api.AbstractOLTClient, clli *string, xosAddress *string, xosPort *uint, rack *uint, shelf *uint) error {
111 fmt.Println("Calling Create Chassis")
112 fmt.Println("clli", *clli)
113 fmt.Println("xos_address", *xosAddress)
114 fmt.Println("xos_port", *xosPort)
115 fmt.Println("rack", *rack)
116 fmt.Println("shelf", *shelf)
117 response, err := c.CreateChassis(context.Background(), &api.AddChassisMessage{CLLI: *clli, VCoreIP: *xosAddress, VCorePort: int32(*xosPort), Rack: int32(*rack), Shelf: int32(*shelf)})
Author Namea594e632018-08-10 11:33:58 -0400118 if err != nil {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400119 fmt.Printf("Error when calling CreateChassis: %s", err)
120 return err
Author Namea594e632018-08-10 11:33:58 -0400121 }
122 log.Printf("Response from server: %s", response.GetDeviceID())
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400123 return nil
124}
125func addOltChassis(c api.AbstractOLTClient, clli *string, oltAddress *string, oltPort *uint, name *string, driver *string, oltType *string) error {
126 fmt.Println("clli", *clli)
127 fmt.Println("olt_address", *oltAddress)
128 fmt.Println("olt_port", *oltPort)
129 fmt.Println("name", *name)
130 fmt.Println("driver", *driver)
131 fmt.Println("type", *oltType)
132 var driverType api.AddOLTChassisMessage_OltDriver
133 var chassisType api.AddOLTChassisMessage_OltType
134 switch *oltType {
135 case "edgecore":
136 chassisType = api.AddOLTChassisMessage_edgecore
137 }
138 switch *driver {
139 case "openolt":
140 driverType = api.AddOLTChassisMessage_openoltDriver
141
142 }
143
144 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 -0400145 if err != nil {
146 debug.PrintStack()
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400147 fmt.Printf("Error when calling CreateOLTChassis: %s", err)
148 return err
Author Namea594e632018-08-10 11:33:58 -0400149 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400150 log.Printf("Response from server: %s", res.GetDeviceID())
151 return nil
152}
153func provisionONT(c api.AbstractOLTClient, clli *string, slot *uint, port *uint, ont *uint, serial *string) error {
154 fmt.Println("clli", *clli)
155 fmt.Println("slot", *slot)
156 fmt.Println("port", *port)
157 fmt.Println("ont", *ont)
158 fmt.Println("serial", *serial)
159 res, err := c.ProvisionOnt(context.Background(), &api.AddOntMessage{CLLI: *clli, SlotNumber: int32(*slot), PortNumber: int32(*port), OntNumber: int32(*ont), SerialNumber: *serial})
160 if err != nil {
161 debug.PrintStack()
162 fmt.Printf("Error when calling ProvsionOnt %s", err)
163 return err
164 }
165 log.Printf("Response from server: %t", res.GetSuccess())
166 return nil
167
168 return nil
169}
170func usage() {
171 var output = `
172 Usage ./client -[methodFlag] params
173 methFlags:
174 -c create chassis
175 params:
176 -clli CLLI_NAME
177 -xos_address XOS_TOSCA_IP
178 -xos_port XOS_TOSCA_LISTEN_PORT
179 -rack [optional default 1]
180 -shelf [optional default 1]
181 e.g. ./client -c -clli MY_CLLI -xos_address 192.168.0.1 -xos_port 30007 -rack 1 -shelf 1
182 -s add physical olt chassis to chassis
183 params:
184 -clli CLLI_NAME - identifies abstract chassis to assign olt chassis to
185 -olt_address - OLT_CHASSIS_IP_ADDRESS
186 -olt_port - OLT_CHASSIS_LISTEN_PORT
187 -name - OLT_NAME internal human readable name to identify OLT_CHASSIS
188 -driver [openolt,asfvolt16,adtran,tibits] - used to tell XOS which driver should be used to manange chassis
189 -type [edgecore,adtran,tibit] - used to tell AbstractOLT how many ports are available on olt chassis
190 e.g. ./client -s -clli MY_CLLI -olt_address 192.168.1.100 -olt_port=9191 -name=slot1 -driver=openolt -type=adtran
191 -o provision ont - adds ont to whitelist in XOS on a specific port on a specific olt chassis based on abstract -> phyisical mapping
192 params:
193 -clli CLLI_NAME
194 -slot SLOT_NUMBER [1-16]
195 -port OLT_PORT_NUMBER [1-16]
196 -ont ONT_NUMBER [1-64]
197 -serial ONT_SERIAL_NUM
198 e.g. ./client -o -clli=MY_CLLI -slot=1 -port=1 -ont=22 -serial=aer900jasdf `
199
200 fmt.Println(output)
Author Namea594e632018-08-10 11:33:58 -0400201}