博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
期末作业验收
阅读量:4887 次
发布时间:2019-06-11

本文共 8883 字,大约阅读时间需要 29 分钟。

·期末作业验收

期末作业

负载均衡程序

小组分工

小组:incredible five

构建拓扑:俞鋆

编写程序:陈绍纬、周龙荣

程序调试和视频录制:陈辉、林德望

程序思路

初步搭建场景二拓扑

from mininet.topo import Topoclass MyTopo( Topo ):    def __init__( self ):        # Initialize topology        Topo.__init__( self )        # Add hosts and switches        h1 = self.addHost( 'h1' )        h2 = self.addHost( 'h2' )        h3 = self.addHost( 'h3' )        h4 = self.addHost( 'h4' )        s1 = self.addSwitch( 's1' )        s2 = self.addSwitch( 's2' )        s3 = self.addSwitch( 's3' )        s4 = self.addSwitch( 's4' )        # Add links        self.addLink( s1, h1, 1, 0 )        self.addLink( s1, s2, 2, 1 )        self.addLink( s1, s3, 3, 1 )        self.addLink( s1, s4, 4, 1 )        self.addLink( s2, s4, 2, 2 )        self.addLink( s3, s4, 2, 3 )        self.addLink( s4, h2, 4, 0 )        self.addLink( s4, h3, 5, 0 )        self.addLink( s4, h4, 6, 0 )topos = { 'mytopo': ( lambda: MyTopo() ) }

场景二默认包从s1-s4路径发送,所以先给s2、s3下发流表,使之通行。

我们小组没有去底层交换机收集信息,再对数据处理得到动态负载均衡(没掌握好这块内容),最后小组讨论,将s1-s4、s1-s2-s4、s1-s3-s4三条线路默认1:2:2的关系,以经历的线路为基准进行负载均衡。

对s4下发流表,使用hardtime机制,让3条线路在一段时间内的占比为2:1:1以达到负载均衡。

#!/usr/bin/python# -*- coding:UTF-8 -*-import httplib2import timeclass OdlUtil:    http = httplib2.Http()      url = ''    def __init__(self, host, port):        self.url = 'http://' + host + ':' + port    def install_flow(self, container_name='default',username="admin", password="admin"):        self.http.add_credentials(username, password)        flow_name = 'flow_' + str(int(time.time()*1000))         h2_s4_s2_1 = '''            {"flow-node-inventory:flow": [            {"id": "1","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":4,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "2"}}]}}]},            "priority": 1000,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "4",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h2_s4_s1_1 = '''            {"flow-node-inventory:flow": [            {"id": "0","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":2,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "1"}}]}}]},            "priority": 1005,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "4",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''               h2_s4_s3_1 = '''            {"flow-node-inventory:flow": [            {"id": "2","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":3,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "3"}}]}}]},            "priority": 1002,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "4",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h3_s4_s2_1='''            {"flow-node-inventory:flow": [            {"id": "4","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":4,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "2"}}]}}]},            "priority": 1000,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "5",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h3_s4_s1_1 = '''            {"flow-node-inventory:flow": [            {"id": "3","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":2,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "1"}}]}}]},            "priority": 1005,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "5",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h3_s4_s3_1 = '''          {"flow-node-inventory:flow": [            {"id": "5","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":3,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "3"}}]}}]},            "priority": 1002,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "5",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h4_s4_s2_1 = '''          {"flow-node-inventory:flow": [            {"id": "7","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":4,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "2"}}]}}]},            "priority": 1000,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "6",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h4_s4_s1_1 = '''          {"flow-node-inventory:flow": [            {"id": "6","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":2,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "1"}}]}}]},            "priority": 1005,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "6",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''        h4_s4_s3_1 = '''          {"flow-node-inventory:flow": [            {"id": "8","flow-name": "s4_s2_1","cookie": 256,            "hard-timeout":3,"instructions": {            "instruction": [{"order": 0,"apply-actions": {            "action": [{"order": 0,"output-action": {            "output-node-connector": "3"}}]}}]},            "priority": 1002,"table_id": 0,"match": {            "ipv4-destination": "10.0.0.1/32","in-port": "6",            "ethernet-match": {"ethernet-type": {"type": 2048}}}}]}         '''                headers = {'Content-type': 'application/json'}        num=0        while num < 4 :            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/0', body=h2_s4_s1_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/1', body=h2_s4_s2_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/2', body=h2_s4_s3_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/3', body=h3_s4_s1_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/4', body=h3_s4_s2_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/5', body=h3_s4_s3_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/6', body=h4_s4_s1_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/7', body=h4_s4_s2_1, method='PUT',headers=headers)            response, content = self.http.request(uri='http://192.168.81.133:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/8', body=h4_s4_s3_1, method='PUT',headers=headers)            print("success")            time.sleep(4)            print(content.decode())if __name__=='__main__':        odl = OdlUtil('192.168.81.133', '8181')    odl.install_flow()

课程总结

  • SDN只有半学期,但我感觉学到的内容是非常多的。

    理论+上机,不仅是课还有作业,这样的形式让我对一些知识掌握程度很高。

  • 软件定义网络,让我了解到了以后网络的发展前景,它会如何发展,为什么会往这个方向发展。而在SDN中最重要的就是控制器。我也随之了解 odl floodlight ryu这些控制器。
  • mininet的使用,如何可视化建立拓扑以及用py语言建立拓扑,一些常规mininet命令的使用。
  • odl查看拓扑,下发流表、组表。结合python脚本对odl下发流表。
  • 抓包,不过是很表面的了解
  • 再一次熟练了ubuntu系统的使用。
  • 负载均衡的原理,如何去实现!!!

转载于:https://www.cnblogs.com/chenshaowei/p/8350293.html

你可能感兴趣的文章
jsp的C标签一般使用方法以及js接收servlet中的对象及对象数字
查看>>
window.frameElement的使用
查看>>
如何使用jQuery $.post() 方法实现前后台数据传递
查看>>
Using Flash Builder with Flash Professional
查看>>
jsp/post中文乱码问题
查看>>
C# 插入或删除word分页符
查看>>
数据库数据的查询----连接查询
查看>>
找不到可安装的ISAM ,asp.net读取数据丢失,解决的一列里有字符与数字的
查看>>
Java学习笔记三(对象的基本思想一)
查看>>
Java程序(文件操作)
查看>>
KMP算法 最小循环节 最大重复次数
查看>>
Proving Equivalences (强连通,缩点)
查看>>
Period (KMP算法 最小循环节 最大重复次数)
查看>>
sgu 103. Traffic Lights
查看>>
poj 3621 Sightseeing Cows
查看>>
hdu 3666 THE MATRIX PROBLEM
查看>>
TopCoder SRM 176 Deranged
查看>>
Javascript中数组与字典(即map)的使用
查看>>
memcached(十三)注意事项
查看>>
ITerms2在mac系统下的安装和配色,并和go2shell关联
查看>>