Harshada Chaundkar | 9204f31 | 2019-07-02 16:01:24 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.segmentrouting.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 24 | import org.onosproject.segmentrouting.mcast.McastFilteringObjStoreKey; |
| 25 | |
| 26 | import java.util.List; |
| 27 | import 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") |
| 35 | public 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 | } |