sayoko

导航

2019 SDN大作业

简单的负载均衡

1.分组情况

组名:蓝蓝的大白牙

学号 姓名 贡献度
031702507 黄皓 13%
031702508 石晓楠 24%
031702511 古力亚尔 13%
031702525 周鑫煌 20%
031702532 陈聪(组长) 30%

2.作业内容

Github仓库

视频链接

3.实现关键

以如下拓扑为基础

img

搭建拓扑的代码如下:

from mininet.topo import Topo

class MyTopo( Topo ):

    def __init__( self ):
    
        # initilaize topology   
        Topo.__init__( self )
    
        # add hosts and switches
        host1 = self.addHost( 'h1' )
        host2 = self.addHost( 'h2' )
    host3 = self.addHost( 'h3' )
        switch1 = self.addSwitch( 's1' )
        switch2 = self.addSwitch( 's2' )
        switch3 = self.addSwitch( 's3' )


        # add links
        self.addLink(host1,switch1)
        self.addLink(switch1,switch2)
        self.addLink(switch1,switch3)
        self.addLink(switch2,switch3)
        self.addLink(switch2,host2)
        self.addLink(switch2,host3)


topos = { 'mytopo': ( lambda: MyTopo() ) }

针对s2这个交换机来看,初始情况下来自h2和h3的数据包都往是s2的1端口通过,欲实现在s2端口1满载时来自h3的数据包改为往s2-eth2通过。

端口的满载状态通过该端口的数据率得以判断。

#获取s2端口1的流量 
uri = 'http://127.0.0.1:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:2/node-connector/openflow:2:1'

response, content = http.request(uri=uri, method='GET')

content = json.loads(content)

statistics = content['node-connector'][0]['opendaylight-port-statistics:flow-capable-node-connector-statistics']

bytes1 = statistics['bytes']['transmitted']
#间隔1s后获取bytes2
speed=float(bytes2-bytes1)/1

下发的流表项代码:

	#s2流表
	#在检测h2发包的时候s2的1口流量空闲时发的流表
	h2_to_s2_1 ='{"flow": [{"id": "0","match": {"ethernet-match":'\
           		'{"ethernet-type": {"type": "2048"}},'\
				'"ipv4-source":"10.0.0.2/32","ipv4-destination": "10.0.0.1/32"},'\
        		'"instructions": {"instruction": [{"order": "0",'\
        		'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        		'"priority": "101","cookie": "1","table_id": "0"}]}'
	#在检测h3发包的时候s2的1口流量空闲时发的流表
	h3_to_s2_1 ='{"flow": [{"id": "1","match": {"ethernet-match":'\
           		'{"ethernet-type": {"type": "2048"}},'\
				'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        		'"instructions": {"instruction": [{"order": "0",'\
            	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        		'"priority": "101","cookie": "1","table_id": "0"}]}'
	h3_to_s2_1_full ='{"flow": [{"id": "1","match": {"ethernet-match":'\
            		'{"ethernet-type": {"type": "2048"}},'\
	 			'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
         		'"instructions": {"instruction": [{"order": "0",'\
            	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "1"},"order": "0"}]}}]},'\
         		'"priority": "100","cookie": "1","table_id": "0"}]}'
	#在检测h3发包的时候s2的1口流量满载时发的流表	
	h3_to_s2_2 ='{"flow": [{"id": "2","match": {"ethernet-match":'\
           		'{"ethernet-type": {"type": "2048"}},'\
				'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        		'"instructions": {"instruction": [{"order": "0",'\
            	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "2"},"order": "0"}]}}]},'\
        		'"priority": "101","cookie": "1","table_id": "0"}]}'
	h3_to_s2_2_full ='{"flow": [{"id": "2","match": {"ethernet-match":'\
            		'{"ethernet-type": {"type": "2048"}},'\
	 			'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
         		'"instructions": {"instruction": [{"order": "0",'\
             	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "2"},"order": "0"}]}}]},'\
        		'"priority": "100","cookie": "1","table_id": "0"}]}'
	#s3流表
	s3_1='{"flow": [{"id": "0","match": {"ethernet-match":'\
        '{"ethernet-type": {"type": "2048"}},'\
		'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        '"instructions": {"instruction": [{"order": "0",'\
        '"apply-actions": {"action": [{"output-action": {'\
        '"output-node-connector": "1"},"order": "0"}]}}]},'\
        '"priority": "101","cookie": "1","table_id": "0"}]}'
	#s1流表
	s1_h2_To_h1='{"flow": [{"id": "0","match": {"ethernet-match":'\
        	'{"ethernet-type": {"type": "2048"}},'\
			'"ipv4-source":"10.0.0.2/32","ipv4-destination": "10.0.0.1/32"},'\
        	'"instructions": {"instruction": [{"order": "0",'\
        	'"apply-actions": {"action": [{"output-action": {'\
        	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        	'"priority": "101","cookie": "1","table_id": "0"}]}'
	s1_h3_To_h1='{"flow": [{"id": "1","match": {"ethernet-match":'\
        	'{"ethernet-type": {"type": "2048"}},'\
			'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        	'"instructions": {"instruction": [{"order": "0",'\
        	'"apply-actions": {"action": [{"output-action": {'\
        	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        	'"priority": "101","cookie": "1","table_id": "0"}]}'
	headers = {'Content-type': 'application/json'}

操作步骤:

  1. 在创建拓扑前,先打开opendaylight控制器
  2. 创建拓扑,并查看拓扑结构
  3. 测试主机之间的连通
  4. wireshark抓包监控流量
  5. 调用负载均衡程序controller.py,使用sudo python controller.py命令执行
  6. 查看交换机s2流表项

此时s2-eth1通畅,h3数据包从1端口出的优先级高
img

此时s2-eth1满载,h3数据包从2端口出的优先级高
img

4.心得体会

黄皓:SDN这门课本就是创新课,很多知识都很新,有很高的实用性和很强的实践性。老师上课的时候也觉得很有意思,结合上课时的知识再加上实验课马上动手操作实践,对于这门课了解的也更加深刻,还知道了P4语言,边缘计算,SVN,ryu控制器,opendaylight控制器,postman的使用,Wireshark的抓包等。在小组汇报中选择了SDN+机器学习的课题,虽然在最后的大作业中没有选择这个题目,但是还是对机器学习和SDN二者的发展和结合有了浅层的了解。负载均衡构建在原有网络结构之上,它提供了一种透明且廉价有效的方法扩展服务器和网络设备的带宽、加强网络数据处理能力、增加吞吐量、提高网络的可用性和灵活性。负载均衡有许多种算法可以用在各种各样的场景下,本次大作业因为时间考试等关系,选择了比较简单的应用场景,但还是从中学习了很多,切实了解了负载均衡的思想。

陈聪:上学期刚把计算机网络学完,还在感叹创造者的智慧,这学期的SDN课就让我拓开了眼界。通过它较为短暂的发展史我也逐步了解的SDN究竟为何物,是否以某个不为人知的事物影响并服务着我们的生活。这门课程学习中的几个实验也着实让我找寻到了乐趣,即使有些时候因学习资料的匮乏和不确定性而心烦意乱(无能狂怒)。由此看来,还得好好培养艰苦奋斗的精神。
今后我也会深入学习网络方面的知识,从繁杂纷乱中找到美好。

石晓楠:在本学期SDN的第一节课,老师问我们对SDN了解多少的时候,说实话我对SDN是真的一无所知,想着又是软件又是网络的,应该很难吧。随着课程的深入,我掌握了越来越多的东西,了解了mininet的使用方法,建拓扑啊之类的,还学会了下发流表,RYU控制器的一些基础的使用方法。老师发布的“阅读作业”也让我了解了一些SDN的知识。平时的作业有时候做的并不是特别好,但还是有所收获。课程虽然短暂,但也算学习了一些新的知识。期末做的有关机器学习和SDN联系的汇报,也让我对这方面内容有了更深的了解和理解。最后的大作业,让我对这门课的理解也更深入了一些,是有关负载均衡的内容,我们的组长带领着我们完成了这个实验,可算是收获了很多,希望以后还有机会能够深入的了解,接触SDN。

posted on 2020-01-06 21:05  sayoko  阅读(438)  评论(0编辑  收藏  举报