Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 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.cli.net; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.incubator.net.routing.Route; |
| 25 | import org.onosproject.incubator.net.routing.RouteAdminService; |
| 26 | |
| 27 | import java.util.Collections; |
| 28 | |
| 29 | /** |
| 30 | * Command to remove a route from the routing table. |
| 31 | */ |
| 32 | @Command(scope = "onos", name = "route-remove", |
| 33 | description = "Removes a route from the route table") |
| 34 | public class RouteRemoveCommand extends AbstractShellCommand { |
| 35 | |
| 36 | @Argument(index = 0, name = "prefix", description = "IP prefix of the route", |
| 37 | required = true) |
| 38 | String prefixString = null; |
| 39 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 40 | @Argument(index = 1, name = "prefix", description = "Next hop IP address", |
| 41 | required = true) |
| 42 | String nextHopString = null; |
| 43 | |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 44 | @Override |
| 45 | protected void execute() { |
| 46 | RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class); |
| 47 | |
| 48 | IpPrefix prefix = IpPrefix.valueOf(prefixString); |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 49 | IpAddress nextHop = IpAddress.valueOf(nextHopString); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 50 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 51 | service.withdraw(Collections.singleton(new Route(Route.Source.STATIC, prefix, nextHop))); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } |