Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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 | **/ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
| 18 | package net.floodlightcontroller.core.web; |
| 19 | |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 20 | import java.util.HashMap; |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 21 | |
| 22 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
| 23 | import org.restlet.resource.Get; |
| 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
| 26 | |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 27 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Return switch statistics information for specific switches |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 30 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | * @author readams |
| 32 | */ |
| 33 | public class SwitchStatisticsResource extends SwitchResourceBase { |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 34 | protected final static Logger log = |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | LoggerFactory.getLogger(SwitchStatisticsResource.class); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 36 | |
| 37 | @Get("json") |
Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 38 | public HashMap<String, Object> retrieve() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 39 | HashMap<String, Object> result = new HashMap<String, Object>(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 40 | Object values = null; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 42 | String switchId = (String) getRequestAttributes().get("switchId"); |
| 43 | String statType = (String) getRequestAttributes().get("statType"); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 45 | if (statType.equals("port")) { |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 46 | values = getSwitchStatistics(switchId, OFStatsType.PORT); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 47 | } else if (statType.equals("queue")) { |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 48 | values = getSwitchStatistics(switchId, OFStatsType.QUEUE); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 49 | } else if (statType.equals("flow")) { |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 50 | values = getSwitchStatistics(switchId, OFStatsType.FLOW); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 51 | } else if (statType.equals("aggregate")) { |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 52 | values = getSwitchStatistics(switchId, OFStatsType.AGGREGATE); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 53 | } else if (statType.equals("desc")) { |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 54 | values = getSwitchStatistics(switchId, OFStatsType.DESC); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 55 | } else if (statType.equals("table")) { |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 56 | values = getSwitchStatistics(switchId, OFStatsType.TABLE); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 57 | } else if (statType.equals("features")) { |
| 58 | values = getSwitchFeaturesReply(switchId); |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 59 | }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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | result.put(switchId, values); |
| 66 | return result; |
Srikanth Vavilapalli | cc49bde | 2014-09-28 22:43:56 -0700 | [diff] [blame] | 67 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 68 | } |