blob: c23acdf6b4ad3fb3069e8b62c21fda49a3244c44 [file] [log] [blame]
senthil7f2018e2023-06-21 22:00:44 +05301/*
2 * Copyright 2023-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 */
16package org.onosproject.netflow.cli;
17
18import org.apache.karaf.shell.api.action.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
21import java.util.List;
22import java.util.Set;
23import java.util.Map;
24import java.util.stream.Collectors;
25
26import org.onosproject.netflow.NetflowController;
27import org.onosproject.netflow.TemplateId;
28import org.onosproject.netflow.DataTemplateRecord;
29import org.onosproject.netflow.DataFlowRecord;
30
31/**
32 * Netflow overall summary report.
33 */
34@Service
35@Command(scope = "onos", name = "netflow-summary",
36 description = "Summary of template flowsets and data flowsets.")
37public class NetflowSummaryCommand extends AbstractShellCommand {
38
39 @Override
40 protected void doExecute() {
41 NetflowController controller = AbstractShellCommand.get(NetflowController.class);
42 Set<DataTemplateRecord> templates = controller.getTemplateFlowSet();
43 if (templates.isEmpty()) {
44 print("Template not found");
45 } else {
46 Set<Integer> templateIds = templates.stream()
47 .map(DataTemplateRecord::getTemplateId)
48 .map(TemplateId::getId)
49 .collect(Collectors.toSet());
50 printTemplateflowSet(templateIds);
51
52 }
53 Map<TemplateId, List<DataFlowRecord>> dataFlowSets = controller.getDataFlowSet();
54 if (dataFlowSets.isEmpty()) {
55 print("Data not found");
56 } else {
57 printDataflowSet(dataFlowSets);
58 }
59 }
60
61 /**
62 * Adds template flowset summary in specified row wise.
63 *
64 * @param templateIds template ids
65 */
66 private void printTemplateflowSet(Set<Integer> templateIds) {
67 print("Number of templates : %d, Template IDs : %s",
68 templateIds.size(),
69 templateIds.toString());
70 }
71
72 /**
73 * Adds data flowset summary in specified row wise.
74 *
75 * @param dataflowMap data flow map
76 */
77 private void printDataflowSet(Map<TemplateId, List<DataFlowRecord>> dataflowMap) {
78 dataflowMap.entrySet().forEach(entry -> {
79 print("Template ID : %d, Data flow count : %d",
80 entry.getKey().getId(),
81 entry.getValue().size());
82 });
83 print("\n");
84 }
85}