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

    ·期末作业验收

    期末作业

    负载均衡程序

    程序视频

    程序代码

    小组分工

    小组:incredible five

    构建拓扑:俞鋆

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

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

    程序思路

    初步搭建场景二拓扑

    from mininet.topo import Topo
    
    class 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下发流表,使之通行。

    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 httplib2
    import time
    
    class 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系统的使用。

    • 负载均衡的原理,如何去实现!!!

  • 相关阅读:
    借助NetFlow Analyzer的IPAM SPM插件,轻松实现IP和交换机端口管理
    补丁日微软修复了129个漏洞,学习补丁管理最佳实践
    如何通过组策略映射驱动器?
    如何预防磁盘使用率过高?
    ITIL是什么意思?
    Applications Manager—打造最佳云监控策略
    Microsoft 365独家安全解决方案
    怎么让Chrome支持小于12px 的文字?
    vue Router的使用
    vue项目中随机生成验证码
  • 原文地址:https://www.cnblogs.com/chenshaowei/p/8350293.html
Copyright © 2011-2022 走看看