OpenDaylight通过netconf对接netopeer2

目的

利用OpenDaylight(client)的南向接口netconf对接netopeer2(server)

搭建netopeer2

  • 启动Ubuntu20的docker,将内部830端口映射为主机的22830端口
admin@ubuntu20:~$ docker run -d --name netopeer2_server --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 22830:830 jrei/systemd-ubuntu:20.04
  • 之前搭建过netopeer2,参考这里
  • 需要注意的是相关组件的版本可能已经升级,例如libsysrepo.so.6已经更新为libsysrepo.so.7
  • 需要在make install的时候,关注编译出的target的名称和路径
  • 进入docker,创建用户名netconf,设置密码也为netconf
# useradd -m netconf -d /home/netconf -s /bin/bash     
# passwd netconf
New password: 
Retype new password: 
passwd: password updated successfully
  • 启动netopeer2-server
# /usr/local/bin/netopeer2-server -d -v 2

运行OpenDaylight

  • 开始去OpenDaylight的网站下载最新版,最后放弃,原因有二:
    • dlux这个GUI已经从源中删除
    • netconf连接不上netopeer2-server
  • 这里下载一个比较老的版本
admin@ubuntu20:~$ wget https://nexus.opendaylight.org/content/repositories/opendaylight.release/org/opendaylight/integration/karaf/0.7.3/karaf-0.7.3.tar.gz
admin@ubuntu20:~$ 
admin@ubuntu20:~$ tar -zxvf karaf-0.7.3.tar.gz 
  • 配套的java8安装一下
admin@ubuntu20:~$ sudo apt install openjdk-8-jre-headless  -y
  • 启动ODL(忽略一些报错)
admin@ubuntu20:~/karaf-0.7.3/bin$ ./karaf 

                                                                                           
    ________                       ________                .__  .__       .__     __       
    \_____  \ ______   ____   ____ \______ \ _____  ___.__.|  | |__| ____ |  |___/  |_     
     /   |   \\____ \_/ __ \ /    \ |    |  \\__  \<   |  ||  | |  |/ ___\|  |  \   __\    
    /    |    \  |_> >  ___/|   |  \|    `   \/ __ \\___  ||  |_|  / /_/  >   Y  \  |      
    \_______  /   __/ \___  >___|  /_______  (____  / ____||____/__\___  /|___|  /__|      
            \/|__|        \/     \/        \/     \/\/            /_____/      \/          
                                                                                           

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown OpenDaylight.

opendaylight-user@root>feature:install odl-netconf-connector-all odl-netconf-topology odl-restconf
opendaylight-user@root>
  • 安装必要的组件
opendaylight-user@root>feature:install odl-netconf-connector-all odl-netconf-topology odl-restconf
opendaylight-user@root>

对接

  • 参考官方文档
  • 因为PUT操作需要加payload,直接用curl不方便写,那么就借助postman
  • 下载
admin@ubuntu20:~$ wget https://dl.pstmn.io/download/latest/linux64
admin@ubuntu20:~$ mv linux64 postman-linux-x64.tar.gz
admin@ubuntu20:~$ 
admin@ubuntu20:~$ tar -zxvf postman-linux-x64.tar.gz 
  • 在Linux的图形界面运行postman
  • 填入内容如下
PUT http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/netopeer2

Headers:
Accept: application/xml
Content-Type: application/xml
Payload:


<node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
  <node-id>netopeer2</node-id>
  <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
  <port xmlns="urn:opendaylight:netconf-node-topology">22830</port>
  <username xmlns="urn:opendaylight:netconf-node-topology">netconf</username>
  <password xmlns="urn:opendaylight:netconf-node-topology">netconf</password>
  <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
  <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->
  <reconnect-on-changed-schema xmlns="urn:opendaylight:netconf-node-topology">false</reconnect-on-changed-schema>
  <connection-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">20000</connection-timeout-millis>
  <max-connection-attempts xmlns="urn:opendaylight:netconf-node-topology">0</max-connection-attempts>
  <between-attempts-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">2000</between-attempts-timeout-millis>
  <sleep-factor xmlns="urn:opendaylight:netconf-node-topology">1.5</sleep-factor>
  <!-- keepalive-delay set to 0 turns off keepalives-->
  <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">120</keepalive-delay>
</node>
  • 几点说明

    • URL最后的device_name(这里是netopeer2),跟下面payload的node-id需要保持一致
    • payload里面的port需要跟端口映射保持一致,当然也可以写docker的IP+830端口
    • username/password需要是docker已有的可以ssh登录的用户名/密码
    • 放几张截图,认证填入用户名密码是ODL本身的用户名/密码
      在这里插入图片描述


    在这里插入图片描述

    • 点击"Send",返回"201 Created"
      在这里插入图片描述

验证

  • 在主机上用curl获取config信息
admin@ubuntu20:~$ curl -u admin:admin http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/netopeer2 | python3 -m json.tool 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   545    0   545    0     0  45416      0 --:--:-- --:--:-- --:--:-- 49545
{
    "node": [
        {
            "node-id": "netopeer2",
            "netconf-node-topology:tcp-only": false,
            "netconf-node-topology:reconnect-on-changed-schema": false,
            "netconf-node-topology:between-attempts-timeout-millis": 2000,
            "netconf-node-topology:host": "127.0.0.1",
            "netconf-node-topology:port": 22830,
            "netconf-node-topology:connection-timeout-millis": 20000,
            "netconf-node-topology:username": "netconf",
            "netconf-node-topology:password": "netconf",
            "netconf-node-topology:max-connection-attempts": 0,
            "netconf-node-topology:sleep-factor": 1.5,
            "netconf-node-topology:keepalive-delay": 120
        }
    ]
}
admin@ubuntu20:~$ 
  • 获取operational的信息
admin@ubuntu20:~$ curl -u admin:admin http://localhost:8181/restconf/operational/network-topology:network-topology/topology/topology-netconf/node/netopeer2 | python3 -m json.tool 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3709    0  3709    0     0   402k      0 --:--:-- --:--:-- --:--:--  402k
{
    "node": [
        {
            "node-id": "netopeer2",
            "netconf-node-topology:available-capabilities": {
                "available-capability": [
                    {
                        "capability": "urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all,report-all-tagged,trim,explicit",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:yang-library:1.1?revision=2019-01-04&content-id=26",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:base:1.1",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:validate:1.1",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:base:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:xpath:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:startup:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:confirmed-commit:1.1",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:writable-running:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:interleave:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:rollback-on-error:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:candidate:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "urn:ietf:params:netconf:capability:notification:1.0",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?revision=2010-10-04)ietf-netconf-monitoring",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-inet-types?revision=2013-07-15)ietf-inet-types",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-yang-types?revision=2013-07-15)ietf-yang-types",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:netmod:notification?revision=2008-07-14)nc-notifications",
                        "capability-origin": "device-advertised"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:netconf:notification:1.0?revision=2008-07-14)notifications",
                        "capability-origin": "device-advertised"
                    }
                ]
            },
            "netconf-node-topology:host": "127.0.0.1",
            "netconf-node-topology:unavailable-capabilities": {
                "unavailable-capability": [
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:1?revision=2022-06-16)yang",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-x509-cert-to-name?revision=2014-12-10)ietf-x509-cert-to-name",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)ietf-netconf-notifications",
                        "failure-reason": "unable-to-resolve"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-netconf-acm?revision=2018-02-14)ietf-netconf-acm",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:sysrepo:plugind?revision=2022-03-10)sysrepo-plugind",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults?revision=2011-06-01)ietf-netconf-with-defaults",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:ietf-yang-metadata?revision=2016-08-05)ietf-yang-metadata",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:yang:iana-crypt-hash?revision=2014-08-06)iana-crypt-hash",
                        "failure-reason": "missing-source"
                    },
                    {
                        "capability": "(urn:ietf:params:xml:ns:netconf:base:1.0?revision=2013-09-29)ietf-netconf",
                        "failure-reason": "missing-source"
                    }
                ]
            },
            "netconf-node-topology:connection-status": "connected",
            "netconf-node-topology:port": 22830
        }
    ]
}
admin@ubuntu20:~$ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值