blob: 468a50eb72fc2b7a1dd6f394fc0ba1310bb5cbab [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford University
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
18package net.floodlightcontroller.core.web;
19
20import java.util.HashMap;
21import java.util.Map;
22
23import org.openflow.protocol.statistics.OFStatisticsType;
24import org.restlet.resource.Get;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28/**
29 * Return switch statistics information for specific switches
Ray Milkey269ffb92014-04-03 14:43:30 -070030 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031 * @author readams
32 */
33public class SwitchStatisticsResource extends SwitchResourceBase {
Ray Milkey269ffb92014-04-03 14:43:30 -070034 protected final static Logger log =
35 LoggerFactory.getLogger(SwitchStatisticsResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036
37 @Get("json")
38 public Map<String, Object> retrieve() {
Ray Milkey269ffb92014-04-03 14:43:30 -070039 HashMap<String, Object> result = new HashMap<String, Object>();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080040 Object values = null;
Ray Milkey269ffb92014-04-03 14:43:30 -070041
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080042 String switchId = (String) getRequestAttributes().get("switchId");
43 String statType = (String) getRequestAttributes().get("statType");
Ray Milkey269ffb92014-04-03 14:43:30 -070044
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045 if (statType.equals("port")) {
46 values = getSwitchStatistics(switchId, OFStatisticsType.PORT);
47 } else if (statType.equals("queue")) {
48 values = getSwitchStatistics(switchId, OFStatisticsType.QUEUE);
49 } else if (statType.equals("flow")) {
50 values = getSwitchStatistics(switchId, OFStatisticsType.FLOW);
51 } else if (statType.equals("aggregate")) {
52 values = getSwitchStatistics(switchId, OFStatisticsType.AGGREGATE);
53 } else if (statType.equals("desc")) {
54 values = getSwitchStatistics(switchId, OFStatisticsType.DESC);
55 } else if (statType.equals("table")) {
56 values = getSwitchStatistics(switchId, OFStatisticsType.TABLE);
57 } else if (statType.equals("features")) {
58 values = getSwitchFeaturesReply(switchId);
59 }
60
61 result.put(switchId, values);
62 return result;
63 }
64}