def terminate(network, conns, yconns, filter): for name in {"local","remote"}: ok = yangcli(yconns[name], "delete /fusion-streams").xpath('./ok') ok = yangcli(yconns[name], "delete /interfaces").xpath('./ok') #assert(len(ok)==1) tntapi.network_commit(conns)
def step_1(network, conns, yconns, filter=filter): result = yangcli(yconns['local'], 'discard-changes') result = yangcli(yconns['middle'], 'discard-changes') result = yangcli(yconns['remote'], 'discard-changes') tntapi.network_commit(conns) yangcli_script_remote = ''' merge /interfaces/interface[name='ge0'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge1'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge2'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge3'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge4'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge5'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge6'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge7'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge8'] -- type='ethernetCsmacd' merge /interfaces/interface[name='ge9'] -- type='ethernetCsmacd' replace /interfaces/interface[name='ge0']/loopback value='near-end' replace /interfaces/interface[name='ge1']/loopback value='near-end' replace /interfaces/interface[name='ge2']/loopback value='near-end' replace /interfaces/interface[name='ge3']/loopback value='near-end' replace /interfaces/interface[name='ge4']/loopback value='near-end' replace /interfaces/interface[name='ge5']/loopback value='near-end' replace /interfaces/interface[name='ge6']/loopback value='near-end' replace /interfaces/interface[name='ge7']/loopback value='near-end' replace /interfaces/interface[name='ge8']/loopback value='near-end' replace /interfaces/interface[name='ge9']/loopback value='near-end' ''' yangcli_ok_script(yconns["remote"], yangcli_script_remote) tntapi.network_commit(conns)
def main(): print(""" #Description: Stop traffic generators #Procedure: #1 - Delete all traffic generator containers. """) parser = argparse.ArgumentParser() parser.add_argument("--config", help="Path to the netconf configuration *.xml file defining the configuration according to ietf-networks, ietf-networks-topology and netconf-node models e.g. ../networks.xml") args = parser.parse_args() tree=etree.parse(args.config) network = tree.xpath('/nc:config/nd:networks/nd:network', namespaces=namespaces)[0] conns = tntapi.network_connect(network) yconns = tntapi.network_connect_yangrpc(network) mylinks = tntapi.parse_network_links(network) print("#1 - Stop all traffic generators.") nodes = network.xpath('nd:node', namespaces=namespaces) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config="" termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text result=yangcli(yconns[node_id],"""delete /interfaces/interface[name='%(name)s']/traffic-generator"""%{'name':tp_id}) tntapi.network_commit(conns)
def step_3(conn_1, conn_2): print( "#3 - Validate /interfaces/interface/bar can be created on session #2." ) result = yangcli( conn_2, "create /interfaces/interface[name='bar'] -- type=ethernetCsmacd bar='hello'" ) print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 1) commit(conn_2) result = yangcli(conn_2, "delete /interfaces/interface[name='bar']") ok = result.xpath('./ok') assert (len(ok) == 1) commit(conn_2)
def step_2(conn_1, conn_2): print( "#2 - Validate /interfaces/interface/foo can be created on session #1." ) result = yangcli( conn_1, "create /interfaces/interface[name='foo'] -- type=ethernetCsmacd foo='hello'" ) print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 1) commit(conn_1) result = yangcli(conn_1, "delete /interfaces/interface[name='foo']") ok = result.xpath('./ok') assert (len(ok) == 1) commit(conn_1)
def yangcli_ok_script(conn, yangcli_script): for line in yangcli_script.splitlines(): line = line.strip() if not line: continue print("Executing: " + line) ok = yangcli(conn, line).xpath('./ok') assert (len(ok) == 1)
def step_6(conn_1, conn_2): print( "#6 - Close session #1 and confirm 'bar' can still be created on session #2." ) yangrpc.close(conn_1) result = yangcli( conn_2, "create /interfaces/interface[name='bar'] -- type=ethernetCsmacd bar='hello'" ) print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 1) commit(conn_2) result = yangcli(conn_2, "delete /interfaces/interface[name='bar']") ok = result.xpath('./ok') assert (len(ok) == 1) commit(conn_2)
def step_5(conn_1, conn_2): print("#5 - Modify candidate from session #1 confirm this is OK.") line = "create /interfaces/interface -- name=foo type=ethernetCsmacd" result = yangcli(conn_1, line) print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 1)
def step_4(conn_1, conn_2): print("#4 - Try to modify candidate from session #2. Validate this fails.") line = "create /interfaces/interface -- name=foo type=ethernetCsmacd" result = yangcli(conn_2, line) print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 0)
def commit(conn): result = yangcli(conn, "commit") print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 0 or len(ok) == 1) if (len(ok) == 1): return True else: return False
def unlock(conn): result = yangcli(conn, "unlock target=candidate") print lxml.etree.tostring(result) ok = result.xpath('./ok') assert (len(ok) == 0 or len(ok) == 1) if (len(ok) == 1): return True else: return False
def yangcli_ok_script(yconn, yangcli_script): for line in yangcli_script.splitlines(): line = line.strip() if not line: continue print("Executing: " + line) result = yangcli(yconn, line) ok = result.xpath('./ok') if (len(ok) != 1): print lxml.etree.tostring(result) assert (0)
def validate(network, conns, yconns, filter, step, with_sm, with_gst): if(with_sm): ok = yangcli(yconns["analyzer"], "create /interfaces/interface[name='xe0']/traffic-analyzer").xpath('./ok') assert(len(ok)==1) if(with_gst): ok = yangcli(yconns["analyzer"], "create /interfaces/interface[name='ge0']/traffic-analyzer").xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) if(with_sm): ok = yangcli(yconns["analyzer"], "create /interfaces/interface[name='xe0']/traffic-generator -- frame-size=1500 interframe-gap=12 ether-type=8100 frames-per-burst=100 interburst-gap=10000").xpath('./ok') assert(len(ok)==1) if(with_gst): ok = yangcli(yconns["analyzer"], "create /interfaces/interface[name='ge0']/traffic-generator -- frame-size=64 interframe-gap=12 ether-type=88F7 frames-per-burst=100 interburst-gap=10000").xpath('./ok') assert(len(ok)==1) state_before = tntapi.network_get_state(network, conns, filter=filter) tntapi.network_commit(conns) print("Start traffic ...") time.sleep(10) print("Stop traffic ...") if(with_sm): ok = yangcli(yconns["analyzer"], "delete /interfaces/interface[name='xe0']/traffic-generator").xpath('./ok') assert(len(ok)==1) if(with_gst): ok = yangcli(yconns["analyzer"], "delete /interfaces/interface[name='ge0']/traffic-generator").xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) state_after = tntapi.network_get_state(network, conns, filter=filter) if(with_sm): ok = yangcli(yconns["analyzer"], "delete /interfaces/interface[name='xe0']/traffic-analyzer").xpath('./ok') assert(len(ok)==1) if(with_gst): ok = yangcli(yconns["analyzer"], "delete /interfaces/interface[name='ge0']/traffic-analyzer").xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) return validate_step_common(state_before, state_after, step, with_sm, with_gst)
def init(network, conns, yconns, filter): for name in {"local", "remote"}: ok = yangcli(yconns[name], "delete /fusion-streams").xpath('./ok') ok = yangcli(yconns[name], "delete /interfaces").xpath('./ok') #assert(len(ok)==1) tntapi.network_commit(conns) yangcli_script_local = ''' create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='matched-tpid'] -- priority=gst filter/tpid=88F7 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false drop[out-port='e0']/pop-vlan-tag=true drop[out-port='e1']/pop-vlan-tag=true drop[out-port='e2']/pop-vlan-tag=true drop[out-port='e3']/pop-vlan-tag=true drop[out-port='e4']/pop-vlan-tag=true drop[out-port='e5']/pop-vlan-tag=true drop[out-port='e6']/pop-vlan-tag=true drop[out-port='e7']/pop-vlan-tag=true drop[out-port='e8']/pop-vlan-tag=true drop[out-port='e9']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='unmatched'] -- priority=sm push-vlan-tag/vlanid=200 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='100'] -- priority=gst filter/tpid=9100 forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='200'] -- priority=sm filter/tpid=9100 forward/pop-vlan-tag=true ''' for i in range(10): yangcli_script_local = yangcli_script_local + ''' create /fusion-streams/aggregation[in-port='e%d']/sm -- out-port=n1 push-vlan-tag/vlanid=1%d push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e%d']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='1%d'] -- priority=sm filter/tpid=9100 drop[out-port='e%d']/pop-vlan-tag=true ''' % (i, i, i, i, i) yangcli_script_remote = ''' create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='matched-tpid'] -- priority=gst filter/tpid=88F7 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='unmatched'] -- priority=sm push-vlan-tag/vlanid=200 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='100'] -- priority=gst filter/tpid=9100 drop[out-port='e0']/pop-vlan-tag=true drop[out-port='e1']/pop-vlan-tag=true drop[out-port='e2']/pop-vlan-tag=true drop[out-port='e3']/pop-vlan-tag=true drop[out-port='e4']/pop-vlan-tag=true drop[out-port='e5']/pop-vlan-tag=true drop[out-port='e6']/pop-vlan-tag=true drop[out-port='e7']/pop-vlan-tag=true drop[out-port='e8']/pop-vlan-tag=true drop[out-port='e9']/pop-vlan-tag=true forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='200'] -- priority=sm filter/tpid=9100 forward/pop-vlan-tag=true ''' for i in range(10): yangcli_script_remote = yangcli_script_remote + ''' create /fusion-streams/aggregation[in-port='e%d']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e%d']/sm -- out-port=n1 push-vlan-tag/vlanid=1%d push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='1%d'] -- filter/tpid=9100 priority=sm drop[out-port='e%d']/pop-vlan-tag=true ''' % (i, i, i, i, i) yangcli_ok_script(yconns["local"], yangcli_script_local) yangcli_ok_script(yconns["remote"], yangcli_script_remote) tntapi.network_commit(conns)
def main(): print(""" #Description: Configure the H100 with example configuration from the userguide. #Procedure: #1 - Create the configuration described in the user guide. #2 - 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME')+"/.ssh/id_rsa.pub", os.getenv('HOME')+"/.ssh/id_rsa", "--dump-session=nc-session-") if(conn==None): print("Error: yangrpc failed to connect!") return(-1) time.sleep(1) #cleanup yangcli(conn, '''delete /fusion-streams''') ok = yangcli(conn, '''commit''').xpath('./ok') assert(len(ok)==1) yangcli_script=''' create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='matched-tpid'] -- priority=gst filter/tpid=88F7 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false drop[out-port='e0']/pop-vlan-tag=true drop[out-port='e1']/pop-vlan-tag=true drop[out-port='e2']/pop-vlan-tag=true drop[out-port='e3']/pop-vlan-tag=true drop[out-port='e4']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='unmatched'] -- priority=sm push-vlan-tag/vlanid=200 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/aggregation[in-port='e0']/sm -- out-port=n1 push-vlan-tag/vlanid=10 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e1']/sm -- out-port=n1 push-vlan-tag/vlanid=11 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e2']/sm -- out-port=n1 push-vlan-tag/vlanid=12 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e3']/sm -- out-port=n1 push-vlan-tag/vlanid=13 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e4']/sm -- out-port=n1 push-vlan-tag/vlanid=14 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e0']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e1']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e2']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e3']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e4']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='100'] -- priority=gst filter/tpid=9100 forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='200'] -- priority=sm filter/tpid=9100 forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='10'] -- priority=sm filter/tpid=9100 drop[out-port='e0']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='11'] -- priority=sm filter/tpid=9100 drop[out-port='e1']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='12'] -- priority=sm filter/tpid=9100 drop[out-port='e2']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='13'] -- priority=sm filter/tpid=9100 drop[out-port='e3']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='14'] -- priority=sm filter/tpid=9100 drop[out-port='e4']/pop-vlan-tag=true commit ''' yangcli_ok_script(conn, yangcli_script) return(0)
def main(): print(""" #Description: Connects and updates the display according to the configuration. #Procedure: #1 - Open session. #2 - Loop reading configuration and displaying text. """) 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME')+"/.ssh/id_rsa.pub", os.getenv('HOME')+"/.ssh/id_rsa") if(conn==None): print("Error: yangrpc failed to connect!") return(-1) time.sleep(1) mylcd = I2C_LCD_driver.lcd() #zeroseg_led = led.sevensegment(cascaded=2) while(1): result = yangcli(conn, "xget /line-display") text = result.xpath('./data/line-display/text') if(len(text)!=1): instance_id = result.xpath('./data/line-display/instance-id') if(len(instance_id)==1): print instance_id[0].text update_interval = result.xpath('./data/line-display/update-interval') result2 = yangcli(conn, "xget %s"%(instance_id[0].text)) text = result2.xpath('./data/%s'%(instance_id[0].text)) mylcd.lcd_clear() mylcd.lcd_display_string(instance_id[0].text[-16:], 1) mylcd.lcd_display_string(text[0].text, 2) else: print text[0].text #zeroseg_led.write_text(1,text[0].text) mylcd.lcd_clear() mylcd.lcd_display_string(text[0].text, 1) time.sleep(1) return(0)
from yangcli import yangcli from lxml import etree import yangrpc import sys import os conn = yangrpc.connect("127.0.0.1", 830, os.getenv('USER'), "dummypass", os.getenv('HOME')+".ssh/id_rsa",os.getenv('HOME')+".ssh/id_rsa.pub") if(conn==None): print("Error: yangrpc failed to connect!") sys.exit(1) yangcli(conn, "create /interfaces/interface[name='blah']/type value='ethernetCsmacd'") result=yangcli(conn, "commit") assert(result.xpath('./ok')) result=yangcli(conn, "xget /interfaces") a=result.xpath('./data/interfaces/interface[name=\'blah\']/a') b=result.xpath('./data/interfaces/interface[name=\'blah\']/b') print(a[0].text) assert(a[0].text=="Hello from a!") print(b[0].text) assert(b[0].text=="Hello from b!") print("Done.")
def validate(network, conns, yconns, inks, load_percent=99, frame_size=1500, interframe_gap=12, frames_per_burst=0, interburst_gap=0): global args filter = "" #"""<filter type="xpath" select="/*[local-name()='interfaces-state' or local-name()='interfaces']/interface/*[local-name()='traffic-analyzer' or local-name()='oper-status' or local-name()='statistics' or local-name()='speed']"/>""" config_idle = {} nodes = network.xpath('nd:node', namespaces=namespaces) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config = "" print node_id termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue ok = yangcli( yconns[node_id], """replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd""" % { 'name': tp_id }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) state_before = tntapi.network_get_state(network, conns, filter=filter) print("Waiting " + "5" + " sec. ...") time.sleep(5) print("Done.") state_after = tntapi.network_get_state(network, conns, filter=filter) mylinks = tntapi.parse_network_links(state_before) t1 = tntapi.parse_network_nodes(state_before) t2 = tntapi.parse_network_nodes(state_after) delta = tntapi.get_network_counters_delta(state_before, state_after) tntapi.print_state_ietf_interfaces_statistics_delta( network, state_before, state_after) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue validate_traffic_off(node_id, tp_id, state_before, state_after, delta, frame_size) load = float(load_percent) / 100 print "ifg=" + str(interframe_gap) if (args.test_internal_loopback == "true"): print("Enabling internal loopbacks.") for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue ok = yangcli( yconns[node_id], """merge /interfaces/interface[name='%(name)s'] -- loopback=internal""" % { 'name': tp_id }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) if (args.test_analyzer == "true"): print("Enabling analyzer.") for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue if (args.direction == 'ingress'): ok = yangcli( yconns[node_id], """create /interfaces/interface[name='%(name)s']/traffic-analyzer-egress""" % { 'name': tp_id }).xpath('./ok') else: ok = yangcli( yconns[node_id], """create /interfaces/interface[name='%(name)s']/traffic-analyzer""" % { 'name': tp_id }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config = "" termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue if (frames_per_burst > 0): my_burst_config = """frames-per-burst=%(frames-per-burst)d interburst-gap=%(interburst-gap)d""" % { 'frames-per-burst': frames_per_burst, 'interburst-gap': interburst_gap - 8 } else: my_burst_config = "" if (args.direction == 'ingress'): generator_direction_suffix = '-ingress' analyzer_direction_suffix = '-egress' else: generator_direction_suffix = '' analyzer_direction_suffix = '' ok = yangcli( yconns[node_id], """create /interfaces/interface[name='%(name)s']/traffic-generator%(generator-direction-suffix)s -- ether-type=%(ether-type)d frame-size=%(frame-size)d interframe-gap=%(interframe-gap)d %(burst)s""" % { 'name': tp_id, 'generator-direction-suffix': generator_direction_suffix, 'frame-size': frame_size, 'ether-type': 0x1234, 'interframe-gap': interframe_gap - 8, 'burst': my_burst_config }).xpath('./ok') assert (len(ok) == 1) state_before = tntapi.network_get_state(network, conns, filter=filter) tntapi.network_commit(conns) print("Waiting " + str(test_time) + " sec. ...") time.sleep(test_time) print("Stopping generators ...") for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config = "" termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue ok = yangcli( yconns[node_id], """delete /interfaces/interface[name='%(name)s']/traffic-generator%(generator-direction-suffix)s""" % { 'name': tp_id, 'generator-direction-suffix': generator_direction_suffix }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) print("Done.") state_after = tntapi.network_get_state(network, conns, filter=filter) t1 = tntapi.parse_network_nodes(state_before) t2 = tntapi.parse_network_nodes(state_after) delta = tntapi.get_network_counters_delta(state_before, state_after) tntapi.print_state_ietf_interfaces_statistics_delta( network, state_before, state_after) load_generated = {} for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue load_generated[node_id, tp_id] = validate_traffic_on( node_id, tp_id, state_before, state_after, delta, test_time, load_percent, frame_size, interframe_gap, frames_per_burst, interburst_gap) if (args.test_analyzer == "true"): print("Disabling analyzer.") for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue ok = yangcli( yconns[node_id], """delete /interfaces/interface[name='%(name)s']/traffic-analyzer%(analyzer-direction-suffix)s""" % { 'name': tp_id, 'analyzer-direction-suffix': analyzer_direction_suffix }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) if (args.test_internal_loopback == "true"): print("Disabling internal loopbacks.") for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (not is_interface_test_enabled(node_id, tp_id)): continue ok = yangcli( yconns[node_id], """delete /interfaces/interface[name='%(name)s']/loopback""" % { 'name': tp_id }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) return (load_percent, load_generated)
def main(): print(""" #Description: Demonstrate that leaf values can be replaced. #Procedure: #1 - Create test-yang-library container. Verify commit succeeds. """) 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa") if (conn == None): print("Error: yangrpc failed to connect!") return (-1) time.sleep(1) result = yangcli( conn, '''xget /modules-state/module[name='test-yang-library'] ''') name = result.xpath('./data/modules-state/module/name') assert (len(name) == 1) conformance_type = result.xpath( './data/modules-state/module/conformance-type') assert (len(conformance_type) == 1) assert (conformance_type[0].text == "implement") result = yangcli( conn, '''xget /modules-state/module[name='test-yang-library-import'] ''') name = result.xpath('./data/modules-state/module/name') assert (len(name) == 1) conformance_type = result.xpath( './data/modules-state/module/conformance-type') assert (len(conformance_type) == 1) #assert(conformance_type[0].text=="import") ok = yangcli(conn, '''delete /foo''').xpath('./ok') ok = yangcli(conn, '''commit''').xpath('./ok') #assert(len(ok)==1) ok = yangcli(conn, '''create /foo''').xpath('./ok') assert (len(ok) == 1) ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) return (0)
def main(): print(""" #Description: Testcase for OpenDaylight interoperability. #Procedure: #1 - Create topology. """) 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 print("Connecting #1 ...") conn = yangrpc.connect(server, port, user, password, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa", "--dump-session=tmp/nc-session-") if (conn == None): print("Error: yangrpc failed to connect!") return (-1) result = yangcli( conn, "delete /modules/module[name='right'][type='sal-netconf-connector']") result = yangcli(conn, "commit") ok = result.xpath('./ok') print(lxml.etree.tostring(result)) assert (len(ok) == 1) result = yangcli( conn, "merge /modules/module[name='right'][type='sal-netconf-connector'] -- address=127.0.0.1 sal-netconf:port=4830 tcp-only=false username=demo password=demo sal-netconf:event-executor/type=netty-event-executor sal-netconf:event-executor/name=global-event-executor sal-netconf:binding-registry/type=binding-broker-osgi-registry sal-netconf:binding-registry/name=binding-osgi-broker sal-netconf:dom-registry/type=dom-broker-osgi-registry sal-netconf:dom-registry/name=dom-broker sal-netconf:client-dispatcher/type=netconf-client-dispatcher sal-netconf:client-dispatcher/name=global-netconf-dispatcher sal-netconf:processing-executor/type=threadpool sal-netconf:processing-executor/name=global-netconf-processing-executor sal-netconf:keepalive-executor/type=scheduled-threadpool sal-netconf:keepalive-executor/name=global-netconf-ssh-scheduled-executor" ) ok = result.xpath('./ok') print(lxml.etree.tostring(result)) assert (len(ok) == 1) result = yangcli(conn, "commit") ok = result.xpath('./ok') print(lxml.etree.tostring(result)) assert (len(ok) == 1) return (0)
def step_1(network, conns, yconns, filter=filter): #Delete all result = yangcli(yconns["local"], "delete /fusion-streams") result = yangcli(yconns["remote"], "delete /fusion-streams") tntapi.network_commit(conns) yangcli_script_local = ''' create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='matched-tpid'] -- priority=gst filter/tpid=88F7 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false drop[out-port='e0']/pop-vlan-tag=true drop[out-port='e1']/pop-vlan-tag=true drop[out-port='e2']/pop-vlan-tag=true drop[out-port='e3']/pop-vlan-tag=true drop[out-port='e4']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='unmatched'] -- priority=sm push-vlan-tag/vlanid=200 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/aggregation[in-port='e0']/sm -- out-port=n1 push-vlan-tag/vlanid=10 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e1']/sm -- out-port=n1 push-vlan-tag/vlanid=11 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e2']/sm -- out-port=n1 push-vlan-tag/vlanid=12 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e3']/sm -- out-port=n1 push-vlan-tag/vlanid=13 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e4']/sm -- out-port=n1 push-vlan-tag/vlanid=14 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e5']/sm -- out-port=n1 push-vlan-tag/vlanid=15 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e6']/sm -- out-port=n1 push-vlan-tag/vlanid=16 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e7']/sm -- out-port=n1 push-vlan-tag/vlanid=17 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e8']/sm -- out-port=n1 push-vlan-tag/vlanid=18 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e9']/sm -- out-port=n1 push-vlan-tag/vlanid=19 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e0']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e1']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e2']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e3']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e4']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e5']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e6']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e7']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e8']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/aggregation[in-port='e9']/gst -- out-port=n0 filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='100'] -- priority=gst filter/tpid=9100 forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='200'] -- priority=sm filter/tpid=9100 forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='10'] -- priority=sm filter/tpid=9100 drop[out-port='e0']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='11'] -- priority=sm filter/tpid=9100 drop[out-port='e1']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='12'] -- priority=sm filter/tpid=9100 drop[out-port='e2']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='13'] -- priority=sm filter/tpid=9100 drop[out-port='e3']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='14'] -- priority=sm filter/tpid=9100 drop[out-port='e4']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='15'] -- priority=sm filter/tpid=9100 drop[out-port='e5']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='16'] -- priority=sm filter/tpid=9100 drop[out-port='e6']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='17'] -- priority=sm filter/tpid=9100 drop[out-port='e7']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='18'] -- priority=sm filter/tpid=9100 drop[out-port='e8']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='19'] -- priority=sm filter/tpid=9100 drop[out-port='e9']/pop-vlan-tag=true ''' yangcli_script_remote = ''' create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='matched-tpid'] -- priority=gst filter/tpid=88F7 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/drop-and-forward[in-port='n0'][filter-rule='unmatched'] -- priority=sm push-vlan-tag/vlanid=200 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 forward/pop-vlan-tag=false create /fusion-streams/aggregation[in-port='e0']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e1']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e2']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e3']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e4']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e5']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e6']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e7']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e8']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e9']/gst -- filter/ether-type=88F7 filter/tpid=88F7 filter/vlanid=1 out-port=n1 push-vlan-tag/vlanid=100 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e0']/sm -- out-port=n1 push-vlan-tag/vlanid=10 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e1']/sm -- out-port=n1 push-vlan-tag/vlanid=11 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e2']/sm -- out-port=n1 push-vlan-tag/vlanid=12 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e3']/sm -- out-port=n1 push-vlan-tag/vlanid=13 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e4']/sm -- out-port=n1 push-vlan-tag/vlanid=14 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e5']/sm -- out-port=n1 push-vlan-tag/vlanid=25 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e6']/sm -- out-port=n1 push-vlan-tag/vlanid=26 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e7']/sm -- out-port=n1 push-vlan-tag/vlanid=27 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e8']/sm -- out-port=n1 push-vlan-tag/vlanid=28 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/aggregation[in-port='e9']/sm -- out-port=n1 push-vlan-tag/vlanid=29 push-vlan-tag/pcp=0 push-vlan-tag/tpid=9100 push-vlan-tag/cfi=1 create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='100'] -- priority=gst filter/tpid=9100 drop[out-port='e0']/pop-vlan-tag=true drop[out-port='e1']/pop-vlan-tag=true drop[out-port='e2']/pop-vlan-tag=true drop[out-port='e3']/pop-vlan-tag=true drop[out-port='e4']/pop-vlan-tag=true forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='200'] -- priority=sm filter/tpid=9100 forward/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='10'] -- filter/tpid=9100 priority=sm drop[out-port='e0']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='11'] -- filter/tpid=9100 priority=sm drop[out-port='e1']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='12'] -- filter/tpid=9100 priority=sm drop[out-port='e2']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='13'] -- filter/tpid=9100 priority=sm drop[out-port='e3']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='14'] -- filter/tpid=9100 priority=sm drop[out-port='e4']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='25'] -- filter/tpid=9100 priority=sm drop[out-port='e5']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='26'] -- filter/tpid=9100 priority=sm drop[out-port='e6']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='27'] -- filter/tpid=9100 priority=sm drop[out-port='e7']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='28'] -- filter/tpid=9100 priority=sm drop[out-port='e8']/pop-vlan-tag=true create /fusion-streams/drop-and-forward[in-port='n1'][filter-rule='29'] -- filter/tpid=9100 priority=sm drop[out-port='e9']/pop-vlan-tag=true ''' yangcli_script_middle = ''' replace /vlans/vlan -- name=trunk id=500 tpid=0x9100 replace /interfaces/interface -- name='xe0' type=ethernetCsmacd replace /interfaces/interface[name='xe0']/ethernet-switching/trunk-interface/vlans/vlan/vlan-name value=trunk replace /interfaces/interface -- name='xe1' type=ethernetCsmacd replace /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan/vlan-name value=trunk replace /hadm/forward-unmatched-packets value=true replace /vlans/vlan -- name=vlan10 id=10 tpid=0x9100 replace /vlans/vlan -- name=vlan11 id=11 tpid=0x9100 replace /vlans/vlan -- name=vlan12 id=12 tpid=0x9100 replace /vlans/vlan -- name=vlan13 id=13 tpid=0x9100 replace /vlans/vlan -- name=vlan14 id=14 tpid=0x9100 replace /vlans/vlan -- name=vlan15 id=15 tpid=0x9100 replace /vlans/vlan -- name=vlan16 id=16 tpid=0x9100 replace /vlans/vlan -- name=vlan17 id=17 tpid=0x9100 replace /vlans/vlan -- name=vlan18 id=18 tpid=0x9100 replace /vlans/vlan -- name=vlan19 id=19 tpid=0x9100 replace /vlans/vlan -- name=vlan20 id=20 tpid=0x9100 replace /vlans/vlan -- name=vlan21 id=21 tpid=0x9100 replace /vlans/vlan -- name=vlan22 id=22 tpid=0x9100 replace /vlans/vlan -- name=vlan23 id=23 tpid=0x9100 replace /vlans/vlan -- name=vlan24 id=24 tpid=0x9100 replace /vlans/vlan -- name=vlan25 id=25 tpid=0x9100 replace /vlans/vlan -- name=vlan26 id=26 tpid=0x9100 replace /vlans/vlan -- name=vlan27 id=27 tpid=0x9100 replace /vlans/vlan -- name=vlan28 id=28 tpid=0x9100 replace /vlans/vlan -- name=vlan29 id=29 tpid=0x9100 create /interfaces/interface -- name='ge0' type=ethernetCsmacd create /interfaces/interface -- name='ge1' type=ethernetCsmacd create /interfaces/interface -- name='ge2' type=ethernetCsmacd create /interfaces/interface -- name='ge3' type=ethernetCsmacd create /interfaces/interface -- name='ge4' type=ethernetCsmacd create /interfaces/interface -- name='ge5' type=ethernetCsmacd create /interfaces/interface -- name='ge6' type=ethernetCsmacd create /interfaces/interface -- name='ge7' type=ethernetCsmacd create /interfaces/interface -- name='ge8' type=ethernetCsmacd create /interfaces/interface -- name='ge9' type=ethernetCsmacd create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan20 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan21 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan22 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan23 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan24 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan25 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan26 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan27 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan28 create /interfaces/interface[name='xe1']/ethernet-switching/trunk-interface/vlans/vlan -- vlan-name=vlan29 create /interfaces/interface[name='ge0']/ethernet-switching/access-interface/vlan -- vlan-name=vlan20 create /interfaces/interface[name='ge1']/ethernet-switching/access-interface/vlan -- vlan-name=vlan21 create /interfaces/interface[name='ge2']/ethernet-switching/access-interface/vlan -- vlan-name=vlan22 create /interfaces/interface[name='ge3']/ethernet-switching/access-interface/vlan -- vlan-name=vlan23 create /interfaces/interface[name='ge4']/ethernet-switching/access-interface/vlan -- vlan-name=vlan24 create /interfaces/interface[name='ge5']/ethernet-switching/access-interface/vlan -- vlan-name=vlan25 create /interfaces/interface[name='ge6']/ethernet-switching/access-interface/vlan -- vlan-name=vlan26 create /interfaces/interface[name='ge7']/ethernet-switching/access-interface/vlan -- vlan-name=vlan27 create /interfaces/interface[name='ge8']/ethernet-switching/access-interface/vlan -- vlan-name=vlan28 create /interfaces/interface[name='ge9']/ethernet-switching/access-interface/vlan -- vlan-name=vlan29 ''' yangcli_ok_script(yconns["local"], yangcli_script_local) yangcli_ok_script(yconns["remote"], yangcli_script_remote) yangcli_ok_script(yconns["middle"], yangcli_script_middle) tntapi.network_commit(conns) state_before = tntapi.network_get_state(network, conns, filter=filter) time.sleep(5) state_after = tntapi.network_get_state(network, conns, filter=filter) validate_step_1(state_before, state_after)
def main(): print(""" #Description: Validate leafs with failing when statements are removed from candidate #Procedure: #1 - Create /top/type = bar. #2 - Create '/top/foo'. #3 - Validate '/top/foo' is not 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa") if (conn == None): print("Error: yangrpc failed to connect!") return (-1) time.sleep(1) print("hello") ok = yangcli(conn, '''create /top/child -- type=bar foo=1''').xpath('./ok') assert (len(ok) == 1) result = yangcli(conn, "xget-config source=candidate /top") foo = result.xpath('./data/top/child/foo') assert (len(foo) == 0) ok = yangcli(conn, '''create /top/child/bar value=1''').xpath('./ok') assert (len(ok) == 1) print("done") return (0)
def main(): print(""" #Description: Demonstrate that leaf values can be replaced. #Procedure: #1 - Create interface "foo" of type=ethernetCsmacd. Verify commit succeeds. #2 - Replace type for interface "foo" with type=other. Read back the type after 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa") if (conn == None): print("Error: yangrpc failed to connect!") return (-1) time.sleep(1) ok = yangcli(conn, '''delete /interfaces''').xpath('./ok') ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) ok = yangcli( conn, '''create /interfaces/interface -- name='foo' type='ethernetCsmacd' ''' ).xpath('./ok') assert (len(ok) == 1) ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) result = yangcli(conn, "xget /interfaces") names = result.xpath('./data/interfaces/interface/name') for name in names: print name.text types = result.xpath('./data/interfaces/interface/type') for type in types: print type.text assert (len(types) == 1) assert (types[0].text == 'ianaift:ethernetCsmacd') ok = yangcli( conn, '''replace /interfaces/interface[name='foo']/type value='other' ''' ).xpath('./ok') assert (len(ok) == 1) ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) result = yangcli(conn, "xget /interfaces") names = result.xpath('./data/interfaces/interface/name') for name in names: print name.text types = result.xpath('./data/interfaces/interface/type') for type in types: print type.text assert (len(types) == 1) assert (types[0].text == 'ianaift:other') result = yangcli(conn, "delete /interfaces").xpath('./ok') assert (len(ok) == 1) result = yangcli(conn, "commit").xpath('./ok') assert (len(ok) == 1) return (0)
import os conn = yangrpc.connect( "127.0.0.1", 830, os.getenv("USER"), "dummypass", os.getenv("HOME") + ".ssh/id_rsa", os.getenv("HOME") + ".ssh/id_rsa.pub", ) if conn == None: print("Error: yangrpc failed to connect!") sys.exit(1) yangcli(conn, "replace /system/hostname value='ok3'") yangcli(conn, "replace /system/location value='ok4'") result = yangcli(conn, "commit") assert result.xpath("./ok") yangcli(conn, "replace /system/hostname value='error1'") yangcli(conn, "replace /system/location value='ok5'") result = yangcli(conn, "commit") assert result.xpath("./rpc-error") yangcli(conn, "discard-changes") yangcli(conn, "replace /system/hostname value='ok6'") yangcli(conn, "replace /system/location value='error2'") result = yangcli(conn, "commit") assert result.xpath("./rpc-error")
def step_1(network, conns, yconns, filter=filter): #Delete all result=yangcli(yconns["local"], "discard-changes") result=yangcli(yconns["local"], "delete /flows") result=yangcli(yconns["local"], "delete /bridge") result=yangcli(yconns["remote"], "discard-changes") result=yangcli(yconns["remote"], "delete /flows") result=yangcli(yconns["remote"], "delete /bridge") result=yangcli(yconns["middle"], "discard-changes") result=yangcli(yconns["middle"], "delete /flows") result=yangcli(yconns["middle"], "delete /bridge") tntapi.network_commit(conns) yangcli_script_local=''' create /bridge/ports/port -- name=n0 create /bridge/ports/port -- name=gm0 create /bridge/ports/port -- name=e0 create /bridge/ports/port -- name=e1 create /bridge/ports/port -- name=e2 create /bridge/ports/port -- name=e3 create /bridge/ports/port -- name=e4 create /bridge/ports/port -- name=e5 create /bridge/ports/port -- name=e6 create /bridge/ports/port -- name=e7 create /bridge/ports/port -- name=e8 create /bridge/ports/port -- name=e9 merge /interfaces/interface -- name=xe0 type=ethernetCsmacd port-name=n0 merge /interfaces/interface -- name=ge15 type=ethernetCsmacd port-name=gm0 merge /interfaces/interface -- name=ge0 type=ethernetCsmacd port-name=e0 merge /interfaces/interface -- name=ge1 type=ethernetCsmacd port-name=e1 merge /interfaces/interface -- name=ge2 type=ethernetCsmacd port-name=e2 merge /interfaces/interface -- name=ge3 type=ethernetCsmacd port-name=e3 merge /interfaces/interface -- name=ge4 type=ethernetCsmacd port-name=e4 merge /interfaces/interface -- name=ge5 type=ethernetCsmacd port-name=e5 merge /interfaces/interface -- name=ge6 type=ethernetCsmacd port-name=e6 merge /interfaces/interface -- name=ge7 type=ethernetCsmacd port-name=e7 merge /interfaces/interface -- name=ge8 type=ethernetCsmacd port-name=e8 merge /interfaces/interface -- name=ge9 type=ethernetCsmacd port-name=e9 create /flows/flow[id='gm0-to-n0-ptp'] -- match/in-port=gm0 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=e0 actions/action[order='1']/output-action/out-port=e1 actions/action[order='2']/output-action/out-port=e2 actions/action[order='3']/output-action/out-port=e3 actions/action[order='4']/output-action/out-port=e4 actions/action[order='5']/output-action/out-port=e5 actions/action[order='6']/output-action/out-port=e6 actions/action[order='7']/output-action/out-port=e7 actions/action[order='8']/output-action/out-port=e8 actions/action[order='9']/output-action/out-port=e9 actions/action[order='10']/push-vlan-action/vlan-id=100 actions/action[order='10']/push-vlan-action/ethernet-type=37120 actions/action[order='11']/output-action/out-port=n0 create /flows/flow[id='gm0-to-n0-unmatched'] -- match/in-port=gm0 actions/action[order='0']/push-vlan-action/vlan-id=200 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e0-to-n0-unmatched'] -- match/in-port=e0 actions/action[order='0']/push-vlan-action/vlan-id=10 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e1-to-n0-unmatched'] -- match/in-port=e1 actions/action[order='0']/push-vlan-action/vlan-id=11 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e2-to-n0-unmatched'] -- match/in-port=e2 actions/action[order='0']/push-vlan-action/vlan-id=12 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e3-to-n0-unmatched'] -- match/in-port=e3 actions/action[order='0']/push-vlan-action/vlan-id=13 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e4-to-n0-unmatched'] -- match/in-port=e4 actions/action[order='0']/push-vlan-action/vlan-id=14 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e5-to-n0-unmatched'] -- match/in-port=e5 actions/action[order='0']/push-vlan-action/vlan-id=15 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e6-to-n0-unmatched'] -- match/in-port=e6 actions/action[order='0']/push-vlan-action/vlan-id=16 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e7-to-n0-unmatched'] -- match/in-port=e7 actions/action[order='0']/push-vlan-action/vlan-id=17 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e8-to-n0-unmatched'] -- match/in-port=e8 actions/action[order='0']/push-vlan-action/vlan-id=18 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e9-to-n0-unmatched'] -- match/in-port=e9 actions/action[order='0']/push-vlan-action/vlan-id=19 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e0-to-n0-ptp'] -- match/in-port=e0 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e1-to-n0-ptp'] -- match/in-port=e1 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e2-to-n0-ptp'] -- match/in-port=e2 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e3-to-n0-ptp'] -- match/in-port=e3 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e4-to-n0-ptp'] -- match/in-port=e4 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e5-to-n0-ptp'] -- match/in-port=e5 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e6-to-n0-ptp'] -- match/in-port=e6 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e7-to-n0-ptp'] -- match/in-port=e7 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e8-to-n0-ptp'] -- match/in-port=e8 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e9-to-n0-ptp'] -- match/in-port=e9 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='n0-to-gm0-ptp'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=100 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=gm0 create /flows/flow[id='n0-to-gm0-unmatched'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=200 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=gm0 create /flows/flow[id='n0-to-e0'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=10 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e0 create /flows/flow[id='n0-to-e1'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=11 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e1 create /flows/flow[id='n0-to-e2'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=12 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e2 create /flows/flow[id='n0-to-e3'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=13 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e3 create /flows/flow[id='n0-to-e4'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=14 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e4 create /flows/flow[id='n0-to-e5'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=15 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e5 create /flows/flow[id='n0-to-e6'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=16 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e6 create /flows/flow[id='n0-to-e7'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=17 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e7 create /flows/flow[id='n0-to-e8'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=18 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e8 create /flows/flow[id='n0-to-e9'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=19 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e9 ''' yangcli_script_remote=''' create /bridge/ports/port -- name=n0 create /bridge/ports/port -- name=gm0 create /bridge/ports/port -- name=e0 create /bridge/ports/port -- name=e1 create /bridge/ports/port -- name=e2 create /bridge/ports/port -- name=e3 create /bridge/ports/port -- name=e4 create /bridge/ports/port -- name=e5 create /bridge/ports/port -- name=e6 create /bridge/ports/port -- name=e7 create /bridge/ports/port -- name=e8 create /bridge/ports/port -- name=e9 merge /interfaces/interface -- name=xe0 type=ethernetCsmacd port-name=n0 merge /interfaces/interface -- name=ge15 type=ethernetCsmacd port-name=gm0 merge /interfaces/interface -- name=ge0 type=ethernetCsmacd port-name=e0 merge /interfaces/interface -- name=ge1 type=ethernetCsmacd port-name=e1 merge /interfaces/interface -- name=ge2 type=ethernetCsmacd port-name=e2 merge /interfaces/interface -- name=ge3 type=ethernetCsmacd port-name=e3 merge /interfaces/interface -- name=ge4 type=ethernetCsmacd port-name=e4 merge /interfaces/interface -- name=ge5 type=ethernetCsmacd port-name=e5 merge /interfaces/interface -- name=ge6 type=ethernetCsmacd port-name=e6 merge /interfaces/interface -- name=ge7 type=ethernetCsmacd port-name=e7 merge /interfaces/interface -- name=ge8 type=ethernetCsmacd port-name=e8 merge /interfaces/interface -- name=ge9 type=ethernetCsmacd port-name=e9 create /flows/flow[id='gm0-to-n0-ptp'] -- match/in-port=gm0 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=e0 actions/action[order='1']/output-action/out-port=e1 actions/action[order='2']/output-action/out-port=e2 actions/action[order='3']/output-action/out-port=e3 actions/action[order='4']/output-action/out-port=e4 actions/action[order='5']/output-action/out-port=e5 actions/action[order='6']/output-action/out-port=e6 actions/action[order='7']/output-action/out-port=e7 actions/action[order='8']/output-action/out-port=e8 actions/action[order='9']/output-action/out-port=e9 actions/action[order='10']/push-vlan-action/vlan-id=100 actions/action[order='10']/push-vlan-action/ethernet-type=37120 actions/action[order='11']/output-action/out-port=n0 create /flows/flow[id='gm0-to-n0-unmatched'] -- match/in-port=gm0 actions/action[order='0']/push-vlan-action/vlan-id=200 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e0-to-n0-unmatched'] -- match/in-port=e0 actions/action[order='0']/push-vlan-action/vlan-id=20 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e1-to-n0-unmatched'] -- match/in-port=e1 actions/action[order='0']/push-vlan-action/vlan-id=21 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e2-to-n0-unmatched'] -- match/in-port=e2 actions/action[order='0']/push-vlan-action/vlan-id=22 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e3-to-n0-unmatched'] -- match/in-port=e3 actions/action[order='0']/push-vlan-action/vlan-id=23 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e4-to-n0-unmatched'] -- match/in-port=e4 actions/action[order='0']/push-vlan-action/vlan-id=24 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e5-to-n0-unmatched'] -- match/in-port=e5 actions/action[order='0']/push-vlan-action/vlan-id=25 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e6-to-n0-unmatched'] -- match/in-port=e6 actions/action[order='0']/push-vlan-action/vlan-id=26 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e7-to-n0-unmatched'] -- match/in-port=e7 actions/action[order='0']/push-vlan-action/vlan-id=27 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e8-to-n0-unmatched'] -- match/in-port=e8 actions/action[order='0']/push-vlan-action/vlan-id=28 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e9-to-n0-unmatched'] -- match/in-port=e9 actions/action[order='0']/push-vlan-action/vlan-id=29 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n0 create /flows/flow[id='e0-to-n0-ptp'] -- match/in-port=e0 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e1-to-n0-ptp'] -- match/in-port=e1 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e2-to-n0-ptp'] -- match/in-port=e2 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e3-to-n0-ptp'] -- match/in-port=e3 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e4-to-n0-ptp'] -- match/in-port=e4 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e5-to-n0-ptp'] -- match/in-port=e5 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e6-to-n0-ptp'] -- match/in-port=e6 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e7-to-n0-ptp'] -- match/in-port=e7 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e8-to-n0-ptp'] -- match/in-port=e8 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='e9-to-n0-ptp'] -- match/in-port=e9 match/ethernet-match/ethernet-type/type=35063 actions/action[order='0']/output-action/out-port=n0 create /flows/flow[id='n0-to-gm0-ptp'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=100 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=gm0 create /flows/flow[id='n0-to-gm0-unmatched'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=200 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=gm0 create /flows/flow[id='n0-to-e0'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=20 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e0 create /flows/flow[id='n0-to-e1'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=21 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e1 create /flows/flow[id='n0-to-e2'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=22 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e2 create /flows/flow[id='n0-to-e3'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=23 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e3 create /flows/flow[id='n0-to-e4'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=24 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e4 create /flows/flow[id='n0-to-e5'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=25 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e5 create /flows/flow[id='n0-to-e6'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=26 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e6 create /flows/flow[id='n0-to-e7'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=27 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e7 create /flows/flow[id='n0-to-e8'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=28 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e8 create /flows/flow[id='n0-to-e9'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=29 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e9 ''' yangcli_script_middle=''' create /bridge/ports/port -- name=n0 create /bridge/ports/port -- name=n1 create /bridge/ports/port -- name=e0 create /bridge/ports/port -- name=e1 create /bridge/ports/port -- name=e2 create /bridge/ports/port -- name=e3 create /bridge/ports/port -- name=e4 create /bridge/ports/port -- name=e5 create /bridge/ports/port -- name=e6 create /bridge/ports/port -- name=e7 create /bridge/ports/port -- name=e8 create /bridge/ports/port -- name=e9 merge /interfaces/interface -- name=xe0 type=ethernetCsmacd port-name=n0 merge /interfaces/interface -- name=xe1 type=ethernetCsmacd port-name=n1 merge /interfaces/interface -- name=ge0 type=ethernetCsmacd port-name=e0 merge /interfaces/interface -- name=ge1 type=ethernetCsmacd port-name=e1 merge /interfaces/interface -- name=ge2 type=ethernetCsmacd port-name=e2 merge /interfaces/interface -- name=ge3 type=ethernetCsmacd port-name=e3 merge /interfaces/interface -- name=ge4 type=ethernetCsmacd port-name=e4 merge /interfaces/interface -- name=ge5 type=ethernetCsmacd port-name=e5 merge /interfaces/interface -- name=ge6 type=ethernetCsmacd port-name=e6 merge /interfaces/interface -- name=ge7 type=ethernetCsmacd port-name=e7 merge /interfaces/interface -- name=ge8 type=ethernetCsmacd port-name=e8 merge /interfaces/interface -- name=ge9 type=ethernetCsmacd port-name=e9 create /flows/flow[id='e0-to-n1'] -- match/in-port=e0 actions/action[order='0']/push-vlan-action/vlan-id=20 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e1-to-n1'] -- match/in-port=e1 actions/action[order='0']/push-vlan-action/vlan-id=21 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e2-to-n1'] -- match/in-port=e2 actions/action[order='0']/push-vlan-action/vlan-id=22 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e3-to-n1'] -- match/in-port=e3 actions/action[order='0']/push-vlan-action/vlan-id=23 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e4-to-n1'] -- match/in-port=e4 actions/action[order='0']/push-vlan-action/vlan-id=24 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e5-to-n1'] -- match/in-port=e5 actions/action[order='0']/push-vlan-action/vlan-id=25 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e6-to-n1'] -- match/in-port=e6 actions/action[order='0']/push-vlan-action/vlan-id=26 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e7-to-n1'] -- match/in-port=e7 actions/action[order='0']/push-vlan-action/vlan-id=27 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e8-to-n1'] -- match/in-port=e8 actions/action[order='0']/push-vlan-action/vlan-id=28 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='e9-to-n1'] -- match/in-port=e9 actions/action[order='0']/push-vlan-action/vlan-id=29 actions/action[order='0']/push-vlan-action/ethernet-type=37120 actions/action[order='1']/output-action/out-port=n1 create /flows/flow[id='n0-to-e0'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=20 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e0 create /flows/flow[id='n0-to-e1'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=21 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e1 create /flows/flow[id='n0-to-e2'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=22 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e2 create /flows/flow[id='n0-to-e3'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=23 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e3 create /flows/flow[id='n0-to-e4'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=24 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e4 create /flows/flow[id='n0-to-e5'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=25 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e5 create /flows/flow[id='n0-to-e6'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=26 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e6 create /flows/flow[id='n0-to-e7'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=27 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e7 create /flows/flow[id='n0-to-e8'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=28 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e8 create /flows/flow[id='n0-to-e9'] -- match/in-port=n0 match/vlan-match/vlan-id/vlan-id=29 match/ethernet-match/ethernet-type/type=37120 actions/action[order='0']/pop-vlan-action actions/action[order='1']/output-action/out-port=e9 create /flows/flow[id='n0-to-n1'] -- match/in-port=n0 actions/action[order='0']/output-action/out-port=n1 create /flows/flow[id='n1-to-n0'] -- match/in-port=n1 actions/action[order='0']/output-action/out-port=n0 ''' yangcli_ok_script(yconns["local"], yangcli_script_local) yangcli_ok_script(yconns["remote"], yangcli_script_remote) yangcli_ok_script(yconns["middle"], yangcli_script_middle) tntapi.network_commit(conns) state_before = tntapi.network_get_state(network, conns, filter=filter) time.sleep(5) state_after = tntapi.network_get_state(network, conns, filter=filter) validate_step_1(state_before, state_after)
def validate(network, conns, yconns, inks, load_percent=99, frame_size=1500, interframe_gap=12, frames_per_burst=0, interburst_gap=0): filter = """<filter type="xpath" select="/interfaces-state/interface/*[local-name()='traffic-analyzer' or local-name()='oper-status' or local-name()='statistics' or local-name()='speed']"/>""" # config_idle=""" #<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> #</config> #""" config_idle = {} nodes = network.xpath('nd:node', namespaces=namespaces) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config = "" termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text ok = yangcli( yconns[node_id], """replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd""" % { 'name': tp_id }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) state_before = tntapi.network_get_state(network, conns, filter=filter) print("Waiting " + "5" + " sec. ...") time.sleep(5) print("Done.") state_after = tntapi.network_get_state(network, conns, filter=filter) mylinks = tntapi.parse_network_links(state_before) t1 = tntapi.parse_network_nodes(state_before) t2 = tntapi.parse_network_nodes(state_after) delta = tntapi.get_network_counters_delta(state_before, state_after) tntapi.print_state_ietf_interfaces_statistics_delta( network, state_before, state_after) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text validate_traffic_off(node_id, tp_id, state_before, state_after, delta) load = float(load_percent) / 100 print "ifg=" + str(interframe_gap) for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config = "" termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text if (frames_per_burst > 0): my_burst_config = """frames-per-burst=%(frames-per-burst)d interburst-gap=%(interburst-gap)d""" % { 'frames-per-burst': frames_per_burst, 'interburst-gap': interburst_gap - 8 } else: my_burst_config = "" ok = yangcli( yconns[node_id], """create /interfaces/interface[name='%(name)s']/traffic-generator -- frame-size=%(frame-size)d interframe-gap=%(interframe-gap)d %(burst)s""" % { 'name': tp_id, 'frame-size': frame_size, 'interframe-gap': interframe_gap - 8, 'burst': my_burst_config }).xpath('./ok') assert (len(ok) == 1) state_before = tntapi.network_get_state(network, conns, filter=filter) tntapi.network_commit(conns) print("Waiting " + str(test_time) + " sec. ...") time.sleep(test_time) print("Stopping generators ...") for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text config = "" termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text ok = yangcli( yconns[node_id], """replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd""" % { 'name': tp_id }).xpath('./ok') assert (len(ok) == 1) tntapi.network_commit(conns) print("Done.") state_after = tntapi.network_get_state(network, conns, filter=filter) t1 = tntapi.parse_network_nodes(state_before) t2 = tntapi.parse_network_nodes(state_after) delta = tntapi.get_network_counters_delta(state_before, state_after) tntapi.print_state_ietf_interfaces_statistics_delta( network, state_before, state_after) load_generated = {} for node in nodes: node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text termination_points = node.xpath('./nt:termination-point', namespaces=namespaces) for termination_point in termination_points: tp_id = termination_point.xpath('nt:tp-id', namespaces=namespaces)[0].text load_generated[node_id, tp_id] = validate_traffic_on( node_id, tp_id, state_before, state_after, delta, test_time, load_percent, frame_size, interframe_gap, frames_per_burst, interburst_gap) return (load_percent, load_generated)
def main(): print(""" #Description: Usecase fo ietf-routing module. #Procedure: #1 - Create interface "eth0" of type=ethernetCsmacd with static ip=10.0.0.2/24 and static default route for destination-prefix=0.0.0.0/0 and next-hop=10.0.0.1. #2 - Validate <get-data> returns identical result as the example 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME')+"/.ssh/id_rsa.pub", os.getenv('HOME')+"/.ssh/id_rsa", "--dump-session=tmp/nc-session-") if(conn==None): print("Error: yangrpc failed to connect!") return(-1) time.sleep(1) result = yangcli(conn, "delete /interfaces") result = yangcli(conn, "commit") ok = result.xpath('./ok') assert(len(ok)==1) yangcli_script=''' create /interfaces/interface -- name=eth0 type=ethernetCsmacd description="Uplink to ISP." create /interfaces/interface[name='eth0']/ipv4/address -- ip=192.0.2.1 prefix-length=24 commit ''' #create /interfaces/interface[name='eth0']/ipv4/forwarding value=true #create /routes/control-plane-protocols/control-plane-protocol -- name=st0 type=static #create /routes/control-plane-protocols/control-plane-protocol[name='st0']/static-routes/ipv4/route -- destination-prefix=0.0.0.0/0 next-hop/next-hop-address=192.0.2.2 #commit #''' yangcli_ok_script(conn, yangcli_script) result = yangcli(conn, "get-data with-origin datastore=operational xpath-filter="/" ) print lxml.etree.tostring(result) return(0)
from yangcli import yangcli from lxml import etree import yangrpc import sys import os conn = yangrpc.connect( "127.0.0.1", 830, os.getenv('USER'), None, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa", ) if (conn == None): print("Error: yangrpc failed to connect!") sys.exit(1) result = yangcli(conn, "commit") assert (result.xpath('./ok')) yangcli(conn, "replace /system/hostname value='ok3'") yangcli(conn, "replace /system/location value='ok4'") result = yangcli(conn, "commit") assert (result.xpath('./ok')) print("Done.")
import sys import os conn = yangrpc.connect( "127.0.0.1", 830, os.getenv('USER'), None, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa", ) if (conn == None): print("Error: yangrpc failed to connect!") sys.exit(1) result = yangcli(conn, "commit") assert (result.xpath('./ok')) yangcli(conn, "replace /system/hostname value='ok3'") yangcli(conn, "replace /system/location value='ok4'") result = yangcli(conn, "commit") assert (result.xpath('./ok')) yangcli(conn, "replace /system/hostname value='error1'") yangcli(conn, "replace /system/location value='ok5'") result = yangcli(conn, "commit") assert (result.xpath('./rpc-error')) yangcli(conn, "discard-changes") yangcli(conn, "replace /system/hostname value='ok6'") yangcli(conn, "replace /system/location value='error2'") result = yangcli(conn, "commit")
from yangcli import yangcli import lxml import yangrpc import sys import os conn = yangrpc.connect( "127.0.0.1", 830, os.getenv('USER'), None, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa", ) if (conn == None): print("Error: yangrpc failed to connect!") sys.exit(1) result = yangcli(conn, "xget /system-state/platform") print lxml.etree.tostring(result) assert ("foo" == result.xpath('./data/system-state/platform/os-name')[0].text) assert ( "bar" == result.xpath('./data/system-state/platform/os-release')[0].text) print("Done.")
def main(): print(""" #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 = yangrpc.connect(server, port, user, password, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa", "--dump-session=tmp/nc-session-") if (conn == None): print("Error: yangrpc failed to connect!") return (-1) time.sleep(1) ok = yangcli(conn, '''delete /vlans''').xpath('./ok') ok = yangcli(conn, '''delete /interfaces''').xpath('./ok') ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) yangcli_script = ''' create /interfaces/interface -- name='xe0' type='ethernetCsmacd' create /interfaces/interface -- name='ge0' type='ethernetCsmacd' create /interfaces/interface -- name='ge1' type='ethernetCsmacd' create /interfaces/interface -- name='ge1-green' type=ethSubInterface parent-interface=ge0 create /interfaces/interface[name='ge1-green']/forwarding-mode value=layer-2-forwarding create /interfaces/interface[name='ge1-green']/encapsulation/flexible/match/dot1q-vlan-tagged/outer-tag/dot1q-tag -- tag-type=c-vlan vlan-id=10 create /interfaces/interface -- name='xe0-green' type=ethSubInterface parent-interface=xe0 create /interfaces/interface[name='xe0-green']/forwarding-mode value=layer-2-forwarding create /interfaces/interface[name='xe0-green']/encapsulation/flexible/match/dot1q-vlan-tagged/outer-tag/dot1q-tag -- tag-type=s-vlan vlan-id=1000 create /interfaces/interface[name='xe0-green']/encapsulation/flexible/match/dot1q-vlan-tagged/second-tag/dot1q-tag -- tag-type=c-vlan vlan-id=10 create /vlans/vlan -- name=green create /vlans/vlan[name='green']/interface value=ge0 create /vlans/vlan[name='green']/interface value=ge1-green create /vlans/vlan[name='green']/interface value=xe0-green commit ''' yangcli_ok_script(conn, yangcli_script) result = yangcli(conn, "xget /interfaces") names = result.xpath('./data/interfaces/interface/name') for name in names: print name.text types = result.xpath('./data/interfaces/interface/type') for type in types: print type.text #cleanup # ok = yangcli(conn, '''delete /vlans''').xpath('./ok') # assert(len(ok)==1) # ok = yangcli(conn, '''delete /interfaces''').xpath('./ok') # assert(len(ok)==1) # ok = yangcli(conn, '''commit''').xpath('./ok') # assert(len(ok)==1) return (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("--operation", help="One of {configure-nacm, create, replace, read}") parser.add_argument("--option", help="One of {foo, bar, baz}") args = parser.parse_args() print( """ #Description: Validate nacm --operation=%(operation)s --option=%(option)s #Procedure: #1 - Do %(operation)s. """ % { 'operation': args.operation, 'option': args.option }) 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 = yangrpc.connect(server, port, user, password, os.getenv('HOME') + "/.ssh/id_rsa.pub", os.getenv('HOME') + "/.ssh/id_rsa") if (conn == None): print("Error: yangrpc failed to connect!") return (-1) if (args.operation == 'configure-nacm'): ok = yangcli( conn, '''create /nacm/groups/group[name='my-operators-group']/user-name value=%s''' % (user)).xpath('./ok') assert (len(ok) == 1) ok = yangcli( conn, '''create /nacm/rule-list[name='my-operators-rules'] -- group=my-operators-group''' ).xpath('./ok') assert (len(ok) == 1) ok = yangcli( conn, '''create /nacm/rule-list[name='my-operators-rules']/rule[name='my-foo-all-permit'] -- module-name=m1 path=/top/foo access-operations=* action=permit comment='With this rule the user can create /top/foo' ''' ).xpath('./ok') assert (len(ok) == 1) ok = yangcli( conn, '''create /nacm/rule-list[name='my-operators-rules']/rule[name='my-baz-read-deny'] -- module-name=m1 path=/top/baz access-operations=read action=deny comment='With this rule the user can not read /top/baz' ''' ).xpath('./ok') assert (len(ok) == 1) ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) elif (args.operation == 'get'): result = yangcli(conn, '''sget /top/%s''' % (args.option)) value = result.xpath('./data/top/%s' % (args.option)) print etree.tostring(result, pretty_print=True, inclusive_ns_prefixes=True) assert (len(value) == 1) assert (value[0].text == args.option) else: ok = yangcli( conn, '''%s /top/%s value=%s''' % (args.operation, args.option, args.option)).xpath('./ok') assert (len(ok) == 1) ok = yangcli(conn, '''commit''').xpath('./ok') assert (len(ok) == 1) print("done") return (0)