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.protocol.OFBarrierReply; |
| 6 | import org.openflow.util.HexString; |
| 7 | import org.restlet.resource.Get; |
| 8 | |
| 9 | /** |
| 10 | * FlowProgrammer REST API implementation: Send barrier message to switch. |
| 11 | * |
Naoki Shiota | 51f76ca | 2013-11-27 14:37:39 -0800 | [diff] [blame] | 12 | * GET /wm/fprog/pusher/barrier/{dpid}/json" |
Naoki Shiota | 2a35b44 | 2013-11-26 19:17:38 -0800 | [diff] [blame] | 13 | */ |
| 14 | public class SendBarrierResource extends PusherResource { |
| 15 | /** |
| 16 | * Implement the API. |
| 17 | * |
| 18 | * @return true if succeeded, false if failed. |
| 19 | */ |
| 20 | @Get("json") |
| 21 | public OFBarrierReply retrieve() { |
| 22 | if (! init()) { |
| 23 | return null; |
| 24 | } |
| 25 | long dpid; |
| 26 | try { |
| 27 | dpid = HexString.toLong((String)getRequestAttributes().get("dpid")); |
| 28 | } catch (NumberFormatException e) { |
| 29 | log.error("Invalid number format"); |
| 30 | return null; |
| 31 | } |
| 32 | |
| 33 | IOFSwitch sw = provider.getSwitches().get(dpid); |
| 34 | if (sw == null) { |
| 35 | log.error("Invalid dpid"); |
| 36 | return null; |
| 37 | } |
| 38 | |
| 39 | return pusher.barrier(sw); |
| 40 | } |
| 41 | } |