sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [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.segmentrouting.cli; |
| 17 | |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.segmentrouting.Policy; |
| 22 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 23 | import org.onosproject.segmentrouting.TunnelPolicy; |
| 24 | |
| 25 | /** |
| 26 | * Command to show the list of policies. |
| 27 | */ |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 28 | @Service |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 29 | @Command(scope = "onos", name = "sr-policy-list", |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 30 | description = "Lists all policies") |
| 31 | public class PolicyListCommand extends AbstractShellCommand { |
| 32 | |
| 33 | private static final String FORMAT_MAPPING_TUNNEL = |
sangho | 8d953f9 | 2015-06-22 15:10:19 -0700 | [diff] [blame] | 34 | " id=%s, type=%s, prio=%d, src=%s, port=%d, dst=%s, port=%d, proto=%s, tunnel=%s"; |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 35 | |
| 36 | @Override |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 37 | protected void doExecute() { |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 38 | |
| 39 | SegmentRoutingService srService = |
| 40 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 41 | |
| 42 | srService.getPolicies().forEach(policy -> printPolicy(policy)); |
| 43 | } |
| 44 | |
| 45 | private void printPolicy(Policy policy) { |
| 46 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
| 47 | print(FORMAT_MAPPING_TUNNEL, policy.id(), policy.type(), policy.priority(), |
sangho | 8d953f9 | 2015-06-22 15:10:19 -0700 | [diff] [blame] | 48 | policy.srcIp(), policy.srcPort(), policy.dstIp(), policy.dstPort(), |
| 49 | (policy.ipProto() == null) ? "" : policy.ipProto(), |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 50 | ((TunnelPolicy) policy).tunnelId()); |
| 51 | } |
| 52 | } |
| 53 | } |