blob: a0cada7e72d6b2717a736caa35813ee4a20c39f1 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* 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**/
17
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
30 * @author readams
31 */
32public class SwitchStatisticsResource extends SwitchResourceBase {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070033 protected final static Logger log =
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034 LoggerFactory.getLogger(SwitchStatisticsResource.class);
35
36 @Get("json")
37 public Map<String, Object> retrieve() {
38 HashMap<String,Object> result = new HashMap<String,Object>();
39 Object values = null;
40
41 String switchId = (String) getRequestAttributes().get("switchId");
42 String statType = (String) getRequestAttributes().get("statType");
43
44 if (statType.equals("port")) {
45 values = getSwitchStatistics(switchId, OFStatisticsType.PORT);
46 } else if (statType.equals("queue")) {
47 values = getSwitchStatistics(switchId, OFStatisticsType.QUEUE);
48 } else if (statType.equals("flow")) {
49 values = getSwitchStatistics(switchId, OFStatisticsType.FLOW);
50 } else if (statType.equals("aggregate")) {
51 values = getSwitchStatistics(switchId, OFStatisticsType.AGGREGATE);
52 } else if (statType.equals("desc")) {
53 values = getSwitchStatistics(switchId, OFStatisticsType.DESC);
54 } else if (statType.equals("table")) {
55 values = getSwitchStatistics(switchId, OFStatisticsType.TABLE);
56 } else if (statType.equals("features")) {
57 values = getSwitchFeaturesReply(switchId);
58 }
59
60 result.put(switchId, values);
61 return result;
62 }
63}