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; |
| 9 | import net.floodlightcontroller.restclient.RestClient; |
| 10 | |
| 11 | |
| 12 | public class BgpRouteResourceSynch extends ServerResource { |
| 13 | |
| 14 | protected static Logger log = LoggerFactory |
| 15 | .getLogger(BgpRouteResource.class); |
| 16 | |
| 17 | @Post |
| 18 | public String store(String fmJson) { |
| 19 | |
| 20 | IBgpRouteService bgpRoute = (IBgpRouteService)getContext().getAttributes(). |
| 21 | get(IBgpRouteService.class.getCanonicalName()); |
| 22 | |
| 23 | String router_id = (String) getRequestAttributes().get("routerid"); |
| 24 | String prefix = (String) getRequestAttributes().get("prefix"); |
| 25 | String mask = (String) getRequestAttributes().get("mask"); |
| 26 | String nexthop = (String) getRequestAttributes().get("nexthop"); |
| 27 | |
| 28 | try{ |
| 29 | |
| 30 | String BGPdRestIp = bgpRoute.getBGPdRestIp(); |
| 31 | |
| 32 | //BGPdRestIp includes port number, such as 1.1.1.1:8080 |
| 33 | RestClient.post("http://"+BGPdRestIp+"/wm/bgp/"+router_id+"/"+prefix+"/"+mask+"/"+nexthop); |
| 34 | }catch(Exception e) |
| 35 | {e.printStackTrace();} |
| 36 | |
| 37 | String reply = ""; |
| 38 | reply = "[POST: " + prefix + "/" + mask + ":" + nexthop + "/synch]"; |
| 39 | log.info(reply); |
| 40 | |
| 41 | return reply + "\n"; |
| 42 | |
| 43 | |
| 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 | reply =reply + "[DELE: " + prefix + "/" + mask + ":" + nextHop + "/synch]"; |
| 66 | |
| 67 | log.info(reply); |
| 68 | |
| 69 | |
| 70 | return reply + "\n"; |
| 71 | } |
| 72 | } |