blob: a633a8aaa8e65af72a6329c373e2c8851989ff0d [file] [log] [blame]
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -07001/*
2 * Copyright 2017-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 */
16package org.onosproject.segmentrouting.cli;
17
18import org.apache.karaf.shell.commands.Command;
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080019import org.onlab.packet.VlanId;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.segmentrouting.SegmentRoutingService;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070022import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
Andreas Pantelopoulosb21547d2018-02-22 12:32:42 -080023import org.onosproject.segmentrouting.pwaas.L2Tunnel;
24import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
25import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070026
27import java.util.List;
28import java.util.stream.Collectors;
29
30/**
31 * Command to show the pseudowires.
32 */
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -070033@Command(scope = "onos", name = "sr-pw-list",
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070034 description = "Lists all pseudowires")
35public class PseudowireListCommand extends AbstractShellCommand {
36
37 private static final String FORMAT_PSEUDOWIRE =
38 "Pseudowire id = %s \n" +
39 " mode : %s, sdTag : %s, pwLabel : %s \n" +
40 " cP1 : %s , cP1OuterTag : %s, cP1InnerTag : %s \n" +
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080041 " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" +
42 " transportVlan : %s";
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070043
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070044 @Override
45 protected void execute() {
46
47 SegmentRoutingService srService =
48 AbstractShellCommand.get(SegmentRoutingService.class);
49
Andreas Pantelopoulosb21547d2018-02-22 12:32:42 -080050 List<L2Tunnel> tunnels = srService.getL2Tunnels();
51 List<L2TunnelPolicy> policies = srService.getL2Policies();
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070052
53 // combine polices and tunnels to pseudowires
Andreas Pantelopoulosb21547d2018-02-22 12:32:42 -080054 List<L2TunnelDescription> pseudowires = tunnels.stream()
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070055 .map(l2Tunnel -> {
Andreas Pantelopoulosb21547d2018-02-22 12:32:42 -080056 L2TunnelPolicy policy = null;
57 for (L2TunnelPolicy l2Policy : policies) {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070058 if (l2Policy.tunnelId() == l2Tunnel.tunnelId()) {
59 policy = l2Policy;
60 break;
61 }
62 }
63
64 return new DefaultL2TunnelDescription(l2Tunnel, policy);
65 })
66 .collect(Collectors.toList());
67
68 pseudowires.forEach(pw -> printPseudowire(pw));
69 }
70
Andreas Pantelopoulosb21547d2018-02-22 12:32:42 -080071 private void printPseudowire(L2TunnelDescription pseudowire) {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070072
73
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080074 VlanId vlan = pseudowire.l2Tunnel().transportVlan().equals(VlanId.vlanId((short) 4094)) ?
75 VlanId.NONE : pseudowire.l2Tunnel().transportVlan();
76
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070077 print(FORMAT_PSEUDOWIRE, pseudowire.l2Tunnel().tunnelId(), pseudowire.l2Tunnel().pwMode(),
78 pseudowire.l2Tunnel().sdTag(), pseudowire.l2Tunnel().pwLabel(),
79 pseudowire.l2TunnelPolicy().cP1(), pseudowire.l2TunnelPolicy().cP1OuterTag(),
80 pseudowire.l2TunnelPolicy().cP1InnerTag(), pseudowire.l2TunnelPolicy().cP2(),
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080081 pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag(),
82 vlan);
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070083 }
84}