blob: 20fc71b086982a236cc53877a4e305a853b10b06 [file] [log] [blame]
Jonathan Hart382623d2014-04-03 09:48:11 -07001package net.onrc.onos.apps.bgproute;
pingping-line2a09ca2013-03-23 09:33:58 +08002
3
pingping-line2a09ca2013-03-23 09:33:58 +08004import org.restlet.resource.Delete;
Jonathan Harta99ec672014-04-03 11:30:34 -07005import org.restlet.resource.Post;
pingping-line2a09ca2013-03-23 09:33:58 +08006import org.restlet.resource.ServerResource;
7import org.slf4j.Logger;
8import org.slf4j.LoggerFactory;
pingping-line2a09ca2013-03-23 09:33:58 +08009
10
11public class BgpRouteResourceSynch extends ServerResource {
Ray Milkey269ffb92014-04-03 14:43:30 -070012
13 protected final static Logger log = LoggerFactory
pingping-line2a09ca2013-03-23 09:33:58 +080014 .getLogger(BgpRouteResource.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070015
16 @Post
17 public String store(String fmJson) {
18
19 IBgpRouteService bgpRoute = (IBgpRouteService) getContext().getAttributes().
pingping-line2a09ca2013-03-23 09:33:58 +080020 get(IBgpRouteService.class.getCanonicalName());
Ray Milkey269ffb92014-04-03 14:43:30 -070021
22 String router_id = (String) getRequestAttributes().get("routerid");
23 String prefix = (String) getRequestAttributes().get("prefix");
24 String mask = (String) getRequestAttributes().get("mask");
25 String nexthop = (String) getRequestAttributes().get("nexthop");
26
27 try {
28
29 String BGPdRestIp = bgpRoute.getBGPdRestIp();
30
31 //bgpdRestIp includes port number, such as 1.1.1.1:8080
32 RestClient.post("http://" + BGPdRestIp + "/wm/bgp/" + router_id + "/" + prefix + "/" + mask + "/" + nexthop);
33 } catch (Exception e) {
34 e.printStackTrace();
35 }
36
37 String reply = "";
38 reply = "[POST: " + prefix + "/" + mask + ":" + nexthop + "/synch]";
39 log.info(reply);
40
41 return reply + "\n";
pingping-line2a09ca2013-03-23 09:33:58 +080042
43
Ray Milkey269ffb92014-04-03 14:43:30 -070044 }
45
46 @Delete
47 public String delete(String fmJson) {
48 IBgpRouteService bgpRoute = (IBgpRouteService) getContext().getAttributes().
49 get(IBgpRouteService.class.getCanonicalName());
50
51 String routerId = (String) getRequestAttributes().get("routerid");
52 String prefix = (String) getRequestAttributes().get("prefix");
53 String mask = (String) getRequestAttributes().get("mask");
54 String nextHop = (String) getRequestAttributes().get("nexthop");
55
56 String reply = "";
57 try {
58 String BGPdRestIp = bgpRoute.getBGPdRestIp();
59
60 RestClient.delete("http://" + BGPdRestIp + "/wm/bgp/" + routerId + "/" + prefix + "/" + mask + "/" + nextHop);
61
62 } catch (Exception e) {
63 e.printStackTrace();
64 }
65
66 reply = reply + "[DELE: " + prefix + "/" + mask + ":" + nextHop + "/synch]";
67
68 log.info(reply);
69
70
71 return reply + "\n";
72 }
pingping-line2a09ca2013-03-23 09:33:58 +080073}