blob: ba752e62e7fb1a805f0de860023bc159a4ce3b1e [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
3import net.floodlightcontroller.core.IOFSwitch;
4
5import org.openflow.util.HexString;
6import org.restlet.resource.Get;
7import org.slf4j.Logger;
8import org.slf4j.LoggerFactory;
9
10/**
11 * FlowProgrammer REST API implementation: Suspend sending message to switch.
Ray Milkey8e5170e2014-04-02 12:09:55 -070012 * <p/>
13 * GET /wm/fprog/pusher/suspend/{dpid}/json"
Naoki Shiota2a35b442013-11-26 19:17:38 -080014 */
15public class SuspendPusherResource extends PusherResource {
16
Ray Milkeyec838942014-04-09 11:28:43 -070017 private static final Logger log = LoggerFactory.getLogger(SetPushRateResource.class);
Naoki Shiota2a35b442013-11-26 19:17:38 -080018
19 /**
20 * Implement the API.
21 *
22 * @return true if succeeded, false if failed.
23 */
24 @Get("json")
25 public boolean retrieve() {
Ray Milkey8e5170e2014-04-02 12:09:55 -070026 if (!init()) {
27 return false;
28 }
Naoki Shiota2a35b442013-11-26 19:17:38 -080029
Ray Milkey8e5170e2014-04-02 12:09:55 -070030 long dpid;
31 try {
32 dpid = HexString.toLong((String) getRequestAttributes().get("dpid"));
33 } catch (NumberFormatException e) {
34 log.error("Invalid number format");
35 return false;
36 }
37
38 IOFSwitch sw = provider.getSwitches().get(dpid);
39 if (sw == null) {
40 log.error("Invalid dpid");
41 return false;
42 }
43
44 return pusher.suspend(sw);
Naoki Shiota2a35b442013-11-26 19:17:38 -080045 }
46}