blob: 6ec156c67069b2d6af0d89b804ba67285ac94db2 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.flowprogrammer.web;
Naoki Shiota2a35b442013-11-26 19:17:38 -08002
Jonathan Hart5302b6c2014-08-13 15:57:59 -07003import net.onrc.onos.core.util.Dpid;
Naoki Shiota2a35b442013-11-26 19:17:38 -08004
Jonathan Hartc78b8f62014-08-07 22:31:09 -07005import org.projectfloodlight.openflow.util.HexString;
Naoki Shiota2a35b442013-11-26 19:17:38 -08006import org.restlet.resource.Get;
7
8/**
9 * FlowProgrammer REST API implementation: Set sending rate to the switch.
Ray Milkey8e5170e2014-04-02 12:09:55 -070010 * <p/>
11 * 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() {
Ray Milkey8e5170e2014-04-02 12:09:55 -070022 if (!init()) {
23 return false;
24 }
Naoki Shiota2a35b442013-11-26 19:17:38 -080025
Ray Milkey8e5170e2014-04-02 12:09:55 -070026 long dpid;
27 long rate;
28
29 try {
30 dpid = HexString.toLong((String) getRequestAttributes().get("dpid"));
Yuta HIGUCHI0fe749a2014-05-27 09:35:16 -070031 rate = Long.parseLong((String) getRequestAttributes().get("rate"));
Ray Milkey8e5170e2014-04-02 12:09:55 -070032 } catch (NumberFormatException e) {
33 log.error("Invalid number format");
34 return false;
35 }
36
Jonathan Hart5302b6c2014-08-13 15:57:59 -070037 pusher.setRate(new Dpid(dpid), rate);
Ray Milkey8e5170e2014-04-02 12:09:55 -070038
39 return true;
Naoki Shiota2a35b442013-11-26 19:17:38 -080040 }
41}