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