我负责的工作:

(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. VMware12 克隆虚拟机并且重新分配ip、mac

    记录如何快速拷贝一台虚拟机,并且重新分配IP.mac等方便自己做实验: 环境:VMWare12  .Redhat6.8 Step1.克隆虚拟机 虚拟机处于未打开状态,右击管理—>克隆 弹出克隆界 ...

  2. postgersql服务启动不了 FATAL: the database system is starting up

    公司装有postgersql的数据库的服务器意外宕机,重启后数据库启动不了了,系统是windows 软件版本10,在网上找了解决方案 参考这篇文章https://blog.csdn.net/baidu ...

  3. Netty 出站缓冲区 ChannelOutboundBuffer 源码解析(isWritable 属性的重要性)

    目录: 前言 ChannelOutboundBuffer 介绍 addMessage 方法 addFlush 方法 flush0 方法 缓冲区扩展思考 总结 每个 ChannelSocket 的 Un ...

  4. 深入出不来nodejs源码-timer模块(C++篇)

    终于可以填上坑了. 简单回顾一下之前JS篇内容,每一次setTimeout的调用,会在一个对象中添加一个键值对,键为延迟时间,值为一个链表,将所有该时间对应的事件串起来,图如下: 而每一个延迟键值对的 ...

  5. C# 字符串首字符大写

    我找到一些把字符串首字符大写的方法. 假如需要把字符串 "red" 转换为 "Red",把 "red house" 转为 "Red ...

  6. [日常] Go语言圣经-错误,函数值习题

    Go语言圣经-错误 1.panic异常.panic是来自被调函数的信号,表示发生了某个已知的bug 2.任何进行I/O操作的函数都会面临出现错误的可能 3.错误是软件包API和应用程序用户界面的一个重 ...

  7. Java基础——Servlet(六)分页相关

    前面写了Servlet(一)到(五),主要是在网上搜罗的视频.对分页这块还是不太清楚.于是有找到一些视频,重新学习了一下.主要是对分页的认识和设计思路.也是为了方便我以后回忆一下.. 一.分页常识 p ...

  8. Java基础——iO(一)

    此文为了解IO知识的基础篇,这块我看了几天,感觉和前段时间学习集合一样,零散又重要.想记录一下这块由浅入深的学习过程.所以,接下来会记录几篇学习笔记,之后会有以前深入总结.因为这块比较重要啊,所以一定 ...

  9. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  10. Swift学习笔记之闭包

    简介 (真的很简) 闭包的完整形态是这个样子的: { (parameters) -> returnType in statements } 写在一行里就是这样: {(parameters) -& ...