2019SDN第4次作业
1.解压配置Java环境
sudo gedit ~/.bashrc
在bashrc文件底部添加java路径
export JAVA_HOME=/home/w/Desktop/test4/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
2.安装插件
进入OpenDayLigh的文件夹,运行./karaf (注意不能用sudo运行):
安装feature
feature:install odl-restconf odl-l2switch-switch-ui odl-openflowplugin-all odl-mdsal-apidocs odl-dlux-core odl-dlux-node odl-dlux-yangui
3.用Python编写代码
from mininet.topo import Topo
class Mytopo(Topo):
def __init__(self):
Topo.__init__(self)
sw=self.addSwitch('s1')
count=1
for i in range(3):
host = self.addHost('h{}'.format(count))
self.addLink(host,sw,1,count)
count = count + 1
topos = {'mytopo': (lambda:Mytopo())}
执行以下命令
sudo mn --custom /home/ubuntu/jlq.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
测试连通性
pingall
4.浏览器访问 http://127.0.0.1:8181/index.html 进入ODL图形化界面
(账号密码均为admin)
在mininet中使用links查看端口
在Opendaylight下设置相关参数下发流表
点击Yang UI>Opendaylight-inventory>config>nodes>table>flow:并分别设置nod、table、flow的值,如下图所示(其中node/openflow:1 交换机编号;table/0 流表编号;flow/不超过1024,不冲突即可流表项编号;GET为查询流表,下发流表要修改为PUT;点击加号添加流表项):
id:流表项id,为任意值,in-port:流表项匹配的进入端口,这里需填h2对应的port号
ethernet-type:以太网类型0x0800,layer-3-match:ipv4-match 三层匹配为ipv4匹配
新增instruction list这是流表项匹配到数据报后要执行的指令,instruction:apply-actions-case 执行动作,action drop-action-case 丢包动作(转发动作为output-action 并要在output-node-connector填写转发端口)
priority 流表项优先级,要大于odl下发的默认流表,这里设置成最大65535,hard-timeout 硬超时,流表项下发后生效时长,table_id 流表id 默认为0
在设置好之后,先在mininet中进行h2 ping h3,然后在WEB UI中选择PUT,并点击旁边的send
5.借助Postman通过OpenDayLight的北向接口下发流表,再利用OpenDayLight北向接口查看已下发的流表。
借助Postman通过OpenDayLight的北向接口下发流表,再利用OpenDayLight北向接口查看已下发的流表。
http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1
{
"flow": [
{
"id": "1",
"match": {
"in-port": "1",
"ethernet-match": {
"ethernet-type": {
"type": "0x0800"
}
},
"ipv4-destination": "10.0.0.3/32"
},
"instructions": {
"instruction": [
{
"order": "0",
"apply-actions": {
"action": [
{
"order": "0",
"drop-action": {}
}
]
}
}
]
},
"priority": "65535",
"hard-timeout": "20",
"table_id": "0"
}
]
}