日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SDN期末作业验收

發(fā)布時(shí)間:2025/4/9 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SDN期末作业验收 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

SDN期末作業(yè)驗(yàn)收

參考場景一

搭建的拓?fù)鋱D:

負(fù)載均衡程序

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.util.Base64;import net.sf.json.*; public class Main {public static JSONObject jsonObject = null;public static JSONObject[] jsonArray = new JSONObject[100];static String url24= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/0";static String url14= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1";static String url21= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/0";static String url12= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1";public static JSONObject httpRequest(String requestUrl, String requestMethod,int index) {StringBuffer buffer = new StringBuffer();try {URL url = new URL(requestUrl);// http協(xié)議傳輸HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();httpUrlConn.setDoOutput(true);httpUrlConn.setDoInput(true);httpUrlConn.setUseCaches(false);String userPassword = "admin" + ":" + "admin";String encoding = Base64.getEncoder().encodeToString((userPassword).getBytes());httpUrlConn.setRequestProperty("Authorization", "Basic " + encoding); httpUrlConn.setRequestProperty("Connection", "Keep-Alive"); // 設(shè)置維持長連接httpUrlConn.setRequestProperty("Charset", "UTF-8");// 設(shè)置文件字符集:// 設(shè)置請(qǐng)求方式(GET/POST)httpUrlConn.setRequestMethod(requestMethod);if ("GET".equalsIgnoreCase(requestMethod)){httpUrlConn.connect();// 將返回的輸入流轉(zhuǎn)換成字符串InputStream inputStream = httpUrlConn.getInputStream();InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");BufferedReader bufferedReader = new BufferedReader(inputStreamReader);String str = null;while ((str = bufferedReader.readLine()) != null) {buffer.append(str);}bufferedReader.close();inputStreamReader.close();// 釋放資源inputStream.close();inputStream = null;httpUrlConn.disconnect();jsonObject = JSONObject.fromObject(buffer.toString());// System.out.println(buffer.toString());}else if("PUT".equalsIgnoreCase(requestMethod)){byte[] data = (jsonArray[index].toString()).getBytes();//轉(zhuǎn)換為字節(jié)數(shù)組httpUrlConn.setRequestProperty("Content-Length", String.valueOf(data.length));// 設(shè)置文件長度httpUrlConn.setRequestProperty("Content-Type", "application/json;charset=utf-8");// 開始連接請(qǐng)求httpUrlConn.connect();OutputStream out = httpUrlConn.getOutputStream(); // 寫入請(qǐng)求的字符串out.write((jsonArray[index].toString()).getBytes());out.flush();out.close();if (httpUrlConn.getResponseCode() == 200) { System.out.println("發(fā)送成功");}}else if("DELETE".equalsIgnoreCase(requestMethod)){}} catch (Exception e) {e.printStackTrace();}return jsonObject;}public static void init() throws IOException{String s = null;int i = 0;try {BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("DATA.txt"),"UTF-8"));while((s = br.readLine())!=null){jsonArray[i] = JSONObject.fromObject(s);i++;}String url31= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:3/flow-node-inventory:table/0/flow/0";String url32= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:3/flow-node-inventory:table/0/flow/1";String url11= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/0";String url22= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/1";String url13= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/2";String url23= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/2";String url33= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:3/flow-node-inventory:table/0/flow/2";httpRequest(url31,"PUT",0);httpRequest(url32,"PUT",1);httpRequest(url21,"PUT",2);httpRequest(url11,"PUT",3);httpRequest(url12,"PUT",4);httpRequest(url22,"PUT",5);httpRequest(url13,"PUT",6);httpRequest(url23,"PUT",7);httpRequest(url33,"PUT",10);} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static int getReceived(String url2){jsonObject = httpRequest(url2,"GET",0);JSONArray j1 = (JSONArray) jsonObject.get("node-connector");JSONObject j2 = (JSONObject) j1.get(0);JSONObject j3 = (JSONObject) j2.get("opendaylight-port-statistics:flow-capable-node-connector-statistics");JSONObject j4 = (JSONObject)j3.get("bytes");int received = (int) j4.get("received");return received;}public static void main(String[] args) {System.out.println("-------------------------------------------------");try {init();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}String s = "";String url = "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:3/flow-node-inventory:table/0/flow/1";String url1= "http://172.17.172.244:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/0";String url2 = "http://172.17.172.244:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:2/node-connector/openflow:2:2"; // jsonObject = httpRequest(url2,"GET",0); // System.out.println(jsonObject.toString());int received ;int temp = 0;while(true){received = getReceived(url2);try {Thread.sleep(5000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();} System.out.println(received-temp);//這里我們?nèi)ヅ袛郤2交換機(jī)通過包的增長數(shù)量來選擇路徑,實(shí)現(xiàn)負(fù)載均衡if(received-temp<10000){//下負(fù)載均衡流表httpRequest(url24,"PUT",8);httpRequest(url14,"PUT",9);}else if(received-temp>10000 ){httpRequest(url21,"PUT",2);httpRequest(url12,"PUT",4);}temp = received;}// jsonObject = httpRequest(url1,"PUT");} }

演示視頻

https://pan.baidu.com/s/1htkKLPM

程序分工

在最后的這次作業(yè)中主要負(fù)責(zé)查找相關(guān)的資料,以及輔助部分代碼的編寫

課程總結(jié)

這學(xué)期的SDN這門課對(duì)我來說,讓我對(duì)現(xiàn)在網(wǎng)絡(luò)前沿的發(fā)展方向有了一個(gè)大體的認(rèn)識(shí)。在平時(shí)的上課與作業(yè)中學(xué)會(huì)了建立結(jié)構(gòu)比較簡單的拓?fù)?#xff0c;以及用python模仿編寫的腳本來建立拓?fù)鋱D。另外,還學(xué)會(huì)了利用ODL下發(fā)流表,不得不說我從中收獲了很多。

轉(zhuǎn)載于:https://www.cnblogs.com/dark-Earl/p/8342475.html

總結(jié)

以上是生活随笔為你收集整理的SDN期末作业验收的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。