pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 1 | package net.floodlightcontroller.bgproute; |
| 2 | |
| 3 | |
| 4 | import org.restlet.resource.Post; |
| 5 | import org.restlet.resource.Delete; |
| 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 { |
| 12 | |
| 13 | protected static Logger log = LoggerFactory |
| 14 | .getLogger(BgpRouteResource.class); |
| 15 | |
| 16 | @Post |
| 17 | public String store(String fmJson) { |
| 18 | |
| 19 | IBgpRouteService bgpRoute = (IBgpRouteService)getContext().getAttributes(). |
| 20 | get(IBgpRouteService.class.getCanonicalName()); |
| 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 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 31 | //bgpdRestIp includes port number, such as 1.1.1.1:8080 |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 32 | RestClient.post("http://"+BGPdRestIp+"/wm/bgp/"+router_id+"/"+prefix+"/"+mask+"/"+nexthop); |
| 33 | }catch(Exception e) |
| 34 | {e.printStackTrace();} |
| 35 | |
| 36 | String reply = ""; |
| 37 | reply = "[POST: " + prefix + "/" + mask + ":" + nexthop + "/synch]"; |
| 38 | log.info(reply); |
| 39 | |
| 40 | return reply + "\n"; |
| 41 | |
| 42 | |
| 43 | } |
| 44 | |
| 45 | @Delete |
| 46 | public String delete(String fmJson) { |
| 47 | IBgpRouteService bgpRoute = (IBgpRouteService)getContext().getAttributes(). |
| 48 | get(IBgpRouteService.class.getCanonicalName()); |
| 49 | |
| 50 | String routerId = (String) getRequestAttributes().get("routerid"); |
| 51 | String prefix = (String) getRequestAttributes().get("prefix"); |
| 52 | String mask = (String) getRequestAttributes().get("mask"); |
| 53 | String nextHop = (String) getRequestAttributes().get("nexthop"); |
| 54 | |
| 55 | String reply = ""; |
| 56 | try{ |
| 57 | String BGPdRestIp = bgpRoute.getBGPdRestIp(); |
| 58 | |
| 59 | RestClient.delete("http://"+BGPdRestIp+"/wm/bgp/"+routerId+"/"+prefix+"/"+mask+"/"+nextHop); |
| 60 | |
| 61 | }catch(Exception e) |
| 62 | {e.printStackTrace();} |
| 63 | |
| 64 | reply =reply + "[DELE: " + prefix + "/" + mask + ":" + nextHop + "/synch]"; |
| 65 | |
| 66 | log.info(reply); |
| 67 | |
| 68 | |
| 69 | return reply + "\n"; |
| 70 | } |
| 71 | } |