Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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; |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 20 | import org.onlab.packet.VlanId; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.segmentrouting.SegmentRoutingService; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 23 | import org.onosproject.segmentrouting.pwaas.L2TunnelDescription; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Command to show the pseudowires. |
| 26 | */ |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 27 | @Service |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 28 | @Command(scope = "onos", name = "sr-pw-list", |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 29 | description = "Lists all pseudowires") |
| 30 | public 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 Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 36 | " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" + |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 37 | " transportVlan : %s \n" + |
| 38 | " pending = %s"; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 39 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 40 | @Override |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 41 | protected void doExecute() { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 42 | |
| 43 | SegmentRoutingService srService = |
| 44 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 45 | |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 46 | srService.getL2TunnelDescriptions(false) |
| 47 | .forEach(pw -> printPseudowire(pw, false)); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 48 | |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 49 | srService.getL2TunnelDescriptions(true) |
| 50 | .forEach(pw -> printPseudowire(pw, true)); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 53 | private void printPseudowire(L2TunnelDescription pseudowire, boolean pending) { |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 54 | VlanId vlan = pseudowire.l2Tunnel().transportVlan().equals(VlanId.vlanId((short) 4094)) ? |
| 55 | VlanId.NONE : pseudowire.l2Tunnel().transportVlan(); |
| 56 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 57 | 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 Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 61 | pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag(), |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 62 | vlan, pending); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 63 | } |
| 64 | } |