blob: 18625db6a38aa47829303dd03fdece6ca5e80f53 [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
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.segmentrouting.SegmentRoutingService;
21import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel;
22import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
23import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
24
25import java.util.List;
26import java.util.stream.Collectors;
27
28/**
29 * Command to show the pseudowires.
30 */
31@Command(scope = "onos", name = "pseudowires",
32 description = "Lists all pseudowires")
33public class PseudowireListCommand extends AbstractShellCommand {
34
35 private static final String FORMAT_PSEUDOWIRE =
36 "Pseudowire id = %s \n" +
37 " mode : %s, sdTag : %s, pwLabel : %s \n" +
38 " cP1 : %s , cP1OuterTag : %s, cP1InnerTag : %s \n" +
39 " cP2 : %s , cP2OuterTag : %s, cP2InnerTag : %s \n" /* +
40 " Path used : (%s - %s) <-> (%s - %s) \n" */;
41
42 // TODO: uncomment string when path failures are fixed also for the links
43 // TODO: used in spine for pw traffic.
44 @Override
45 protected void execute() {
46
47 SegmentRoutingService srService =
48 AbstractShellCommand.get(SegmentRoutingService.class);
49
50 List<DefaultL2Tunnel> tunnels = srService.getL2Tunnels();
51 List<DefaultL2TunnelPolicy> policies = srService.getL2Policies();
52
53 // combine polices and tunnels to pseudowires
54 List<DefaultL2TunnelDescription> pseudowires = tunnels.stream()
55 .map(l2Tunnel -> {
56 DefaultL2TunnelPolicy policy = null;
57 for (DefaultL2TunnelPolicy l2Policy : policies) {
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
71 private void printPseudowire(DefaultL2TunnelDescription pseudowire) {
72
73
74 print(FORMAT_PSEUDOWIRE, pseudowire.l2Tunnel().tunnelId(), pseudowire.l2Tunnel().pwMode(),
75 pseudowire.l2Tunnel().sdTag(), pseudowire.l2Tunnel().pwLabel(),
76 pseudowire.l2TunnelPolicy().cP1(), pseudowire.l2TunnelPolicy().cP1OuterTag(),
77 pseudowire.l2TunnelPolicy().cP1InnerTag(), pseudowire.l2TunnelPolicy().cP2(),
78 pseudowire.l2TunnelPolicy().cP2OuterTag(), pseudowire.l2TunnelPolicy().cP2InnerTag()/*,
79 pseudowire.l2Tunnel().pathUsed().get(0).src(), pseudowire.l2Tunnel().pathUsed().get(0).dst(),
80 pseudowire.l2Tunnel().pathUsed().get(1).src(), pseudowire.l2Tunnel().pathUsed().get(1).dst()*/);
81
82 // TODO: uncomment arguments when path issue is fixed for spine switches
83 }
84}