samanwita pal | f66ed8a | 2015-07-21 15:45:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
| 16 | package org.onosproject.dhcpserver.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.dhcpserver.DHCPService; |
| 23 | |
| 24 | /** |
| 25 | * Removes a static MAC Address to IP Mapping from the DHCP Server. |
| 26 | */ |
| 27 | @Command(scope = "onos", name = "dhcp-remove-static-mapping", |
| 28 | description = "Removes a static MAC Address to IP Mapping from the DHCP Server") |
| 29 | public class DHCPRemoveStaticMapping extends AbstractShellCommand { |
| 30 | |
| 31 | @Argument(index = 0, name = "macAddr", |
| 32 | description = "MAC Address of the client", |
| 33 | required = true, multiValued = false) |
| 34 | String macAddr = null; |
| 35 | |
| 36 | private static final String DHCP_SUCCESS = "Static Mapping Successfully Removed."; |
| 37 | private static final String DHCP_FAILURE = "Static Mapping Failed. " + |
| 38 | "Either the mapping does not exist or it is not static."; |
| 39 | |
| 40 | @Override |
| 41 | protected void execute() { |
| 42 | DHCPService dhcpService = AbstractShellCommand.get(DHCPService.class); |
| 43 | |
| 44 | try { |
| 45 | MacAddress macID = MacAddress.valueOf(macAddr); |
| 46 | if (dhcpService.removeStaticMapping(macID)) { |
| 47 | print(DHCP_SUCCESS); |
| 48 | } else { |
| 49 | print(DHCP_FAILURE); |
| 50 | } |
| 51 | |
| 52 | } catch (IllegalArgumentException e) { |
| 53 | print(e.getMessage()); |
| 54 | } |
| 55 | } |
| 56 | } |