blob: f2573a54ba33ab7d0bfb0894ba0040d7ec14eb64 [file] [log] [blame]
Kalhee Kimba366062017-11-07 16:32:09 +00001/*
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
17package org.onosproject.dhcprelay.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019//import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Kalhee Kimba366062017-11-07 16:32:09 +000021import org.onosproject.cli.AbstractShellCommand;
22
23import org.onosproject.dhcprelay.api.DhcpRelayService;
24import org.onosproject.routing.fpm.api.FpmRecord;
25
26import 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.")
33public 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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070042 protected void doExecute() {
Kalhee Kimba366062017-11-07 16:32:09 +000043
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}