2017-07-19 63 views
0

我想添加流条目使用 基于RYU OFCTL REST的api(ryu.readthedocs.io/en/latest/app/ofctl_rest.html)用于将流添加到OVS开关ON mininet运行使用RYU REST API添加基于IP的流条目

RYU运行ofctl_restsimple_switch这两个应用程序

我使用一个开关3台主机一个简单的拓扑... H1 = 10.0.0.1

h2 = 10.0.0.2

H3 = 10.0.0.3

如何添加流条目阻止主机H1所有的报文。
我用JSON对象

data={ 
    "dpid": 1, 
    "cookie": 2802, 
    "priority": 3000, 
    "match":{ 
    "nw_src": "10.0.0.1", 
    }, 
    "actions": [ ] 
} 

但这流条目阻止所有坪从所有的机器...

可有人建议如何使用API​​

在OVS添加和IP地址过滤规则

回答

0

我想同样的事情,使用下面的命令:

curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 100, 
    "flags": 1, 
    "match":{ 
     "nw_src": "10.0.0.1", 
     "dl_type": 2048 
    }, 
    "actions":[ 
    ] 
}' http://localhost:8080/stats/flowentry/add 

结果是OK。

mininet> dpctl dump-flows 
*** s1 ------------------------------------------------------------------------ 
NXST_FLOW reply (xid=0x4): 
cookie=0x0, duration=6.722s, table=0, n_packets=0, n_bytes=0, idle_age=6, priority=100,ip,nw_src=10.0.0.1 actions=drop 
... 

插入此规则后:

mininet> h1 ping h2 
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. 
^C 
--- 10.0.0.2 ping statistics --- 
2 packets transmitted, 0 received, 100% packet loss, time 1000ms 

mininet> h2 ping h3 
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data. 
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=0.147 ms 
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.063 ms 

我用ofctl_rest应用此设置,首先插入所有必要的规则,使主机可达对方。这里是脚本插入这些规则:

curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 0, 
    "flags": 1, 
    "match":{}, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": "CONTROLLER" 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 


    curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 1, 
    "flags": 1, 
    "match":{ 
     "in_port":2, 
       "dl_dst":"00:00:00:00:00:01" 
    }, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": 1 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 


curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 1, 
    "flags": 1, 
    "match":{ 
     "in_port":1, 
       "dl_dst":"00:00:00:00:00:02" 
    }, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": 2 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 


curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 1, 
    "flags": 1, 
    "match":{ 
     "in_port":3, 
       "dl_dst":"00:00:00:00:00:01" 
    }, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": 1 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 


curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 1, 
    "flags": 1, 
    "match":{ 
     "in_port":1, 
       "dl_dst":"00:00:00:00:00:03" 
    }, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": 3 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 



curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 1, 
    "flags": 1, 
    "match":{ 
     "in_port":3, 
       "dl_dst":"00:00:00:00:00:02" 
    }, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": 2 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 


curl -X POST -d '{ 
    "dpid": 1, 
    "cookie": 0, 
    "table_id": 0, 
    "priority": 1, 
    "flags": 1, 
    "match":{ 
     "in_port":2, 
       "dl_dst":"00:00:00:00:00:03" 
    }, 
    "actions":[ 
     { 
      "type":"OUTPUT", 
      "port": 3 
     } 
    ] 
}' http://localhost:8080/stats/flowentry/add 
+0

谢谢你这么多的解决方案,我将尝试使用这个请求而不是RYU ofctl API ...当你说插入所有必要的规则 – user3445623

+0

谢谢你这么多的解决方案我会尝试使用此请求,而不是RYU ofctl API ...当您说插入所有必要的规则时,他们不会添加当我使用pingall命令?或有一些不同的规则,我需要添加....请帮助这个查询...也请分享所有有关ryu mininet命令和添加流量的命令 – user3445623

+0

我编辑了我的答案并添加了脚本我用了。 Ofctl_rest没有规则。您可以使用我添加的脚本添加规则。之后,平阿尔就好了。然后您可以添加放置操作规则。 –