Naoki Shiota | 2a35b44 | 2013-11-26 19:17:38 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowprogrammer.web; |
| 2 | |
| 3 | import net.floodlightcontroller.core.IOFSwitch; |
| 4 | |
| 5 | import org.openflow.util.HexString; |
| 6 | import org.restlet.resource.Get; |
| 7 | |
| 8 | /** |
| 9 | * FlowProgrammer REST API implementation: Set sending rate to the switch. |
| 10 | * |
| 11 | * GET /wm/fprog/setrate/{dpid}/{rate}/json" |
| 12 | */ |
| 13 | public class SetPushRateResource extends PusherResource { |
| 14 | |
| 15 | /** |
| 16 | * Implement the API. |
| 17 | * |
| 18 | * @return true if succeeded, false if failed. |
| 19 | */ |
| 20 | @Get("json") |
| 21 | public boolean retrieve() { |
| 22 | if (! init()) { |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | long dpid; |
| 27 | long rate; |
| 28 | |
| 29 | try { |
| 30 | dpid = HexString.toLong((String)getRequestAttributes().get("dpid")); |
| 31 | rate = Long.valueOf((String)getRequestAttributes().get("rate")); |
| 32 | } catch (NumberFormatException e) { |
| 33 | log.error("Invalid number format"); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | IOFSwitch sw = provider.getSwitches().get(dpid); |
| 38 | if (sw == null) { |
| 39 | log.error("Invalid dpid"); |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | pusher.setRate(sw, rate); |
| 44 | |
| 45 | return true; |
| 46 | } |
| 47 | } |