Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Portions copyright 2019-present Open Networking Foundation |
| 3 | * Original copyright 2019-present Ciena Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package commands |
| 19 | |
| 20 | import ( |
| 21 | "context" |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 22 | "fmt" |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 23 | "os" |
| 24 | "strconv" |
| 25 | "strings" |
| 26 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 27 | "github.com/jessevdk/go-flags" |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 28 | "github.com/olekukonko/tablewriter" |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 29 | pb "github.com/opencord/bbsim/api/bbsim" |
| 30 | "github.com/opencord/bbsim/internal/bbsimctl/config" |
| 31 | "github.com/opencord/cordctl/pkg/format" |
| 32 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | const ( |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 36 | DEFAULT_ONU_DEVICE_HEADER_FORMAT = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .PortNo }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .ImageSoftwareExpectedSections }}\t{{ .ImageSoftwareReceivedSections }}\t{{ .ActiveImageEntityId }}\t{{ .CommittedImageEntityId }}" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 37 | DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .PortNo }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .ImageSoftwareExpectedSections }}\t{{ .ImageSoftwareReceivedSections }}\t{{ .ActiveImageEntityId }}\t{{ .CommittedImageEntityId }}\t{{ .Unis }}\t{{ .Services }}" |
| 38 | DEFAULT_UNI_HEADER_FORMAT = "table{{ .OnuSn }}\t{{ .OnuID }}\t{{ .ID }}\t{{ .MeID }}\t{{ .OperState }}" |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 39 | ) |
| 40 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 41 | type OnuSnString string |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 42 | type IgmpSubAction string |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 43 | type GroupAddress string |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 44 | |
| 45 | const IgmpJoinKey string = "join" |
| 46 | const IgmpLeaveKey string = "leave" |
Arjun E K | dd443f0 | 2020-02-07 15:24:01 +0000 | [diff] [blame] | 47 | const IgmpJoinKeyV3 string = "joinv3" |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 48 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 49 | var IgmpAllowedActions = []string{IgmpJoinKey, IgmpLeaveKey, IgmpJoinKeyV3} |
| 50 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 51 | type ONUList struct { |
| 52 | Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"` |
| 53 | } |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 54 | |
| 55 | type ONUGet struct { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 56 | Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"` |
| 57 | Args struct { |
| 58 | OnuSn OnuSnString |
| 59 | } `positional-args:"yes" required:"yes"` |
| 60 | } |
| 61 | |
| 62 | type ONUServices struct { |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 63 | Args struct { |
| 64 | OnuSn OnuSnString |
| 65 | } `positional-args:"yes" required:"yes"` |
| 66 | } |
| 67 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 68 | type ONUUnis struct { |
| 69 | Args struct { |
| 70 | OnuSn OnuSnString |
| 71 | } `positional-args:"yes" required:"yes"` |
| 72 | } |
| 73 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 74 | type ONUShutDown struct { |
| 75 | Args struct { |
| 76 | OnuSn OnuSnString |
| 77 | } `positional-args:"yes" required:"yes"` |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 80 | type ONUPowerOn struct { |
| 81 | Args struct { |
| 82 | OnuSn OnuSnString |
| 83 | } `positional-args:"yes" required:"yes"` |
| 84 | } |
| 85 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 86 | type ONUEapolRestart struct { |
| 87 | Args struct { |
| 88 | OnuSn OnuSnString |
| 89 | } `positional-args:"yes" required:"yes"` |
| 90 | } |
| 91 | |
| 92 | type ONUDhcpRestart struct { |
| 93 | Args struct { |
| 94 | OnuSn OnuSnString |
| 95 | } `positional-args:"yes" required:"yes"` |
| 96 | } |
| 97 | |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 98 | type ONUIgmp struct { |
| 99 | Args struct { |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 100 | OnuSn OnuSnString |
| 101 | SubAction IgmpSubAction |
| 102 | GroupAddress GroupAddress |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 103 | } `positional-args:"yes" required:"yes"` |
| 104 | } |
| 105 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 106 | type ONUTrafficSchedulers struct { |
| 107 | Args struct { |
| 108 | OnuSn OnuSnString |
| 109 | } `positional-args:"yes" required:"yes"` |
| 110 | } |
| 111 | |
| 112 | type ONUFlows struct { |
| 113 | Args struct { |
| 114 | OnuSn OnuSnString |
| 115 | } `positional-args:"yes" required:"yes"` |
| 116 | } |
| 117 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 118 | type ONUOptions struct { |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 119 | List ONUList `command:"list"` |
| 120 | Get ONUGet `command:"get"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 121 | Services ONUServices `command:"services"` |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 122 | Unis ONUUnis `command:"unis"` |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 123 | ShutDown ONUShutDown `command:"shutdown"` |
| 124 | PowerOn ONUPowerOn `command:"poweron"` |
| 125 | RestartEapol ONUEapolRestart `command:"auth_restart"` |
| 126 | RestartDchp ONUDhcpRestart `command:"dhcp_restart"` |
| 127 | Igmp ONUIgmp `command:"igmp"` |
| 128 | TrafficSchedulers ONUTrafficSchedulers `command:"traffic_schedulers"` |
Anand S Katti | 86552f9 | 2020-03-03 21:56:32 +0530 | [diff] [blame] | 129 | Alarms AlarmOptions `command:"alarms"` |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 130 | Flows ONUFlows `command:"flows"` |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | func RegisterONUCommands(parser *flags.Parser) { |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 134 | _, _ = parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{}) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 137 | func getONUs() *pb.ONUs { |
| 138 | |
| 139 | client, conn := connect() |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 140 | defer conn.Close() |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 141 | |
| 142 | // Contact the server and print out its response. |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 143 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 144 | defer cancel() |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 145 | |
| 146 | onus, err := client.GetONUs(ctx, &pb.Empty{}) |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 147 | if err != nil { |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 148 | log.Fatalf("could not get OLT: %v", err) |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 149 | return nil |
| 150 | } |
| 151 | return onus |
| 152 | } |
| 153 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 154 | func (options *ONUList) Execute(args []string) error { |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 155 | onus := getONUs() |
| 156 | |
| 157 | // print out |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 158 | var tableFormat format.Format |
| 159 | if options.Verbose { |
| 160 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES) |
| 161 | } else { |
| 162 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT) |
| 163 | } |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 164 | if err := tableFormat.Execute(os.Stdout, true, onus.Items); err != nil { |
| 165 | log.Fatalf("Error while formatting ONUs table: %s", err) |
| 166 | } |
| 167 | |
| 168 | return nil |
| 169 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 170 | |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 171 | func (options *ONUGet) Execute(args []string) error { |
| 172 | client, conn := connect() |
| 173 | defer conn.Close() |
| 174 | |
| 175 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 176 | defer cancel() |
| 177 | req := pb.ONURequest{ |
| 178 | SerialNumber: string(options.Args.OnuSn), |
| 179 | } |
| 180 | res, err := client.GetONU(ctx, &req) |
| 181 | |
| 182 | if err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 183 | log.Fatalf("Cannot not get ONU %s: %v", options.Args.OnuSn, err) |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 184 | return err |
| 185 | } |
| 186 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 187 | var tableFormat format.Format |
| 188 | if options.Verbose { |
| 189 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES) |
| 190 | } else { |
| 191 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT) |
| 192 | } |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 193 | if err := tableFormat.Execute(os.Stdout, true, []*pb.ONU{res}); err != nil { |
| 194 | log.Fatalf("Error while formatting ONUs table: %s", err) |
| 195 | } |
| 196 | |
| 197 | return nil |
| 198 | } |
| 199 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 200 | func (options *ONUServices) Execute(args []string) error { |
| 201 | |
| 202 | client, conn := connect() |
| 203 | defer conn.Close() |
| 204 | |
| 205 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 206 | defer cancel() |
| 207 | req := pb.ONURequest{ |
| 208 | SerialNumber: string(options.Args.OnuSn), |
| 209 | } |
| 210 | res, err := client.GetOnuServices(ctx, &req) |
| 211 | |
| 212 | if err != nil { |
| 213 | log.Fatalf("Cannot not get services for ONU %s: %v", options.Args.OnuSn, err) |
| 214 | return err |
| 215 | } |
| 216 | |
| 217 | tableFormat := format.Format(DEFAULT_SERVICE_HEADER_FORMAT) |
| 218 | if err := tableFormat.Execute(os.Stdout, true, res.Items); err != nil { |
| 219 | log.Fatalf("Error while formatting Services table: %s", err) |
| 220 | } |
| 221 | |
| 222 | return nil |
| 223 | } |
| 224 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 225 | func (options *ONUUnis) Execute(args []string) error { |
| 226 | |
| 227 | client, conn := connect() |
| 228 | defer conn.Close() |
| 229 | |
| 230 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 231 | defer cancel() |
| 232 | req := pb.ONURequest{ |
| 233 | SerialNumber: string(options.Args.OnuSn), |
| 234 | } |
| 235 | res, err := client.GetOnuUnis(ctx, &req) |
| 236 | |
| 237 | if err != nil { |
| 238 | log.Fatalf("Cannot not get unis for ONU %s: %v", options.Args.OnuSn, err) |
| 239 | return err |
| 240 | } |
| 241 | |
| 242 | tableFormat := format.Format(DEFAULT_UNI_HEADER_FORMAT) |
| 243 | if err := tableFormat.Execute(os.Stdout, true, res.Items); err != nil { |
| 244 | log.Fatalf("Error while formatting Unis table: %s", err) |
| 245 | } |
| 246 | |
| 247 | return nil |
| 248 | } |
| 249 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 250 | func (options *ONUShutDown) Execute(args []string) error { |
| 251 | |
| 252 | client, conn := connect() |
| 253 | defer conn.Close() |
| 254 | |
| 255 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 256 | defer cancel() |
| 257 | req := pb.ONURequest{ |
| 258 | SerialNumber: string(options.Args.OnuSn), |
| 259 | } |
| 260 | res, err := client.ShutdownONU(ctx, &req) |
| 261 | |
| 262 | if err != nil { |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 263 | log.Fatalf("Cannot shutdown ONU %s: %v", options.Args.OnuSn, err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 264 | return err |
| 265 | } |
| 266 | |
| 267 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 268 | |
| 269 | return nil |
| 270 | } |
| 271 | |
| 272 | func (options *ONUPowerOn) Execute(args []string) error { |
| 273 | client, conn := connect() |
| 274 | defer conn.Close() |
| 275 | |
| 276 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 277 | defer cancel() |
| 278 | req := pb.ONURequest{ |
| 279 | SerialNumber: string(options.Args.OnuSn), |
| 280 | } |
| 281 | res, err := client.PoweronONU(ctx, &req) |
| 282 | |
| 283 | if err != nil { |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 284 | log.Fatalf("Cannot power on ONU %s: %v", options.Args.OnuSn, err) |
| 285 | return err |
| 286 | } |
| 287 | |
| 288 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 289 | |
| 290 | return nil |
| 291 | } |
| 292 | |
| 293 | func (options *ONUEapolRestart) Execute(args []string) error { |
| 294 | client, conn := connect() |
| 295 | defer conn.Close() |
| 296 | |
| 297 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 298 | defer cancel() |
| 299 | req := pb.ONURequest{ |
| 300 | SerialNumber: string(options.Args.OnuSn), |
| 301 | } |
| 302 | res, err := client.RestartEapol(ctx, &req) |
| 303 | |
| 304 | if err != nil { |
| 305 | log.Fatalf("Cannot restart EAPOL for ONU %s: %v", options.Args.OnuSn, err) |
| 306 | return err |
| 307 | } |
| 308 | |
| 309 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 310 | |
| 311 | return nil |
| 312 | } |
| 313 | |
| 314 | func (options *ONUDhcpRestart) Execute(args []string) error { |
| 315 | client, conn := connect() |
| 316 | defer conn.Close() |
| 317 | |
| 318 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 319 | defer cancel() |
| 320 | req := pb.ONURequest{ |
| 321 | SerialNumber: string(options.Args.OnuSn), |
| 322 | } |
| 323 | res, err := client.RestartDhcp(ctx, &req) |
| 324 | |
| 325 | if err != nil { |
| 326 | log.Fatalf("Cannot restart DHCP for ONU %s: %v", options.Args.OnuSn, err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 327 | return err |
| 328 | } |
| 329 | |
| 330 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 331 | |
| 332 | return nil |
| 333 | } |
| 334 | |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 335 | func (options *ONUIgmp) Execute(args []string) error { |
| 336 | client, conn := connect() |
| 337 | defer conn.Close() |
| 338 | |
| 339 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 340 | defer cancel() |
| 341 | |
| 342 | req := pb.ONURequest{ |
| 343 | SerialNumber: string(options.Args.OnuSn), |
| 344 | } |
| 345 | |
| 346 | var subActionVal pb.SubActionTypes |
| 347 | if string(options.Args.SubAction) == IgmpJoinKey { |
| 348 | subActionVal = pb.SubActionTypes_JOIN |
| 349 | } else if string(options.Args.SubAction) == IgmpLeaveKey { |
| 350 | subActionVal = pb.SubActionTypes_LEAVE |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 351 | } else if string(options.Args.SubAction) == IgmpJoinKeyV3 { |
| 352 | subActionVal = pb.SubActionTypes_JOINV3 |
| 353 | } |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 354 | |
| 355 | igmpReq := pb.IgmpRequest{ |
| 356 | OnuReq: &req, |
| 357 | SubActionVal: subActionVal, |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 358 | GroupAddress: string(options.Args.GroupAddress), |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 359 | } |
| 360 | res, err := client.GetONU(ctx, igmpReq.OnuReq) |
| 361 | if err != nil { |
| 362 | log.WithFields(log.Fields{ |
| 363 | "SerialNumber": options.Args.OnuSn, |
| 364 | }).Errorf("Cannot not get details on ONU error: %v", err) |
| 365 | } |
| 366 | log.WithFields(log.Fields{ |
| 367 | "SerialNumber": igmpReq.OnuReq.SerialNumber, |
Onur Kalinagac | 9f9faca | 2021-01-21 14:04:34 +0000 | [diff] [blame] | 368 | }).Debugf("ONU has identified : %s", res) |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 369 | |
| 370 | igmpRes, igmpErr := client.ChangeIgmpState(ctx, &igmpReq) |
| 371 | if igmpErr != nil { |
| 372 | log.WithFields(log.Fields{ |
| 373 | "SubAction": options.Args.SubAction, |
| 374 | }).Errorf("Could not process Action: error: %v", igmpErr) |
| 375 | } else { |
| 376 | log.WithFields(log.Fields{ |
| 377 | "SubAction": options.Args.SubAction, |
| 378 | }).Debugf("igmp state has been changed with response: %s", |
| 379 | igmpRes.Message) |
| 380 | } |
| 381 | |
| 382 | return nil |
| 383 | } |
| 384 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 385 | func (options *ONUFlows) Execute(args []string) error { |
| 386 | client, conn := connect() |
| 387 | defer conn.Close() |
| 388 | |
| 389 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 390 | defer cancel() |
| 391 | req := pb.ONURequest{ |
| 392 | SerialNumber: string(options.Args.OnuSn), |
| 393 | } |
| 394 | res, err := client.GetFlows(ctx, &req) |
| 395 | if err != nil { |
| 396 | log.Errorf("Cannot get flows for ONU %s: %v", options.Args.OnuSn, err) |
| 397 | return err |
| 398 | } |
| 399 | |
| 400 | if res.Flows == nil { |
| 401 | fmt.Println(fmt.Sprintf("ONU %s has no flows", options.Args.OnuSn)) |
| 402 | return nil |
| 403 | } |
| 404 | |
| 405 | flowHeader := []string{ |
| 406 | "access_intf_id", |
| 407 | "onu_id", |
| 408 | "uni_id", |
| 409 | "flow_id", |
| 410 | "flow_type", |
| 411 | "eth_type", |
| 412 | "alloc_id", |
| 413 | "network_intf_id", |
| 414 | "gemport_id", |
| 415 | "classifier", |
| 416 | "action", |
| 417 | "priority", |
| 418 | "cookie", |
| 419 | "port_no", |
| 420 | } |
| 421 | |
| 422 | tableFlow := tablewriter.NewWriter(os.Stdout) |
| 423 | tableFlow.SetRowLine(true) |
| 424 | fmt.Fprintf(os.Stdout, "ONU Flows:\n") |
| 425 | tableFlow.SetHeader(flowHeader) |
| 426 | |
| 427 | for _, flow := range res.Flows { |
| 428 | flowInfo := []string{} |
| 429 | flowInfo = append(flowInfo, |
| 430 | strconv.Itoa(int(flow.AccessIntfId)), |
| 431 | strconv.Itoa(int(flow.OnuId)), |
| 432 | strconv.Itoa(int(flow.UniId)), |
| 433 | strconv.Itoa(int(flow.FlowId)), |
| 434 | flow.FlowType, |
| 435 | fmt.Sprintf("%x", flow.Classifier.EthType), |
| 436 | strconv.Itoa(int(flow.AllocId)), |
| 437 | strconv.Itoa(int(flow.NetworkIntfId)), |
| 438 | strconv.Itoa(int(flow.GemportId)), |
| 439 | flow.Classifier.String(), |
| 440 | flow.Action.String(), |
| 441 | strconv.Itoa(int(flow.Priority)), |
| 442 | strconv.Itoa(int(flow.Cookie)), |
| 443 | strconv.Itoa(int(flow.PortNo)), |
| 444 | ) |
| 445 | tableFlow.Append(flowInfo) |
| 446 | } |
| 447 | tableFlow.Render() |
| 448 | tableFlow.SetNewLine("") |
| 449 | return nil |
| 450 | } |
| 451 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 452 | func (onuSn *OnuSnString) Complete(match string) []flags.Completion { |
| 453 | client, conn := connect() |
| 454 | defer conn.Close() |
| 455 | |
| 456 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 457 | defer cancel() |
| 458 | |
| 459 | onus, err := client.GetONUs(ctx, &pb.Empty{}) |
| 460 | if err != nil { |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 461 | log.Fatalf("could not get ONUs: %v", err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 462 | return nil |
| 463 | } |
| 464 | |
| 465 | list := make([]flags.Completion, 0) |
| 466 | for _, k := range onus.Items { |
| 467 | if strings.HasPrefix(k.SerialNumber, match) { |
| 468 | list = append(list, flags.Completion{Item: k.SerialNumber}) |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | return list |
| 473 | } |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 474 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 475 | func (onuSn *IgmpSubAction) Complete(match string) []flags.Completion { |
| 476 | list := make([]flags.Completion, 0) |
| 477 | for _, k := range IgmpAllowedActions { |
| 478 | if strings.HasPrefix(k, match) { |
| 479 | list = append(list, flags.Completion{Item: k}) |
| 480 | } |
| 481 | } |
| 482 | return list |
| 483 | } |
| 484 | |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 485 | func (options *ONUTrafficSchedulers) Execute(args []string) error { |
| 486 | client, conn := connect() |
| 487 | defer conn.Close() |
| 488 | |
| 489 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 490 | defer cancel() |
| 491 | req := pb.ONURequest{ |
| 492 | SerialNumber: string(options.Args.OnuSn), |
| 493 | } |
| 494 | res, err := client.GetOnuTrafficSchedulers(ctx, &req) |
| 495 | if err != nil { |
| 496 | log.Fatalf("Cannot get traffic schedulers for ONU %s: %v", options.Args.OnuSn, err) |
| 497 | return err |
| 498 | } |
| 499 | |
| 500 | if res.TraffSchedulers == nil { |
| 501 | log.Fatalf("Cannot get traffic schedulers for ONU: %s (unavailable)", options.Args.OnuSn) |
| 502 | return nil |
| 503 | } |
| 504 | |
| 505 | SchedulerHeader := []string{"Direction", |
| 506 | "AllocId", |
| 507 | "Scheduler.Direction", |
| 508 | "Scheduler.AdditionalBw", |
| 509 | "Scheduler.Priority", |
| 510 | "Scheduler.Weight", |
| 511 | "Scheduler.SchedPolicy", |
| 512 | } |
| 513 | |
| 514 | ShapingInfoHeader := []string{"InferredAdditionBwIndication", |
| 515 | "Cbs", |
| 516 | "Cir", |
| 517 | "Gir", |
| 518 | "Pbs", |
| 519 | "Pir", |
| 520 | } |
| 521 | |
| 522 | SchedulerVals := []string{} |
| 523 | ShapingInfoVals := []string{} |
| 524 | for _, v := range res.TraffSchedulers.TrafficScheds { |
| 525 | SchedulerVals = append(SchedulerVals, |
| 526 | v.GetDirection().String(), |
| 527 | strconv.Itoa(int(v.GetAllocId())), |
| 528 | v.Scheduler.GetDirection().String(), |
| 529 | v.Scheduler.GetAdditionalBw().String(), |
| 530 | strconv.Itoa(int(v.Scheduler.GetPriority())), |
| 531 | strconv.Itoa(int(v.Scheduler.GetWeight())), |
| 532 | v.GetScheduler().GetSchedPolicy().String(), |
| 533 | ) |
| 534 | |
| 535 | ShapingInfoVals = append(ShapingInfoVals, |
| 536 | v.TrafficShapingInfo.GetAddBwInd().String(), |
| 537 | strconv.Itoa(int(v.TrafficShapingInfo.GetCbs())), |
| 538 | strconv.Itoa(int(v.TrafficShapingInfo.GetCir())), |
| 539 | strconv.Itoa(int(v.TrafficShapingInfo.GetGir())), |
| 540 | strconv.Itoa(int(v.TrafficShapingInfo.GetPbs())), |
| 541 | strconv.Itoa(int(v.TrafficShapingInfo.GetPir())), |
| 542 | ) |
| 543 | } |
| 544 | |
| 545 | fmt.Fprintf(os.Stdout, "OnuId: %d \n", int(res.TraffSchedulers.OnuId)) |
| 546 | fmt.Fprintf(os.Stdout, "IntfId: %d \n", int(res.TraffSchedulers.IntfId)) |
| 547 | fmt.Fprintf(os.Stdout, "UniId: %d \n", int(res.TraffSchedulers.UniId)) |
| 548 | fmt.Fprintf(os.Stdout, "OnuPortNo: %d \n", int(res.TraffSchedulers.PortNo)) |
| 549 | |
| 550 | tableSched := tablewriter.NewWriter(os.Stdout) |
| 551 | tableSched.SetRowLine(true) |
| 552 | fmt.Fprintf(os.Stdout, "Traffic Schedulers Info:\n") |
| 553 | tableSched.SetHeader(SchedulerHeader) |
| 554 | tableSched.Append(SchedulerVals) |
| 555 | tableSched.Render() |
| 556 | tableSched.SetNewLine("") |
| 557 | |
| 558 | tableShap := tablewriter.NewWriter(os.Stdout) |
| 559 | tableShap.SetRowLine(true) |
| 560 | fmt.Fprintf(os.Stdout, "Traffic Shaping Info:\n") |
| 561 | tableShap.SetHeader(ShapingInfoHeader) |
| 562 | tableShap.Append(ShapingInfoVals) |
| 563 | tableShap.Render() |
| 564 | |
| 565 | return nil |
| 566 | } |