SDN负载均衡

本文介绍了在SDN环境中使用Python实现负载均衡的思路和过程。作者从前期工作思路设计、代码修正到视频制作进行了详细阐述。负载均衡通过在交换机s1处分配相等时长的时间片给不同链路,实现分时机制,确保流量均匀分布。由于资料有限,最终选择了简单的Python连接ODL并下发流表的方法。
摘要由CSDN通过智能技术生成

我负责的工作:

(1)、前期工作思路设计及方案选定、讲解

(2)、后期代码修正

(3)、视频制作


负载均衡程序

程序流程图

1227195-20180125220232662-243862291.png

代码


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-mat
  • 2
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值