blob: 70ae32f98f7ec82c2216ec64fffc5eaaf6889dc4 [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
18import org.apache.karaf.shell.commands.Command;
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080019import org.onlab.packet.VlanId;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.segmentrouting.SegmentRoutingService;
22import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel;
23import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
24import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
25
26import java.util.List;
27import java.util.stream.Collectors;
28
29/**
30 * Command to show the pseudowires.
31 */
32@Command(scope = "onos", name = "pseudowires",
33 description = "Lists all pseudowires")
34public class PseudowireListCommand extends AbstractShellCommand {
35
36 private static final String FORMAT_PSEUDOWIRE =
37 "Pseudowire id = %s \n" +
38 " mode : %s, sdTag : %s, pwLabel : %s \n" +
39 " cP1 : %s , cP1OuterTag : %s, cP1InnerTag : %s \n" +
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080040 " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" +
41 " transportVlan : %s";
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070042
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070043 @Override
44 protected void execute() {
45
46 SegmentRoutingService srService =
47 AbstractShellCommand.get(SegmentRoutingService.class);
48
49 List<DefaultL2Tunnel> tunnels = srService.getL2Tunnels();
50 List<DefaultL2TunnelPolicy> policies = srService.getL2Policies();
51
52 // combine polices and tunnels to pseudowires
53 List<DefaultL2TunnelDescription> pseudowires = tunnels.stream()
54 .map(l2Tunnel -> {
55 DefaultL2TunnelPolicy policy = null;
56 for (DefaultL2TunnelPolicy l2Policy : policies) {
57 if (l2Policy.tunnelId() == l2Tunnel.tunnelId()) {
58 policy = l2Policy;
59 break;
60 }
61 }
62
63 return new DefaultL2TunnelDescription(l2Tunnel, policy);
64 })
65 .collect(Collectors.toList());
66
67 pseudowires.forEach(pw -> printPseudowire(pw));
68 }
69
70 private void printPseudowire(DefaultL2TunnelDescription pseudowire) {
71
72
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080073 VlanId vlan = pseudowire.l2Tunnel().transportVlan().equals(VlanId.vlanId((short) 4094)) ?
74 VlanId.NONE : pseudowire.l2Tunnel().transportVlan();
75
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070076 print(FORMAT_PSEUDOWIRE, pseudowire.l2Tunnel().tunnelId(), pseudowire.l2Tunnel().pwMode(),
77 pseudowire.l2Tunnel().sdTag(), pseudowire.l2Tunnel().pwLabel(),
78 pseudowire.l2TunnelPolicy().cP1(), pseudowire.l2TunnelPolicy().cP1OuterTag(),
79 pseudowire.l2TunnelPolicy().cP1InnerTag(), pseudowire.l2TunnelPolicy().cP2(),
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080080 pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag(),
81 vlan);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070082 }
83}