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

    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()

    代码大概思路:
    服务器h2 ,h3,h4,h1是客户端,当h2,h1,h3向h1传输数据时,根据链路的使用状况动态的调整路由规则。

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

    四、课程总结
    1.了解什么是SDN:SDN 是一种集中控制的新网络架构,支持动态弹性管理,其将数据平面和控制平面解耦分离,抽象了数据平面网络资源,并支持通过统一的开放接口对网络直接进行编程控制。一般来说, SDN 网络体系结构主要包括 SDN 网络应用、北向接口、 SDN 控制器、南向接口和 SDN 数据平面共五部分。
    2.学习使用mininet
    3.利用可视化界面、字符串命令及简单Python脚本创建拓扑
    4.了解了几种SDN控制器,并初步学习使用 Floodlight 控制器和 OpenDayLight 控制器
    5.Wiresharke抓包
    6.使用ODL下发流表、组表
    7.初步学习了解P4语言

  • 相关阅读:
    js高级1
    JUC总览
    7 种阻塞队列相关整理
    Exchanger 相关整理
    Semaphore 相关整理
    ConcurrentLinkedQueue 相关整理
    ConcurrentHashMap(1.8) 相关整理
    ConcurrentHashMap(1.7) 相关整理
    ReentrantReadWriteLock 相关整理
    LockSupport 工具相关整理
  • 原文地址:https://www.cnblogs.com/bokers/p/8343502.html
Copyright © 2011-2022 走看看