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 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | b3a5b8d | 2018-10-03 11:16:11 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 24 | import org.onosproject.dhcp.DhcpService; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Removes a static MAC Address to IP Mapping from the DHCP Server. |
| 28 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 29 | @Service |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 30 | @Command(scope = "onos", name = "dhcp-remove-static-mapping", |
| 31 | 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] | 32 | public class DhcpRemoveStaticMapping extends AbstractShellCommand { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 33 | |
| 34 | @Argument(index = 0, name = "macAddr", |
| 35 | description = "MAC Address of the client", |
| 36 | required = true, multiValued = false) |
Ray Milkey | b3a5b8d | 2018-10-03 11:16:11 -0700 | [diff] [blame] | 37 | @Completion(MacIdCompleter.class) |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 38 | String macAddr = null; |
| 39 | |
| 40 | private static final String DHCP_SUCCESS = "Static Mapping Successfully Removed."; |
| 41 | private static final String DHCP_FAILURE = "Static Mapping Removal Failed. " + |
| 42 | "Either the mapping does not exist or it is not static."; |
| 43 | |
| 44 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 45 | protected void doExecute() { |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 46 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 47 | |
| 48 | try { |
| 49 | MacAddress macID = MacAddress.valueOf(macAddr); |
| 50 | if (dhcpService.removeStaticMapping(macID)) { |
| 51 | print(DHCP_SUCCESS); |
| 52 | } else { |
| 53 | print(DHCP_FAILURE); |
| 54 | } |
| 55 | |
| 56 | } catch (IllegalArgumentException e) { |
| 57 | print(e.getMessage()); |
| 58 | } |
| 59 | } |
| 60 | } |