blob: 780f9e5c93620b333244528ad823274c6d78c484 [file] [log] [blame]
kalagesa1a1867a2017-03-07 13:06:41 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
kalagesa1a1867a2017-03-07 13:06:41 +05303 *
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 */
16package org.onosproject.fwd;
17import org.apache.karaf.shell.console.Completer;
18import org.apache.karaf.shell.console.completer.StringsCompleter;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.store.service.EventuallyConsistentMap;
21import java.util.List;
22import java.util.SortedSet;
23import org.onlab.packet.MacAddress;
24
25/**
26 * Sample reactive forwarding application.
27 */
28public class MacAddressCompleter implements Completer {
29 @Override
30 public int complete(String buffer, int cursor, List<String> candidates) {
31 // Delegate string completer
32 StringsCompleter delegate = new StringsCompleter();
33 EventuallyConsistentMap<MacAddress, ReactiveForwardMetrics> macAddress;
34 // Fetch our service and feed it's offerings to the string completer
35 ReactiveForwarding reactiveForwardingService = AbstractShellCommand.get(ReactiveForwarding.class);
36 macAddress = reactiveForwardingService.getMacAddress();
37 SortedSet<String> strings = delegate.getStrings();
38 for (MacAddress key : macAddress.keySet()) {
39 strings.add(key.toString());
40 }
41 // Now let the completer do the work for figuring out what to offer.
42 return delegate.complete(buffer, cursor, candidates);
43 }
44}