blob: bc1eb427bf4739547239890f876f789ea190f111 [file] [log] [blame]
Harshada Chaundkarb42abd42019-07-02 16:01:24 +00001/*
2 * Copyright 2020-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.segmentrouting.cli;
18
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.segmentrouting.SegmentRoutingService;
24import org.onosproject.segmentrouting.mcast.McastFilteringObjStoreKey;
25
26import java.util.List;
27import java.util.Map;
28
29/**
30 * Command to show the list of mcast filtering obj.
31 */
32@Service
33@Command(scope = "onos", name = "sr-filt-mcast",
34 description = "Lists all mcast filtering objs")
35public class McastFilterListCommand extends AbstractShellCommand {
36
37 private static final String FORMAT_HEADER = "device=%s";
38 private static final String FILTER_HEADER = "\t%s,%s,%s";
39
40 @Override
41 protected void doExecute() {
42 // Get SR service
43 SegmentRoutingService srService = get(SegmentRoutingService.class);
44 // Get the filt objs
45 Map<DeviceId, List<McastFilteringObjStoreKey>> filteringObjKeys = srService.getMcastFilters();
46 filteringObjKeys.forEach(this::printMcastFilter);
47 }
48
49 private void printMcastFilter(DeviceId deviceId, List<McastFilteringObjStoreKey> filteringObjs) {
50 print(FORMAT_HEADER, deviceId);
51 filteringObjs.forEach(filteringObj -> print(FILTER_HEADER, filteringObj.ingressCP(),
52 filteringObj.isIpv4() ? "IPv4" : "IPv6",
53 filteringObj.vlanId()));
54 }
55}