#!/usr/bin/env bash # Netconf Hello functionality # See RFC6241 Sec 8.1 # For prolog, ie see test_xml.sh # Note clixon sends rpc-error back on primitive errors prior to knowing it is an rpc. # This means that some errors for hello messages get an rpc-error back which is somewhat # fringe to the standard. # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example cfg=$dir/conf_yang.xml tmp=$dir/tmp.x # Use yang in example cat < $cfg $cfg ietf-netconf:startup 42 /usr/local/share/clixon $IETFRFC clixon-example /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/lib/$APPNAME/netconf /usr/local/lib/$APPNAME/restconf /usr/local/lib/$APPNAME/cli $APPNAME $dir/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME true EOF new "test params: -f $cfg -- -s" # Bring your own backend if [ $BE -ne 0 ]; then # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -- -s" start_backend -s init -f $cfg -- -s fi new "wait backend" wait_backend # Hello new "Netconf snd hello with xmldecl" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" '^$' '^$' # Hello, lowercase encoding new "Netconf snd hello with xmldecl (lowercase encoding)" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" '^$' '^$' new "Netconf snd hello without xmldecl" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" '^$' '^$' new "Netconf snd hello with RFC 4741 base capability" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.0]]>]]>" '^$' '^$' new "Netconf snd hello with wrong base capability" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.2]]>]]>" '^$' 'Server received hello without netconf base capability urn:ietf:params:netconf:base:1.1' # This is a case where hello error gets an rpc-error back. Not strictly correct. new "Netconf hello with session-id is wrong" expecteof "$clixon_netconf -qf $cfg" 0 "42urn:ietf:params:netconf:base:1.2]]>]]>" '^protocolunknown-elementsession-iderrorUnrecognized hello/capabilities element]]>]]>$' '^$' # When comparing protocol version capability URIs, only the base part is used, in the event any # parameters are encoded at the end of the URI string. new "Netconf snd hello with base capability with extra arguments" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1?arg=val]]>]]>" '^$' '^$' # This is hello - shouldnt really get rpc back? new "Netconf snd hello with wrong prefix" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" '^$' 'XML error: No appropriate namespace associated with prefix:xx: Bad address' new "Netconf snd hello with prefix" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" '^$' '^$' new "netconf snd + rcv hello" expecteof "$clixon_netconf -f $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" "^urn:ietf:params:netconf:base:1.1urn:ietf:params:netconf:base:1.0urn:ietf:params:netconf:capability:yang-library:1.0?revision=2019-01-04&module-set-id=42urn:ietf:params:netconf:capability:candidate:1.0urn:ietf:params:netconf:capability:validate:1.1urn:ietf:params:netconf:capability:startup:1.0urn:ietf:params:netconf:capability:xpath:1.0urn:ietf:params:netconf:capability:notification:1.0[0-9]*]]>]]>$" '^$' new "Netconf snd hello with extra element" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" '^protocolunknown-elementextra-elementerrorUnrecognized hello/capabilities element]]>]]>$' '^$' new "Netconf send rpc without hello error" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "rpcoperation-failederrorClient must send an hello element before any RPC]]>]]>" '^$' new "Netconf send rpc without hello w CLICON_NETCONF_HELLO_OPTIONAL" expecteof "$clixon_netconf -qf $cfg -o CLICON_NETCONF_HELLO_OPTIONAL=true" 0 "]]>]]>" "]]>]]>" '^$' if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg fi rm -rf $dir new "endtest" endtest