blob: d10795215d1518f129754a65f64c242a3849053a [file] [log] [blame]
Tunahan Sezen03e55272020-04-18 09:18:53 +00001/*
Joey Armstrong53fcac22023-01-11 13:25:01 -05002 * Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Tunahan Sezen03e55272020-04-18 09:18:53 +00003 *
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.opencord.maclearner.app.cli;
17
18import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.Completion;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.PortNumber;
25import org.opencord.maclearner.api.MacLearnerService;
26
27import java.util.Map;
28import java.util.Set;
29
30/**
31 * Gets ignored port information for MAC Mapping.
32 */
33@Service
34@Command(scope = "onos", name = "mac-learner-list-ignored-ports",
35 description = "Gets ignored port information for MAC Mapping")
36public class MacLearnerListIgnoredPorts extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "deviceId",
39 description = "Device Id")
40 @Completion(MappedDeviceIdCompleter.class)
41 String devId = null;
42
43 @Override
44 protected void doExecute() {
45 try {
46 MacLearnerService macLearnerService = AbstractShellCommand.get(MacLearnerService.class);
47 Map<DeviceId, Set<PortNumber>> ignoredPorts = macLearnerService.getIgnoredPorts();
48 if (devId == null) {
49 if (ignoredPorts != null && !ignoredPorts.isEmpty()) {
50 for (Map.Entry<DeviceId, Set<PortNumber>> entry : ignoredPorts.entrySet()) {
51 print("Port(s): %s ignored of device with ID: %s", entry.getValue(), entry.getKey());
52 }
53 } else {
54 print("There is no ignored port.");
55 }
56 } else {
57 Set<PortNumber> portNumbers = ignoredPorts.get(DeviceId.deviceId(devId));
58 if (!ignoredPorts.isEmpty()) {
59 print("Port(s): %s ignored of device with ID: %s", portNumbers, devId);
60 } else {
61 print("There is no ignored port of device with ID: %s", devId);
62 }
63 }
64
65 } catch (IllegalArgumentException e) {
66 String msg = String.format("Exception occurred while executing %s command",
67 this.getClass().getSimpleName());
68 print(msg);
69 log.error(msg, e);
70 }
71 }
72
73}