blob: 13434dc1ad1a2ef8da32a909b1858b4c2649d719 [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
Jonathan Hart938a0152014-04-07 18:27:31 -070047 StringBuilder reply = new StringBuilder();
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
Jonathan Hart938a0152014-04-07 18:27:31 -070054 reply.append("[DELE: ")
55 .append(prefix)
56 .append('/')
57 .append(mask)
58 .append(':')
59 .append(nextHop)
60 .append("/synch]");
Ray Milkey269ffb92014-04-03 14:43:30 -070061
Jonathan Hart938a0152014-04-07 18:27:31 -070062 log.info(reply.toString());
Ray Milkey269ffb92014-04-03 14:43:30 -070063
Jonathan Hart938a0152014-04-07 18:27:31 -070064 return reply.append("\n").toString();
Ray Milkey269ffb92014-04-03 14:43:30 -070065 }
pingping-line2a09ca2013-03-23 09:33:58 +080066}