blob: 44cd120f38fb4efeb139490c0a0ad33267fdc128 [file] [log] [blame]
William Daviesd3687502019-06-19 20:23:17 +00001/*
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.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onlab.packet.IpAddress;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.routing.fpm.FpmInfoService;
24import org.onosproject.routing.fpm.FpmPeer;
25import org.onosproject.routing.fpm.FpmPeerAcceptRoutes;
26
27import java.util.Collections;
28
29/**
30 * Sets acceptRoute flag for given peer.
31 */
32@Command(scope = "onos", name = "fpm-set-accept-routes",
33 description = "Adds a flag to Fpm peer to accept or discard routes")
34public class FpmSetAcceptRoutesCommand extends AbstractShellCommand {
35 @Argument(index = 0, name = "peerAddress", description = "IpAddress of peer",
36 required = true)
37 String peerAddressString = null;
38
39 @Argument(index = 1, name = "peerPort", description = "Port of peer",
40 required = true)
41 String peerPort = null;
42
pierc58776c2019-10-09 18:08:43 +020043 @Argument(index = 2, name = "acceptRoutes", description = "Flag to accept or discard routes",
William Daviesd3687502019-06-19 20:23:17 +000044 required = true)
45 String acceptRoutesString = null;
46
47 @Override
48 protected void execute() {
49 FpmInfoService service = AbstractShellCommand.get(FpmInfoService.class);
50
51 IpAddress peerAddress = IpAddress.valueOf(peerAddressString);
52 boolean isAcceptRoutes = Boolean.parseBoolean(acceptRoutesString);
53 int port = Integer.parseInt(peerPort);
54 FpmPeer peer = new FpmPeer(peerAddress, port);
55 service.updateAcceptRouteFlag(Collections.singleton(new FpmPeerAcceptRoutes(peer, isAcceptRoutes)));
56
57 }
58}