blob: 6c5f33d7ffcc30adb645ad9f6d1241bad9762eaf [file] [log] [blame]
sangho2eae4c62015-06-11 14:49:59 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho2eae4c62015-06-11 14:49:59 -07003 *
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.segmentrouting.cli;
17
Ray Milkeydb38bc82018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Command;
Ray Milkey52ca4e92018-09-28 10:58:28 -070019import org.apache.karaf.shell.api.action.lifecycle.Service;
sangho2eae4c62015-06-11 14:49:59 -070020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.segmentrouting.SegmentRoutingService;
22import org.onosproject.segmentrouting.Tunnel;
23
24/**
25 * Command to show the list of tunnels.
26 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070027@Service
Saurav Das07c74602016-04-27 18:35:50 -070028@Command(scope = "onos", name = "sr-tunnel-list",
sangho2eae4c62015-06-11 14:49:59 -070029 description = "Lists all tunnels")
30public class TunnelListCommand extends AbstractShellCommand {
31
32 private static final String FORMAT_MAPPING =
33 " id=%s, path=%s";
34
35 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070036 protected void doExecute() {
sangho2eae4c62015-06-11 14:49:59 -070037
38 SegmentRoutingService srService =
39 AbstractShellCommand.get(SegmentRoutingService.class);
40
41 srService.getTunnels().forEach(tunnel -> printTunnel(tunnel));
42 }
43
44 private void printTunnel(Tunnel tunnel) {
45 print(FORMAT_MAPPING, tunnel.id(), tunnel.labelIds());
46 }
47}