blob: 6c91b8b80fce70d984875f8b34bd8c1aa2385b5f [file] [log] [blame]
sangho6703da22015-06-11 14:49:59 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho6703da22015-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
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.segmentrouting.Policy;
21import org.onosproject.segmentrouting.SegmentRoutingService;
22import org.onosproject.segmentrouting.TunnelPolicy;
23
24/**
25 * Command to show the list of policies.
26 */
Saurav Das59232cf2016-04-27 18:35:50 -070027@Command(scope = "onos", name = "sr-policy-list",
sangho6703da22015-06-11 14:49:59 -070028 description = "Lists all policies")
29public class PolicyListCommand extends AbstractShellCommand {
30
31 private static final String FORMAT_MAPPING_TUNNEL =
sanghofe4e3082015-06-22 15:10:19 -070032 " id=%s, type=%s, prio=%d, src=%s, port=%d, dst=%s, port=%d, proto=%s, tunnel=%s";
sangho6703da22015-06-11 14:49:59 -070033
34 @Override
35 protected void execute() {
36
37 SegmentRoutingService srService =
38 AbstractShellCommand.get(SegmentRoutingService.class);
39
40 srService.getPolicies().forEach(policy -> printPolicy(policy));
41 }
42
43 private void printPolicy(Policy policy) {
44 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
45 print(FORMAT_MAPPING_TUNNEL, policy.id(), policy.type(), policy.priority(),
sanghofe4e3082015-06-22 15:10:19 -070046 policy.srcIp(), policy.srcPort(), policy.dstIp(), policy.dstPort(),
47 (policy.ipProto() == null) ? "" : policy.ipProto(),
sangho6703da22015-06-11 14:49:59 -070048 ((TunnelPolicy) policy).tunnelId());
49 }
50 }
51}