blob: f9786ac4fb096cc97c8d5174e0e4753b58d678e1 [file] [log] [blame]
Jian Li0b93b002018-07-31 13:41:08 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.openstacktroubleshoot.cli;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService;
21import org.onosproject.openstacktroubleshoot.api.Reachability;
22
23import java.util.Map;
24
25/**
26 * Checks the east-west VMs connectivity.
27 */
28@Command(scope = "onos", name = "openstack-check-east-west",
29 description = "Checks the east-west VMs connectivity")
30public class OpenstackEastWestProbeCommand extends AbstractShellCommand {
31
32 private static final String REACHABLE = "Reachable :)";
33 private static final String UNREACHABLE = "Unreachable :(";
34 private static final String ARROW = "->";
35
36 private static final String FORMAT = "%-20s%-5s%-20s%-20s";
37
38 @Override
39 protected void execute() {
40 OpenstackTroubleshootService troubleshootService =
41 AbstractShellCommand.get(OpenstackTroubleshootService.class);
42
43 if (troubleshootService == null) {
44 error("Failed to troubleshoot openstack networking.");
45 return;
46 }
47
48 print(FORMAT, "Source IP", "", "Destination IP", "Reachability");
49
50 Map<String, Reachability> map = troubleshootService.probeEastWestBulk();
51
52 map.values().forEach(r -> {
53 String result = r.isReachable() ? REACHABLE : UNREACHABLE;
54 print(FORMAT, r.srcIp().toString(), ARROW, r.dstIp().toString(), result);
55 });
56 }
57}