SDN 期末作业验收

课题:负载均衡

一、个人分工

我主要负责拥塞状况和负载均衡结果的查看,以及视频的录制。

拓扑图
1287640-20180125024022678-2030563374.png

查看s2,s3流表
1287640-20180127004028709-605945919.png

h1向h2发送数据
1287640-20180127003248006-373965218.png

查看s2,s3流表
1287640-20180127003714537-1242907628.png

h1向h2发送数据包,h1经s3转发,当s3流量达到极限值,h1部分数据经s2转发,从而实现负载均衡。

二、实现代码

1、建立拓扑
s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')
        s3 = self.addSwitch('s3')
        s4 = self.addSwitch('s4')

        h1 = self.addHost('h1')
        h2 = self.addHost('h2')
        h3 = self.addHost('h3')
        
        self.addLink(h1,s1)
        self.addLink(s1,s2)
        self.addLink(s1,s3)
        self.addLink(s2,s4)
        self.addLink(s3,s4)
        self.addLink(h2,s4)
        self.addLink(h3,s4)

topos = { 'mytopo': ( lambda: MyTopo() ) }
2、下发流表
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))
       h1h2body2 ='{"flow": [{"id": "3","match": {"ethernet-match":'\
                  '{"ethernet-type": {"type": "2048"}},'\
                  '"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'\
                  '"instructions": {"instruction": [{"order": "0",'\
                  '"apply-actions": {"action": [{"output-action": {'\
                  '"output-node-connector": "3"},"order": "0"}]}}]},'\
                  '"priority": "699","cookie": "3","table_id": "0"}]}'

       mh1h2body2 ='{"flow": [{"id": "3","match": {"ethernet-match":'\
                   '{"ethernet-type": {"type": "2048"}},'\
                   '"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'\
                   '"instructions": {"instruction": [{"order": "0",'\
                   '"apply-actions": {"action": [{"output-action": {'\
                   '"output-node-connector": "3"},"order": "0"}]}}]},'\
                   '"priority": "702","cookie": "3","table_id": "0"}]}'
       h1h2body3 ='{"flow": [{"id": "5","match": {"ethernet-match":'\
                  '{"ethernet-type": {"type": "2048"}},'\
                  '"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'\
                  '"instructions": {"instruction": [{"order": "0",'\
                  '"apply-actions": {"action": [{"output-action": {'\
                  '"output-node-connector": "2"},"order": "0"}]}}]},'\
                  '"priority": "700","cookie": "5","table_id": "0"}]}'

       mh1h2body3 ='{"flow": [{"id": "5","match": {"ethernet-match":'\
                   '{"ethernet-type": {"type": "2048"}},'\
                   '"ipv4-source":"10.0.0.1/32","ipv4-destination": "10.0.0.2/32"},'\
                   '"instructions": {"instruction": [{"order": "0",'\
                   '"apply-actions": {"action": [{"output-action": {'\
                   '"output-node-connector": "2"},"order": "0"}]}}]},'\
                   '"priority": "702","cookie": "5","table_id": "0"}]}'
       headers = {'Content-type': 'application/json'}
       num=0
       while num < 4 :
            
                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/5', body=h1h2body3, 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/3', body=mh1h2body2, method='PUT',headers=headers)
                
                time.sleep(0.1) 
            
                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/3', body=h1h2body2, 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/5', body=mh1h2body3, method='PUT',headers=headers)
        
                time.sleep(0.1) 
   
       print(content.decode())

odl = OdlUtil('127.0.0.1','8181')
odl.install_flow()

四、学习总结

首先,在这次课程学习中最大的收获是学会运用虚拟机的部分终端指令,Mininet,Floodlight,ODL,Wireshark等软件的基本用法和用途,以及负载均衡的原理及实现。
在一开始学习的过程中,对sdn课程的学习十分迷茫,上机课也总是跟不上进度,有时作业的完成也是跟着ppt依葫芦画瓢地照做。后来要求逐渐提高,许多都是以前面课程的一些学习为基础进行的。通过反复翻看以往的步骤和上网查阅相关资料后,渐渐对实验的内容有所理解和掌握,大体了解了每次上机的要求是什么。因此,在计算机的学习中,自学是非常重要的,且要多试多摸索。

转载于:https://www.cnblogs.com/Zhamao/p/8346548.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值