blob: e86bb618e7241311c237c93d73e6c8024f72e67c [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
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070020import java.util.HashMap;
21import java.util.Map;
22
23import org.projectfloodlight.openflow.protocol.OFStatsType;
24import org.restlet.resource.Get;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028
29/**
30 * Return switch statistics information for specific switches
Ray Milkey269ffb92014-04-03 14:43:30 -070031 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032 * @author readams
33 */
34public class SwitchStatisticsResource extends SwitchResourceBase {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070035 protected final static Logger log =
Ray Milkey269ffb92014-04-03 14:43:30 -070036 LoggerFactory.getLogger(SwitchStatisticsResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080037
38 @Get("json")
39 public Map<String, Object> retrieve() {
Ray Milkey269ffb92014-04-03 14:43:30 -070040 HashMap<String, Object> result = new HashMap<String, Object>();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080041 Object values = null;
Ray Milkey269ffb92014-04-03 14:43:30 -070042
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080043 String switchId = (String) getRequestAttributes().get("switchId");
44 String statType = (String) getRequestAttributes().get("statType");
Ray Milkey269ffb92014-04-03 14:43:30 -070045
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046 if (statType.equals("port")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070047 values = getSwitchStatistics(switchId, OFStatsType.PORT);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080048 } else if (statType.equals("queue")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070049 values = getSwitchStatistics(switchId, OFStatsType.QUEUE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080050 } else if (statType.equals("flow")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070051 values = getSwitchStatistics(switchId, OFStatsType.FLOW);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080052 } else if (statType.equals("aggregate")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070053 values = getSwitchStatistics(switchId, OFStatsType.AGGREGATE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080054 } else if (statType.equals("desc")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070055 values = getSwitchStatistics(switchId, OFStatsType.DESC);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080056 } else if (statType.equals("table")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070057 values = getSwitchStatistics(switchId, OFStatsType.TABLE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 } else if (statType.equals("features")) {
59 values = getSwitchFeaturesReply(switchId);
60 }
61
62 result.put(switchId, values);
63 return result;
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070064 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080065}