2

我们有一个启用 netconf 的路由器,我可以使用 Mg-Soft 客户端浏览器执行 get/get-config 操作。这是 getConfig() 的输出 -

请求:

<nc:get-config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <nc:source>
    <nc:running/>
  </nc:source>
</nc:get-config>

响应式:

<?xml version="1.0" encoding="utf-8"?>
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf">
    <qos>
      <sap-ingress>
      .....
</data>

但我无法使用 tailf Netconf 客户端执行相同的操作。这是我的代码 -

public class Client {
    public static void main(String args[]) throws JNCException, 
            ParserConfigurationException, SAXException, IOException {

        DeviceUser deviceUser;
        String deviceUserName = "user";
        deviceUser = new DeviceUser(deviceUserName, "admin", "admin");
        Device device = new Device("simulator", deviceUser, "10.135.16.13", 830);
        device.connect(deviceUserName);
        device.newSession(new Subscriber("simulator"), "mySession");
        NetconfSession session = device.getSession("mySession");

        NodeSet config = session.getConfig(NetconfSession.RUNNING);
        String xmlString = config.toXMLString();
        session.closeSession();
        System.out.println(xmlString);
    }
}

class Subscriber extends IOSubscriber {
    String devName;
    public static boolean rawMode = false;
    Subscriber(String devName) {
        super(rawMode);
        this.devName = devName;
    }
    public void input(String data) {
        System.out.println("RECV: " + data);
    }

    public void output(String data) {
        System.out.println("SEND: " + data);
    }
}

我在 Eclipse 控制台中得到以下信息 -

SEND: <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <capabilities>
    <capability>urn:ietf:params:netconf:base:1.0</capability>
  </capabilities>
</hello>

RECV: <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <capabilities>
    <capability>urn:ietf:params:netconf:base:1.0</capability>
    <capability>urn:ietf:params:netconf:base:1.1</capability>
    <capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:candidate:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:validate:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:validate:1.1</capability>
    <capability>urn:ietf:params:netconf:capability:startup:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:url:1.0?scheme=ftp,tftp,file</capability>
    <capability>urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=trim&amp;also-supported=report-all</capability>
    <capability>urn:ietf:params:xml:ns:netconf:base:1.0?module=ietf-netconf&amp;revision=2011-06-01&amp;features=writable-running,validate,startup,url&amp;deviations=alu-netconf-deviations-r13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:netconf-deviations-r13?module=alu-netconf-deviations-r13&amp;revision=2015-01-23</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:cli-content-layer-r13?module=alu-cli-content-layer-r13&amp;revision=2015-01-23</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-r13?module=alu-conf-r13&amp;revision=2016-06-24</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-aaa-r13?module=alu-conf-aaa-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-aa-r13?module=alu-conf-aa-r13&amp;revision=2016-06-23</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-calltrace-r13?module=alu-conf-calltrace-r13&amp;revision=2016-04-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-card-r13?module=alu-conf-card-r13&amp;revision=2015-10-30</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-cflowd-r13?module=alu-conf-cflowd-r13&amp;revision=2015-01-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-conn-prof-r13?module=alu-conf-conn-prof-r13&amp;revision=2015-11-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-con-profvlan-r13?module=alu-conf-con-profvlan-r13&amp;revision=2015-08-28</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-eth-cfm-r13?module=alu-conf-eth-cfm-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-eth-ring-r13?module=alu-conf-eth-ring-r13&amp;revision=2014-10-17</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-eth-tunnel-r13?module=alu-conf-eth-tunnel-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-filter-r13?module=alu-conf-filter-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-gmpls-tunnel-r13?module=alu-conf-gmpls-tunnel-r13&amp;revision=2014-12-09</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-ifgrphandler-r13?module=alu-conf-ifgrphandler-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-isa-r13?module=alu-conf-isa-r13&amp;revision=2016-02-29</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-lag-r13?module=alu-conf-lag-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-li-r13?module=alu-conf-li-r13&amp;revision=2016-04-21</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-log-r13?module=alu-conf-log-r13&amp;revision=2016-06-01</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-mcastmgmt-r13?module=alu-conf-mcastmgmt-r13&amp;revision=2015-03-12</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-mirror-r13?module=alu-conf-mirror-r13&amp;revision=2016-01-08</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-oam-pm-r13?module=alu-conf-oam-pm-r13&amp;revision=2015-11-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-open-flow-r13?module=alu-conf-open-flow-r13&amp;revision=2015-11-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-r13?module=alu-conf-port-r13&amp;revision=2015-08-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-access-r13?module=alu-conf-port-access-r13&amp;revision=2014-10-31</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-aps-r13?module=alu-conf-port-aps-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-ethernet-r13?module=alu-conf-port-ethernet-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-mbundle-r13?module=alu-conf-port-mbundle-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-network-r13?module=alu-conf-port-network-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-sonetsdh-r13?module=alu-conf-port-sonetsdh-r13&amp;revision=2015-06-11</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-tdm-r13?module=alu-conf-port-tdm-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-tdm-ds1-r13?module=alu-conf-port-tdm-ds1-r13&amp;revision=2014-12-15</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-tdm-ds3-r13?module=alu-conf-port-tdm-ds3-r13&amp;revision=2014-12-15</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-tdm-e1-r13?module=alu-conf-port-tdm-e1-r13&amp;revision=2014-12-15</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-tdm-e3-r13?module=alu-conf-port-tdm-e3-r13&amp;revision=2014-12-15</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-port-policy-r13?module=alu-conf-port-policy-r13&amp;revision=2015-12-09</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-pxc-r13?module=alu-conf-pxc-r13&amp;revision=2015-04-24</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-python-r13?module=alu-conf-python-r13&amp;revision=2016-06-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-qos-r13?module=alu-conf-qos-r13&amp;revision=2016-04-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-redundancy-r13?module=alu-conf-redundancy-r13&amp;revision=2016-03-25</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-r13?module=alu-conf-router-r13&amp;revision=2016-05-09</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-bgp-r13?module=alu-conf-router-bgp-r13&amp;revision=2016-06-06</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-dhcps-r13?module=alu-conf-router-dhcps-r13&amp;revision=2015-09-21</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-dhcp6-r13?module=alu-conf-router-dhcp6-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-fspec-r13?module=alu-conf-router-fspec-r13&amp;revision=2015-12-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-gmpls-r13?module=alu-conf-router-gmpls-r13&amp;revision=2015-11-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-igmp-r13?module=alu-conf-router-igmp-r13&amp;revision=2015-11-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-if-r13?module=alu-conf-router-if-r13&amp;revision=2016-04-29</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-isis-r13?module=alu-conf-router-isis-r13&amp;revision=2016-02-18</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-l2tp-r13?module=alu-conf-router-l2tp-r13&amp;revision=2016-05-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-ldp-r13?module=alu-conf-router-ldp-r13&amp;revision=2016-05-02</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-lmp-r13?module=alu-conf-router-lmp-r13&amp;revision=2015-09-08</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-mccacpl-r13?module=alu-conf-router-mccacpl-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-mld-r13?module=alu-conf-router-mld-r13&amp;revision=2015-09-22</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-mpls-r13?module=alu-conf-router-mpls-r13&amp;revision=2016-04-28</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-mpls-tp-r13?module=alu-conf-router-mpls-tp-r13&amp;revision=2015-11-09</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-nat-r13?module=alu-conf-router-nat-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-ogvalid-r13?module=alu-conf-router-ogvalid-r13&amp;revision=2015-11-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-ospf-r13?module=alu-conf-router-ospf-r13&amp;revision=2016-06-22</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-ospf3-r13?module=alu-conf-router-ospf3-r13&amp;revision=2016-06-22</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-pcep-r13?module=alu-conf-router-pcep-r13&amp;revision=2016-03-07</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-pim-r13?module=alu-conf-router-pim-r13&amp;revision=2016-06-07</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-policy-r13?module=alu-conf-router-policy-r13&amp;revision=2016-05-19</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-radprox-r13?module=alu-conf-router-radprox-r13&amp;revision=2015-11-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-rip-r13?module=alu-conf-router-rip-r13&amp;revision=2015-06-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-nhroute-r13?module=alu-conf-router-nhroute-r13&amp;revision=2014-09-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-radvert-r13?module=alu-conf-router-radvert-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-rsvp-r13?module=alu-conf-router-rsvp-r13&amp;revision=2015-06-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-wlan-r13?module=alu-conf-router-wlan-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-router-wpp-r13?module=alu-conf-router-wpp-r13&amp;revision=2015-03-04</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-saa-r13?module=alu-conf-saa-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-service-r13?module=alu-conf-service-r13&amp;revision=2016-03-23</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-apipe-r13?module=alu-conf-svc-apipe-r13&amp;revision=2016-02-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-cpipe-r13?module=alu-conf-svc-cpipe-r13&amp;revision=2016-02-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-cust-r13?module=alu-conf-svc-cust-r13&amp;revision=2015-09-23</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-dynsrv-r13?module=alu-conf-svc-dynsrv-r13&amp;revision=2015-09-11</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-egrmcgroup-r13?module=alu-conf-svc-egrmcgroup-r13&amp;revision=2015-09-11</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-epipe-r13?module=alu-conf-svc-epipe-r13&amp;revision=2016-06-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-fpipe-r13?module=alu-conf-svc-fpipe-r13&amp;revision=2016-02-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-ies-r13?module=alu-conf-svc-ies-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-ies-if-r13?module=alu-conf-svc-ies-if-r13&amp;revision=2016-06-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-ies-subif-r13?module=alu-conf-svc-ies-subif-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-ipfix-r13?module=alu-conf-svc-ipfix-r13&amp;revision=2014-09-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-ipipe-r13?module=alu-conf-svc-ipipe-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-nat-r13?module=alu-conf-svc-nat-r13&amp;revision=2016-04-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-sdp-r13?module=alu-conf-svc-sdp-r13&amp;revision=2016-05-09</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-template-r13?module=alu-conf-svc-template-r13&amp;revision=2016-04-06</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-upnp-r13?module=alu-conf-svc-upnp-r13&amp;revision=2015-09-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-r13?module=alu-conf-svc-vpls-r13&amp;revision=2016-06-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-igmp-r13?module=alu-conf-svc-vpls-igmp-r13&amp;revision=2014-09-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-macmo-r13?module=alu-conf-svc-vpls-macmo-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-macpr-r13?module=alu-conf-svc-vpls-macpr-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-meshs-r13?module=alu-conf-svc-vpls-meshs-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-mld-r13?module=alu-conf-svc-vpls-mld-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-pim-r13?module=alu-conf-svc-vpls-pim-r13&amp;revision=2015-07-07</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-sap-r13?module=alu-conf-svc-vpls-sap-r13&amp;revision=2016-06-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-split-r13?module=alu-conf-svc-vpls-split-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-spoke-r13?module=alu-conf-svc-vpls-spoke-r13&amp;revision=2016-06-13</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-spb-r13?module=alu-conf-svc-vpls-spb-r13&amp;revision=2016-02-04</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vpls-stp-r13?module=alu-conf-svc-vpls-stp-r13&amp;revision=2014-09-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-r13?module=alu-conf-svc-vprn-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-bgp-r13?module=alu-conf-svc-vprn-bgp-r13&amp;revision=2016-05-04</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-dhcps-r13?module=alu-conf-svc-vprn-dhcps-r13&amp;revision=2015-09-21</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-dhcp6-r13?module=alu-conf-svc-vprn-dhcp6-r13&amp;revision=2016-06-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-fspec-r13?module=alu-conf-svc-vprn-fspec-r13&amp;revision=2016-02-11</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-igmp-r13?module=alu-conf-svc-vprn-igmp-r13&amp;revision=2015-11-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-if-r13?module=alu-conf-svc-vprn-if-r13&amp;revision=2016-06-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-isis-r13?module=alu-conf-svc-vprn-isis-r13&amp;revision=2016-02-18</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-l2tp-r13?module=alu-conf-svc-vprn-l2tp-r13&amp;revision=2016-05-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-mld-r13?module=alu-conf-svc-vprn-mld-r13&amp;revision=2015-10-14</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-nat-r13?module=alu-conf-svc-vprn-nat-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-nwif-r13?module=alu-conf-svc-vprn-nwif-r13&amp;revision=2016-04-29</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svs-vprn-ntp-r13?module=alu-conf-svs-vprn-ntp-r13&amp;revision=2015-05-05</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-ospf-r13?module=alu-conf-svc-vprn-ospf-r13&amp;revision=2016-06-22</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-ospf3-r13?module=alu-conf-svc-vprn-ospf3-r13&amp;revision=2016-06-22</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-pim-r13?module=alu-conf-svc-vprn-pim-r13&amp;revision=2015-08-17</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-ptp-r13?module=alu-conf-svc-vprn-ptp-r13&amp;revision=2015-05-22</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-vprn-radprox-r13?module=alu-conf-vprn-radprox-r13&amp;revision=2015-06-23</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-rip-r13?module=alu-conf-svc-vprn-rip-r13&amp;revision=2015-06-03</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-ripng-r13?module=alu-conf-svc-vprn-ripng-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-radv-r13?module=alu-conf-svc-vprn-radv-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-srcad-r13?module=alu-conf-svc-vprn-srcad-r13&amp;revision=2015-01-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-spoke-r13?module=alu-conf-svc-vprn-spoke-r13&amp;revision=2015-12-17</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-subif-r13?module=alu-conf-svc-vprn-subif-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-wlan-r13?module=alu-conf-svc-vprn-wlan-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-svc-vprn-wpp-r13?module=alu-conf-svc-vprn-wpp-r13&amp;revision=2015-03-04</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-sflow-r13?module=alu-conf-sflow-r13&amp;revision=2014-09-26</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-sfm-r13?module=alu-conf-sfm-r13&amp;revision=2014-10-20</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-subscrmgmt-r13?module=alu-conf-subscrmgmt-r13&amp;revision=2016-06-27</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-submgmt-ludb-r13?module=alu-conf-submgmt-ludb-r13&amp;revision=2016-06-14</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-submgmt-wlangw-r13?module=alu-conf-submgmt-wlangw-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-system-r13?module=alu-conf-system-r13&amp;revision=2016-06-08</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-sys-pwrmgmt-r13?module=alu-conf-sys-pwrmgmt-r13&amp;revision=2015-05-25</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-sys-ptp-r13?module=alu-conf-sys-ptp-r13&amp;revision=2015-06-25</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-sys-sec-r13?module=alu-conf-sys-sec-r13&amp;revision=2016-06-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-vrrp-r13?module=alu-conf-vrrp-r13&amp;revision=2015-10-14</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:conf-vsm-r13?module=alu-conf-vsm-r13&amp;revision=2015-09-16</capability>
    <capability>urn:alcatel-lucent.com:sros:ns:yang:types?module=alu-types&amp;revision=2015-01-19</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:conf?module=nokia-conf&amp;revision=2016-01-01</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:sros-yang-extensions?module=nokia-sros-yang-extensions&amp;revision=2016-01-01</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:types-filter?module=nokia-types-filter&amp;revision=2016-01-01</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:types-qos?module=nokia-types-qos&amp;revision=2016-01-01</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:types-services?module=nokia-types-services&amp;revision=2016-01-01</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:types-sros?module=nokia-types-sros&amp;revision=2016-01-01</capability>
    <capability>urn:nokia.com:sros:ns:yang:sr:major-release-14</capability>
  </capabilities>
  <session-id>52</session-id>
</hello>

SEND: <nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:message-id="1">
  <nc:get-config>
    <nc:source>
      <nc:running/>    </nc:source>
  </nc:get-config>
</nc:rpc>

RECV: <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply urn:ietf:params:xml:ns:netconf:base:1.0:message-id="1" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <rpc-error>
        <error-type>rpc</error-type>
        <error-tag>missing-attribute</error-tag>
        <error-severity>error</error-severity>
        <error-info>
            <bad-element>message-id</bad-element>
            <bad-element>rpc</bad-element>
        </error-info>
        <error-message>
            Check that message-id attribute is present and less than 4096 characters
        </error-message>
    </rpc-error>
</rpc-reply>

[Fatal Error] :2:20: Attribute name "urn:ietf" associated with an element type "rpc-reply" must be followed by the ' = ' character.
[Fatal Error] :2:20: Attribute name "urn:ietf" associated with an element type "rpc-reply" must be followed by the ' = ' character.
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 20; Attribute name "urn:ietf" associated with an element type "rpc-reply" must be followed by the ' = ' character.
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1239)
    at com.tailf.jnc.YangXMLParser.parse(YangXMLParser.java:50)
    at com.tailf.jnc.XMLParser.parse(XMLParser.java:154)
    at com.tailf.jnc.NetconfSession.recv_rpc_reply(NetconfSession.java:1495)
    at com.tailf.jnc.NetconfSession.recv_rpc_reply_data(NetconfSession.java:1472)
    at com.tailf.jnc.NetconfSession.getConfig(NetconfSession.java:443)
    at client.Client.main(Client.java:51)
Exception in thread "main" Parse error: parse error: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 20; Attribute name "urn:ietf" associated with an element type "rpc-reply" must be followed by the ' = ' character.
    at com.tailf.jnc.YangXMLParser.parse(YangXMLParser.java:54)
    at com.tailf.jnc.XMLParser.parse(XMLParser.java:154)
    at com.tailf.jnc.NetconfSession.recv_rpc_reply(NetconfSession.java:1495)
    at com.tailf.jnc.NetconfSession.recv_rpc_reply_data(NetconfSession.java:1472)
    at com.tailf.jnc.NetconfSession.getConfig(NetconfSession.java:443)
    at client.Client.main(Client.java:51)
4

1 回答 1

3

你实际上似乎有两个问题,这两个问题似乎都不是你的错。来自 JNC 的 get-config 请求似乎格式错误:message-id属性应该在默认命名空间中,而不是在 NETCONF 消息命名空间中。

SEND: <nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:message-id="1">
  <nc:get-config>
    <nc:source>
      <nc:running/>    </nc:source>
  </nc:get-config>
</nc:rpc>

实际上应该是:

SEND: <nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <nc:get-config>
    <nc:source>
      <nc:running/>    </nc:source>
  </nc:get-config>
</nc:rpc>

第二个问题是您的服务器,它似乎无法处理这个格式错误的请求 - 并且正在响应格式错误的消息(它甚至不是 XML 消息):

RECV: <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply urn:ietf:params:xml:ns:netconf:base:1.0:message-id="1" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <rpc-error>
        <error-type>rpc</error-type>
        <error-tag>missing-attribute</error-tag>
        <error-severity>error</error-severity>
        <error-info>
            <bad-element>message-id</bad-element>
            <bad-element>rpc</bad-element>
        </error-info>
        <error-message>
            Check that message-id attribute is present and less than 4096 characters
        </error-message>
    </rpc-error>
</rpc-reply>

它应该回应:

RECV: <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply nc:message-id="1" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <rpc-error>
        <error-type>rpc</error-type>
        <error-tag>missing-attribute</error-tag>
        <error-severity>error</error-severity>
        <error-info>
            <bad-element>message-id</bad-element>
            <bad-element>rpc</bad-element>
        </error-info>
        <error-message>
            Check that message-id attribute is present and less than 4096 characters
        </error-message>
    </rpc-error>
</rpc-reply>

因为它应该逐字返回所有属性。message-id否则,当没有属性的消息被发送到服务器时,这将是标准行为。

下面是相关的 RFC4741 文本(同样适用于 RFC6241、NETCONF 1.1)。

第 4.1 节

<rpc> 元素有一个强制属性“message-id”,它是由 RPC 的发送者选择的任意字符串,通常会编码一个单调递增的整数。RPC 的接收者不会解码或解释这个字符串,而只是将其保存为在任何生成的 <rpc-reply> 消息中用作“message-id”属性。例如: <rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <some-method> <!-- method parameters here... --> </some-method> </rpc>

如果在 <rpc> 元素中存在附加属性,NETCONF 对等体必须在 <rpc-reply> 元素中返回它们,而不加修改。

第 4.3 节

如果接收到没有 message-id 属性的 <rpc> 元素,则会返回错误。请注意,只有在这种情况下,NETCONF 对等方才可接受在 <rpc-reply> 元素中省略 message-id 属性。

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <get-config> <source> <running/> </source> </get-config> </rpc> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <rpc-error> <error-type>rpc</error-type> <error-tag>missing-attribute</error-tag> <error-severity>error</error-severity> <error-info> <bad-attribute>message-id</bad-attribute> <bad-element>rpc</bad-element> </error-info> </rpc-error> </rpc-reply>

因此,我认为您应该向设备制造商和 JNC 的创建者报告两个问题。

它与 MG-SOFT 客户端一起工作的原因是它发送了一个正确的message-id属性,所以你的情况永远不会发生。

于 2016-06-29T14:05:01.347 回答