blob: 4f454638178511932190563a8b492d9689085087 [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;
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070021
22import org.projectfloodlight.openflow.protocol.OFStatsType;
23import org.restlet.resource.Get;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070027
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028/**
29 * Return switch statistics information for specific switches
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070030 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031 * @author readams
32 */
33public class SwitchStatisticsResource extends SwitchResourceBase {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070034 protected final static Logger log =
Ray Milkey269ffb92014-04-03 14:43:30 -070035 LoggerFactory.getLogger(SwitchStatisticsResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036
37 @Get("json")
Srikanth Vavilapallib7258512014-09-29 13:24:11 -070038 public HashMap<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")) {
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070046 values = getSwitchStatistics(switchId, OFStatsType.PORT);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080047 } else if (statType.equals("queue")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070048 values = getSwitchStatistics(switchId, OFStatsType.QUEUE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080049 } else if (statType.equals("flow")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070050 values = getSwitchStatistics(switchId, OFStatsType.FLOW);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080051 } else if (statType.equals("aggregate")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070052 values = getSwitchStatistics(switchId, OFStatsType.AGGREGATE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080053 } else if (statType.equals("desc")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070054 values = getSwitchStatistics(switchId, OFStatsType.DESC);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080055 } else if (statType.equals("table")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070056 values = getSwitchStatistics(switchId, OFStatsType.TABLE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080057 } else if (statType.equals("features")) {
58 values = getSwitchFeaturesReply(switchId);
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070059 }else if (statType.equals("groupDesc")) {
60 values = getSwitchStatistics(switchId, OFStatsType.GROUP_DESC);
61 }else if (statType.equals("groupStats")) {
62 values = getSwitchStatistics(switchId, OFStatsType.GROUP);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080063 }
64
65 result.put(switchId, values);
66 return result;
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070067 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080068}