samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
samanwita pal | f28207b | 2015-09-04 10:41:56 -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 | package org.onosproject.dhcp.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; |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 22 | import org.onosproject.dhcp.DhcpService; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 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") |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 29 | public class DhcpRemoveStaticMapping extends AbstractShellCommand { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 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 Removal Failed. " + |
| 38 | "Either the mapping does not exist or it is not static."; |
| 39 | |
| 40 | @Override |
| 41 | protected void execute() { |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 42 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 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 | } |