jcc | d869723 | 2015-05-05 14:42:23 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
jcc | d869723 | 2015-05-05 14:42:23 +0800 | [diff] [blame] | 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.cli.net; |
| 17 | |
| 18 | import java.util.Collection; |
| 19 | |
| 20 | import org.apache.karaf.shell.commands.Argument; |
| 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.DefaultApplicationId; |
Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 25 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 26 | import org.onosproject.incubator.net.tunnel.TunnelSubscription; |
jcc | d869723 | 2015-05-05 14:42:23 +0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Query all tunnel subscriptions of consumer by consumer id. |
| 30 | * It's used by consumers. |
| 31 | */ |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 32 | @Command(scope = "onos", name = "tunnel-subscriptions", |
jcc | d869723 | 2015-05-05 14:42:23 +0800 | [diff] [blame] | 33 | description = "Query all request orders of consumer by consumer id. It's used by consumers.") |
Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 34 | public class TunnelQuerySubscriptionCommand extends AbstractShellCommand { |
jcc | d869723 | 2015-05-05 14:42:23 +0800 | [diff] [blame] | 35 | @Argument(index = 0, name = "consumerId", |
| 36 | description = "consumer id means provider id", |
| 37 | required = true, multiValued = false) |
| 38 | String consumerId = null; |
| 39 | private static final String FMT = "appId=%s, src=%s, dst=%s," |
| 40 | + "type=%s, tunnelId=%s"; |
| 41 | |
| 42 | @Override |
| 43 | protected void execute() { |
| 44 | TunnelService service = get(TunnelService.class); |
| 45 | ApplicationId applicationId = new DefaultApplicationId(1, consumerId); |
| 46 | Collection<TunnelSubscription> tunnelSet = service.queryTunnelSubscription(applicationId); |
| 47 | for (TunnelSubscription order : tunnelSet) { |
| 48 | print(FMT, order.consumerId(), order.src(), order.dst(), |
| 49 | order.type(), order.tunnelId()); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | } |