blob: 4e702af1da3dae6ce775af99220ace095b9b6b3b [file] [log] [blame]
pierventre1483e642016-06-08 18:52:29 +02001/*
2 * Copyright 2016-present Open Networking Laboratory
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 org.onosproject.sdxl2.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.sdxl2.SdxL2ConnectionPoint;
23import org.onosproject.sdxl2.SdxL2Service;
24import org.onosproject.sdxl2.SdxL2State;
25
26import java.util.Optional;
27import java.util.Set;
28
29/**
30 * CLI to list the SDX-L2 connection points.
31 */
Carolina Fernandezad893432016-07-18 11:11:34 +020032@Command(scope = "sdxl2", name = "sdxl2cp-list", description = "Lists " +
33 "all the SDX-L2 Connection Points. Argument not required the name of SDX-L2")
pierventre1483e642016-06-08 18:52:29 +020034public class SdxL2ListCPCommand extends AbstractShellCommand {
35
Carolina Fernandezad893432016-07-18 11:11:34 +020036 @Argument(index = 0, name = "sdxl2name", description = "Name of SDX-L2", required = false, multiValued = false)
37 private String sdxl2 = null;
pierventre1483e642016-06-08 18:52:29 +020038
39 private static final String HEADER = "\n\u001B[1;37mStatus\t\tSDXL2 Connection Point\u001B[0m";
40 private static final String SEPARATOR = "\u001B[1;37m-----------------------------------------------\u001B[0m";
41 private static final String FORMAT_SDXL2CP_ONLINE = "\u001B[1;32m%s\u001B[0m\t\t\u001B[1;37m%s\u001B[0m";
42 private static final String FORMAT_SDXL2CP_OFFLINE = "\u001B[1;31m%s\u001B[0m\t\t\u001B[1;37m%s\u001B[0m";
43
44 @Override
45 protected void execute() {
46 SdxL2Service sdxl2Service = get(SdxL2Service.class);
47 Optional<String> sdxl2name = Optional.ofNullable(sdxl2);
48 Set<String> result = sdxl2Service.getSdxL2ConnectionPoints(sdxl2name);
49 SdxL2ConnectionPoint sdxl2ConnectionPoint;
50 SdxL2State sdxl2cpState;
Carolina Fernandezad893432016-07-18 11:11:34 +020051 print(HEADER);
52 print(SEPARATOR);
pierventre1483e642016-06-08 18:52:29 +020053 if (result.size() > 0) {
pierventre1483e642016-06-08 18:52:29 +020054 for (String sdxl2cp : result) {
55 sdxl2ConnectionPoint = sdxl2Service.getSdxL2ConnectionPoint(sdxl2cp);
56 if (sdxl2ConnectionPoint == null) {
57 return;
58 }
59 sdxl2cpState = sdxl2Service.getEdgePortState(sdxl2ConnectionPoint.connectPoint());
60 if (sdxl2cpState == SdxL2State.ONLINE) {
61 print(FORMAT_SDXL2CP_ONLINE, "ONLINE", sdxl2cp);
62 } else if (sdxl2cpState == SdxL2State.OFFLINE) {
63 print(FORMAT_SDXL2CP_OFFLINE, "OFFLINE", sdxl2cp);
64 }
65 }
66 print("");
67 }
68 }
69}