blob: 9431d658f6665051d93e400c9a3dba368d4047e2 [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 *
Naoki Shiota6cbe1172013-11-27 14:37:39 -080011 * GET /wm/fprog/pusher/setrate/{dpid}/{rate}/json"
Naoki Shiota2a35b442013-11-26 19:17:38 -080012 */
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}