blob: 08a728e4ce64483d822a6a52781f227a3213c7a7 [file] [log] [blame]
Naoki Shiota2a35b442013-11-26 19:17:38 -08001package net.onrc.onos.ofcontroller.flowprogrammer.web;
2
3import net.floodlightcontroller.core.IOFSwitch;
4
5import org.openflow.util.HexString;
6import 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 */
13public 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}