blob: 475ce26906356fe33f47b5155bbba3f5f2e6e3d4 [file] [log] [blame]
Andreas Pantelopoulos5e7be3d2017-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 Milkeydb38bc82018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Command;
Ray Milkey52ca4e92018-09-28 10:58:28 -070019import org.apache.karaf.shell.api.action.lifecycle.Service;
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080020import org.onlab.packet.VlanId;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.segmentrouting.SegmentRoutingService;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080023import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070024/**
25 * Command to show the pseudowires.
26 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070027@Service
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -070028@Command(scope = "onos", name = "sr-pw-list",
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070029 description = "Lists all pseudowires")
30public class PseudowireListCommand extends AbstractShellCommand {
31
32 private static final String FORMAT_PSEUDOWIRE =
33 "Pseudowire id = %s \n" +
34 " mode : %s, sdTag : %s, pwLabel : %s \n" +
35 " cP1 : %s , cP1OuterTag : %s, cP1InnerTag : %s \n" +
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080036 " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" +
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -070037 " transportVlan : %s \n" +
38 " pending = %s";
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070039
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070040 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070041 protected void doExecute() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070042
43 SegmentRoutingService srService =
44 AbstractShellCommand.get(SegmentRoutingService.class);
45
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -070046 srService.getL2TunnelDescriptions(false)
47 .forEach(pw -> printPseudowire(pw, false));
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070048
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -070049 srService.getL2TunnelDescriptions(true)
50 .forEach(pw -> printPseudowire(pw, true));
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070051 }
52
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -070053 private void printPseudowire(L2TunnelDescription pseudowire, boolean pending) {
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080054 VlanId vlan = pseudowire.l2Tunnel().transportVlan().equals(VlanId.vlanId((short) 4094)) ?
55 VlanId.NONE : pseudowire.l2Tunnel().transportVlan();
56
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070057 print(FORMAT_PSEUDOWIRE, pseudowire.l2Tunnel().tunnelId(), pseudowire.l2Tunnel().pwMode(),
58 pseudowire.l2Tunnel().sdTag(), pseudowire.l2Tunnel().pwLabel(),
59 pseudowire.l2TunnelPolicy().cP1(), pseudowire.l2TunnelPolicy().cP1OuterTag(),
60 pseudowire.l2TunnelPolicy().cP1InnerTag(), pseudowire.l2TunnelPolicy().cP2(),
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080061 pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag(),
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -070062 vlan, pending);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070063 }
64}