Kalhee Kim | ba36606 | 2017-11-07 16:32:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.dhcprelay.cli; |
| 18 | |
| 19 | //import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | |
| 23 | import org.onosproject.dhcprelay.api.DhcpRelayService; |
| 24 | import org.onosproject.routing.fpm.api.FpmRecord; |
| 25 | |
| 26 | import java.util.Collection; |
| 27 | |
| 28 | /** |
| 29 | * Prints Dhcp FPM Routes information. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "dhcp-fpm-routes", |
| 32 | description = "DHCP FPM routes cli.") |
| 33 | public class DhcpFpmRoutesCommand extends AbstractShellCommand { |
| 34 | private static final String NO_RECORDS = "No DHCP FPM Route record found"; |
| 35 | private static final String HEADER = "DHCP FPM Routes records :"; |
| 36 | private static final String ROUTE = "prefix=%s, next-hop=%s"; |
| 37 | |
| 38 | |
| 39 | private static final DhcpRelayService DHCP_RELAY_SERVICE = get(DhcpRelayService.class); |
| 40 | |
| 41 | @Override |
| 42 | protected void execute() { |
| 43 | |
| 44 | print("Dhcp Fpm Feature is %s !", DHCP_RELAY_SERVICE.isDhcpFpmEnabled() ? "enabled" : "disabled"); |
| 45 | print("\n"); |
| 46 | Collection<FpmRecord> records = DHCP_RELAY_SERVICE.getFpmRecords(); |
| 47 | if (records.isEmpty()) { |
| 48 | print(NO_RECORDS); |
| 49 | return; |
| 50 | } |
| 51 | print(HEADER); |
| 52 | records.forEach(record -> print(ROUTE, |
| 53 | record.ipPrefix(), |
| 54 | record.nextHop())); |
| 55 | } |
| 56 | } |