Jonathan Hart | 382623d | 2014-04-03 09:48:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.bgproute; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 2 | |
| 3 | |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 4 | import org.restlet.resource.Delete; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 5 | import org.restlet.resource.Post; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 6 | import org.restlet.resource.ServerResource; |
| 7 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 9 | |
| 10 | |
| 11 | public class BgpRouteResourceSynch extends ServerResource { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 12 | |
| 13 | protected final static Logger log = LoggerFactory |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 14 | .getLogger(BgpRouteResource.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 15 | |
| 16 | @Post |
| 17 | public String store(String fmJson) { |
| 18 | |
| 19 | IBgpRouteService bgpRoute = (IBgpRouteService) getContext().getAttributes(). |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 20 | get(IBgpRouteService.class.getCanonicalName()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 21 | |
| 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-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 42 | |
| 43 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 44 | } |
| 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-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 73 | } |