Floodlight Mininet自定义拓扑及流表

实验拓扑:


目的:(1)自定义构建以上拓扑

   (2)实现h1,h2能通信,h3,h4不能通信,h1,h2与h3,h4之间能相互通信


基本操作这里就不仔细介绍了,可以参考之前的两篇文。

1.构建拓扑,用Python实现以上自定义拓扑

代码:

[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. from mininet.topo import Topo, Node  
  2.   
  3. class MyTopo( Topo ):  
  4.     "Simple topology example."  
  5.   
  6.     def __init__( self, enable_all = True ):  
  7.         "Create custom topo."  
  8.   
  9.         # Add default members to class.  
  10.         super( MyTopo, self ).__init__()  
  11.   
  12.         # Set Node IDs for hosts and switches  
  13.         leftHost1 = 1  
  14.         leftHost2 = 2  
  15.         leftSwitch = 3  
  16.         rightSwitch = 4  
  17.         rightHost1 = 5  
  18.         rightHost2 = 6  
  19.   
  20.         # Add nodes  
  21.           
  22.         self.add_node( leftSwitch, Node( is_switch=True ) )  
  23.         self.add_node( rightSwitch, Node( is_switch=True ) )  
  24.         self.add_node( leftHost1, Node( is_switch=False ) )  
  25.         self.add_node( leftHost2, Node( is_switch=False ) )  
  26.         self.add_node( rightHost1, Node( is_switch=False ) )  
  27.         self.add_node( rightHost2, Node( is_switch=False ) )  
  28.   
  29.         # Add edges  
  30.         self.add_edge( leftHost1, leftSwitch )  
  31.         self.add_edge( leftHost2, leftSwitch )  
  32.         self.add_edge( leftSwitch, rightSwitch )  
  33.         self.add_edge( rightSwitch, rightHost1 )  
  34.         self.add_edge( rightSwitch, rightHost2 )  
  35.   
  36.         # Consider all switches and hosts 'on'  
  37.         self.enable_all()  
  38.   
  39.   
  40. topos = { 'mytopo': ( lambda: MyTopo() ) }  

2.在floodlight的web页面点击host如下图


可以看到链接交换机03的host端口号为1,2,那么可以推断04交换机链接到03交换机的3端口。同样链接交换机04的host端口号为2,3,那么可以推断03交换机链接到04交换机的1端口(写流表就是根据这些信息来的)。


3.此时使用pingall,得到相互ping不通,(在删除.property文件中的Forwarding则默认相互不通,参考上一篇文)如下图



4.写流表

python代码:

[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. import httplib  
  2. import json  
  3.   
  4. class StaticFlowPusher(object):  
  5.   
  6.     def __init__(self, server):  
  7.         self.server = server  
  8.   
  9.     def get(self, data):  
  10.         ret = self.rest_call({}, 'GET')  
  11.         return json.loads(ret[2])  
  12.   
  13.     def set(self, data):  
  14.         ret = self.rest_call(data, 'POST')  
  15.         return ret[0] == 200  
  16.   
  17.     def remove(self, objtype, data):  
  18.         ret = self.rest_call(data, 'DELETE')  
  19.         return ret[0] == 200  
  20.   
  21.     def rest_call(self, data, action):  
  22.         path = '/wm/staticflowentrypusher/json'  
  23.         headers = {  
  24.             'Content-type''application/json',  
  25.             'Accept''application/json',  
  26.             }  
  27.         body = json.dumps(data)  
  28.         conn = httplib.HTTPConnection(self.server, 8080)  
  29.         conn.request(action, path, body, headers)  
  30.         response = conn.getresponse()  
  31.         ret = (response.status, response.reason, response.read())  
  32.         print ret  
  33.         conn.close()  
  34.         return ret  
  35.   
  36. pusher = StaticFlowPusher('192.168.131.129')  
  37.   
  38. flow1 = {  
  39.     'switch':"00:00:00:00:00:00:00:03",  
  40.     "name":"flow-mod-1",  
  41.     "cookie":"0",  
  42.     "priority":"32768",  
  43.     "ingress-port":"1",  
  44.     "active":"true",  
  45.     "actions":"output=flood"  
  46.     }  
  47.       
  48. flow2 = {  
  49.     'switch':"00:00:00:00:00:00:00:03",  
  50.     "name":"flow-mod-2",  
  51.     "cookie":"0",  
  52.     "priority":"32768",  
  53.     "ingress-port":"2",  
  54.     "active":"true",  
  55.     "actions":"output=flood"  
  56.     }  
  57.   
  58. flow3 = {  
  59.     'switch':"00:00:00:00:00:00:00:03",  
  60.     "name":"flow-mod-3",  
  61.     "cookie":"0",  
  62.     "priority":"32768",  
  63.     "ingress-port":"3",  
  64.     "active":"true",  
  65.     "actions":"output=flood"  
  66.     }  
  67.   
  68. flow4 = {  
  69.     'switch':"00:00:00:00:00:00:00:04",  
  70.     "name":"flow-mod-4",  
  71.     "cookie":"0",  
  72.     "priority":"32768",  
  73.     "ingress-port":"2",  
  74.     "active":"true",  
  75.     "actions":"output=1"  
  76.     }  
  77.       
  78. flow5 = {  
  79.     'switch':"00:00:00:00:00:00:00:04",  
  80.     "name":"flow-mod-5",  
  81.     "cookie":"0",  
  82.     "priority":"32768",  
  83.     "ingress-port":"3",  
  84.     "active":"true",  
  85.     "actions":"output=1"  
  86.     }  
  87.   
  88. flow6 = {  
  89.     'switch':"00:00:00:00:00:00:00:04",  
  90.     "name":"flow-mod-6",  
  91.     "cookie":"0",  
  92.     "priority":"32768",  
  93.     "ingress-port":"1",  
  94.     "active":"true",  
  95.     "actions":"output=flood"  
  96.     }  
  97. pusher.set(flow1)  
  98. pusher.set(flow2)  
  99. pusher.set(flow3)  
  100. pusher.set(flow4)  
  101. pusher.set(flow5)  
  102. pusher.set(flow6)  


如下图达到实验目的:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值