blob: e104d4c28f54b7f1f8b6ba84861b13bfc5e10897 [file] [log] [blame]
Jonathan Hartbfc5c482016-04-05 18:57:00 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hartbfc5c482016-04-05 18:57:00 -07003 *
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 Milkey69ec8712017-08-08 13:00:43 -070017package org.onosproject.routeservice.cli;
Jonathan Hartbfc5c482016-04-05 18:57:00 -070018
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Jonathan Hartbfc5c482016-04-05 18:57:00 -070022import org.onlab.packet.IpAddress;
23import org.onlab.packet.IpPrefix;
24import org.onosproject.cli.AbstractShellCommand;
Ray Milkey69ec8712017-08-08 13:00:43 -070025import org.onosproject.routeservice.Route;
26import org.onosproject.routeservice.RouteAdminService;
Jonathan Hartbfc5c482016-04-05 18:57:00 -070027
28import java.util.Collections;
29
30/**
31 * Command to add a route to the routing table.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
Jonathan Hartbfc5c482016-04-05 18:57:00 -070034@Command(scope = "onos", name = "route-add",
35 description = "Adds a route to the route table")
36public class RouteAddCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "prefix", description = "IP prefix of the route",
39 required = true)
40 String prefixString = null;
41
42 @Argument(index = 1, name = "nextHop", description = "IP address of the next hop",
43 required = true)
44 String nextHopString = null;
45
46 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070047 protected void doExecute() {
Jonathan Hartbfc5c482016-04-05 18:57:00 -070048 RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class);
49
50 IpPrefix prefix = IpPrefix.valueOf(prefixString);
51 IpAddress nextHop = IpAddress.valueOf(nextHopString);
52
53 service.update(Collections.singleton(new Route(Route.Source.STATIC, prefix, nextHop)));
54 }
55
56}