blob: b38a400d71e1230f4c7970095e768b4ffc5592e3 [file] [log] [blame]
Jonathan Hart382623d2014-04-03 09:48:11 -07001package net.onrc.onos.apps.bgproute;
pingping-line2a09ca2013-03-23 09:33:58 +08002
pingping-line2a09ca2013-03-23 09:33:58 +08003import org.restlet.resource.Delete;
Jonathan Harta99ec672014-04-03 11:30:34 -07004import org.restlet.resource.Post;
pingping-line2a09ca2013-03-23 09:33:58 +08005import org.restlet.resource.ServerResource;
6import org.slf4j.Logger;
7import org.slf4j.LoggerFactory;
pingping-line2a09ca2013-03-23 09:33:58 +08008
pingping-line2a09ca2013-03-23 09:33:58 +08009public class BgpRouteResourceSynch extends ServerResource {
Jonathan Hart738980f2014-04-04 10:11:15 -070010 private final static Logger log = LoggerFactory.getLogger(BgpRouteResourceSynch.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070011
12 @Post
13 public String store(String fmJson) {
14
15 IBgpRouteService bgpRoute = (IBgpRouteService) getContext().getAttributes().
pingping-line2a09ca2013-03-23 09:33:58 +080016 get(IBgpRouteService.class.getCanonicalName());
Ray Milkey269ffb92014-04-03 14:43:30 -070017
Jonathan Hart738980f2014-04-04 10:11:15 -070018 String routerId = (String) getRequestAttributes().get("routerid");
Ray Milkey269ffb92014-04-03 14:43:30 -070019 String prefix = (String) getRequestAttributes().get("prefix");
20 String mask = (String) getRequestAttributes().get("mask");
21 String nexthop = (String) getRequestAttributes().get("nexthop");
22
Jonathan Hart738980f2014-04-04 10:11:15 -070023 String bgpdRestIp = bgpRoute.getBGPdRestIp();
Ray Milkey269ffb92014-04-03 14:43:30 -070024
Jonathan Hart738980f2014-04-04 10:11:15 -070025 // bgpdRestIp includes port number, e.g. 1.1.1.1:8080
26 RestClient.post("http://" + bgpdRestIp + "/wm/bgp/" + routerId + "/" + prefix + "/"
27 + mask + "/" + nexthop);
Ray Milkey269ffb92014-04-03 14:43:30 -070028
29 String reply = "";
30 reply = "[POST: " + prefix + "/" + mask + ":" + nexthop + "/synch]";
31 log.info(reply);
32
33 return reply + "\n";
pingping-line2a09ca2013-03-23 09:33:58 +080034
Ray Milkey269ffb92014-04-03 14:43:30 -070035 }
36
37 @Delete
38 public String delete(String fmJson) {
39 IBgpRouteService bgpRoute = (IBgpRouteService) getContext().getAttributes().
40 get(IBgpRouteService.class.getCanonicalName());
41
42 String routerId = (String) getRequestAttributes().get("routerid");
43 String prefix = (String) getRequestAttributes().get("prefix");
44 String mask = (String) getRequestAttributes().get("mask");
45 String nextHop = (String) getRequestAttributes().get("nexthop");
46
47 String reply = "";
Ray Milkey269ffb92014-04-03 14:43:30 -070048
Jonathan Hart738980f2014-04-04 10:11:15 -070049 String bgpdRestIp = bgpRoute.getBGPdRestIp();
Ray Milkey269ffb92014-04-03 14:43:30 -070050
Jonathan Hart738980f2014-04-04 10:11:15 -070051 RestClient.delete("http://" + bgpdRestIp + "/wm/bgp/" + routerId + "/" + prefix + "/"
52 + mask + "/" + nextHop);
Ray Milkey269ffb92014-04-03 14:43:30 -070053
54 reply = reply + "[DELE: " + prefix + "/" + mask + ":" + nextHop + "/synch]";
55
56 log.info(reply);
57
Ray Milkey269ffb92014-04-03 14:43:30 -070058 return reply + "\n";
59 }
pingping-line2a09ca2013-03-23 09:33:58 +080060}