blob: 956a7fbae9ddbdc4a18c87ea13883f9b6b2e3ea4 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.flowprogrammer.web;
Naoki Shiota7b2ab4a2013-12-04 18:05:39 -08002
3import net.floodlightcontroller.core.IOFSwitch;
4
Jonathan Hartc78b8f62014-08-07 22:31:09 -07005import org.projectfloodlight.openflow.util.HexString;
Naoki Shiota7b2ab4a2013-12-04 18:05:39 -08006import org.restlet.resource.Get;
7
8/**
9 * FlowProgrammer REST API implementation: Begin synchronization to a switch.
Ray Milkey8e5170e2014-04-02 12:09:55 -070010 * <p/>
11 * GET /wm/fprog/synchronizer/sync/{dpid}/json"
Naoki Shiota7b2ab4a2013-12-04 18:05:39 -080012 */
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() {
Ray Milkey8e5170e2014-04-02 12:09:55 -070021 if (!init()) {
22 return false;
23 }
Naoki Shiota7b2ab4a2013-12-04 18:05:39 -080024
Ray Milkey8e5170e2014-04-02 12:09:55 -070025 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 Shiota7b2ab4a2013-12-04 18:05:39 -080042 }
43
44}