diff --git a/gctrl-spring/gctrl/src/main/java/SDNCtrlAPI.java b/gctrl-spring/gctrl/src/main/java/SDNCtrlAPI.java index 23c44b9..4acc14b 100644 --- a/gctrl-spring/gctrl/src/main/java/SDNCtrlAPI.java +++ b/gctrl-spring/gctrl/src/main/java/SDNCtrlAPI.java @@ -5,6 +5,7 @@ import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -20,17 +21,30 @@ class SDNCtrlAPI { String status = "OK"; Main.logger(this.getClass().getSimpleName(), "olddestip = " + olddestip + "; newdestip = " + newdestip); + //On s3: Redirect traffic from gwf2 to gwi2 through s4 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") + HttpPost httpPost = new HttpPost("http://127.0.0.1:8080/stats/flowentry/add"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json");//vnfinfos.get("image") + String match = "{\n" + + " \"ipv4_dst\": \"10.2.2.1\",\n" + + " \"eth_type\": 2048,\n" + + " \"ipv4_src\": \"10.0.2.100\"\n" + + "}"; + String actions = "[\n" + + " {\"type\": \"SET_FIELD\", \"field\":\"eth_dst\", \"value\":\"00:00:00:00:00:20\"}, \n" + + " {\"type\": \"SET_FIELD\", \"field\":\"ipv4_dst\", \"value\":\"10.2.2.2\"}, \n" + + " {\"type\": \"OUTPUT\", \"port\":2} \n" + + "]"; String inputJson = "{\n" + - " \"image\": \"+gateway:topo+\",\n" + - " \"network\": \"(id=input,ip=10.2.2.2/8)\"\n" + + " \"dpid\": 3,\n" + + " \"priority\": 1,\n" + + " \"match\": "+match+",\n" + + " \"actions\": "+actions+"\n" + "}"; StringEntity stringEntity = new StringEntity(inputJson); - httpPut.setEntity(stringEntity); - HttpResponse response = httpclient.execute(httpPut); + httpPost.setEntity(stringEntity); + HttpResponse response = httpclient.execute(httpPost); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); @@ -40,7 +54,179 @@ class SDNCtrlAPI { while ((line = br.readLine()) != null) { System.out.println("Response : \n" + result.append(line)); } - + + //On s3: Redirect traffic from gwf3 to gwi2 through s4 + httpPost = new HttpPost("http://127.0.0.1:8080/stats/flowentry/add"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json");//vnfinfos.get("image") + match = "{\n" + + " \"ipv4_dst\": \"10.2.2.1\",\n" + + " \"eth_type\": 2048,\n" + + " \"ipv4_src\": \"10.0.3.100\"\n" + + "}"; + actions = "[\n" + + " {\"type\": \"SET_FIELD\", \"field\":\"eth_dst\", \"value\":\"00:00:00:00:00:20\"}, \n" + + " {\"type\": \"SET_FIELD\", \"field\":\"ipv4_dst\", \"value\":\"10.2.2.2\"}, \n" + + " {\"type\": \"OUTPUT\", \"port\":2} \n" + + "]"; + inputJson = "{\n" + + " \"dpid\": 3,\n" + + " \"priority\": 1,\n" + + " \"match\": "+match+",\n" + + " \"actions\": "+actions+"\n" + + "}"; + stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + response = httpclient.execute(httpPost); + br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); + } + result = new StringBuffer(); + line = ""; + while ((line = br.readLine()) != null) { + System.out.println("Response : \n" + result.append(line)); + } + + //On s3: Redirect traffic from gwf1 to gwi1 through s2 + httpPost = new HttpPost("http://127.0.0.1:8080/stats/flowentry/add"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json");//vnfinfos.get("image") + match = "{\n" + + " \"ipv4_dst\": \"10.2.2.1\",\n" + + " \"eth_type\": 2048,\n" + + " \"ipv4_src\": \"10.0.1.100\"\n" + + "}"; + actions = "[\n" + + " {\"type\": \"OUTPUT\", \"port\":1} \n" + + "]"; + inputJson = "{\n" + + " \"dpid\": 3,\n" + + " \"priority\": 1,\n" + + " \"match\": "+match+",\n" + + " \"actions\": "+actions+"\n" + + "}"; + stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + response = httpclient.execute(httpPost); + br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); + } + result = new StringBuffer(); + line = ""; + while ((line = br.readLine()) != null) { + System.out.println("Response : \n" + result.append(line)); + } + + + //On s4: Redirect traffic from s3 to gwi2 + httpPost = new HttpPost("http://127.0.0.1:8080/stats/flowentry/add"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json");//vnfinfos.get("image") + match = "{\n" + + " \"in_port\": 1,\n" + + " \"eth_type\": 2048,\n" + + " \"ipv4_dst\": \"10.2.2.2\"\n" + + "}"; + actions = "[\n" + + " {\"type\": \"OUTPUT\", \"port\":2} \n" + + "]"; + inputJson = "{\n" + + " \"dpid\": 4,\n" + + " \"priority\": 1,\n" + + " \"match\": "+match+",\n" + + " \"actions\": "+actions+"\n" + + "}"; + stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + response = httpclient.execute(httpPost); + br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); + } + result = new StringBuffer(); + line = ""; + while ((line = br.readLine()) != null) { + System.out.println("Response : \n" + result.append(line)); + } + + //On s4: Redirect traffic from gwf3 to gwi2 + httpPost = new HttpPost("http://127.0.0.1:8080/stats/flowentry/add"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json");//vnfinfos.get("image") + match = "{\n" + + " \"ipv4_dst\": \"10.2.2.1\",\n" + + " \"eth_type\": 2048,\n" + + " \"ipv4_src\": \"10.0.3.100\"\n" + + "}"; + actions = "[\n" + + " {\"type\": \"SET_FIELD\", \"field\":\"eth_dst\", \"value\":\"00:00:00:00:00:20\"}, \n" + + " {\"type\": \"SET_FIELD\", \"field\":\"ipv4_dst\", \"value\":\"10.2.2.2\"}, \n" + + " {\"type\": \"OUTPUT\", \"port\":2} \n" + + "]"; + inputJson = "{\n" + + " \"dpid\": 4,\n" + + " \"priority\": 1,\n" + + " \"match\": "+match+",\n" + + " \"actions\": "+actions+"\n" + + "}"; + stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + response = httpclient.execute(httpPost); + br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); + } + result = new StringBuffer(); + line = ""; + while ((line = br.readLine()) != null) { + System.out.println("Response : \n" + result.append(line)); + } + + + //Fixing script gateway.js registering bug + //Manually registering gwf2 + httpPost = new HttpPost("http://172.17.0.17:8181/gateways/register"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + inputJson = "{\n" + + " \"Name\": \"gwf2\",\n" + + " \"PoC\": \"http://10.0.2.100:8282\"\n" + + "}"; + stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + response = httpclient.execute(httpPost); + br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); + } + result = new StringBuffer(); + line = ""; + while ((line = br.readLine()) != null) { + System.out.println("Response : \n" + result.append(line)); + } + //Manually registering gwf3 + httpPost = new HttpPost("http://172.17.0.17:8181/gateways/register"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + inputJson = "{\n" + + " \"Name\": \"gwf3\",\n" + + " \"PoC\": \"http://10.0.3.100:8282\"\n" + + "}"; + stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + response = httpclient.execute(httpPost); + br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); + } + result = new StringBuffer(); + line = ""; + while ((line = br.readLine()) != null) { + System.out.println("Response : \n" + result.append(line)); + } + return status; } diff --git a/gctrl-spring/gctrl/src/main/java/fr/laas/gctrl/GctrlApplication.java b/gctrl-spring/gctrl/src/main/java/fr/laas/gctrl/GctrlApplication.java index 2ab24c8..16b4887 100644 --- a/gctrl-spring/gctrl/src/main/java/fr/laas/gctrl/GctrlApplication.java +++ b/gctrl-spring/gctrl/src/main/java/fr/laas/gctrl/GctrlApplication.java @@ -12,6 +12,7 @@ import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -48,7 +49,7 @@ public class GctrlApplication { }*/ //RestTemplate restTemplate = new RestTemplate(); - CloseableHttpClient httpclient = HttpClients.createDefault(); + /*CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPut httpPut = new HttpPut("http://127.0.0.1:5001/restapi/compute/dc1/gwi2"); httpPut.setHeader("Accept", "application/json"); httpPut.setHeader("Content-type", "application/json"); @@ -68,7 +69,40 @@ public class GctrlApplication { while ((line = br.readLine()) != null) { System.out.println("Response : \n" + result.append(line)); } - System.out.println("Does Reponse contains 'datacenter'? :" + result.toString().contains("datacenter")); + System.out.println("Does Reponse contains 'datacenter'? :" + result.toString().contains("datacenter"));*/ + + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost("http://127.0.0.1:8080/stats/flowentry/add"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + String match = "{\n" + + " \"ipv4_dst\": \"10.0.0.1\",\n" + + " \"eth_type\": 2048,\n" + + " \"ipv4_src\": \"10.0.2.100\"\n" + + "}"; + String actions = "[\n" + + " {\"type\": \"SET_FIELD\", \"field\":\"eth_dst\", \"value\":\"00:00:00:00:00:20\"}, \n" + + " {\"type\": \"OUTPUT\", \"port\":2} \n" + + "]"; + String inputJson = "{\n" + + " \"dpid\": 3,\n" + + " \"priority\": 1,\n" + + " \"match\": "+match+",\n" + + " \"actions\": "+actions+"\n" + + "}"; + System.out.println(inputJson); + StringEntity stringEntity = new StringEntity(inputJson); + httpPost.setEntity(stringEntity); + HttpResponse response = httpclient.execute(httpPost); + 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)); + } } }