コード例 #1
0
	def __init__(self,host="localhost",port=830,username="******",password=None,timeout=100):
		conn = litenc.litenc()
		if(password==None):
			password_str=""
		else:
			password_str="password="******"[FAILED] Connecting to server=%(server)s:" % {'server':host}
			assert(0)
		print "[OK] Connecting to server=%(server)s:" % {'server':host}

		ret = conn.send("""
<hello>
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>\
 </capabilities>\
</hello>
""")
		if ret != 0:
			print("[FAILED] Sending <hello>")
			assert(0)
		(ret, reply_xml)=conn.receive()
		if ret != 0:
			print("[FAILED] Receiving <hello>")
			assert(0)

		print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml':reply_xml}
		self.litenc_session=conn
コード例 #2
0
def connect(server, port, user, password):
    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}
    return conn_raw
コード例 #3
0
ファイル: session.litenc.py プロジェクト: xorrkaz/yuma123
def step_1(server, port, user, password):
    print("#1")
    print("Connecting ...")
    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        assert (0)
    print("Connected ...")
    return (conn_raw)
コード例 #4
0
def main():
    print("""
#Description: Demonstrate that ietf-yang-library is implemented.
#Procedure:
#1 - Verify ietf-yang-library is listed as capability in the hello message.
#2 - Verify /modules-state/module[name='test-yang-library'] container is present.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    print(
        "#1 - Verify ietf-yang-library is listed as capability in the hello message."
    )
    print lxml.etree.tostring(result)
    result = litenc_lxml.strip_namespaces(result)
    found = False
    for capability in result.xpath("/hello/capabilities/capability"):
        #print lxml.etree.tostring(capability)
        print capability.text
        if (capability.text.startswith(
                'urn:ietf:params:netconf:capability:yang-library:1.0?')):
            print("Found it:" + capability.text)
            found = True
    assert (found == True)

    print(
        "#2 - Verify /modules-state/module[name='test-yang-library'] container is present."
    )

    get_rpc = """
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <filter type="subtree">
  <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library">
   <module><name>test-yang-library</name></module>
  </modules-state>
 </filter>
</get>
"""
    print("get ...")
    result = conn.rpc(get_rpc)
    result = litenc_lxml.strip_namespaces(result)

    print lxml.etree.tostring(result)
    name = result.xpath('data/modules-state/module/name')
    assert (len(name) == 1)

    namespace = result.xpath('data/modules-state/module/namespace')
    assert (len(namespace) == 1)
    assert (namespace[0].text == "http://yuma123.org/ns/test-yang-library")

    conformance_type = result.xpath(
        'data/modules-state/module/conformance-type')
    assert (len(conformance_type) == 1)
    assert (conformance_type[0].text == "implement")

    feature = result.xpath('data/modules-state/module/feature')
    assert (len(feature) == 1)
    assert (feature[0].text == "foo")

    deviation = result.xpath('data/modules-state/module/deviation/name')
    assert (len(deviation) == 1)
    assert (deviation[0].text == "test-yang-library-deviation")

    get_rpc = """
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <filter type="subtree">
  <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library">
   <module><name>test-yang-library-import</name></module>
  </modules-state>
 </filter>
</get>
"""
    print("get ...")
    result = conn.rpc(get_rpc)
    result = litenc_lxml.strip_namespaces(result)

    print lxml.etree.tostring(result)
    name = result.xpath('data/modules-state/module/name')
    assert (len(name) == 1)

    namespace = result.xpath('data/modules-state/module/namespace')
    assert (len(namespace) == 1)
    assert (
        namespace[0].text == "http://yuma123.org/ns/test-yang-library-import")

    conformance_type = result.xpath(
        'data/modules-state/module/conformance-type')
    assert (len(conformance_type) == 1)
    #assert(conformance_type[0].text=="import")

    return (0)
コード例 #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")
    parser.add_argument(
        "--debug",
        help="show debug messages (not yuma123 library debugging",
        action='store_true')

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    if args.debug:
        DEBUG = True

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print("[FAILED] Connecting to server=%s:" % {'server': server})
        return (-1)
    print("[OK] Connecting to server=%(server)s:" % {'server': server})
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")

    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    results = run_tests(conn, tests)
    ok = True
    for x in results:
        print("%-70.70s : %s" % (x[0], 'PASS' if x[1] == 0 else 'FAIL'))
        if x[1] > 0:
            ok = False

    return 0 if ok else 1
コード例 #6
0
def main():
	print("""
#Description: Connect to opendaylight and <get> /.
#Procedure:
#1 - Print the <hello>
#2 - Print the operational state.
""")

	parser = argparse.ArgumentParser()
	parser.add_argument("--server", help="server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)")
	parser.add_argument("--user", help="username e.g. admin ($USER if not specified)")
	parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
	parser.add_argument("--password", help="password e.g. mypass123 (passwordless if not specified)")

	args = parser.parse_args()

	if(args.server==None or args.server==""):
		server="127.0.0.1"
	else:
		server=args.server

	if(args.port==None or args.port==""):
		port=830
	else:
		port=int(args.port)

	if(args.user==None or args.user==""):
		user=os.getenv('USER')
	else:
		user=args.user

	if(args.password==None or args.password==""):
		password=None
	else:
		password=args.password


	conn_raw = litenc.litenc()
	ret = conn_raw.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print "[FAILED] Connecting to server=%(server)s:" % {'server':server}
		return(-1)
	print "[OK] Connecting to server=%(server)s:" % {'server':server}
	conn=litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
	ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)

	# receive <hello>
	result=conn.receive()

	print("#1 - Print the <hello>")
	print lxml.etree.tostring(result)

        print("#2 - Print the operational state.")

	get_rpc = """
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
</get>
"""
	print("get / ...")
	result = conn.rpc(get_rpc)

	print lxml.etree.tostring(result)

	delete_config_rpc = """
  <edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <config>
      <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
        <module
          xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
          nc:operation="delete">
          <type
            xmlns:sal-netconf="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">sal-netconf:sal-netconf-connector</type>
          <name>left</name>
        </module>
      </modules>
    </config>
  </edit-config>
"""
	print("delete-config ...")
	result = conn.rpc(delete_config_rpc)

	commit_rpc = """
<commit/>
"""
	print("commit ...")
	result = conn.rpc(commit_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('ok')
	assert(len(ok)==1)

	edit_config_rpc = """
  <edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <config>
      <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
        <module
          xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
          nc:operation="merge">
          <type
            xmlns:sal-netconf="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">sal-netconf:sal-netconf-connector</type>
          <name>left</name>
          <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">127.0.0.1</address>
          <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">3830</port>
          <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
          <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">demo</username>
          <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">demo</password>
  <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-event-executor</type>
    <name>global-event-executor</name>
  </event-executor>
  <binding-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
    <name>binding-osgi-broker</name>
  </binding-registry>
  <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
    <name>dom-broker</name>
  </dom-registry>
  <client-dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf">prefix:netconf-client-dispatcher</type>
    <name>global-netconf-dispatcher</name>
  </client-dispatcher>
  <processing-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:threadpool</type>
    <name>global-netconf-processing-executor</name>
  </processing-executor>
  <keepalive-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:scheduled-threadpool</type>
    <name>global-netconf-ssh-scheduled-executor</name>
  </keepalive-executor>
        </module>
      </modules>
    </config>
  </edit-config>
"""


	print("edit-config ...")
	result = conn.rpc(edit_config_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('ok')
	assert(len(ok)==1)

	commit_rpc = """
<commit/>
"""
	print("commit ...")
	result = conn.rpc(commit_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('ok')
	assert(len(ok)==1)

        return(0)
コード例 #7
0
def main():
    print(
        "#Description: Attempt to create a leaf with a conditional identity.")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print("[FAILED] Connecting to server=%s:" % {'server': server})
        return (-1)
    print("[OK] Connecting to server=%(server)s:" % {'server': server})
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")

    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    results = run_tests(conn, tests)
    ok = True
    for x in results:
        print("%-70.70s : %s" % (x[0], 'PASS' if x[1] == 0 else 'FAIL'))
        if x[1] > 0:
            ok = False

    send_rpc(conn, rpc_discard_changes)

    return 0 if ok else 1
コード例 #8
0
def main():
	print("""
#Description: Demonstrate that duplicated list entries in edit-config are detected.
#Procedure:
#1 - Create interface "foo" and commit. Verify commit succeeds.
#2 - Create 2x duplicate interface "bar" and commit. Verify commit fails.
""")

	parser = argparse.ArgumentParser()
	parser.add_argument("--server", help="server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)")
	parser.add_argument("--user", help="username e.g. admin ($USER if not specified)")
	parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
	parser.add_argument("--password", help="password e.g. mypass123 (passwordless if not specified)")

	args = parser.parse_args()

	if(args.server==None or args.server==""):
		server="127.0.0.1"
	else:
		server=args.server

	if(args.port==None or args.port==""):
		port=830
	else:
		port=int(args.port)

	if(args.user==None or args.user==""):
		user=os.getenv('USER')
	else:
		user=args.user

	if(args.password==None or args.password==""):
		password=None
	else:
		password=args.password


	conn_raw = litenc.litenc()
	ret = conn_raw.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print "[FAILED] Connecting to server=%(server)s:" % {'server':server}
		return(-1)
	print "[OK] Connecting to server=%(server)s:" % {'server':server}
	conn=litenc_lxml.litenc_lxml(conn_raw)
	ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)
	(ret, reply_xml)=conn_raw.receive()
	if ret != 0:
		print("[FAILED] Receiving <hello>")
		return(-1)

	print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml':reply_xml}


	print("Connected ...")

	commit_rpc = """
<commit/>
"""
	print("commit ...")
	result = conn.rpc(commit_rpc)

	edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>foo</name>
          <type
            xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
        </interface>
      </interfaces>
    </config>
  </edit-config>
"""
	print("edit-config - create single 'foo' ...")
	result = conn.rpc(edit_config_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('ok')
	print result
	print ok
	print lxml.etree.tostring(result)
	assert(len(ok)==1)

	commit_rpc = """
<commit/>
"""
	print("commit ...")
	result = conn.rpc(commit_rpc)

	edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>bar</name>
          <type
            xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
        </interface>
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>bar</name>
          <type
            xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
        </interface>
      </interfaces>
    </config>
  </edit-config>
"""
	print("edit-config - attempt to create duplicated 'bar's ...")
	result = conn.rpc(edit_config_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('//ok')
	assert(len(ok)!=1)

	edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
      </interfaces>
    </config>
  </edit-config>
"""
	print("edit-config - delete /interfaces ...")
	result = conn.rpc(edit_config_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('//ok')
	assert(len(ok)==1)

	print("commit ...")
	result = conn.rpc(commit_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('//ok')
	assert(len(ok)==1)
コード例 #9
0
ファイル: session.litenc.py プロジェクト: nitzan-tz/yuma123
def main():
	print("""
#Description: Verify netconf-* session-start, etc. notifications are implemented.
#Procedure:
#1 - Open session #1 and <create-subscription>
#2 - Open additional session #2 and verify <netconf-session-start> is sent with correct paramenters on #1.
#3 - TODO
""")

	parser = argparse.ArgumentParser()
	parser.add_argument("--server", help="server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)")
	parser.add_argument("--user", help="username e.g. admin ($USER if not specified)")
	parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
	parser.add_argument("--password", help="password e.g. mypass123 (passwordless if not specified)")
	parser.add_argument("--with-filter-subtree", action='store_true', help="when present create-subscription has a filter to receive only netconf-session-end")

	args = parser.parse_args()

	if(args.server==None or args.server==""):
		server="127.0.0.1"
	else:
		server=args.server

	if(args.port==None or args.port==""):
		port=830
	else:
		port=int(args.port)

	if(args.user==None or args.user==""):
		user=os.getenv('USER')
	else:
		user=args.user

	if(args.password==None or args.password==""):
		password=None
	else:
		password=args.password

	conn = litenc.litenc()
	ret = conn.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print "[FAILED] Connecting to server=%(server)s:" % {'server':server}
		return(-1)
	print "[OK] Connecting to server=%(server)s:" % {'server':server}
	conn_lxml=litenc_lxml.litenc_lxml(conn,strip_namespaces=True)
	ret = conn.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")

#  <capability>urn:ietf:params:netconf:capability:notification:1.0</capability>
#  <capability>urn:ietf:params:netconf:capability:interleave:1.0</capability>
#  <capability>urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?module=ietf-netconf-notifications&amp;revision=2012-02-06</capability>

	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)
	(ret, reply_xml)=conn.receive()
	if ret != 0:
		print("[FAILED] Receiving <hello>")
		return(-1)

	print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml':reply_xml}

	filter=""
	if(args.with_filter_subtree):
		filter="""
<filter xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0" xmlns:netconf="urn:ietf:params:xml:ns:netconf:base:1.0" netconf:type="subtree">
 <netconf-session-end xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"/>
</filter>"""

	ret = conn.send("""
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
 <create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
 %(filter)s
</create-subscription>
</rpc>
"""%{'filter':filter})
	if ret != 0:
		print("[FAILED] Sending <create-subscription>")
		return(-1)

	(ret, reply_xml)=conn.receive()
	if ret != 0:
		print("[FAILED] Receiving <create-subscription> reply")
		return(-1)

	print "[OK] Receiving <create-subscription> reply =%(reply_xml)s:" % {'reply_xml':reply_xml}

	conn2 = litenc.litenc()
	ret = conn2.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print "[FAILED] Connecting to server=%(server)s:" % {'server':server}
		return(-1)
	print "[OK] Connecting to server=%(server)s:" % {'server':server}

	ret = conn2.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)
	(ret, reply_xml)=conn2.receive()
	if ret != 0:
		print("[FAILED] Receiving <hello>")
		return(-1)

	print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml':reply_xml}

	conn2_lxml=litenc_lxml.litenc_lxml(conn2,strip_namespaces=True)
	ret = conn2_lxml.rpc("""
<close-session/>
""")
	if(not args.with_filter_subtree):
		notification_xml=conn_lxml.receive()
		if notification_xml == None:
			print("[FAILED] Receiving <netconf-session-start> notification")
			return(-1)

		print lxml.etree.tostring(notification_xml)

	notification_xml=conn_lxml.receive()
	if notification_xml == None:
		print("[FAILED] Receiving <netconf-session-end> notification")
		return(-1)

	print lxml.etree.tostring(notification_xml)

	notification_xml=litenc_lxml.strip_namespaces(notification_xml)
	match=notification_xml.xpath("/notification/netconf-session-end")
	assert(len(match)==1)

	print "[OK] Receiving <netconf-session-end>"

	return(0)
コード例 #10
0
def main():
    print("""
#Description: Demonstrate that duplicated list entries in edit-config are detected.
#Procedure:
#1 - Create interface "foo" and commit. Verify commit succeeds.
#2 - Create 2x duplicate interface "bar" and commit. Verify commit fails.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    namespaces = {
        "nc": "urn:ietf:params:xml:ns:netconf:base:1.0",
        "test-anyxml":
        "http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml",
        "one": "urn:1",
        "two": "urn:2"
    }

    ping_pong_rpc = """
<ping-pong xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml"><ping><one foo="blah" xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml"><two bar="blaer" xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml">2</two><!--<tree/>--></one></ping></ping-pong>
"""
    print("ping-pong ...")
    (ret, reply_xml) = conn_raw.rpc(ping_pong_rpc)
    print(reply_xml)

    request = lxml.etree.fromstring(ping_pong_rpc)

    reply = lxml.etree.fromstring(reply_xml)
    one_sent = request.xpath("./test-anyxml:ping/test-anyxml:one",
                             namespaces=namespaces)
    one_received = reply.xpath("./test-anyxml:pong/test-anyxml:one",
                               namespaces=namespaces)
    print one_sent
    print one_received
    assert (len(one_sent) == 1)
    assert (len(one_received) == 1)
コード例 #11
0
def main():
    print("""
#Description: Testcase for draft-ietf-netmod-rfc7223bis-00.txt ietf-interfaces module.
#Procedure:
#1 - <edit-config> configuration as in rfc7223bis Appendix D.
#2 - <get-data> the /interfaces container and verify data is same as in rfc7223bis Appendix E.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    get_yang_library_rpc = """
<get>
  <filter type="subtree">
    <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"/>
  </filter>
</get>
"""

    print("<get> - /ietf-yang-library:modules-state ...")
    result = conn.rpc(get_yang_library_rpc, strip_ns=False)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    namespaces = {"nc": "urn:ietf:params:xml:ns:netconf:base:1.0"}
    data = result.xpath('./nc:data', namespaces=namespaces)
    assert (len(data) == 1)
    #Copied from draft-ietf-netmod-rfc7223bis-00 Appendix D.
    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
           xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type"
           xmlns:vlan="http://example.com/vlan"
           nc:operation="replace">
         <interface>
           <name>eth0</name>
           <type>ianaift:ethernetCsmacd</type>
           <enabled>false</enabled>
         </interface>

         <interface>
           <name>eth1</name>
           <type>ianaift:ethernetCsmacd</type>
           <enabled>true</enabled>
           <vlan:vlan-tagging>true</vlan:vlan-tagging>
         </interface>

         <interface>
           <name>eth1.10</name>
           <type>ianaift:l2vlan</type>
           <enabled>true</enabled>
           <vlan:base-interface>eth1</vlan:base-interface>
           <vlan:vlan-id>10</vlan:vlan-id>
         </interface>

         <interface>
           <name>lo1</name>
           <type>ianaift:softwareLoopback</type>
           <enabled>true</enabled>
         </interface>
       </interfaces>
    </config>
</edit-config>
"""

    print("<edit-config> - load Appendix D. example config to 'candidate' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('./ok')
    assert (len(ok) == 1)

    commit_rpc = '<commit/>'

    print("<commit> - commit example config ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('./ok')
    assert (len(ok) == 1)

    get_example_data_rpc = """
<get-data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-datastores">
  <datastore xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">ds:operational</datastore>
  <subtree-filter>
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
  </subtree-filter>
  <with-origin/>
</get-data>
"""

    print("<get-data> - Appendix E. data ...")
    result = conn.rpc(get_example_data_rpc, strip_ns=False)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    namespaces = {
        "ncds": "urn:ietf:params:xml:ns:yang:ietf-netconf-datastores"
    }
    data = result.xpath('./ncds:data', namespaces=namespaces)
    assert (len(data) == 1)
    #Copy from draft-netconf-nmda-netconf-01
    expected = """
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-datastores" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <interfaces
      xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"
      xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type"
      xmlns:vlan="http://example.com/vlan"
      xmlns:or="urn:ietf:params:xml:ns:yang:ietf-origin">
    <interface or:origin="or:intended">
      <name>eth0</name>
      <type>ianaift:ethernetCsmacd</type>
      <enabled>false</enabled>
      <admin-status>down</admin-status>
      <oper-status>down</oper-status>
      <if-index>2</if-index>
      <phys-address>00:01:02:03:04:05</phys-address>
      <statistics>
        <discontinuity-time>
          2013-04-01T03:00:00+00:00
        </discontinuity-time>
        <!-- counters now shown here -->
      </statistics>
    </interface>

    <interface or:origin="or:intended">
      <name>eth1</name>
      <type>ianaift:ethernetCsmacd</type>
      <enabled>true</enabled>
      <admin-status>up</admin-status>
      <oper-status>up</oper-status>
      <if-index>7</if-index>
      <phys-address>00:01:02:03:04:06</phys-address>
      <higher-layer-if>eth1.10</higher-layer-if>
      <statistics>
        <discontinuity-time>
          2013-04-01T03:00:00+00:00
        </discontinuity-time>
       <!-- counters now shown here -->
     </statistics>
      <vlan:vlan-tagging>true</vlan:vlan-tagging>
    </interface>
    <interface or:origin="or:intended">
      <name>eth1.10</name>
      <type>ianaift:l2vlan</type>
      <enabled>true</enabled>
      <admin-status>up</admin-status>
      <oper-status>up</oper-status>
      <if-index>9</if-index>
      <lower-layer-if>eth1</lower-layer-if>
      <statistics>
       <discontinuity-time>
         2013-04-01T03:00:00+00:00
        </discontinuity-time>
        <!-- counters now shown here -->
      </statistics>
      <vlan:base-interface>eth1</vlan:base-interface>
     <vlan:vlan-id>10</vlan:vlan-id>
    </interface>
    <!-- This interface is not configured -->
    <interface or:origin="or:system">
      <name>eth2</name>
      <type>ianaift:ethernetCsmacd</type>
      <admin-status>down</admin-status>
      <oper-status>down</oper-status>
      <if-index>8</if-index>
      <phys-address>00:01:02:03:04:07</phys-address>
      <statistics>
        <discontinuity-time>
          2013-04-01T03:00:00+00:00
        </discontinuity-time>
        <!-- counters now shown here -->
      </statistics>
     </interface>
     <interface or:origin="or:intended">
      <name>lo1</name>
      <type>ianaift:softwareLoopback</type>
      <enabled>true</enabled>
      <admin-status>up</admin-status>
      <oper-status>up</oper-status>
      <if-index>1</if-index>
      <statistics>
        <discontinuity-time>
          2013-04-01T03:00:00+00:00
        </discontinuity-time>
        <!-- counters now shown here -->
      </statistics>
    </interface>
  </interfaces>
</data>
"""

    expected = lxml.etree.fromstring(expected)

    #strip comments
    comments = expected.xpath('//comment()')
    for c in comments:
        p = c.getparent()
        p.remove(c)

#strip namespaces
    data1 = expected.xpath('.', namespaces=namespaces)
    data_expected = strip_namespaces(data1[0])
    data_received = strip_namespaces(data[0])

    #sort schema lists by key in alphabetical key order - hardcoded /interfaces/interface[name]
    for node in data_expected.findall("./interfaces"):
        node[:] = sorted(node, key=lambda child: get_interface_name(child))
    for node in data_received.findall("./interfaces"):
        node[:] = sorted(node, key=lambda child: get_interface_name(child))

    #sort attributes
    a = StringIO()
    b = StringIO()
    data_expected.write_c14n(a)
    data_received.write_c14n(b)

    print("Expected:")
    print(a.getvalue())
    print("Received:")
    print(b.getvalue())
    if yang_data_equal(lxml.etree.fromstring(a.getvalue()),
                       lxml.etree.fromstring(b.getvalue())):
        print "Bingo!"
        return 0
    else:
        print "Error: YANG data not equal!"
        return 1
コード例 #12
0
def main():
    print("""
#Description: Testcase for draft-ietf-netmod-rfc7277bis-00.txt ietf-ip module.
#Procedure:
#1 - <edit-config> configuration as in rfc7277bis Appendix A.
#2 - <get-data> the /interfaces container and verify data is same as in rfc7277bis Appendix B.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    get_yang_library_rpc = """
<get>
  <filter type="subtree">
    <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"/>
  </filter>
</get>
"""

    print("<get> - /ietf-yang-library:modules-state ...")
    result = conn.rpc(get_yang_library_rpc, strip_ns=False)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    namespaces = {"nc": "urn:ietf:params:xml:ns:netconf:base:1.0"}
    data = result.xpath('./nc:data', namespaces=namespaces)
    assert (len(data) == 1)
    #Copied from draft-ietf-netmod-rfc7277bis-00 Appendix A.
    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
       <interfaces
           xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"
           xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">
         <interface>
           <name>eth0</name>
           <type>ianaift:ethernetCsmacd</type>
           <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
             <address>
               <ip>192.0.2.1</ip>
               <prefix-length>24</prefix-length>
             </address>
           </ipv4>
           <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
             <mtu>1280</mtu>
             <address>
               <ip>2001:db8::10</ip>
               <prefix-length>32</prefix-length>
             </address>
             <dup-addr-detect-transmits>0</dup-addr-detect-transmits>
           </ipv6>
         </interface>
       </interfaces>
    </config>
</edit-config>
"""

    print("<edit-config> - load Appendix B. example config to 'candidate' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('./ok')
    assert (len(ok) == 1)

    commit_rpc = '<commit/>'

    print("<commit> - commit example config ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('./ok')
    assert (len(ok) == 1)

    get_example_data_rpc = """
<get-data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-datastores">
  <datastore xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">ds:operational</datastore>
  <subtree-filter>
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
  </subtree-filter>
  <with-origin/>
</get-data>
"""

    print("<get-data> - Appendix B. data ...")
    result = conn.rpc(get_example_data_rpc, strip_ns=False)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    namespaces = {
        "ncds": "urn:ietf:params:xml:ns:yang:ietf-netconf-datastores"
    }
    data = result.xpath('./ncds:data', namespaces=namespaces)
    assert (len(data) == 1)
    #Copy from draft-netconf-nmda-netconf-01
    #removed  <forwarding>false</forwarding> if this is the default value then enabled should also be present
    #removed  <mtu>1500</mtu> since it is not in the configuration
    #add or:origin="or:learned" to the ipv4 neighbor
    #removed   <forwarding>false</forwarding> from ipv6 since it is not in the configuration

    expected = """
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-datastores" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
       <interfaces
           xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"
           xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type"
           xmlns:or="urn:ietf:params:xml:ns:yang:ietf-origin">
         <interface or:origin="or:intended">
           <name>eth0</name>
           <type>ianaift:ethernetCsmacd</type>
           <!-- other parameters from ietf-interfaces omitted -->
           <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
             <address>
               <ip>192.0.2.1</ip>
               <prefix-length>24</prefix-length>
               <origin>static</origin>
             </address>
             <neighbor or:origin="or:learned">
               <ip>192.0.2.2</ip>
               <link-layer-address>
                 00:01:02:03:04:05
               </link-layer-address>
             </neighbor>
           </ipv4>
           <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
             <mtu>1280</mtu>
             <address>
               <ip>2001:db8::10</ip>
               <prefix-length>32</prefix-length>
               <origin>static</origin>
               <status>preferred</status>
             </address>
             <address or:origin="or:learned">
               <ip>2001:db8::1:100</ip>
               <prefix-length>32</prefix-length>
               <origin>dhcp</origin>
               <status>preferred</status>
             </address>
             <dup-addr-detect-transmits>0</dup-addr-detect-transmits>
             <neighbor or:origin="or:learned">
               <ip>2001:db8::1</ip>
               <link-layer-address>
                 00:01:02:03:04:05
               </link-layer-address>
               <origin>dynamic</origin>
               <is-router/>
               <state>reachable</state>
             </neighbor>
             <neighbor or:origin="or:learned">
               <ip>2001:db8::4</ip>
               <origin>dynamic</origin>
               <state>incomplete</state>
             </neighbor>
           </ipv6>
         </interface>
       </interfaces>
</data>
"""

    expected = lxml.etree.fromstring(expected)

    #strip comments
    comments = expected.xpath('//comment()')
    for c in comments:
        p = c.getparent()
        p.remove(c)

#strip namespaces
    data1 = expected.xpath('.', namespaces=namespaces)
    data_expected = strip_namespaces(data1[0])
    data_received = strip_namespaces(data[0])

    #sort schema lists by key in alphabetical key order - hardcoded /interfaces/interface[name]
    for node in data_expected.findall("./interfaces"):
        node[:] = sorted(node, key=lambda child: get_interface_name(child))
    for node in data_received.findall("./interfaces"):
        node[:] = sorted(node, key=lambda child: get_interface_name(child))

    #sort attributes
    a = StringIO()
    b = StringIO()
    data_expected.write_c14n(a)
    data_received.write_c14n(b)

    print("Expected:")
    print(a.getvalue())
    print("Received:")
    print(b.getvalue())
    if yang_data_equal(lxml.etree.fromstring(a.getvalue()),
                       lxml.etree.fromstring(b.getvalue())):
        print "Bingo!"
        return 0
    else:
        print "Error: YANG data not equal!"
        return 1
コード例 #13
0
def main():
	print("""
#Description: Connect to opendaylight and <get> /.
#Procedure:
#1 - Print the <hello>
#2 - Print the operational state.
""")

	parser = argparse.ArgumentParser()
	parser.add_argument("--server", help="server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)")
	parser.add_argument("--user", help="username e.g. admin ($USER if not specified)")
	parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
	parser.add_argument("--password", help="password e.g. mypass123 (passwordless if not specified)")

	args = parser.parse_args()

	if(args.server==None or args.server==""):
		server="127.0.0.1"
	else:
		server=args.server

	if(args.port==None or args.port==""):
		port=830
	else:
		port=int(args.port)

	if(args.user==None or args.user==""):
		user=os.getenv('USER')
	else:
		user=args.user

	if(args.password==None or args.password==""):
		password=None
	else:
		password=args.password


	conn_raw = litenc.litenc()
	ret = conn_raw.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print "[FAILED] Connecting to server=%(server)s:" % {'server':server}
		return(-1)
	print "[OK] Connecting to server=%(server)s:" % {'server':server}
	conn=litenc_lxml.litenc_lxml(conn_raw)
	ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)

	# receive <hello>
	result=conn.receive()

	print("#1 - Print the <hello>")
	print lxml.etree.tostring(result)

        print("#2 - Print the operational state.")

	get_rpc = """
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <filter type="xpath" select="/">
 </filter>
</get>
"""
	print("get / ...")
	result = conn.rpc(get_rpc)

	print lxml.etree.tostring(result)

        return(0)
コード例 #14
0
def main():
    print("""
#Description: Demonstrate that duplicated list entries in edit-config are detected.
#Procedure:
#Description: Using sub-interfaces configure vlan bridge.
#Procedure:
#1 - Create interface "xe0", "ge0", "ge1" of type=ethernetCsmacd.
#2 - Create sub-interface "xe0-green" - s-vlan-id=1000, "ge1-green" - c-vlan-id=10 of type=ethSubInterface.
#3 - Create VLAN bridge with "ge0", "ge1-green" and "xe0-green".
#4 - Commit.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)

    edit_config_rpc = """
<edit-config>
   <target>
     <candidate/>
   </target>
   <default-operation>merge</default-operation>
   <test-option>set</test-option>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
    <interface>
      <name>ge0</name>
      <type
        xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
    </interface>
    <interface>
      <name>ge1</name>
      <type
        xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
    </interface>
    <interface>
      <name>ge1-green</name>
      <type
        xmlns:if-cmn="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">if-cmn:ethSubInterface</type>
      <encapsulation xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">
        <flexible xmlns="urn:ietf:params:xml:ns:yang:ietf-flexible-encapsulation">
          <match>
            <dot1q-vlan-tagged>
              <outer-tag>
                <dot1q-tag>
                  <tag-type
                    xmlns:dot1q-types="urn:ieee:std:802.1Q:yang:ieee802-dot1q-types">dot1q-types:c-vlan</tag-type>
                  <vlan-id>10</vlan-id>
                </dot1q-tag>
              </outer-tag>
            </dot1q-vlan-tagged>
          </match>
        </flexible>
      </encapsulation>
      <forwarding-mode xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces-common" xmlns:if-cmn="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">if-cmn:layer-2-forwarding</forwarding-mode>
      <parent-interface xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">ge0</parent-interface>
    </interface>
    <interface>
      <name>xe0</name>
      <type
        xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
    </interface>
    <interface>
      <name>xe0-green</name>
      <type
        xmlns:if-cmn="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">if-cmn:ethSubInterface</type>
      <encapsulation xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">
        <flexible xmlns="urn:ietf:params:xml:ns:yang:ietf-flexible-encapsulation">
          <match>
            <dot1q-vlan-tagged>
              <outer-tag>
                <dot1q-tag>
                  <tag-type
                    xmlns:dot1q-types="urn:ieee:std:802.1Q:yang:ieee802-dot1q-types">dot1q-types:s-vlan</tag-type>
                  <vlan-id>1000</vlan-id>
                </dot1q-tag>
              </outer-tag>
              <second-tag>
                <dot1q-tag>
                  <tag-type
                    xmlns:dot1q-types="urn:ieee:std:802.1Q:yang:ieee802-dot1q-types">dot1q-types:c-vlan</tag-type>
                  <vlan-id>10</vlan-id>
                </dot1q-tag>
              </second-tag>
            </dot1q-vlan-tagged>
          </match>
        </flexible>
      </encapsulation>
      <forwarding-mode xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces-common" xmlns:if-cmn="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">if-cmn:layer-2-forwarding</forwarding-mode>
      <parent-interface xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces-common">xe0</parent-interface>
    </interface>
  </interfaces>
  <nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"/>
  <vlans xmlns="http://example.com/ns/vlans">
    <vlan>
      <name>green</name>
      <interface>ge0</interface>
      <interface>ge1-green</interface>
      <interface>xe0-green</interface>
    </vlan>
  </vlans>
</config>
 </edit-config>
"""
    print("edit-config - create vlan ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
   <target>
     <candidate/>
   </target>
   <default-operation>merge</default-operation>
   <test-option>set</test-option>
 <config>
  <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
  </interfaces>
  <vlans xmlns="http://example.com/ns/vlans" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
  </vlans>
 </config>
 </edit-config>
"""
    print("edit-config - clean-up ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)
コード例 #15
0
def main():
    print("""
#Description: Test instance-identifier built-in type.
#Procedure:
#1 - Create  /top/list[idx="4"] and /top/id-list[id="/top/list[idx=\"4\"]"].
#2 - Try to create /top/id-list[id="/top/list[idx=\"5\"]"].
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <top xmlns="http://yuma123.org/ns/test-instance-identifier" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
      </top>
    </config>
  </edit-config>
"""
    print("edit-config ...")
    result = conn.rpc(edit_config_rpc)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    print(
        '''#1 - Create  /top/list[idx="4"] and /top/id-list[id="/top/list[idx=\"4\"]"].'''
    )
    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <top xmlns="http://yuma123.org/ns/test-instance-identifier">
          <list xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
              <idx>4</idx>
          </list>
          <id-list xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
              <id xmlns:tii="http://yuma123.org/ns/test-instance-identifier">/tii:top/tii:list[tii:idx="4"]</id>
          </id-list>
      </top>
    </config>
  </edit-config>
"""
    #          <id-list xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
    #              <id>/top/list[idx=4]</id>
    #          </id-list>

    print("edit-config ...")
    result = conn.rpc(edit_config_rpc)
    print result
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    print('''#2 - Try to create /top/id-list[id="/top/list[idx=\"5\"]"].''')

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <top xmlns="http://yuma123.org/ns/test-instance-identifier">
          <id-list xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
              <id xmlns:tii="http://yuma123.org/ns/test-instance-identifier">/tii:top/tii:list[tii:idx="5"]</id>
          </id-list>
      </top>
    </config>
  </edit-config>
"""

    print("edit-config ...")
    result = conn.rpc(edit_config_rpc)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    print result
    ok = result.xpath('//ok')
    assert (len(ok) == 0)

    discard_changes_rpc = """
<discard-changes/>
"""
    print("discard-changes ...")
    result = conn.rpc(discard_changes_rpc)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <top xmlns="http://yuma123.org/ns/test-instance-identifier" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
      </top>
    </config>
  </edit-config>
"""
    print("edit-config ...")
    result = conn.rpc(edit_config_rpc)
    result = conn.rpc(commit_rpc)
    ok = result.xpath('//ok')

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)
コード例 #16
0
def main():
    print("""
#Description: Send invalid configuration.  Check later to see if
# netconfd crashed.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    print("# send invalid value for union element of leaf-list")

    get_rpc = """
<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <target>
    <candidate/>
  </target>
  <default-operation>merge</default-operation>
  <test-option>set</test-option>
  <config>
    <test
      xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
      nc:operation="create"
      xmlns="http://yuma123.org/ns/test-leaflist-union-test">
      <address>this should not work</address>
    </test>
  </config>
</edit-config>
"""
    print("edit-config ...")
    result = conn.rpc(get_rpc)
    result = litenc_lxml.strip_namespaces(result)

    print lxml.etree.tostring(result)

    return (0)
コード例 #17
0
ファイル: session.litenc.py プロジェクト: xorrkaz/yuma123
def main():
    print("""
#Description: Demonstrate that re-match works.
#Procedure:
#1 - Validate 1.22.333 is accepted as /xpath-re-match-test-string value.
#2 - Validate a.bb.ccc is not accepted as /xpath-re-match-test-string value..
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <test-xpath-re-match-string xmlns="http://yuma123.org/ns/test-xpath-re-match">1.22.333</test-xpath-re-match-string>
    </config>
  </edit-config>
"""
    print("edit-config - create  'test-xpath-re-match-string=1.22.333' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <test-xpath-re-match-string xmlns="http://yuma123.org/ns/test-xpath-re-match" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"/>
    </config>
  </edit-config>
"""
    print("edit-config - delete 'test-xpath-re-match-string' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <test-xpath-re-match-string xmlns="http://yuma123.org/ns/test-xpath-re-match">a.bb.ccc</test-xpath-re-match-string>
    </config>
  </edit-config>
"""
    print("edit-config - create  'test-xpath-re-match-string=a.bb.ccc' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)
    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) != 1)
コード例 #18
0
ファイル: session.litenc.py プロジェクト: xorrkaz/yuma123
def main():
    print("""
#Description: Demonstrate that derived-from() works.
#Procedure:
#1 - Create interfaces foo type=fast-ethernet and bar type=other.
#2 - Validate ethernet-mac leaf can be commited on foo.
#3 - Validate ethernet-mac leaf can not be commited on bar.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"/>
    </config>
  </edit-config>
"""
    print("edit-config - delete /interfaces ...")
    result = conn.rpc(edit_config_rpc)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>foo</name>
          <type
            xmlns:txfd="http://yuma123.org/ns/test-xpath-derived-from">txfd:fast-ethernet</type>
        </interface>
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>bar</name>
          <type
            xmlns:txfd="http://yuma123.org/ns/test-xpath-derived-from">txfd:other</type>
        </interface>
      </interfaces>
    </config>
  </edit-config>
"""
    print("edit-config - create  'foo' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface>
          <name>foo</name>
          <ethernet-mac xmlns="http://yuma123.org/ns/test-xpath-derived-from" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">01:23:45:67:89:AB</ethernet-mac>
        </interface>
      </interfaces>
    </config>
  </edit-config>
"""
    print("edit-config - create  'foo' ethernet-mac ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface>
          <name>bar</name>
          <ethernet-mac xmlns="http://yuma123.org/ns/test-xpath-derived-from" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">01:23:45:67:89:AB</ethernet-mac>
        </interface>
      </interfaces>
    </config>
  </edit-config>
"""
    print("edit-config - create  'bar' ethernet-mac ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    #assert(len(ok)==0)
    commit_rpc = """
<commit/>
"""
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    get_config_rpc = """
<get-config>
 <source>
  <running/>
 </source>
</get-config>
"""
    print("get-config ...")
    result = conn.rpc(get_config_rpc)

    ethernet_mac_foo = result.xpath(
        'data/interfaces/interface[name="foo"]/ethernet-mac')
    ethernet_mac_bar = result.xpath(
        'data/interfaces/interface[name="bar"]/ethernet-mac')
    assert (len(ethernet_mac_foo) == 1)
    assert (len(ethernet_mac_bar) == 0)
コード例 #19
0
def main():
    print("""
#Description: Demonstrate that deref() works.
#Procedure:
#1 - Create interfaces foo enabled=true and bar enabled=false.
#2 - Validate management-interface/name=foo can be created.
#3 - Validate management-interface/name=bar can not be created.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"/>
    </config>
  </edit-config>
"""
    print("edit-config - delete /interfaces ...")
    result = conn.rpc(edit_config_rpc)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>foo</name>
          <type
            xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
          <enabled>true</enabled>
        </interface>
        <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
          <name>bar</name>
          <type
            xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
          <enabled>false</enabled>
        </interface>
      </interfaces>
    </config>
  </edit-config>
"""
    print("edit-config - create  'foo and bar' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
        <mgmt-interface xmlns="http://yuma123.org/ns/test-xpath-deref"><name>foo</name><type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type></mgmt-interface>
    </config>
  </edit-config>
"""
    print("edit-config - create mgmt-interface=foo ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
        <mgmt-interface xmlns="http://yuma123.org/ns/test-xpath-deref"><name>foo</name><type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type></mgmt-interface>
    </config>
  </edit-config>
"""
    print("edit-config - delete mgmt-interface ...")
    result = conn.rpc(edit_config_rpc)

    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
        <mgmt-interface xmlns="http://yuma123.org/ns/test-xpath-deref"><name>bar</name><type>ianaift:ethernetCsmacd</type></mgmt-interface>
    </config>
  </edit-config>
"""
    print("edit-config - create mgmt-interface=bar ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) == 1)

    print("commit ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('//ok')
    assert (len(ok) != 1)
コード例 #20
0
def main():
    print(
        "#Description: Attempt to create a leaf with a conditional identity.")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")
    parser.add_argument("--expectfail",
                        help="Feature is disabled and RPC is expected to fail",
                        action='store_true')

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print("[FAILED] Connecting to server=%s:" % {'server': server})
        return (-1)
    print("[OK] Connecting to server=%(server)s:" % {'server': server})
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")

    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    exp = None
    if args.expectfail:
        exp = ['//bad-value']

    rv, reply = send_rpc(conn, rpc_discard_changes)
    if rv > 0:
        return rv

    rv, reply = send_rpc(conn, rpc_create, exp)
    if rv > 0:
        return rv

    return 0
コード例 #21
0
def main():
    print("""
#Description: Testcase for draft-ietf-netmod-rfc8022bis-04 ietf-routing module.
#Procedure:
#1 - <edit-config> configuration as in rfc8022bis Appendix D.
#2 - <get-data> the /interfaces and /routing containers and verify data is same as in rfc8022bis Appendix E.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    get_yang_library_rpc = """
<get>
  <filter type="subtree">
    <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"/>
  </filter>
</get>
"""

    print("<get> - /ietf-yang-library:modules-state ...")
    result = conn.rpc(get_yang_library_rpc, strip_ns=False)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    namespaces = {"nc": "urn:ietf:params:xml:ns:netconf:base:1.0"}
    data = result.xpath('./nc:data', namespaces=namespaces)
    assert (len(data) == 1)
    #Copied from draft-ietf-netmod-rfc8022bis-00 Appendix E.
    json_config = """
   {
     "ietf-interfaces:interfaces": {
       "interface": [
         {
           "name": "eth0",
           "type": "iana-if-type:ethernetCsmacd",
           "description": "Uplink to ISP.",
           "phys-address": "00:0C:42:E5:B1:E9",
           "oper-status": "up",
           "statistics": {
             "discontinuity-time": "2015-10-24T17:11:27+02:00"
           },
           "ietf-ip:ipv4": {
             "forwarding": true,
             "mtu": 1500,
             "address": [
               {
                 "ip": "192.0.2.1",
                 "prefix-length": 24
               }
             ],
           },
           "ietf-ip:ipv6": {
             "forwarding": true,
             "mtu": 1500,
             "address": [
               {
                 "ip": "2001:0db8:0:1::1",
                 "prefix-length": 64
               }
             ],
             "autoconf": {
               "create-global-addresses": false
             }
             "ietf-ipv6-unicast-routing:
                ipv6-router-advertisements": {
               "send-advertisements": false
             }
           }
         },
         {
           "name": "eth1",
           "type": "iana-if-type:ethernetCsmacd",
           "description": "Interface to the internal network.",
           "phys-address": "00:0C:42:E5:B1:EA",
           "oper-status": "up",
           "statistics": {
             "discontinuity-time": "2015-10-24T17:11:29+02:00"
           },
           "ietf-ip:ipv4": {
             "forwarding": true,
             "mtu": 1500,
             "address": [
               {
                 "ip": "198.51.100.1",
                 "prefix-length": 24
               }
             ],
           },
           "ietf-ip:ipv6": {
             "forwarding": true,
             "mtu": 1500,
             "address": [
               {
                 "ip": "2001:0db8:0:2::1",
                 "prefix-length": 64
               }
             ],
             "autoconf": {
               "create-global-addresses": false
             },
             "ietf-ipv6-unicast-routing:
                ipv6-router-advertisements": {
               "send-advertisements": true,
               "prefix-list": {
                 "prefix": [
                   {
                     "prefix-spec": "2001:db8:0:2::/64"
                   }
                 ]
               }
             }
           }
         }
       ]
     },

     "ietf-routing:routing": {
       "router-id": "192.0.2.1",
       "control-plane-protocols": {
         "control-plane-protocol": [
           {
             "type": "ietf-routing:static",
             "name": "st0",
             "description":
               "Static routing is used for the internal network.",
             "static-routes": {
               "ietf-ipv4-unicast-routing:ipv4": {
                 "route": [
                   {
                     "destination-prefix": "0.0.0.0/0",
                     "next-hop": {
                       "next-hop-address": "192.0.2.2"
                     }
                   }
                 ]
               },
               "ietf-ipv6-unicast-routing:ipv6": {
                 "route": [
                   {
                     "destination-prefix": "::/0",
                     "next-hop": {
                       "next-hop-address": "2001:db8:0:1::2"
                     }
                   }
                 ]
               }
             }
           }
         ]
       }
       "ribs": {
         "rib": [
           {
             "name": "ipv4-master",
             "address-family":
               "ietf-ipv4-unicast-routing:ipv4-unicast",
             "default-rib": true,
             "routes": {
               "route": [
                 {
                   "ietf-ipv4-unicast-routing:destination-prefix":
                     "192.0.2.1/24",
                   "next-hop": {
                     "outgoing-interface": "eth0"
                   },
                   "route-preference": 0,
                   "source-protocol": "ietf-routing:direct",
                   "last-updated": "2015-10-24T17:11:27+02:00"
                 },
                 {
                   "ietf-ipv4-unicast-routing:destination-prefix":
                     "198.51.100.0/24",
                   "next-hop": {
                     "outgoing-interface": "eth1"
                   },
                   "source-protocol": "ietf-routing:direct",
                   "route-preference": 0,
                   "last-updated": "2015-10-24T17:11:27+02:00"
                 },
                 {
                   "ietf-ipv4-unicast-routing:destination-prefix":
                     "0.0.0.0/0",
                   "source-protocol": "ietf-routing:static",
                   "route-preference": 5,
                   "next-hop": {
                     "ietf-ipv4-unicast-routing:next-hop-address":
                       "192.0.2.2"
                   },
                   "last-updated": "2015-10-24T18:02:45+02:00"
                 }
               ]
             }
           },
           {
             "name": "ipv6-master",
             "address-family":
               "ietf-ipv6-unicast-routing:ipv6-unicast",
             "default-rib": true,
             "routes": {
               "route": [
                 {
                   "ietf-ipv6-unicast-routing:destination-prefix":
                     "2001:db8:0:1::/64",
                   "next-hop": {
                     "outgoing-interface": "eth0"
                   },
                   "source-protocol": "ietf-routing:direct",
                   "route-preference": 0,
                   "last-updated": "2015-10-24T17:11:27+02:00"
                 },
                 {
                   "ietf-ipv6-unicast-routing:destination-prefix":
                     "2001:db8:0:2::/64",
                   "next-hop": {
                     "outgoing-interface": "eth1"
                   },
                   "source-protocol": "ietf-routing:direct",
                   "route-preference": 0,
                   "last-updated": "2015-10-24T17:11:27+02:00"
                 },
                 {
                   "ietf-ipv6-unicast-routing:destination-prefix":
                     "::/0",
                   "next-hop": {
                     "ietf-ipv6-unicast-routing:next-hop-address":
                       "2001:db8:0:1::2"
                   },
                   "source-protocol": "ietf-routing:static",
                   "route-preference": 5,
                   "last-updated": "2015-10-24T18:02:45+02:00"
                 }
               ]
             }
           }
         ]
       }
     },
   }
"""
    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
    %(xml_config)
    </config>
</edit-config>
""" % {
        'xml_config': json2xml(json_config)
    }

    print("<edit-config> - load Appendix D. example config to 'candidate' ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('./ok')
    assert (len(ok) == 1)

    commit_rpc = '<commit/>'

    print("<commit> - commit example config ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result)
    ok = result.xpath('./ok')
    assert (len(ok) == 1)

    get_example_data_rpc = """
<get-data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-datastores">
  <datastore xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">ds:operational</datastore>
  <subtree-filter>
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
    <routing xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/>
  </subtree-filter>
  <with-origin/>
</get-data>
"""

    print("<get-data> - Appendix E. data ...")
    result = conn.rpc(get_example_data_rpc, strip_ns=False)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    namespaces = {
        "ncds": "urn:ietf:params:xml:ns:yang:ietf-netconf-datastores"
    }
    data = result.xpath('./ncds:data', namespaces=namespaces)
    assert (len(data) == 1)

    expected = """
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-datastores" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
      <routing
        xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"
        xmlns:or="urn:ietf:params:xml:ns:yang:ietf-origin">

        <router-id or:origin="or:intended">192.0.2.1</router-id>
        <control-plane-protocols or:origin="or:intended">
          <control-plane-protocl>
            <type>ietf-routing:static</type>
            <name></name>
            <static-routes>
              <ietf-ipv4-unicast-routing:ipv4>
                <route>
                  <destination-prefix>0.0.0.0/0</destination-prefix>
                  <next-hop>
                    <next-hop-address>192.0.2.2</next-hop-address>
                  </next-hop>
                </route>
              </ietf-ipv4-unicast-routing:ipv4>
              <ietf-ipv6-unicast-routing:ipv6>
                <route>
                  <destination-prefix>::/0</destination-prefix>
                  <next-hop>
                    <next-hop-address>2001:db8:0:1::2</next-hop-address>
                  </next-hop>
                </route>
              </ietf-ipv6-unicast-routing:ipv6>
            </static-routes>
          </control-plane-protocl>
        </control-plane-protocols>

        <ribs>
          <rib or:origin="or:intended">
            <name>ipv4-master</name>
            <address-family>
              ietf-ipv4-unicast-routing:ipv4-unicast
            </address-family>
            <default-rib>true</default-rib>
            <routes>
              <route>
                <ietf-ipv4-unicast-routing:destination-prefix>
                  192.0.2.1/24
                </ietf-ipv4-unicast-routing:destination-prefix>
                <next-hop>
                  <outgoing-interface>eth0</outgoing-interface>

                </next-hop>
                <route-preference>0</route-preference>
                <source-protocol>ietf-routing:direct</source-protocol>
                <last-updated>2015-10-24T17:11:27+02:00</last-updated>
              </route>
              <route>
                <ietf-ipv4-unicast-routing:destination-prefix>
                  98.51.100.0/24
                </ietf-ipv4-unicast-routing:destination-prefix>
                <next-hop>
                  <outgoing-interface>eth1</outgoing-interface>
                </next-hop>
                <route-preference>0</route-preference>
                <source-protocol>ietf-routing:direct</source-protocol>
                <last-updated>2015-10-24T17:11:27+02:00</last-updated>
              </route>
              <route>
                <ietf-ipv4-unicast-routing:destination-prefix>0.0.0.0/0
                </ietf-ipv4-unicast-routing:destination-prefix>
                <next-hop>
                  <ietf-ipv4-unicast-routing:next-hop-address>192.0.2.2
                  </ietf-ipv4-unicast-routing:next-hop-address>
                </next-hop>
                <route-preference>5</route-preference>
                <source-protocol>ietf-routing:static</source-protocol>
                <last-updated>2015-10-24T18:02:45+02:00</last-updated>
              </route>
            </routes>
          </rib>
          <rib or:origin="or:intended">
            <name>ipv6-master</name>
            <address-family>
              ietf-ipv6-unicast-routing:ipv6-unicast
            </address-family>
            <default-rib>true</default-rib>
            <routes>
              <route>
                <ietf-ipv6-unicast-routing:destination-prefix>
                  2001:db8:0:1::/64
                </ietf-ipv6-unicast-routing:destination-prefix>
                <next-hop>
                  <outgoing-interface>eth0</outgoing-interface>
                </next-hop>
                <route-preference>0</route-preference>
                <source-protocol>ietf-routing:direct</source-protocol>
                <last-updated>2015-10-24T17:11:27+02:00</last-updated>
              </route>
              <route>
                <ietf-ipv6-unicast-routing:destination-prefix>
                  2001:db8:0:2::/64
                </ietf-ipv6-unicast-routing:destination-prefix>
                <next-hop>
                  <outgoing-interface>eth1</outgoing-interface>
                </next-hop>
                <route-preference>0</route-preference>
                <source-protocol>ietf-routing:direct</source-protocol>
                <last-updated>2015-10-24T17:11:27+02:00</last-updated>
              </route>
              <route>
                <ietf-ipv6-unicast-routing:destination-prefix>::/0
                </ietf-ipv6-unicast-routing:destination-prefix>
                <next-hop>
                  <ietf-ipv6-unicast-routing:next-hop-address>
                    2001:db8:0:1::2
                  </ietf-ipv6-unicast-routing:next-hop-address>
                </next-hop>
                <route-preference>5</route-preference>
                <source-protocol>ietf-routing:static</source-protocol>
                <last-updated>2015-10-24T18:02:45+02:00</last-updated>
              </route>
            </routes>
          </rib>
        </ribs>
      </routing>
</data>
"""

    expected = lxml.etree.fromstring(expected)

    #strip comments
    comments = expected.xpath('//comment()')
    for c in comments:
        p = c.getparent()
        p.remove(c)

#strip namespaces
    data1 = expected.xpath('.', namespaces=namespaces)
    data_expected = strip_namespaces(data1[0])
    data_received = strip_namespaces(data[0])

    #sort schema lists by key in alphabetical key order - hardcoded /interfaces/interface[name]
    for node in data_expected.findall("./interfaces"):
        node[:] = sorted(node, key=lambda child: get_interface_name(child))
    for node in data_received.findall("./interfaces"):
        node[:] = sorted(node, key=lambda child: get_interface_name(child))

    #sort attributes
    a = StringIO()
    b = StringIO()
    data_expected.write_c14n(a)
    data_received.write_c14n(b)

    print("Expected:")
    print(a.getvalue())
    print("Received:")
    print(b.getvalue())
    if yang_data_equal(lxml.etree.fromstring(a.getvalue()),
                       lxml.etree.fromstring(b.getvalue())):
        print "Bingo!"
        return 0
    else:
        print "Error: YANG data not equal!"
        return 1
コード例 #22
0
def main():
	print("""
#Description: Testcase for RFC8022 ietf-routing module.
#Procedure:
#1 - <edit-config> configuration as in RFC8022 Appendix D.
#2 - <get> the /interfaces /interfaces-state /routing /routing-state and verify data is same as in RFC8022 Appendix D.
""")

	parser = argparse.ArgumentParser()
	parser.add_argument("--server", help="server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)")
	parser.add_argument("--user", help="username e.g. admin ($USER if not specified)")
	parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
	parser.add_argument("--password", help="password e.g. mypass123 (passwordless if not specified)")

	args = parser.parse_args()

	if(args.server==None or args.server==""):
		server="127.0.0.1"
	else:
		server=args.server

	if(args.port==None or args.port==""):
		port=830
	else:
		port=int(args.port)

	if(args.user==None or args.user==""):
		user=os.getenv('USER')
	else:
		user=args.user

	if(args.password==None or args.password==""):
		password=None
	else:
		password=args.password


	conn_raw = litenc.litenc()
	ret = conn_raw.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print "[FAILED] Connecting to server=%(server)s:" % {'server':server}
		return(-1)
	print "[OK] Connecting to server=%(server)s:" % {'server':server}
	conn=litenc_lxml.litenc_lxml(conn_raw,strip_namespaces=True)
	ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)
	(ret, reply_xml)=conn_raw.receive()
	if ret != 0:
		print("[FAILED] Receiving <hello>")
		return(-1)

	print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml':reply_xml}

	print("Connected ...")

	get_yang_library_rpc = """
<get>
  <filter type="subtree">
    <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"/>
  </filter>
</get>
"""

	print("<get> - /ietf-yang-library:modules-state ...")
	result = conn.rpc(get_yang_library_rpc, strip_ns=False)
	print lxml.etree.tostring(result, pretty_print=True, inclusive_ns_prefixes=True)
        namespaces = {"nc":"urn:ietf:params:xml:ns:netconf:base:1.0"}
	data = result.xpath('./nc:data', namespaces=namespaces)
	assert(len(data)==1)

	edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="replace">
        <interface>
          <name>eth0</name>
          <description>Uplink to ISP.</description>
          <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
          <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
            <address>
              <ip>192.0.2.1</ip>
              <prefix-length>24</prefix-length>
            </address>
          </ipv4>
        </interface>
      </interfaces>
    </config>
</edit-config>
"""

	print("<edit-config> - load example config to 'candidate' ...")
	result = conn.rpc(edit_config_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('./ok')
	assert(len(ok)==1)

	commit_rpc = '<commit/>'

	print("<commit> - commit example config ...")
	result = conn.rpc(commit_rpc)
	print lxml.etree.tostring(result)
	ok = result.xpath('./ok')
	assert(len(ok)==1)



	get_example_data_rpc = """
<get>
  <filter type="subtree">
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
    <interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
    <routing xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/>
    <routing-state xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/>
  </filter>
</get>
"""

	print("<get> - example data ...")
	result = conn.rpc(get_example_data_rpc, strip_ns=False)
	print lxml.etree.tostring(result, pretty_print=True, inclusive_ns_prefixes=True)
        namespaces = {"nc":"urn:ietf:params:xml:ns:netconf:base:1.0"}
	data = result.xpath('./nc:data', namespaces=namespaces)
	assert(len(data)==1)

	expected="""
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
      <interface>
        <name>eth0</name>
        <description>Uplink to ISP.</description>
        <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
        <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
          <address>
            <ip>192.0.2.1</ip>
            <prefix-length>24</prefix-length>
          </address>
        </ipv4>
      </interface>
    </interfaces>
    <interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
      <interface>
        <name>eth0</name>
        <description>Uplink to ISP.</description>
        <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
        <phys-address>00:0C:42:E5:B1:E9</phys-address>
        <oper-status>up</oper-status>
	<statistics>
          <discontinuity-time>2015-10-24T17:11:27+02:00</discontinuity-time>
        </statistics>
        <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
          <address>
            <ip>192.0.2.1</ip>
            <prefix-length>24</prefix-length>
          </address>
        </ipv4>
      </interface>
    </interfaces-state>
</data>
"""

	data_expected=etree.parse(StringIO(lxml.etree.tostring(lxml.etree.fromstring(expected), pretty_print=True)))
	data_received=etree.parse(StringIO(lxml.etree.tostring(data[0], pretty_print=True)))

	a = StringIO();
	b = StringIO();
	data_expected.write_c14n(a)
	data_received.write_c14n(b)

	if yang_data_equal(lxml.etree.fromstring(a.getvalue()), lxml.etree.fromstring(b.getvalue())):
		print "Bingo!"
		return 0
	else:
		print "Expected (A) different from received (B):"
		print "A:"
		print a.getvalue()
		print "B:"
		print b.getvalue()
		return 1
コード例 #23
0
def main():
    print("""
#Description: Demonstrate that ietf-yang-library is implemented.
#Procedure:
#1 - Verify /modules-state/module[name='test-yang-library-submodules'] container is present.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    print(
        "#1 - Verify /modules-state/module[name='test-yang-library-submodules'] container is present."
    )

    get_rpc = """
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <filter type="subtree">
  <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library">
   <module><name>test-yang-library-submodules</name></module>
  </modules-state>
 </filter>
</get>
"""
    print("get ...")
    result = conn.rpc(get_rpc)

    print lxml.etree.tostring(result)
    name = result.xpath('data/modules-state/module/name')
    assert (len(name) == 1)

    namespace = result.xpath('data/modules-state/module/namespace')
    assert (len(namespace) == 1)
    assert (namespace[0].text ==
            "http://yuma123.org/ns/test-yang-library-submodules")

    conformance_type = result.xpath(
        'data/modules-state/module/conformance-type')
    assert (len(conformance_type) == 1)

    submodule_name = result.xpath('data/modules-state/module/submodule/name')
    assert (len(submodule_name) == 1)
    assert (submodule_name[0].text == "test-yang-library-submodules-sub1")

    return (0)
コード例 #24
0
def main():
	print("#Description: compare list of supported modules reported by server to modules loaded by client.")

	parser = argparse.ArgumentParser()
	parser.add_argument("--server", help="server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)")
	parser.add_argument("--user", help="username e.g. admin ($USER if not specified)")
	parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
	parser.add_argument("--password", help="password e.g. mypass123 (passwordless if not specified)")
	parser.add_argument("--module-list", help="Client's module list - one module@revision per line")

	args = parser.parse_args()

	if(args.server==None or args.server==""):
		server="127.0.0.1"
	else:
		server=args.server

	if(args.port==None or args.port==""):
		port=830
	else:
		port=int(args.port)

	if(args.user==None or args.user==""):
		user=os.getenv('USER')
	else:
		user=args.user

	if(args.password==None or args.password==""):
		password=None
	else:
		password=args.password

	if args.module_list == None or args.module_list == "":
		module_list_fn = 'tmp/modlist'
	else:
		module_list_fn = args.module_list

	client_module_list = load_client_module_list(module_list_fn)
	if client_module_list == None:
		print("[FAILED] load client modules list")
		return(-1)

	conn_raw = litenc.litenc()
	ret = conn_raw.connect(server=server, port=port, user=user, password=password)
	if ret != 0:
		print("[FAILED] Connecting to server=%s:" % {'server':server})
		return(-1)
	print("[OK] Connecting to server=%(server)s:" % {'server':server})
	conn=litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
	ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")

	if ret != 0:
		print("[FAILED] Sending <hello>")
		return(-1)

	# receive <hello>
	result=conn.receive()

	# get the modules list
	(rv, reply) = send_rpc(conn, tests[0]['RPC'], tests[0]['edit-config-results'])
	if rv > 0:
		print('%s: sending RPC failed.' % tests[0]['name'])

	server_module_list = parse_server_module_list(reply)
	ok = compare_module_lists(server_module_list, client_module_list)
	return 0 if ok else 1
コード例 #25
0
def main():
    print("""
#Description:
## Verify get-schema works for a submodule.
#Procedure:
## loaded modules and submodules should be represented to netconf-state/schema list and they should be also retrieved by get-schema rpc.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)

    # receive <hello>
    result = conn.receive()

    get_rpc = """
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <filter type="subtree">
  <netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
   <schemas><schema><identifier>%(identifier)s</identifier></schema></schemas>
  </netconf-state>
 </filter>
</get>
"""

    for identifier in {"main-module", "sub-module"}:
        print("get %s." % (identifier))
        result = conn.rpc(get_rpc % {'identifier': identifier})
        ok = result.xpath('data/netconf-state/schemas/schema/identifier')
        print result
        # print ok
        # print lxml.etree.tostring(result)
        #assert(len(ok)==1)
        print "[OK] Retrieving a (sub)module"

        get_schema = """
<get-schema xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
  <identifier>%(identifier)s</identifier>
</get-schema>
"""
        print("")
        print("get-schema")

        print(get_schema % {'identifier': identifier})
        result = conn.rpc(get_schema % {'identifier': identifier})
        print lxml.etree.tostring(result)
        rpc_error = result.xpath('rpc-error')
        assert (len(rpc_error) == 0)
        print "[OK] Retrieving a (sub)module"
コード例 #26
0
def main():
    print("""
#Description: Demonstrate <get-schema> returns correct versions.
#Procedure:
#1 - <get-schema> ietf-yang-types, ietf-yang-types@2013-07-15 and ietf-yang-types@2010-09-29. Confirm ietf-yang-types@2010-09-29 is different.
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)

    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    #check for /hello/capabilities/capability == urn:ietf:params:xml:ns:yang:ietf-yang-types?module=ietf-yang-types&amp;revision=2013-07-15
    #check for /hello/capabilities/capability == urn:ietf:params:xml:ns:yang:ietf-yang-types?module=ietf-yang-types&amp;revision=2010-09-24

    get_schema_rpc = """
  <get-schema xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
    <identifier>ietf-yang-types</identifier>
  </get-schema>
"""
    print("get-schema - get ietf-yang-types ...")
    result = conn.rpc(get_schema_rpc)
    print lxml.etree.tostring(result)
    error_app_tag = result.xpath('rpc-error/error-app-tag')
    assert (len(error_app_tag) == 1)
    assert (error_app_tag[0].text == "data-not-unique")

    get_schema_rpc = """
  <get-schema xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
    <identifier>ietf-yang-types</identifier>
    <version>2013-07-15</version>
  </get-schema>
"""
    print("get-schema - get ietf-yang-types@2013-07-15 ...")
    result1 = conn.rpc(get_schema_rpc)
    print lxml.etree.tostring(result1)
    data1 = result1.xpath('data')
    assert (len(data1) == 1)

    get_schema_rpc = """
  <get-schema xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
    <identifier>ietf-yang-types</identifier>
    <version>2013-07-15</version>
  </get-schema>
"""
    print("get-schema - get ietf-yang-types@2013-07-15 ...")
    result2 = conn.rpc(get_schema_rpc)
    print lxml.etree.tostring(result2)
    data2 = result2.xpath('data')
    assert (len(data2) == 1)

    get_schema_rpc = """
  <get-schema xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
    <identifier>ietf-yang-types</identifier>
    <version>2010-09-24</version>
  </get-schema>
"""
    print("get-schema - get ietf-yang-types@2010-09-24 ...")
    result3 = conn.rpc(get_schema_rpc)
    print lxml.etree.tostring(result3)
    data3 = result3.xpath('data')
    assert (len(data3) == 1)

    if (lxml.etree.tostring(data1[0]) != lxml.etree.tostring(data2[0])):
        print("Error: Should be the same schema file")
        assert (0)

    if (lxml.etree.tostring(data2[0]) == lxml.etree.tostring(data3[0])):
        print("Error: Should be different schema file")
        assert (0)

    print("OK: All good.")

    return 0
コード例 #27
0
def session(args):
    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()

    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)

    if (args.skip_hello == "true"):
        conn_raw.close()
        return (0)

    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    #print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml':reply_xml}

    print("Connected ...")

    if (int(args.interfaces_count) > 0):
        edit_config(conn, args)

    conn_raw.close()
    return (0)
コード例 #28
0
def main():
    print("""
#Description: Demonstrate that edit-config works.
#Procedure:
#1 - Create interface "foo" and commit. Verify commit succeeds.
#2 - Create interface "bar" and commit. Verify commit fails.
""")

    port = 830
    server = "127.0.0.1"

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server, port=port, user=os.getenv('USER'))
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw)
    ret = conn_raw.send("""
<hello>
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>\
 </capabilities>\
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    print("Connected ...")

    edit_rpc = """
<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <target>
  <candidate/>
 </target>
 <default-operation>merge</default-operation>
 <test-option>set</test-option>
 <config>
  <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
   <interface xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="create">
     <name>%(interface)s</name>
     <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
   </interface>
  </interfaces>
 </config>
</edit-config>
"""
    print("edit-config - create 'foo' ...")
    result = conn.rpc(edit_rpc % {'interface': "foo"})
    ok = result.xpath('ok')
    print result
    print ok
    print lxml.etree.tostring(result)
    assert (len(ok) == 1)

    commit_rpc = """
<commit/>
"""
    print("commit ...")
    result = conn.rpc(commit_rpc)

    print("edit-config - create 'bar' ...")
    result = conn.rpc(edit_rpc % {'interface': "bar"})

    print("commit ...")
    result = conn.rpc(commit_rpc)
    ok = result.xpath('//ok')
    assert (len(ok) != 1)
コード例 #29
0
def main():
    print("""
#Description: Verify netconf-* session-start, etc. notifications are implemented.
#Procedure:
#1 - Open session #1 and <create-subscription>
#2 - Open additional session #2 and verify <netconf-session-start> is sent with correct paramenters on #1.
#3 - TODO
""")

    user = os.getenv('USER')
    port = 830
    server = "127.0.0.1"

    conn = litenc.litenc()
    ret = conn.connect(server=server, port=port, user=user)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn_lxml = litenc_lxml.litenc_lxml(conn)
    ret = conn.send("""
<hello>
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>\
 </capabilities>\
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    ret = conn.send("""
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
 <create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"/>
</rpc>
""")
    if ret != 0:
        print("[FAILED] Sending <create-subscription>")
        return (-1)

    (ret, reply_xml) = conn.receive()
    if ret != 0:
        print("[FAILED] Receiving <create-subscription> reply")
        return (-1)

    print "[OK] Receiving <create-subscription> reply =%(reply_xml)s:" % {
        'reply_xml': reply_xml
    }

    conn2 = litenc.litenc()
    ret = conn2.connect(server=server, port=port, user=user)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}

    ret = conn2.send("""
<hello>
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>\
 </capabilities>\
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn2.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}

    (ret, notification_xml) = conn.receive()
    if ret != 0:
        print("[FAILED] Receiving <netconf-session-start> notification")
        return (-1)

    print "[OK] Receiving <netconf-session-start> notification =%(notification_xml)s:" % {
        'notification_xml': notification_xml
    }

    return (0)
コード例 #30
0
def main():
    print("""
#Description: Read and edit anyxml.
#Procedure:
#1 - Read /c/a and validate
#2 - Replace /c/a read back and validate
""")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--server",
        help=
        "server name e.g. 127.0.0.1 or server.com (127.0.0.1 if not specified)"
    )
    parser.add_argument("--user",
                        help="username e.g. admin ($USER if not specified)")
    parser.add_argument("--port", help="port e.g. 830 (830 if not specified)")
    parser.add_argument(
        "--password",
        help="password e.g. mypass123 (passwordless if not specified)")

    args = parser.parse_args()

    if (args.server == None or args.server == ""):
        server = "127.0.0.1"
    else:
        server = args.server

    if (args.port == None or args.port == ""):
        port = 830
    else:
        port = int(args.port)

    if (args.user == None or args.user == ""):
        user = os.getenv('USER')
    else:
        user = args.user

    if (args.password == None or args.password == ""):
        password = None
    else:
        password = args.password

    conn_raw = litenc.litenc()
    ret = conn_raw.connect(server=server,
                           port=port,
                           user=user,
                           password=password)
    if ret != 0:
        print "[FAILED] Connecting to server=%(server)s:" % {'server': server}
        return (-1)
    print "[OK] Connecting to server=%(server)s:" % {'server': server}
    conn = litenc_lxml.litenc_lxml(conn_raw, strip_namespaces=True)
    ret = conn_raw.send("""
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <capabilities>
  <capability>urn:ietf:params:netconf:base:1.0</capability>
 </capabilities>
</hello>
""")
    if ret != 0:
        print("[FAILED] Sending <hello>")
        return (-1)
    (ret, reply_xml) = conn_raw.receive()
    if ret != 0:
        print("[FAILED] Receiving <hello>")
        return (-1)

    print "[OK] Receiving <hello> =%(reply_xml)s:" % {'reply_xml': reply_xml}
    conn = litenc_lxml.litenc_lxml(conn_raw)

    print("Connected ...")

    namespaces = {
        "nc": "urn:ietf:params:xml:ns:netconf:base:1.0",
        "test-anyxml":
        "http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml",
        "one": "urn:1",
        "two": "urn:2"
    }

    edit_config_rpc = """
<edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <c xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="replace">
        <a>
          <one foo="blah" xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml"><two bar="blaer" xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml">2</two><!--<tree/>--></one>
        </a>
      </c>
    </config>
</edit-config>
"""
    commit_rpc = """
<commit/>
"""

    get_rpc = """
<get>
  <filter type="subtree">
    <c xmlns="http://yuma123.org/ns/test/netconfd/anyxml/test-anyxml">
      <a/>
    </c>
  </filter>
</get>
"""

    print("<edit-config> - /c/a ...")
    result = conn.rpc(edit_config_rpc)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    print("<commit> ...")
    result = conn.rpc(commit_rpc)
    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    print("<get> - /c/a ...")
    result = conn.rpc(get_rpc)

    print lxml.etree.tostring(result,
                              pretty_print=True,
                              inclusive_ns_prefixes=True)
    one = result.xpath("./nc:data/test-anyxml:c/test-anyxml:a/test-anyxml:one",
                       namespaces=namespaces)
    assert (len(one) == 1)