实验 7:OpenDaylight 实验——Python 中的 REST API 调用

一、实验准备

1.实验环境

  • 安装了 Ubuntu 18.04.5 Desktop amd64 的虚拟机

2.实验目的

  • 对 Python 调用 OpenDaylight 的 REST API 方法有初步了解。
  • 通过 Python 程序调用 OpenDaylight 的北向接口下发关于硬超时的流表,实现拓扑内主机在一定时间内的网络通断。

3.实验工具

二、实验过程

1.开启OpenDaylight

cd lancl/OpenDaylight
./distribution-karaf-0.6.4-Carbon/bin/karaf

2.生成拓扑(生成方法同上一个实验一致):

sudo mn --topo=single,3 --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13

  • 先在 Mininet CLI 中运行 h1 ping h3,
h1 ping h3

3.运行 Python 代码,完成流表下发

cd lancl
python odlnorth.py

  • 中断结束后,终止ping过程。
    ctrl+c

4.扫尾

  • 关闭-脚本终端
exit
  • 关闭-拓扑
quit
sudo mn -c
exit
  • 关闭-odl
logout
exit

Tips

  • 报错-->复制源码的格式错误、字符缺失
File "odlnorth.py", line 8
headers = {'Content-Type':'application/json'}
^
IndentationError: unexpected indent

indentation是缩进,缩排的意思。unexpected indent 就是说“h”是一个“意外的”缩进。

{"errors":{"error":[{"error-type":"protocol","error-tag":"unknown-element","error-message":"\"flownode-inventory\" module does not exist."}]}}

flow-node-inventory

url = 'http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1'
posted @ 2020-10-14 20:47  兰小路  阅读(268)  评论(0编辑  收藏  举报