blob: e1da70a8054ee012c7d12a82302cac09f39160f6 [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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.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 Pantelopoulosb21547d2018-02-22 12:32:42 -080022import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070023/**
24 * Command to show the pseudowires.
25 */
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -070026@Command(scope = "onos", name = "sr-pw-list",
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070027 description = "Lists all pseudowires")
28public class PseudowireListCommand extends AbstractShellCommand {
29
30 private static final String FORMAT_PSEUDOWIRE =
31 "Pseudowire id = %s \n" +
32 " mode : %s, sdTag : %s, pwLabel : %s \n" +
33 " cP1 : %s , cP1OuterTag : %s, cP1InnerTag : %s \n" +
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080034 " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" +
Andreas Pantelopoulos811bbae2018-03-15 16:56:09 -070035 " transportVlan : %s \n" +
36 " pending = %s";
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070037
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070038 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070039 protected void doExecute() {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070040
41 SegmentRoutingService srService =
42 AbstractShellCommand.get(SegmentRoutingService.class);
43
Andreas Pantelopoulos811bbae2018-03-15 16:56:09 -070044 srService.getL2TunnelDescriptions(false)
45 .forEach(pw -> printPseudowire(pw, false));
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070046
Andreas Pantelopoulos811bbae2018-03-15 16:56:09 -070047 srService.getL2TunnelDescriptions(true)
48 .forEach(pw -> printPseudowire(pw, true));
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070049 }
50
Andreas Pantelopoulos811bbae2018-03-15 16:56:09 -070051 private void printPseudowire(L2TunnelDescription pseudowire, boolean pending) {
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080052 VlanId vlan = pseudowire.l2Tunnel().transportVlan().equals(VlanId.vlanId((short) 4094)) ?
53 VlanId.NONE : pseudowire.l2Tunnel().transportVlan();
54
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070055 print(FORMAT_PSEUDOWIRE, pseudowire.l2Tunnel().tunnelId(), pseudowire.l2Tunnel().pwMode(),
56 pseudowire.l2Tunnel().sdTag(), pseudowire.l2Tunnel().pwLabel(),
57 pseudowire.l2TunnelPolicy().cP1(), pseudowire.l2TunnelPolicy().cP1OuterTag(),
58 pseudowire.l2TunnelPolicy().cP1InnerTag(), pseudowire.l2TunnelPolicy().cP2(),
Andreas Pantelopoulos77031712018-02-13 15:38:53 -080059 pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag(),
Andreas Pantelopoulos811bbae2018-03-15 16:56:09 -070060 vlan, pending);
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070061 }
62}