William Davies | d368750 | 2019-06-19 20:23:17 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.routing.fpm.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.routing.fpm.FpmInfoService; |
| 24 | import org.onosproject.routing.fpm.FpmPeer; |
| 25 | import org.onosproject.routing.fpm.FpmPeerAcceptRoutes; |
| 26 | |
| 27 | import 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") |
| 34 | public 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 | |
| 43 | @Argument(index = 1, name = "acceptRoutes", description = "Flag to accept or discard routes", |
| 44 | 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 | } |