Jian Li | 0b93b00 | 2018-07-31 13:41:08 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.openstacktroubleshoot.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
| 19 | import org.onosproject.cli.AbstractShellCommand; |
| 20 | import org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService; |
| 21 | import org.onosproject.openstacktroubleshoot.api.Reachability; |
| 22 | |
| 23 | import 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") |
| 30 | public 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 | } |