blob: ce2221e0d4aca06c5d28214c6fa4703e54c8a64b [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;
Fahad Naeem Khand563af62014-10-08 17:37:25 -070023import org.projectfloodlight.openflow.util.HexString;
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070024import org.restlet.resource.Get;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070028
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080029/**
30 * Return switch statistics information for specific switches
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -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")
Srikanth Vavilapallib7258512014-09-29 13:24:11 -070039 public HashMap<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");
Fahad Naeem Khand563af62014-10-08 17:37:25 -070045 String tableType = null;
46 if(getRequestAttributes().containsKey("tableType")){
47 tableType = (String) getRequestAttributes().get("tableType");
48 }
Ray Milkey269ffb92014-04-03 14:43:30 -070049
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080050 if (statType.equals("port")) {
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070051 values = getSwitchStatistics(switchId, OFStatsType.PORT);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080052 } else if (statType.equals("queue")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070053 values = getSwitchStatistics(switchId, OFStatsType.QUEUE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080054 } else if (statType.equals("flow")) {
Fahad Naeem Khand563af62014-10-08 17:37:25 -070055 if (tableType != null){
56 values = getSwitchStatisticsForTable(HexString.toLong(switchId), OFStatsType.FLOW, tableType);
57 }
58 else{
59 values = getSwitchStatistics(switchId, OFStatsType.FLOW);
60 }
61 }
62 else if (statType.equals("aggregate")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070063 values = getSwitchStatistics(switchId, OFStatsType.AGGREGATE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080064 } else if (statType.equals("desc")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070065 values = getSwitchStatistics(switchId, OFStatsType.DESC);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080066 } else if (statType.equals("table")) {
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070067 values = getSwitchStatistics(switchId, OFStatsType.TABLE);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080068 } else if (statType.equals("features")) {
69 values = getSwitchFeaturesReply(switchId);
Fahad Naeem Khan9ae7fa12014-10-03 14:30:55 -070070 }else if (statType.equals("groupDesc")) {
71 values = getSwitchStatistics(switchId, OFStatsType.GROUP_DESC);
72 }else if (statType.equals("groupStats")) {
73 values = getSwitchStatistics(switchId, OFStatsType.GROUP);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080074 }
75
76 result.put(switchId, values);
77 return result;
Srikanth Vavilapallicc49bde2014-09-28 22:43:56 -070078 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080079}