我负责的工作:

(1)、前期工作思路设计及方案选定、讲解

(2)、后期代码修正

(3)、视频制作


负载均衡程序

程序流程图

代码


from mininet.topo import Topo class MyTopo( Topo ):
"Simple topology example." def __init__( self ): # Initialize topology
Topo.__init__( self ) sw1 = self.addSwitch('s1')
sw2 = self.addSwitch('s2')
sw3 = self.addSwitch('s3')
sw4 = self.addSwitch('s4') h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4') self.addLink(h1,sw1,1)
self.addLink(sw1,sw2,2,1)
self.addLink(sw1,sw4,3,2)
self.addLink(sw1,sw3,4,1)
self.addLink(sw2,sw4,2,1)
self.addLink(sw3,sw4,2,3)
self.addLink(sw4,h2,4)
self.addLink(sw4,h3,5)
self.addLink(sw4,h4,6) topos = { 'mytopo': ( lambda: MyTopo() ) }
//拓扑


import httplib2
import time class OdlUtil:
url = ''
def __init__(self, host, port):
self.url = 'http://' + host + ':' + str(port)
def install_flow(self, container_name='default',username="admin", password="admin"):
http = httplib2.Http()
http.add_credentials(username, password)
headers = {'Accept': 'application/json'}
flow_name = 'flow_' + str(int(time.time()*1000))
h1h4body1 ='{"flow": [{"id": "1","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.4/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "4"},"order": "0"}]}}]},'
'"priority": "101","cookie": "1","table_id": "0"}]}'
mh1h4body1 ='{"flow": [{"id": "1","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.4/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "4"},"order": "0"}]}}]},'
'"priority": "102","cookie": "1","table_id": "0"}]}'
h1h4body2 ='{"flow": [{"id": "5","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.4/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "2"},"order": "0"}]}}]},'
'"priority": "100","cookie": "5","table_id": "0"}]}'
mh1h4body2 ='{"flow": [{"id": "5","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.4/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "2"},"order": "0"}]}}]},'
'"priority": "102","cookie": "5","table_id": "0"}]}'
h1h4body3 ='{"flow": [{"id": "6","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.4/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "3"},"order": "0"}]}}]},'
'"priority": "99","cookie": "6","table_id": "0"}]}'
mh1h4body3 ='{"flow": [{"id": "6","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.4/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "3"},"order": "0"}]}}]},'
'"priority": "102","cookie": "6","table_id": "0"}]}'
h1h2body1 ='{"flow": [{"id": "1","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "4"},"order": "0"}]}}]},'
'"priority": "101","cookie": "1","table_id": "0"}]}'
mh1h2body1 ='{"flow": [{"id": "1","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "4"},"order": "0"}]}}]},'
'"priority": "102","cookie": "1","table_id": "0"}]}'
h1h2body2 ='{"flow": [{"id": "5","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "2"},"order": "0"}]}}]},'
'"priority": "100","cookie": "5","table_id": "0"}]}'
mh1h2body2 ='{"flow": [{"id": "5","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "2"},"order": "0"}]}}]},'
'"priority": "102","cookie": "5","table_id": "0"}]}'
h1h2body3 ='{"flow": [{"id": "6","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "3"},"order": "0"}]}}]},'
'"priority": "99","cookie": "6","table_id": "0"}]}'
mh1h2body3 ='{"flow": [{"id": "6","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "3"},"order": "0"}]}}]},'
'"priority": "102","cookie": "6","table_id": "0"}]}'
h1h3body1 ='{"flow": [{"id": "1","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.3/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "4"},"order": "0"}]}}]},'
'"priority": "101","cookie": "1","table_id": "0"}]}'
mh1h3body1 ='{"flow": [{"id": "1","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.3/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "4"},"order": "0"}]}}]},'
'"priority": "102","cookie": "1","table_id": "0"}]}'
h1h3body2 ='{"flow": [{"id": "5","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.3/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "2"},"order": "0"}]}}]},'
'"priority": "100","cookie": "5","table_id": "0"}]}'
mh1h3body2 ='{"flow": [{"id": "5","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.3/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "2"},"order": "0"}]}}]},'
'"priority": "102","cookie": "5","table_id": "0"}]}'
h1h3body3 ='{"flow": [{"id": "6","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.3/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "3"},"order": "0"}]}}]},'
'"priority": "99","cookie": "6","table_id": "0"}]}'
mh1h3body3 ='{"flow": [{"id": "6","match": {"ethernet-match":'
'{"ethernet-type": {"type": "2048"}},'
'"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.3/32"},'
'"instructions": {"instruction": [{"order": "0",'
'"apply-actions": {"action": [{"output-action": {'
'"output-node-connector": "3"},"order": "0"}]}}]},'
'"priority": "102","cookie": "6","table_id": "0"}]}'
headers = {'Content-type': 'application/json'}
num=0
while num < 4 :
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=mh1h4body1, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=mh1h3body1, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=mh1h2body1, method='PUT',headers=headers) time.sleep(0.1) response, content = http.request(uri='http://127.0.01:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=h1h4body1, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.01:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/5', body=mh1h4body2, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.01:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=h1h3body1, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.01:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/5', body=mh1h3body2, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.01:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=h1h2body1, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.01:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/5', body=mh1h2body2, method='PUT',headers=headers) time.sleep(0.1) response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/5', body=h1h4body2, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/6', body=mh1h4body3, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/5', body=h1h3body2, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/6', body=mh1h3body3, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/5', body=h1h2body2, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/6', body=mh1h2body3, method='PUT',headers=headers) time.sleep(0.1) response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/6', body=h1h4body3, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/6', body=h1h3body3, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/6', body=h1h2body3, method='PUT',headers=headers) print(content.decode()) odl = OdlUtil('127.0.0.1', '8181')
odl.install_flow()

代码思路

拓扑结构

代码分析

因为对该拓扑结构,只需要在s1处进行负载均衡,s2、s3、s4到任何目的主机或交换机的链路都是唯一的,所以不需要考虑负载均衡。

我们原本打算尝试更复杂一些的可以实现在节点上进行阻塞判断的负载均衡,但因为ODL方面编程的资料我们能找到的不是很充足,而且关于北向接口可以参考的实例程序几乎没有,再加之Python入门水平实在十分有限,因此也一度决定改用Ryu尝试开发,因为我们找到了北邮李呈所写的一个简单的负载均衡,可以进行参考。然而最终也是因为许多接口的用法、代码不能理解而无法成功开发。因为时间有限,又在期末时期学业十分紧张,我们最终选择了在群内学长分析的简单的以Python连接ODL然后下发流表的方式,实现一个简单的分时机制进行负载均衡。具体方法是为每一条链路分配相等时长的时间片,这里设置为0.1s。具体算法的原理是:首先将端口2出发的链路优先级设为最高(102),每一次分配时间片时,将下一条链路的优先级设为最高(102),上一次最高优先级的链路设为最低(当前最低值-1),反复循环,即可实现在2,3,4链路上按分时机制进行负载均衡。

应用到我们选用的具体拓扑上,就是:

2端口,优先级102(最高)
0.1s后
3端口,优先级102
2端口,优先级101(102-1)
0.1s后
4端口,优先级102
3端口,优先级100(101-1)
0.1s后
4端口,优先级99(100-1)


演示视频

SDN负载均衡演示


SDN负载均衡的更多相关文章

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

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

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

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

  3. 基于SDN网络的负载均衡研究与实现

    为什么需要软件定义网络 1.网络缺乏可扩展性,创新正在停滞不前.   我们最新的研究发现,几乎每两个组织中就有一个认为需要将网络功能扩展为采用SDN的主要业务触发因素,而不是其他催化剂.这一统计数据一 ...

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

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

  5. SDN第五次上机作业--基于组表的简单负载均衡

    0.作业链接 http://www.cnblogs.com/easteast/p/8125383.html 1.实验目的 1.搭建如下拓扑并连接控制器 2.下发相关流表和组表实现负载均衡 3.抓包分析 ...

  6. 高性能Linux服务器 第11章 构建高可用的LVS负载均衡集群

    高性能Linux服务器 第11章 构建高可用的LVS负载均衡集群 libnet软件包<-依赖-heartbeat(包含ldirectord插件(需要perl-MailTools的rpm包)) l ...

  7. centos LB负载均衡集群 三种模式区别 LVS/NAT 配置 LVS/DR 配置 LVS/DR + keepalived配置 nginx ip_hash 实现长连接 LVS是四层LB 注意down掉网卡的方法 nginx效率没有LVS高 ipvsadm命令集 测试LVS方法 第三十三节课

    centos   LB负载均衡集群 三种模式区别 LVS/NAT 配置  LVS/DR 配置  LVS/DR + keepalived配置  nginx ip_hash 实现长连接  LVS是四层LB ...

  8. 【大型网站技术实践】初级篇:借助LVS+Keepalived实现负载均衡

    一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务器集群技术,集群即将相同服务部署在多台服务器上构成一个集群整体对外提供服务,这些集群可以是Web应用服务 ...

  9. Windows平台分布式架构实践 - 负载均衡

    概述 最近.NET的世界开始闹腾了,微软官方终于加入到了对.NET跨平台的支持,并且在不久的将来,我们在VS里面写的代码可能就可以通过Mono直接在Linux和Mac上运行.那么大家(开发者和企业)为 ...

随机推荐

  1. laravel 单词

    return view('admin.user.login'); 返回 admin文件夹下, user文件夹中 login文件模板 setcookie 语法 setcookie(name,value, ...

  2. Android - 注解

    原理: http://www.cnblogs.com/Fndroid/p/5354644.html http://www.jianshu.com/p/28edf5352b63 开源库: ButterK ...

  3. 一些减少代码量、提高开发效率的利器(Java)

    Spring Boot mybatis-plus代码生成器和自带CRUD接口 lombok 库: Apache Commons & guava AOP Java8: stream & ...

  4. 在pycharm中进行ORM操作

    打开manage.py, 复制 import..... if.......os.....  导入django,开启django, 导入app中的models  orm操作 import os if _ ...

  5. JavaScript--表单处理(27)

    一 表单介绍 // 在HTML中,表单是由<form>元素来表示的,而在JavaScript中,表单对应的则是HTMLFormElement类型; // HTMLFormElement继承 ...

  6. DOM(JavaScript高程笔记)

    一.节点层次 1.Node类型 if (someNode.nodeType == 1){ // 适用于所有浏览器 alert("Node is an element."); } N ...

  7. JavaScript中七种数据类型·中·一

    Standing on Shoulders of Giants; 说到JavaScript里的类型很容易就让人想起 42和"42",分别是string型和number型,但是他们可 ...

  8. CentOS7安装tomcat9

    1.去官网下载tomcat9的tar.gz安装包 2.移到centos7中并解压 解压命令: tar -xzvf tomcat9.tar.gz 3.打开文件 /etc 目录下的 profile 文件: ...

  9. Js获取地址栏参数值

    function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...

  10. vue Element-UI 分页使用(1)

    最近在使用Element-UI这套框架配合Vue来写前端页面.在用Element-UI来制作表格的时候,遇到了一些小问题,记录方便学习. 其中两个事件是关于切换当前页和切换显示的列表条数的.另外的属性 ...