Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.flowprogrammer.web; |
Naoki Shiota | 7b2ab4a | 2013-12-04 18:05:39 -0800 | [diff] [blame] | 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: Begin synchronization to a switch. |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 10 | * <p/> |
| 11 | * GET /wm/fprog/synchronizer/sync/{dpid}/json" |
Naoki Shiota | 7b2ab4a | 2013-12-04 18:05:39 -0800 | [diff] [blame] | 12 | */ |
| 13 | public class DoSynchronizeResource extends SynchronizerResource { |
| 14 | /** |
| 15 | * Implement the API. |
| 16 | * |
| 17 | * @return true if succeeded, false if failed. |
| 18 | */ |
| 19 | @Get("json") |
| 20 | public boolean retrieve() { |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 21 | if (!init()) { |
| 22 | return false; |
| 23 | } |
Naoki Shiota | 7b2ab4a | 2013-12-04 18:05:39 -0800 | [diff] [blame] | 24 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 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 false; |
| 31 | } |
| 32 | |
| 33 | IOFSwitch sw = provider.getSwitches().get(dpid); |
| 34 | if (sw == null) { |
| 35 | log.error("Invalid dpid"); |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | synchronizer.synchronize(sw); |
| 40 | |
| 41 | return true; |
Naoki Shiota | 7b2ab4a | 2013-12-04 18:05:39 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | } |