blob: 3e216f95d83dfecb276302f0739bc608b34890ca [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 = "remove-route", description = "Removes static route")
33public class RemoveRouteCommand extends AbstractShellCommand {
34 @Argument(index = 0, name = "prefix IP MAC",
35 description = "prefix nexthopIP nexthopMAC",
36 required = true, multiValued = true)
37 String[] fibEntryString = null;
38
39 @Override
40 protected void execute() {
41 StaticRoutingService routingService = get(StaticRoutingService.class);
42
43 if (fibEntryString.length < 3) {
44 return;
45 }
46
47 IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]);
48 IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]);
49 MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]);
50 FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac);
51 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry);
52
53 FibListener fibListener = routingService.getFibListener();
54 fibListener.update(Collections.emptyList(), Arrays.asList(fibUpdate));
55 }
56}