Naoki Shiota | 7b2ab4a | 2013-12-04 18:05:39 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowprogrammer.web; |
| 2 | |
| 3 | import net.floodlightcontroller.core.IOFSwitch; |
| 4 | |
| 5 | import org.openflow.util.HexString; |
| 6 | import org.restlet.resource.Get; |
| 7 | |
| 8 | /** |
| 9 | * FlowProgrammer REST API implementation: Interrupt synchronization to a switch. |
| 10 | * |
| 11 | * GET /wm/fprog/synchronizer/interrupt/{dpid}/json" |
| 12 | */ |
| 13 | public class DoInterruptResource extends SynchronizerResource { |
| 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 | try { |
| 28 | dpid = HexString.toLong((String)getRequestAttributes().get("dpid")); |
| 29 | } catch (NumberFormatException e) { |
| 30 | log.error("Invalid number format"); |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | IOFSwitch sw = provider.getSwitches().get(dpid); |
| 35 | if (sw == null) { |
| 36 | log.error("Invalid dpid"); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | synchronizer.interrupt(sw); |
| 41 | |
| 42 | return true; |
| 43 | } |
| 44 | } |