zoukankan      html  css  js  c++  java
  • SDN期末作业

    一、项目描述

    负载均衡程序

    二、个人分工

    小组成员:李文博,冉思银,侯振源,李熙,汪志彬

    三、代码演示及过程描述

    拓扑代码:

    from mininet.topo import Topo

    class MyTopo( Topo ):
    "Simple topology example."

    def init( self ):

    # Initialize topology
    Topo.__init__( self )
    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')
    
    self.addLink(h1,s1)
    self.addLink(s1,s2)
    self.addLink(s1,s3)
    self.addLink(s1,s4)
    self.addLink(s2,s4)
    self.addLink(s3,s4)
    self.addLink(s4,h2)
    self.addLink(s4,h3)
    self.addLink(s4,h4)
    

    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))
    s1zbody='{"group": [{ "group-type": "group-select","group-id": "1","group-name": "loadbalance","buckets": {"bucket": [{"bucket-id": "1","weight": "3","action": [{"order": "0","output-action": {"output-node-connector": "4"}}]},{"bucket-id": "2","weight": "2","action": [{"order": "0","output-action": {"output-node-connector": "2"}}]},{"bucket-id": "3","weight": "2","action": [{"order": "0","output-action": {"output-node-connector": "3"}}]}]}}]}'
    s1lbody='{"flow": [{"id": "1","match": {"in-port": "1"},"instructions": {"instruction": [{"order": "0","apply-actions": {"action": [{"order": "0","group-action": {"group-id": "1"}}]}}]},"flow-name": "s1","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s2lbody='{"flow": [{"id": "1","match": {"in-port": "1"},"instructions": {"instruction": [{"order": "0","apply-actions": {"action": [{"order": "0","output-action": {"output-node-connector": "2"}}]}}]},"flow-name": "s2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s3lbody='{"flow": [{"id": "1","match": {"in-port": "1"},"instructions": {"instruction": [{"order": "0","apply-actions": {"action": [{"order": "0","output-action": {"output-node-connector": "2"}}]}}]},"flow-name": "s3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody='{"flow": [{"id": "1","match": {"in-port": "2","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.2/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "4"}}]}}]},"flow-name": "s4:s2toh2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody2='{"flow": [{"id": "2","match": {"in-port": "2","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.3/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "5"}}]}}]},"flow-name": "s4:s2toh3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody3='{"flow": [{"id": "3","match": {"in-port": "2","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.4/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "6"}}]}}]},"flow-name": "s4:s2toh4","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody4='{"flow": [{"id": "4","match": {"in-port": "1","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.2/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "4"}}]}}]},"flow-name": "s4:s1toh2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody5='{"flow": [{"id": "5","match": {"in-port": "1","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.3/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "5"}}]}}]},"flow-name": "s4:s1toh3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody6='{"flow": [{"id": "6","match": {"in-port": "1","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.4/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "6"}}]}}]},"flow-name": "s4:s1toh4","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody7='{"flow": [{"id": "7","match": {"in-port": "3","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.2/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "4"}}]}}]},"flow-name": "s4:s3toh2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody8='{"flow": [{"id": "8","match": {"in-port": "3","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.3/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "5"}}]}}]},"flow-name": "s4:s3toh3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    s4lbody9='{"flow": [{"id": "9","match": {"in-port": "3","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.4/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "6"}}]}}]},"flow-name": "s4:s3toh4","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
    headers = {'Content-type': 'application/json'}
    num=0
    while num < 1 :
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:group/1', body=s1zbody, 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=s1lbody, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/1', body=s2lbody, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:3/flow-node-inventory:table/0/flow/1', body=s3lbody, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/1', body=s4lbody, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/2', body=s4lbody2, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/3', body=s4lbody3, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/4', body=s4lbody4, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/5', body=s4lbody5, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/6', body=s4lbody6, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/7', body=s4lbody7, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/8', body=s4lbody8, method='PUT',headers=headers)
    response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/9', body=s4lbody9, method='PUT',headers=headers)
    num=num + 1
    print(content.decode())
    odl = OdlUtil('127.0.0.1', '8181')
    odl.install_flow()

    大概思路:

    拓扑图左侧三台主机作为服务端,右侧为客户端,最初思路很简单是下发流表根据不同服务机送来的数据设置不同的优先级,使得一个服务机有一个专门的传输通路互不干扰达成负载均衡,但是后来发现这只是对应三台服务机一起工作的情况,如果只有一台服务机工作,明明有三条通路然而只使用一条通路进行传输没有实现负载均衡。重新思考后决定左侧三台的主机都先使用一条通路向客户端传输数据,然后检测传输通路使用情况如果发现三条通路负载不均衡再根据不同的流表将数据分路传输。但是实际做的时候碍于能力,如何检测通路使用情况的方法没有做好,还有下发的流表觉得不对,实验没有成功,截止日期将近没有办法写上没有完成的期末作业报告上交。

    视频:
    由于实验失败无视频

    四、课程总结

    SDN是一门新型的网络管理模式,通过上软件定义网络这门课使我对SDN有了初步的认识,虽然听上去用代码控制网络运行情况就觉得好像跟写实现一些小要求的代码一样容易,但是上机实验的时候才知道用软件代码实现网络控制并不容易,使用现有的SDN工具就觉得很不顺手,如果要深入学习还要多花时间和精力了解SDN,以及学习一些相关编程语言和计算机知识。当然自己的学习态度也是一个问题,当中期课程任务一多做一些环境准备有些麻烦就有些不怎么认真,作业也做得并不好。即使课程结束,为了了解更多计算机行业的新兴概念和知识,学习也不能懈怠,应继续努力学习。

    附:SDN上机第二次作业和第三次作业博客内容已变动,补做了一些题目,请老师查收。

    第二次上机作业:http://www.cnblogs.com/sheogorath/p/8360956.html

    第三次上机作业:http://www.cnblogs.com/sheogorath/p/8053080.html

  • 相关阅读:
    JDBC 实例--JDBC通过工具类DBUtil连接到数据库,让我们不再恐惧操作数据库
    揭开JDBC的神秘面纱,让JDBC数据库的连接参数不再神秘
    实验六 最小代价生成树
    实验五 背包问题和带时限的作业排序
    实验四 图的遍历算法设计与实现
    实验三 跳表算法设计与实现
    实验二 伸展树算法设计与实现
    算法实例一 算法问题求解基础--欧几里得递归算法和递归算法
    2013年 蓝桥杯预赛 java 本科A 题目
    java常用开发工具类之 图片水印,文字水印,缩放,补白工具类
  • 原文地址:https://www.cnblogs.com/sheogorath/p/8361073.html
Copyright © 2011-2022 走看看