blob: c9bf3646521ef7f838d3b3970ca89afb7e1e45ce [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Kalhee Kimba366062017-11-07 16:32:09 +000022import org.onosproject.cli.AbstractShellCommand;
23
24import org.onosproject.dhcprelay.api.DhcpRelayService;
25import org.onosproject.routing.fpm.api.FpmRecord;
26
27import java.util.Collection;
28
29/**
30 * Prints Dhcp FPM Routes information.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Kalhee Kimba366062017-11-07 16:32:09 +000033@Command(scope = "onos", name = "dhcp-fpm-routes",
34 description = "DHCP FPM routes cli.")
35public class DhcpFpmRoutesCommand extends AbstractShellCommand {
36 private static final String NO_RECORDS = "No DHCP FPM Route record found";
37 private static final String HEADER = "DHCP FPM Routes records :";
38 private static final String ROUTE = "prefix=%s, next-hop=%s";
39
40
41 private static final DhcpRelayService DHCP_RELAY_SERVICE = get(DhcpRelayService.class);
42
43 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070044 protected void doExecute() {
Kalhee Kimba366062017-11-07 16:32:09 +000045
46 print("Dhcp Fpm Feature is %s !", DHCP_RELAY_SERVICE.isDhcpFpmEnabled() ? "enabled" : "disabled");
47 print("\n");
48 Collection<FpmRecord> records = DHCP_RELAY_SERVICE.getFpmRecords();
49 if (records.isEmpty()) {
50 print(NO_RECORDS);
51 return;
52 }
53 print(HEADER);
54 records.forEach(record -> print(ROUTE,
55 record.ipPrefix(),
56 record.nextHop()));
57 }
58}