Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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 | |
Ray Milkey | 69ec871 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 17 | package org.onosproject.routeservice.cli; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 23 | import org.onlab.packet.IpPrefix; |
| 24 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | 69ec871 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 25 | import org.onosproject.routeservice.Route; |
| 26 | import org.onosproject.routeservice.RouteAdminService; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 27 | |
| 28 | import java.util.Collections; |
| 29 | |
| 30 | /** |
| 31 | * Command to remove a route from the routing table. |
| 32 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 33 | @Service |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 34 | @Command(scope = "onos", name = "route-remove", |
| 35 | description = "Removes a route from the route table") |
| 36 | public class RouteRemoveCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "prefix", description = "IP prefix of the route", |
| 39 | required = true) |
| 40 | String prefixString = null; |
| 41 | |
Charles Chan | 1778b52 | 2016-10-24 15:10:02 -0700 | [diff] [blame] | 42 | @Argument(index = 1, name = "nextHop", description = "IP address of the next hop", |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 43 | required = true) |
| 44 | String nextHopString = null; |
| 45 | |
snehaprem | 7828d01 | 2018-11-01 01:02:21 -0400 | [diff] [blame] | 46 | @Argument(index = 2, name = "source", description = "Source type of the route", |
| 47 | required = false) |
| 48 | String source = null; |
| 49 | |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 50 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 51 | protected void doExecute() { |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 52 | RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class); |
| 53 | |
| 54 | IpPrefix prefix = IpPrefix.valueOf(prefixString); |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 55 | IpAddress nextHop = IpAddress.valueOf(nextHopString); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 56 | |
snehaprem | 7828d01 | 2018-11-01 01:02:21 -0400 | [diff] [blame] | 57 | // Routes through cli without mentioning source then it is created as STATIC, |
| 58 | // otherwise routes are created with corresponding source. |
| 59 | |
| 60 | Route route = source == null ? |
| 61 | new Route(Route.Source.STATIC, prefix, nextHop) : |
| 62 | new Route(Route.Source.valueOf(source), prefix, nextHop); |
| 63 | |
| 64 | service.withdraw(Collections.singleton(route)); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | } |