blob: b219ca2c24209dde2fefdc9bd0e1b159354de2d9 [file] [log] [blame]
William Davies5bae5052019-10-19 01:25:01 -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 */
16
17package org.onosproject.routing.fpm.cli;
18
19import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onlab.packet.IpAddress;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.routing.fpm.FpmInfoService;
25import org.onosproject.routing.fpm.FpmPeer;
26import org.onosproject.routing.fpm.FpmPeerInfo;
27
28import java.util.Comparator;
29import java.util.Map;
30
31/**
32 * Displays the acceptRoute flag value for given peer.
33 */
34@Service
35@Command(scope = "onos", name = "fpm-get-accept-route",
36 description = "Displays the acceptRoute flag value for given peer")
37public class FpmAcceptRoutesInfoCommand extends AbstractShellCommand {
38
39 private static final String FORMAT = "peer %s port %s acceptRoutes %s";
40
41 @Argument(index = 0, name = "peerAddress", description = "Peer Ip address",
42 required = false, multiValued = false)
43 String peerAddress = null;
44
45
46
47 @Override
48 protected void doExecute() {
49 FpmInfoService fpmInfo = get(FpmInfoService.class);
50 if (peerAddress != null) {
51 IpAddress address = IpAddress.valueOf(peerAddress);
52 fpmInfo.peers().entrySet().stream()
53 .filter(peer -> peer.getKey().address().equals(address))
54 .map(Map.Entry::getValue)
55 .forEach(this::print);
56 } else {
57 fpmInfo.peers().entrySet().stream()
58 .sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address())
59 .thenComparing(e -> e.getKey().port()))
60 .map(Map.Entry::getValue)
61 .forEach(this::print);
62 }
63 }
64
65 private void print(FpmPeerInfo info) {
66 info.connections().forEach(cinfo ->
67 print(FORMAT, cinfo.peer().address(),
68 cinfo.peer().port(),
69 cinfo.isAcceptRoutes())
70 );
71 }
72}