前言

  • 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 期末作业验收的更多相关文章

  1. SDN期末作业验收

    作业链接:https://edu.cnblogs.com/campus/fzu/SoftwareDefinedNetworking2017/homework/1585 负载均衡程序 1.github链 ...

  2. SDN期末作业——负载均衡

    作业链接 期末作业 1.负载均衡程序 代码 2.演示视频 地址 3.小组分工 小组:incredible five 构建拓扑:俞鋆 编写程序:陈绍纬.周龙荣 程序调试和视频录制:陈辉.林德望 4.个人 ...

  3. SDN期末作业

    期末项目 代码仓库:传送门 视频:组长已经发送给朱老师 选题:负载均衡场景3 选题内容: 该拓扑是数据中心拓扑的一部分,其中h1是数据中心外的一台客户机,h2-h5是数据中心内的服务器,请根据该拓扑实 ...

  4. SDN期末作业-通过SDN的应用实现负载均衡

    负载均衡程序 1.程序链接:https://github.com/424baopu/software/tree/master/LoadBalance 2.场景 topo: 场景描述: 服务器host ...

  5. SDN期末作业博客

    一.项目描述 A P4-based Network Load Balancing Application 基于P4的网络负载均衡项目 二.个人分工 The Controller : Acquire t ...

  6. SDN2017 期末作业验收

    GIT仓库:GITHUB 负载均衡程序 拓扑如图 目的 实现一个负载均衡的北向程序: 服务器host 2 ,host 3,host 4上各自有不同的服务,host 1是客户端 当host 2,host ...

  7. 《SDN期末作业——实现负载均衡》

    队名:取个队名真难 一.网络拓扑(场景二) 二.负载均衡程序 1.建立拓扑的代码 拓扑 2.下发组表流表的代码 下发组表流表 三.演示视频 1.目的 服务器h2,h3,h4上各自有不同的服务,h1是客 ...

  8. SDN课程作业总结

    SDN 期末作业总结 设计场景 我们采用参考场景一,实现负载均衡,拓扑图及端口示意如下: 演示视频 视频地址 关键代码 package loadBalance; import java.io.Buff ...

  9. 分享:计算机图形学期末作业!!利用WebGL的第三方库three.js写一个简单的网页版“我的世界小游戏”

    这几天一直在忙着期末考试,所以一直没有更新我的博客,今天刚把我的期末作业完成了,心情澎湃,所以晚上不管怎么样,我也要写一篇博客纪念一下我上课都没有听,还是通过强大的度娘完成了我的作业的经历.(当然作业 ...

随机推荐

  1. PowerBuilder编程新思维3:适配(三层架构与GraphQL)

    PowerBuilder编程新思维3:适配(三层架构与GraphQL) PB在富客户端时代,是一线开发工具.随着网络发展,主流架构演进到三层架构的时代,PB拿不出有力的三层架构,已经明显力不从心,市场 ...

  2. Spring学习之路-从放弃到入门

    AOP:方法拦截器 IOC:类管理容器 主要讲讲这一天看Spring视频学到的东西,以下的叫法全是自创的. 1.类实例管理容器 关于Spring,首先是对类的管理,在常规情况,生成一个类需要调用new ...

  3. 30分钟搞定后台登录界面(103个后台PSD源文件、素材网站)

    去年八月时要做一个OA系统为了后台界面而烦恼,后来写了一篇博客(<后台管理UI的选择>)介绍了选择过程与常用后台UI,令我想不到的时竟然有许多开发者与我一样都为这个事情而花费不少时间,最后 ...

  4. SqlSession对象之StatementHandler

    上一篇讲了SqlSession对象中的Executor,接下来将对SqlSession的另一个对象StatementHandler进行讲解. 一.StatementHandler介绍 Statemen ...

  5. js-权威指南-Web套接字

    HTTP是一种无状态的协议,,由客户端请求和服务端响应组成.HTTP实际上是比较特殊的网络协议. 大多数基于因特网的网络连接通常包含长连接和基于TCP套接字的双向消息交换.让不信任的客户端脚本访问底层 ...

  6. h5新增加的存储方法

    h4中使用的cookie把用户信息保存在客户端浏览器,但是它受到很多限制. 大小:最多能存储4k 带宽:它是随着http请求一起发送到服务器的,因此浪费一部分的带宽. 复杂度:操作复杂. h5新增加了 ...

  7. 浅谈对NaN的理解

    1.NaN : Not a Number 不是一个数字 2.NaN 与其他数值进行比较的结果总是不相等的,包括它自身在内 3.判断是否是NaN, 方法一  :is.NaN(变量): 方法二   :Nu ...

  8. Maven安装本地jar包

    mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging= ...

  9. ActiveReports 报表控件V12新特性 -- 可定制的安装设置

    ActiveReports是一款专注于 .NET 平台的报表控件,全面满足 HTML5 / WinForms / ASP.NET / ASP.NET MVC / WPF 等平台下报表设计和开发工作需求 ...

  10. Cobalt Strike 学习

    前言 本文以一个模拟的域环境为例对 Cobalt Strike 的使用实践一波. 环境拓扑图如下: 攻击者(kali) 位于 192.168.245.0/24 网段,域环境位于 192.168.31. ...