SDN负载均衡
我负责的工作:
(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期末作业-通过SDN的应用实现负载均衡
负载均衡程序 1.程序链接:https://github.com/424baopu/software/tree/master/LoadBalance 2.场景 topo: 场景描述: 服务器host ...
- SDN期末作业——负载均衡
作业链接 期末作业 1.负载均衡程序 代码 2.演示视频 地址 3.小组分工 小组:incredible five 构建拓扑:俞鋆 编写程序:陈绍纬.周龙荣 程序调试和视频录制:陈辉.林德望 4.个人 ...
- 基于SDN网络的负载均衡研究与实现
为什么需要软件定义网络 1.网络缺乏可扩展性,创新正在停滞不前. 我们最新的研究发现,几乎每两个组织中就有一个认为需要将网络功能扩展为采用SDN的主要业务触发因素,而不是其他催化剂.这一统计数据一 ...
- 《SDN期末作业——实现负载均衡》
队名:取个队名真难 一.网络拓扑(场景二) 二.负载均衡程序 1.建立拓扑的代码 拓扑 2.下发组表流表的代码 下发组表流表 三.演示视频 1.目的 服务器h2,h3,h4上各自有不同的服务,h1是客 ...
- SDN第五次上机作业--基于组表的简单负载均衡
0.作业链接 http://www.cnblogs.com/easteast/p/8125383.html 1.实验目的 1.搭建如下拓扑并连接控制器 2.下发相关流表和组表实现负载均衡 3.抓包分析 ...
- 高性能Linux服务器 第11章 构建高可用的LVS负载均衡集群
高性能Linux服务器 第11章 构建高可用的LVS负载均衡集群 libnet软件包<-依赖-heartbeat(包含ldirectord插件(需要perl-MailTools的rpm包)) l ...
- 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 ...
- 【大型网站技术实践】初级篇:借助LVS+Keepalived实现负载均衡
一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务器集群技术,集群即将相同服务部署在多台服务器上构成一个集群整体对外提供服务,这些集群可以是Web应用服务 ...
- Windows平台分布式架构实践 - 负载均衡
概述 最近.NET的世界开始闹腾了,微软官方终于加入到了对.NET跨平台的支持,并且在不久的将来,我们在VS里面写的代码可能就可以通过Mono直接在Linux和Mac上运行.那么大家(开发者和企业)为 ...
随机推荐
- Apriori算法进行关联分析
设全集U = {a, b, c, d, e},其元素a,b, c, d, e称为项. 数据集: D = [ {a, b}, {b, c, d}, {d, e}, {b, c, e}, {a,b, c, ...
- flex弹性布局学习总结
本文首次发布在我的个人博客:Claiyre的个人博客 https://claiyre.github.io/ 博客园地址:http://www.cnblogs.com/nuannuan7362/如需转载 ...
- [转]小程序web-view组件
本文转自:https://www.cnblogs.com/-nothing-/p/7910355.html 1,web-view这个组件是什么鬼? 官网的介绍:web-view 组件是一个可以用来承载 ...
- JS DOM操作(一) 对页面的操作
DOM ——文档对象模型(Document Object Model)是表示和处理一个HTML或XML文档的常用方法. 在网页上,组织页面(或文档)的对象被组织在一个树形结构中,用来表示文档中对象的标 ...
- echarts展示箱型图&正态分布曲线
效果图: 直接上代码吧: <!DOCTYPE HTML> <html> <head> <style type="text/css"> ...
- vscode 自动提示Threejs
转自:https://blog.csdn.net/github_39125824/article/details/82633993 1.首先,你要安装Node.js 2.在vscode的 查看-> ...
- [PHP] 看博客学习插入排序
定义数组长度变量$len,使用count()函数,参数:数组 for循环数组,条件:从第二个开始,遍历数组,循环内 定义临时变量$temp,赋值当前元素 for循环数组,条件:遍历当前元素前面的所有元 ...
- Factorial Problem in Base K(zoj3621)
Factorial Problem in Base K Time Limit: 2 Seconds Memory Limit: 65536 KB How many zeros are there in ...
- Velocity快速入门
Velocity 介绍 Velocity是一个基于java的模板引擎.它允许任何人使用简单但功能强大的模板语言引用Java代码中定义的对象. 当Velocity用于web开发时,web设计人员可以与J ...
- python 约束,异常处理与MD5加密
1. 类的约束 1. 写一个父类. 父类中的某个方法要抛出一个异常 NotImplementedError (重点) 2. 抽象类和抽象方法 # 语法 # from abc import ABCMet ...