blob: 452a145e690edb4e9a9cc0c188682467ec6193a6 [file] [log] [blame]
Marc De Leenheer48a91f72015-06-05 23:35:41 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.routing.cli;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.packet.IpAddress;
21import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.routing.FibEntry;
25import org.onosproject.routing.FibListener;
26import org.onosproject.routing.FibUpdate;
27import org.onosproject.routing.StaticRoutingService;
28
29import java.util.Arrays;
30import java.util.Collections;
31
32@Command(scope = "onos", name = "add-route", description = "Installs static route")
33public class AddRouteCommand extends AbstractShellCommand {
34
35 @Argument(index = 0, name = "prefix IP MAC",
36 description = "prefix nexthopIP nexthopMAC",
37 required = true, multiValued = true)
38 String[] fibEntryString = null;
39
40 @Override
41 protected void execute() {
42 StaticRoutingService routingService = get(StaticRoutingService.class);
43
44 if (fibEntryString.length < 3) {
45 return;
46 }
47
48 IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]);
49 IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]);
50 MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]);
51 FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac);
52 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
53
54 FibListener fibListener = routingService.getFibListener();
55 fibListener.update(Arrays.asList(fibUpdate), Collections.emptyList());
56 }
57}