# sdn-executor **Repository Path**: movee/sdn-executor ## Basic Information - **Project Name**: sdn-executor - **Description**: SDN命令执行器,支持GNMI、Netconf、CLI、SNMP等协议与设备交互 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-17 - **Last Updated**: 2024-12-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # sdn-executor ## 1 介绍 一个高并发、高性能的SDN(Software Defined Networking)命令执行器,支持的主要特性包括: 1. 支持通过GNMI、Netconf、CLI向设备发送命令 2. 每个设备拥有一个独立的命令执行引擎,设备和设备间完全解耦 3. 每个命令执行引擎支持多个命令下发通道(channel),每个下发通道支持多个优先级(priority) 4. 每个命令执行引擎默认支持4个命令下发通道:读写,只读,巡检,变更读 5. 每个命令执行引擎只有一个读写通道(通道1),其他的通道都是只读的 6. CLI命令支持命令编排,支持条件分支 7. 支持同步执行和异步执行,支持同步超时后改为异步 8. 支持GNMI capability、get、update、replace、delete操作 9. 支持netconf操作 10. 支持CLI操作 11. 支持snmp get、getnext、getbulk、bulkwalk、walk操作 12. 支持prometheus指标监控 ## 2 编译打包 ```bash $ cd sdn-executor/cmd/executor $ ./build.sh ``` 结果在`output`目录下 ```bash $ ls output bin conf $ ls output/bin executor_env.sh executorctl sdn-executor supervisor_sdn-executor $ ls output/conf config-default.yaml config.yaml ``` ## 3 启动停止 ```bash $ ./bin/executorctl start $ ./bin/executorctl stop ``` ## 4 应用举例 ### 4.1 GNMI #### 4.1.1 capability ```bash curl -X POST 'http://127.0.0.1:8080/api/v1/gnmi/capability' \ --data-raw '{ "device": "127.0.0.1", "port": 10161, "user": "admin", "password": "admin", "asyncTimeoutMs": 10000, "channel": 1, "priority": 0, "readOnly": true, "caller": "movee" }' ``` 响应: ```json { "code": 0, "msg": "ok", "RequestId": "TR-GNMICAP-935d244c644b4bb081e60960a1e4397b", "Status": "SUCCESS", "Response": { "supported_models": [ { "name": "openconfig-interfaces", "organization": "OpenConfig working group", "version": "2.0.0" }, { "name": "openconfig-openflow", "organization": "OpenConfig working group", "version": "0.1.0" }, { "name": "openconfig-platform", "organization": "OpenConfig working group", "version": "0.5.0" }, { "name": "openconfig-system", "organization": "OpenConfig working group", "version": "0.2.0" } ], "supported_encodings": [ 0, 4 ], "gNMI_version": "0.8.0" } } ``` #### 4.1.2 get ```bash curl -X POST 'http://127.0.0.1:8080/api/v1/gnmi/get' \ --data-raw '{ "device": "127.0.0.1", "port": 10161, "user": "admin", "password": "admin", "asyncTimeoutMs": 10000, "channel": 1, "priority": 0, "caller": "movee", "xpath": ["/system/openflow/agent/config/max-backoff"] }' ``` 响应: ```json { "code": 0, "msg": "ok", "RequestId": "TR-GNMIGET-cd4c8484dcbc4220aa531e92490d4bd9", "Status": "SUCCESS", "Response": { "notification": [ { "timestamp": 1711944697139157000, "prefix": {}, "update": [ { "path": { "elem": [ { "name": "system" }, { "name": "openflow" }, { "name": "agent" }, { "name": "config" }, { "name": "max-backoff" } ] }, "val": { "Value": { "UintVal": 10 } } } ] } ] } } ``` #### 4.1.3 update ```bash curl -X POST 'http://127.0.0.1:8080/api/v1/gnmi/update' \ --data-raw '{ "device": "127.0.0.1", "port": 10161, "user": "admin", "password": "admin", "asyncTimeoutMs": 10000, "channel": 1, "priority": 0, "caller": "movee", "xpath": "/system/openflow/agent", "content": { "config": { "max-backoff": 20 } } }' ``` 响应: ```json { "code": 0, "msg": "ok", "RequestId": "TR-GNMIUPDATE-2f71ea882bc04a82b7d1db10377fa8e1", "Status": "SUCCESS", "Response": { "prefix": {}, "response": [ { "path": { "elem": [ { "name": "system" }, { "name": "openflow" }, { "name": "agent" } ] }, "op": 3 } ] } } ``` ### 4.2 netconf ```bash curl -X POST 'http://127.0.0.1:8080/api/v1/netconf/command' \ --data-raw '{ "device": "127.0.0.1", "port": 830, "user": "netconf", "password": "netconf", "asyncTimeoutMs": 10000, "channel": 1, "priority": 0, "caller": "yang", "rpc": "" }' ``` 响应 ```json { "code": 0, "msg": "ok", "RequestId": "TR-NETCONF-2d46b4e09bab461fa81e1342522f01b4", "Status": "SUCCESS", "RpcReply": "genkeyrsa2048MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsKs9JB7+4mXV0qmEmmE8r3bU2sifGKrtwYai1kLqbFEVp5EicfF1LFLcEjr04hIjTwi/FDkGmli9zizsiqpXQj/bmX0k3f+Oztu7Ozk5tdGyrC095k5Ntfm8y7JT4Fp7caxU2Sc6RtByI1H9FjWGcCBNx2PG2QGHXQ4t/JEttKEawY3VmwtF1MZsglQ4fKLnHoDi4R49dsPWuYgUhCqLMdE+t5miFa/DNCFOx52kNbKffzgSZsoCOa/hBVoe2qNu/Vvb/6R+ZjEh2Z2CBbYVqc6TtCTKJLElyJLTQRZHwFY2a//jbzY+7avF3epSCx61gXXqmN5I0x+wYjKDYy2tDQIDAQABdefault-ssh0.0.0.01105default-keygenkey" } ``` ### 4.3 CLI ```bash curl -X POST 'http://127.0.0.1:8080/api/v1/cli/command' \ --data-raw '{ "device": "127.0.0.1", "port": 2222, "user": "root", "password": "root", "asyncTimeoutMs": 10000, "channel": 1, "priority": 0, "caller": "movee", "cmds": [ { "index": 0, "cmd": "pwd" }, { "index": 1, "cmd": "ls /usr/local/" } ] }' ``` 响应: ```json { "code": 0, "msg": "ok", "requestId": "TR-CLI-c9e66d82f603408fa97a67233dff9a82", "status": "SUCCESS", "echos": [ { "order": 1, "status": "SUCCESS", "cmd": "pwd", "echo": "/root\r\nroot@6a1c64d4c0f8:~# " }, { "order": 2, "status": "SUCCESS", "cmd": "ls /usr/local/", "echo": "bin etc games include lib man sbin share src\r\nroot@6a1c64d4c0f8:~# " } ] } ```