blob: dc8d431e8c2485b3d7ead644de0de03e0f4073a8 [file] [log] [blame]
Naoki Shiota7b2ab4a2013-12-04 18:05:39 -08001package net.onrc.onos.ofcontroller.flowprogrammer.web;
2
3import net.floodlightcontroller.core.IOFSwitch;
4
5import org.openflow.util.HexString;
6import org.restlet.resource.Get;
7
8/**
9 * FlowProgrammer REST API implementation: Begin synchronization to a switch.
10 *
11 * GET /wm/fprog/synchronizer/sync/{dpid}/json"
12 */
13public 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() {
21 if (! init()) {
22 return false;
23 }
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 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;
42 }
43
44}