Andreas Pantelopoulos | 27532cd | 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 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
Andreas Pantelopoulos | 7703171 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 19 | import org.onlab.packet.VlanId; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.segmentrouting.SegmentRoutingService; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 22 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription; |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 23 | import org.onosproject.segmentrouting.pwaas.L2Tunnel; |
| 24 | import org.onosproject.segmentrouting.pwaas.L2TunnelDescription; |
| 25 | import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 26 | |
| 27 | import java.util.List; |
| 28 | import java.util.stream.Collectors; |
| 29 | |
| 30 | /** |
| 31 | * Command to show the pseudowires. |
| 32 | */ |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame^] | 33 | @Command(scope = "onos", name = "sr-pw-list", |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 34 | description = "Lists all pseudowires") |
| 35 | public 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 Pantelopoulos | 7703171 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 41 | " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" + |
| 42 | " transportVlan : %s"; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 43 | |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 44 | @Override |
| 45 | protected void execute() { |
| 46 | |
| 47 | SegmentRoutingService srService = |
| 48 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 49 | |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 50 | List<L2Tunnel> tunnels = srService.getL2Tunnels(); |
| 51 | List<L2TunnelPolicy> policies = srService.getL2Policies(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 52 | |
| 53 | // combine polices and tunnels to pseudowires |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 54 | List<L2TunnelDescription> pseudowires = tunnels.stream() |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 55 | .map(l2Tunnel -> { |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 56 | L2TunnelPolicy policy = null; |
| 57 | for (L2TunnelPolicy l2Policy : policies) { |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 58 | 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 Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 71 | private void printPseudowire(L2TunnelDescription pseudowire) { |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 72 | |
| 73 | |
Andreas Pantelopoulos | 7703171 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 74 | VlanId vlan = pseudowire.l2Tunnel().transportVlan().equals(VlanId.vlanId((short) 4094)) ? |
| 75 | VlanId.NONE : pseudowire.l2Tunnel().transportVlan(); |
| 76 | |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 77 | 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 Pantelopoulos | 7703171 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 81 | pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag(), |
| 82 | vlan); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 83 | } |
| 84 | } |