SDN 期末作业验收
前言
- SDN 期末作业验收我们是采用的参考场景一,我们在此场景的基础上来做负载均衡,下面是我们搭建的拓扑图
演示视频
https://pan.baidu.com/s/1htkKLPM
负载均衡程序
相关的关键代码
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协议传输
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"); // 设置维持长连接
httpUrlConn.setRequestProperty("Charset", "UTF-8");// 设置文件字符集:
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
{
httpUrlConn.connect();
// 将返回的输入流转换成字符串
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();//转换为字节数组
httpUrlConn.setRequestProperty("Content-Length", String.valueOf(data.length));// 设置文件长度
httpUrlConn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
// 开始连接请求
httpUrlConn.connect();
OutputStream out = httpUrlConn.getOutputStream();
// 写入请求的字符串
out.write((jsonArray[index].toString()).getBytes());
out.flush();
out.close();
if (httpUrlConn.getResponseCode() == 200) {
System.out.println("发送成功");
}
}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 block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.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 block
e.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 block
e.printStackTrace();
}
System.out.println(received-temp);
//这里我们去判断S2交换机通过包的增长数量来选择路径,实现负载均衡
if(received-temp<10000){
//下负载均衡流表
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");
}
}
期末分工
- 我在本次期末作业中,主要是搭建场景,以及设计负载均衡,和最后的视频录制,关于代码实现这部分我参与的比较少。
课程总结
- 虽然在本次课程前我是有接触过一些SDN的相关知识,但在一些课程中也有我之前从未接触过的知识,比例ODL的使用以及开发。也同时在课程中重新复习了SDN的知识,也得到了新的知识。这次的负载均衡也是之前理论上知道,但实际并未去实现。通过这次的SDN课程可以说的是收获很多了。
SDN 期末作业验收的更多相关文章
- SDN期末作业验收
作业链接:https://edu.cnblogs.com/campus/fzu/SoftwareDefinedNetworking2017/homework/1585 负载均衡程序 1.github链 ...
- SDN期末作业——负载均衡
作业链接 期末作业 1.负载均衡程序 代码 2.演示视频 地址 3.小组分工 小组:incredible five 构建拓扑:俞鋆 编写程序:陈绍纬.周龙荣 程序调试和视频录制:陈辉.林德望 4.个人 ...
- SDN期末作业
期末项目 代码仓库:传送门 视频:组长已经发送给朱老师 选题:负载均衡场景3 选题内容: 该拓扑是数据中心拓扑的一部分,其中h1是数据中心外的一台客户机,h2-h5是数据中心内的服务器,请根据该拓扑实 ...
- SDN期末作业-通过SDN的应用实现负载均衡
负载均衡程序 1.程序链接:https://github.com/424baopu/software/tree/master/LoadBalance 2.场景 topo: 场景描述: 服务器host ...
- SDN期末作业博客
一.项目描述 A P4-based Network Load Balancing Application 基于P4的网络负载均衡项目 二.个人分工 The Controller : Acquire t ...
- SDN2017 期末作业验收
GIT仓库:GITHUB 负载均衡程序 拓扑如图 目的 实现一个负载均衡的北向程序: 服务器host 2 ,host 3,host 4上各自有不同的服务,host 1是客户端 当host 2,host ...
- 《SDN期末作业——实现负载均衡》
队名:取个队名真难 一.网络拓扑(场景二) 二.负载均衡程序 1.建立拓扑的代码 拓扑 2.下发组表流表的代码 下发组表流表 三.演示视频 1.目的 服务器h2,h3,h4上各自有不同的服务,h1是客 ...
- SDN课程作业总结
SDN 期末作业总结 设计场景 我们采用参考场景一,实现负载均衡,拓扑图及端口示意如下: 演示视频 视频地址 关键代码 package loadBalance; import java.io.Buff ...
- 分享:计算机图形学期末作业!!利用WebGL的第三方库three.js写一个简单的网页版“我的世界小游戏”
这几天一直在忙着期末考试,所以一直没有更新我的博客,今天刚把我的期末作业完成了,心情澎湃,所以晚上不管怎么样,我也要写一篇博客纪念一下我上课都没有听,还是通过强大的度娘完成了我的作业的经历.(当然作业 ...
随机推荐
- linux笔记-tar 解压缩命令
tar 解压缩命令 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只 ...
- 解决:git使用git push 命令跳出remote: Permission to A denied to B的问题
开始git上传项目,不料,在git push这一步骤发生了错误? remote: Permission to qwe2193066947/firstRepository.git denied to m ...
- 使用Spring JPA中Page、Pageable接口和Sort类完成分页排序
显示时,有三个参数,前两个必填,第几页,一页多少个size,第三个参数默认可以不填. 但是发现这个方法已经过时了,通过查看它的源码发现,新方法为静态方法PageRequest of(page,size ...
- Saving HDU(hdu2111,贪心)
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【JavaFx教程】第四部分:CSS 样式
第4部分主题 CSS样式表 添加应用程序图标 CSS样式表 在JavaFX中,你能使用层叠样式表修饰你的用户接口.这非常好!自定义Java应用界面从来不是件简单的事情. 在本教程中,我们将创建一个*D ...
- ubuntu16.04 linux 编译安装apache2.4.33
下载软件包: wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.33.tar.gz wget http://mirrors.tuna.tsin ...
- php pdo对象使用详解: 连接数据库与exec方法
要使用pdo,首先需要开启pdo扩展,我这里已经开启了mysql的pdo扩展 ghostwu@dev:~$ php -m | grep pdo pdo_mysql ghostwu@dev:~$ 1,连 ...
- POJ1458(KB12-L LCS)
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 51319 Accepted: 21 ...
- django-csrf攻击
一.原理 csrf(Cross Site Request Forgery, 跨站域请求伪造:CSRF 攻击允许恶意用户在另一个用户不知情或者未同意的情况下,以他的身份执 行操作. CSRF 攻击是黑客 ...
- css3 flex弹性盒子布局梳理,打通任督二脉
挺早就接触了css的flex布局,深入使用也就是在近期移动端开发.老来多健忘,只能自己梳理一下知识点,当做温故知新吧. ,请原谅小白的才疏学浅,写的不到位的地方请指正. flex属性用于设置或检索弹性 ...