64 lines
2.4 KiB
Java
64 lines
2.4 KiB
Java
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.util.List;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.ClientProtocolException;
|
|
import org.apache.http.client.methods.HttpPut;
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
|
/**
|
|
* @author couedrao on 27/11/2019.
|
|
* @project gctrl
|
|
*/
|
|
class SDNCtrlAPI {
|
|
|
|
String redirect_traffic(String olddestip, String newdestip) throws ClientProtocolException, IOException{
|
|
String status = "OK";
|
|
Main.logger(this.getClass().getSimpleName(), "olddestip = " + olddestip + "; newdestip = " + newdestip);
|
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
HttpPut httpPut = new HttpPut("http://127.0.0.1:5001/restapi/compute/dc1/");
|
|
httpPut.setHeader("Accept", "application/json");
|
|
httpPut.setHeader("Content-type", "application/json");//vnfinfos.get("image")
|
|
String inputJson = "{\n" +
|
|
" \"image\": \"+gateway:topo+\",\n" +
|
|
" \"network\": \"(id=input,ip=10.2.2.2/8)\"\n" +
|
|
"}";
|
|
StringEntity stringEntity = new StringEntity(inputJson);
|
|
httpPut.setEntity(stringEntity);
|
|
HttpResponse response = httpclient.execute(httpPut);
|
|
BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
|
|
if (response.getStatusLine().getStatusCode() != 200) {
|
|
throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
|
|
}
|
|
StringBuffer result = new StringBuffer();
|
|
String line = "";
|
|
while ((line = br.readLine()) != null) {
|
|
System.out.println("Response : \n" + result.append(line));
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
String insert_a_loadbalancer(String oldgwip, String lbip, List<String> newgwsip) {
|
|
String status = "OK";
|
|
Main.logger(this.getClass().getSimpleName(), "oldgwip = " + oldgwip + "; lbip = " + lbip + "; newgwsip = " + newgwsip);
|
|
//TODO
|
|
|
|
return status;
|
|
}
|
|
|
|
String remove_less_important_traffic(String importantsrcip) {
|
|
String status = "OK";
|
|
Main.logger(this.getClass().getSimpleName(), "importantsrcip = " + importantsrcip);
|
|
//TODO
|
|
|
|
return status;
|
|
}
|
|
|
|
|
|
}
|