blob: d0204ff0e2bf4db408fa879d765f9e1bf2176f2d [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.FpmPeerAcceptRoutes;
27
28import java.util.Collections;
29
30/**
31 * Sets acceptRoute flag for given peer.
32 */
33@Service
34@Command(scope = "onos", name = "fpm-set-accept-routes",
35 description = "Adds a flag to Fpm peer to accept or discard routes")
36public class FpmSetAcceptRoutesCommand extends AbstractShellCommand {
37 @Argument(index = 0, name = "peerAddress", description = "IpAddress of peer",
38 required = true)
39 String peerAddressString = null;
40
41 @Argument(index = 1, name = "peerPort", description = "Port of peer",
42 required = true)
43 String peerPort = null;
44
45 @Argument(index = 2, name = "acceptRoutes", description = "Flag to accept or discard routes",
46 required = true)
47 String acceptRoutesString = null;
48
49 @Override
50 protected void doExecute() {
51 FpmInfoService service = AbstractShellCommand.get(FpmInfoService.class);
52
53 IpAddress peerAddress = IpAddress.valueOf(peerAddressString);
54 boolean isAcceptRoutes = Boolean.parseBoolean(acceptRoutesString);
55 int port = Integer.parseInt(peerPort);
56 FpmPeer peer = new FpmPeer(peerAddress, port);
57 service.updateAcceptRouteFlag(Collections.singleton(new FpmPeerAcceptRoutes(peer, isAcceptRoutes)));
58
59 }
60}