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