Ejemplo n.º 1
0
def of_demo_3():
    f = "cfg.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 3 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    print ("<<< Creating Controller instance")
    time.sleep(rundelay)
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd, None)
    print ("'Controller':")
    print ctrl.brief_json()

    print ("\n")
    print ("<<< Get detailed information about ports on OpenFlow node '%s'" %
           nodeName)
    time.sleep(rundelay)
    ofswitch = OFSwitch(ctrl, nodeName)

    result = ofswitch.get_ports_list()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        ports = result.get_data()
        for port in ports:
            result = ofswitch.get_port_detail_info(port)
            status = result.get_status()
            if(status.eq(STATUS.OK)):
                print ("Port '%s' info:" % port)
                info = result.get_data()
                print json.dumps(info, indent=4)
            else:
                print ("\n")
                print ("!!!Demo terminated, reason: %s" %
                       status.brief().lower())
                exit(0)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 2
0
    def test_ControllerGetSchemas(self, controller):

        print ("--------------------------------------------------------- ")
        print ("<< Test ControllerGetSchemas Start")
        print ("--------------------------------------------------------- ")
        print ("<< Creating Controller instance")
        time.sleep(self.rundelay)
        ctrl = Controller(self.ctrlIpAddr, self.ctrlPortNum, self.ctrlUname, self.ctrlPswd)
        print ("<< 'Controller':")
        print ctrl.to_json()

        print ("\n<< Getting list of YANG models supported by the Controller ")
        time.sleep(self.rundelay)
        nodeName = "controller-config"

        result = ctrl.get_schemas(nodeName)
        status = result.get_status()

        if(status.eq(STATUS.OK)):
            slist = result.get_data()
            print "\n<< YANG models list: %s" % slist
            print "\n<< JSON dumps:"
            print json.dumps(slist, default=lambda o: o.__dict__,
                             sort_keys='True', indent=4)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.brief())

        # and verify the results
        self.assertEquals(str(slist), "[{u'location': [u'NETCONF'], u'identifier': u'threadpool-impl', u'namespace': u'urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl', u'version': u'2013-04-05', u'format': u'ietf-netconf-monitoring:yang'}]")
Ejemplo n.º 3
0
    def test_ControllerGetSchemas(self, controller):

        print ("--------------------------------------------------------- ")
        print ("<< Test ControllerGetSchemas Start")
        print ("--------------------------------------------------------- ")
        print ("<< Creating Controller instance")
        time.sleep(self.rundelay)
        ctrl = Controller(self.ctrlIpAddr, self.ctrlPortNum, self.ctrlUname, self.ctrlPswd)
        print ("<< 'Controller':")
        print ctrl.to_json()

        print ("\n<< Getting list of YANG models supported by the Controller ")
        time.sleep(self.rundelay)
        nodeName = "controller-config"

        result = ctrl.get_schemas(nodeName)
        status = result.get_status()

        if(status.eq(STATUS.OK)):
            slist = result.get_data()
            print "\n<< YANG models list: %s" % slist
            print "\n<< JSON dumps:"
            print json.dumps(slist, default=lambda o: o.__dict__,
                             sort_keys='True', indent=4)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.brief())

        # and verify the results
        self.assertEquals(str(slist), "[u'(urn:ietf:params:xml:ns:yang:ietf-network-topology?revision=2015-06-08)ietf-network-topology', u'(urn:opendaylight:flow:errors?revision=2013-11-16)flow-errors', u'(urn:opendaylight:params:xml:ns:yang:topology:pcep?revision=2013-10-24)network-topology-pcep', u'(urn:opendaylight:params:xml:ns:yang:bgp-message?revision=2013-09-19)bgp-message', u'(urn:opendaylight:params:xml:ns:yang:netvirt:providers:config?revision=2016-01-09)netvirt-providers-config', u'(urn:opendaylight:params:xml:ns:yang:controller:netty:timer?revision=2013-11-19)netty-timer']")
Ejemplo n.º 4
0
    def test_ControllerGetNodeList(self, controller):

        print ("--------------------------------------------------------- ")
        print ("<< Test ControllerNodeList Start")
        print ("--------------------------------------------------------- ")
        print ("<< Getting list of all nodes registered on the Controller ")

        ctrl = Controller(self.ctrlIpAddr, self.ctrlPortNum, self.ctrlUname, self.ctrlPswd)
        result = ctrl.get_nodes_operational_list()
        status = result.get_status()

        if(status.eq(STATUS.OK)):
            print "Nodes:"
            nlist = result.get_data()
            for item in nlist:
                print "   * {} *".format(item)
        else:
            print ("\n")
            print ("!!!Failed, reason: %s" % status.brief().lower())
            exit(0)
        print "<  Number of nodes in list: %s > " % len(nlist)
        print "\n"

        # and verify the results
        self.assertEquals(3, len(nlist))
Ejemplo n.º 5
0
def do_vr_cfg_1(vr_cfg_params):
    logging.info("in do_vr_cfg_1 for %s", vr_cfg_params['nodeName_1'])

    ctrl = Controller(vr_cfg_params['ctrlIpAddr'], vr_cfg_params['ctrlPortNum'],
                      vr_cfg_params['ctrlUname'], vr_cfg_params['ctrlPswd'])

    vrouter = VRouter5600(ctrl, vr_cfg_params['nodeName_1'], vr_cfg_params['nodeIpAddr_1'],
                          vr_cfg_params['nodePortNum_1'], vr_cfg_params['nodeUname_1'], vr_cfg_params['nodePswd_1'])

    node_configured = False
    result = ctrl.check_node_config_status(vr_cfg_params['nodeName_1'])
    status = result.get_status()
    if status.eq(STATUS.NODE_CONFIGURED):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % vr_cfg_params['nodeName_1'])
    elif status.eq(STATUS.DATA_NOT_FOUND):
        node_configured = False
    else:
        logging.info ("\n")
        logging.info ("Failed to get configuration status for the '%s'" % vr_cfg_params['nodeName_1'])
        logging.info ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if status.eq(STATUS.OK):
            logging.info ("<<< '%s' added to the Controller" % vr_cfg_params['nodeName_1'])
        else:
            logging.info ("\n")
            logging.info ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    result = ctrl.check_node_conn_status(vr_cfg_params['nodeName_1'])
    status = result.get_status()
    if status.eq(STATUS.NODE_CONNECTED):
        logging.info ("<<< '%s' is connected to the Controller" % vr_cfg_params['nodeName_1'])
    else:
        logging.info ("\n")
        logging.info ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    set_loopback_interface_1(ctrl, vr_cfg_params)

    dp1_1 = DataPlaneInterface(vr_cfg_params['dp1Name_1'])
    dp1_1.set_address(vr_cfg_params['dp1Addr_1'])
    vrouter.set_dataplane_interface_cfg(dp1_1)

    dp2_1 = DataPlaneInterface(vr_cfg_params['dp1Name_2'])
    dp2_1.set_address(vr_cfg_params['dp1Addr_2'])
    vrouter.set_dataplane_interface_cfg(dp2_1)

    dp3_1 = DataPlaneInterface(vr_cfg_params['dp1Name_3'])
    dp3_1.set_address(vr_cfg_params['dp1Addr_3'])
    vrouter.set_dataplane_interface_cfg(dp3_1)

    set_ospf_cfg_1(ctrl, vr_cfg_params)
    set_bgp_cfg_1(ctrl, vr_cfg_params)

    sys.exit(0)
Ejemplo n.º 6
0
def nc_demo_2():

    f = "cfg1.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    print ("<<< Creating Controller instance")
    time.sleep(rundelay)
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("'Controller':")
    print ctrl.to_json()

    print "\n"
    yangModelName = "flow-topology-discovery"
    yangModelVerson = "2013-08-19"
    print ("<<< Retrieve '%s' YANG model definition "
           "from the Controller" % yangModelName)
    time.sleep(rundelay)
    nodeName = "controller-config"
    result = ctrl.get_schema(nodeName, yangModelName, yangModelVerson)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("YANG model:")
        schema = result.get_data()
        print schema
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 7
0
 def __init__(self, ip, port, user, password):
     Controller.__init__(self, ip, port, user, password)
     # initialize session object
     result = self.build_inventory_object()
     if(result.status.eq(STATUS.OK)):
         self.inventory = result.data
         result = self.build_topology_object("flow:1")
         if(result.status.eq(STATUS.OK)):
             self.topology = result.data
         else:
             print "Warning: Can't build topology"
     else:
         print "Houston we have a problem {}".format(result.status.to_string())
         exit()
Ejemplo n.º 8
0
def nc_demo_3():

    f = "cfg1.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    print ("<<< Creating Controller instance")
    time.sleep(rundelay)
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("'Controller':")
    print ctrl.to_json()

    print "\n"
    print ("<<< Get list of service provider applications "
           "available on the Controller")
    time.sleep(rundelay)
    result = ctrl.get_service_providers_info()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        services = result.get_data()
        print "Service providers:"
        print json.dumps(services, default=lambda o: o.__dict__,
                         sort_keys=True, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 9
0
def nc_demo_5():

    f = "cfg1.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    print ("<<< Creating Controller instance")
    time.sleep(rundelay)
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("'Controller':")
    print ctrl.to_json()

    print "\n"
    print ("<<< Show list of all NETCONF operations "
           "supported by the Controller")
    time.sleep(rundelay)
    result = ctrl.get_netconf_operations("controller-config")
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "NETCONF operations:"
        slist = result.get_data()
        print json.dumps(slist, default=lambda o: o.__dict__,
                         sort_keys=True, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 10
0
    def test_ControllerGetSchemas_404(self, controller):

        print ("--------------------------------------------------------- ")
        print ("<< Test ControllerGetSchemas_HTTP_Error Start")
        print ("--------------------------------------------------------- ")
        print ("<< Creating Controller instance")
        time.sleep(self.rundelay)
        ctrl = Controller(self.ctrlIpAddr, self.ctrlPortNum, self.ctrlUname, self.ctrlPswd)
        print ("\n<< Getting list of YANG models supported by the Controller ")
        time.sleep(self.rundelay)
        nodeName = "controller-config"

        result = ctrl.get_schemas(nodeName)
        status = result.get_status()
        print ("<< Request Status: %s" % status.brief())

        # and verify the results: STATUS.HTTP_ERROR
        self.assertEquals(10, status.status_code)
Ejemplo n.º 11
0
    def test_ControllerGetSchemas_no_content(self, controller):

        print ("--------------------------------------------------------- ")
        print ("<< Test ControllerGetSchemas_no_content Start")
        print ("--------------------------------------------------------- ")
        print ("<< Creating Controller instance")
        time.sleep(self.rundelay)
        ctrl = Controller(self.ctrlIpAddr, self.ctrlPortNum, self.ctrlUname, self.ctrlPswd)
        print ("<< 'Controller':")
        print ctrl.to_json()

        print ("\n<< Getting list of YANG models supported by the Controller ")
        time.sleep(self.rundelay)
        nodeName = "controller-config"

        result = ctrl.get_schemas(nodeName)
        status = result.get_status()
        print ("<< Verifying STATUS.DATA_NOT_FOUND ")

        # and verify the results: STATUS.DATA_NOT_FOUND
        self.assertEquals(2, status.status_code)
Ejemplo n.º 12
0
    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    node = NetconfNode(ctrl, nodeName, nodeIpAddr, nodePortNum,
                       nodeUname, nodePswd)

    print (">>> Adding '%s' to the Controller '%s'" % (nodeName, ctrlIpAddr))
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is already configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print ("!!!Failed, reason: %s" % status.brief().lower())
Ejemplo n.º 13
0
def vr_demo_1():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr,
                          nodePortNum, nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print ("\n")
    print ("<<< Get list of all YANG models supported by the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_schemas()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "YANG models list:"
        slist = result.get_data()
        print json.dumps(slist, default=lambda o: o.__dict__,
                         sort_keys=True, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 14
0
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print "\n"
    print ("<<< Get list of all nodes registered on the Controller")
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    result = ctrl.get_nodes_operational_list()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Nodes:"
        nlist = result.get_data()
        for item in nlist:
            print "   '{}'".format(item)
    else:
        print ("\n")
        print ("!!!Failed, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
Ejemplo n.º 15
0
def of_demo_44():
    f = "cfg.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit(0)

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    openflow_nodes = []

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 44 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print "\n"
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum))
    time.sleep(rundelay)

    print "\n".strip()
    print ("<<< Get OpenFlow switches information")
    time.sleep(rundelay)

    inv_obj = None
    result = ctrl.build_inventory_object()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        inv_obj = result.get_data()
        assert(isinstance(inv_obj, Inventory))
    else:
        print ("\n")
        print ("!!!Error, failed to obtain inventory info, reason: %s" %
               status.brief().lower())
        exit(0)

    assert(inv_obj)
    openflow_node_ids = inv_obj.get_openflow_node_ids()
    for node_id in openflow_node_ids:
        node = inv_obj.get_openflow_node(node_id)
        assert(isinstance(node, OpenFlowCapableNode))
        openflow_nodes.append(node)

    print "\n".strip()
    print ("<<< OpenFlow switches in the inventory store")
    s1 = 'IP Address'
    s2 = 'OpenFlow Id'
    sym = '-'
    print "\n".strip()
    print "        {0:<15}  {1:<30}".format(s1, s2)
    print "        {0:<15}  {1:<30}".format(sym * 15, sym * 30)
    for node in openflow_nodes:
        addr = node.get_ip_address()
        node_id = node.get_id()
        print "        {0:<15}  {1:<30}".format(addr, node_id)

    print "\n".strip()
    print ("<<< Get Meter Features Information")
    time.sleep(rundelay)
    for node in openflow_nodes:
        assert(isinstance(node, OpenFlowCapableNode))
        print "\n".strip()
        switch_id = node.get_id()
        print ("        Switch '%s'") % switch_id
        print "\n".strip()
        meter_features = node.get_meter_features()
        assert(isinstance(meter_features, MeterFeatures))

        s = 'Max meters'
        v = meter_features.get_max_meters()
        if v is not None:
            print "            %s    : %s" % (s, v)
        else:
            print "            %s    : %s" % (s, "n/a")
        s = "Max bands"
        v = meter_features.get_max_bands()
        if v is not None:
            print "            %s     : %s" % (s, v)
        else:
            print "            %s    : %s" % (s, "n/a")
        s = "Max colors"
        v = meter_features.get_max_colors()
        if v is not None:
            print "            %s    : %s" % (s, v)
        else:
            print "            %s    : %s" % (s, "n/a")

        q = 4  # number of list items to be in a single chunk (output string)

        s = 'Band types'
        alist = meter_features.get_band_types()
        if alist:
            chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
            print "            %s    :" % s,
            for i in range(0, len(chunks)):
                n = 0 if i == 0 else len(s) + 18
                print "%s%s" % (" " * n, ", ".join(chunks[i]))
        else:
            print "            %s    : %s" % (s, "n/a")

        s = 'Capabilities'
        alist = meter_features.get_capabilities()
        if alist:
            chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
            print "            %s  :" % s,
            for i in range(0, len(chunks)):
                n = 0 if i == 0 else len(s) + 16
                print "%s%s" % (" " * n, ", ".join(chunks[i]))
        else:
            print "            %s  : %s" % (s, "n/a")

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 16
0
def of_demo_32():
    f = "cfg.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit(0)

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    openflow_nodes = []

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 32 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print "\n"
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum))
    time.sleep(rundelay)

    print "\n".strip()
    print ("<<< Get OpenFlow switches information")
    time.sleep(rundelay)

    inv_obj = None
    result = ctrl.build_inventory_object()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        inv_obj = result.get_data()
        assert(isinstance(inv_obj, Inventory))
    else:
        print ("\n")
        print ("!!!Error, failed to obtain inventory info, reason: %s" %
               status.brief().lower())
        exit(0)

    assert(inv_obj)
    openflow_node_ids = inv_obj.get_openflow_node_ids()
    for node_id in openflow_node_ids:
        node = inv_obj.get_openflow_node(node_id)
        assert(isinstance(node, OpenFlowCapableNode))
        openflow_nodes.append(node)

    print "\n".strip()
    print ("<<< OpenFlow switches in the inventory store")
    s1 = 'IP Address'
    s2 = 'OpenFlow Id'
    sym = '-'
    print "\n".strip()
    print "        {0:<15}  {1:<30}".format(s1, s2)
    print "        {0:<15}  {1:<30}".format(sym * 15, sym * 30)
    for node in openflow_nodes:
        addr = node.get_ip_address()
        node_id = node.get_id()
        print "        {0:<15}  {1:<30}".format(addr, node_id)

    print "\n".strip()
    print ("<<< Get Group Features Information")
    time.sleep(rundelay)
    for node in openflow_nodes:
        assert(isinstance(node, OpenFlowCapableNode))
        print "\n".strip()
        switch_id = node.get_id()
        print ("        Switch '%s'") % switch_id
        print "\n".strip()
        group_features = node.get_group_features()
        assert(isinstance(group_features, GroupFeatures))

        q = 2  # number of list items to be in a single chunk (output string)

        s = 'Max groups'
        alist = group_features.get_max_groups()
        if alist:
            chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
            print "            %s     :" % s,
            for i in range(0, len(chunks)):
                n = 0 if i == 0 else len(s) + 19
                print "%s%s" % (" " * n, ", ".join(map(str, chunks[i])))
        else:
            print "            %s     : %s" % (s, "n/a")

        s = 'Group types'
        alist = group_features.get_types()
        if alist:
            chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
            print "            %s    :" % s,
            for i in range(0, len(chunks)):
                n = 0 if i == 0 else len(s) + 18
                print "%s%s" % (" " * n, ", ".join(chunks[i]))
        else:
            print "            %s    : %s" % (s, "n/a")

        s = 'Capabilities'
        alist = group_features.get_capabilities()
        if alist:
            chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
            print "            %s   :" % s,
            for i in range(0, len(chunks)):
                n = 0 if i == 0 else len(s) + 17
                print "%s%s" % (" " * n, ", ".join(chunks[i]))
        else:
            print "            %s   : %s" % (s, "n/a")

        s = 'Actions'
        actions = group_features.get_actions()
        if actions:
            print "            %s        :" % s,
            for i, alist in enumerate(actions):
                n = 0 if i == 0 else len(s) + 12
                chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
                for j in range(0, len(chunks)):
                    n = 0 if i == 0 and j == 0 else len(s) + 22
                    print "%s%s" % (" " * n, ", ".join(chunks[j]))
                print "\n".strip()
        else:
            print "            %s        : %s" % (s, "n/a")

        print "\n".strip()
        total_num = node.get_groups_total_num()
        s = 'Num of groups'
        print "            %s  : %s" % (s, total_num)

        s = 'Group IDs'
        alist = node.get_group_ids()
        if alist:
            chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)]
            print "            %s      :" % s,
            for i in range(0, len(chunks)):
                n = 0 if i == 0 else len(s) + 13
                print "%s%s" % (" " * n, ", ".join(map(str, chunks[i])))
        else:
            print "            %s      : %s" % (s, "")

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 17
0
        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']

        interfaceName = d['interfaceName']

        vifId = d['vifId']
    except:
        print ("Failed to get Controller and Node device attributes from Configuration file %s" % f)
        exit(0)

    # Instantiate the Controller and vr5600 node
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)

    print ("Configuration Information: 'Controller IP': %s, vr5600 Name:IP:vlan-id '%s': %s : %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr, vifId))

    # wait on input
    print "\n"
    user_input = raw_input("Press any key to add the vr5600: ")

    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
Ejemplo n.º 18
0
def vr_demo_8():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show VPN configuration on the '%s'" % nodeName)
    result = vrouter.get_vpn_cfg()
    time.sleep(rundelay)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' VPN configuration:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No VPN configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print (">>> Create new VPN configuration on the '%s'" % (nodeName))
    description = ("Remote Access VPN Configuration Example - "
                   "L2TP/IPsec with Pre-Shared Key")
    external_ipaddr = "12.34.56.78"
    nexthop_ipaddr = "12.34.56.254"
    nat_traversal = True
    nat_allow_network = "192.168.100.0/24"
    client_ip_pool_start = "192.168.100.11"
    client_ip_pool_end = "192.168.100.210"
    ipsec_auth_mode = "pre-shared-secret"
    ipsec_auth_secret = "!secrettext!"
    l2tp_auth_mode = "local"
    uname1 = "user1"
    upswd1 = "user1_password"
    uname2 = "user2"
    upswd2 = "user2_password"
    uname3 = "user3"
    upswd3 = "user3_password"
    dns_srv1 = "192.168.100.1"
    dns_srv2 = "192.168.100.2"
    wins_srv1 = "192.168.100.3"
    wins_srv2 = "192.168.100.4"
    mtu = "16384"
    print (" VPN options to be set:\n"
           "   - Configuration description            : '%s'\n"
           "   - Server external address              : '%s'\n"
           "   - Next hop router address              : '%s'\n"
           "   - NAT_traversal                        : '%s'\n"
           "   - NAT allowed networks                 : '%s'\n"
           "   - Client addresses pool (start/end)    : '%s'/'%s'\n"
           "   - IPsec authentication (mode/secret)   : '%s'/'%s'\n"
           "   - L2TP authentication  mode            : '%s'\n"
           "   - Allowed users (name/password)        : '%s'/'%s'\n"
           "                                            '%s'/'%s'\n"
           "                                            '%s'/'%s'\n"
           "   - DNS servers (primary/secondary)      : '%s'/'%s'\n"
           "   - WINS servers (primary/secondary)     : '%s'/'%s'\n"
           "   - Maximum Transmission Unit            : '%s'\n"
           % (description, external_ipaddr, nexthop_ipaddr,
              "enabled" if nat_traversal else "disabled",
              nat_allow_network,
              client_ip_pool_start, client_ip_pool_end,
              ipsec_auth_mode, ipsec_auth_secret,
              l2tp_auth_mode,
              uname1, upswd1,
              uname2, upswd2,
              uname3, upswd3,
              dns_srv1, dns_srv2,
              wins_srv1, wins_srv2,
              mtu
              )
           )

    time.sleep(rundelay)

    # -------------------------------------------------------------------------
    # Encode VPN configuration options by using 'Vpn' object
    # -------------------------------------------------------------------------
    vpn = Vpn()

    # This VPN configuration description
    vpn.set_l2tp_remote_access_description(description)

    # Enable NAT traversal
    vpn.set_nat_traversal(nat_traversal)

    # Set the allowed subnets
    vpn.set_nat_allow_network(nat_allow_network)

    # Bind the L2TP server to the external IP address
    vpn.set_l2tp_remote_access_outside_address(external_ipaddr)

    # Set the next hop IP address for reaching the VPN clients
    vpn.set_l2tp_remote_access_outside_nexthop(nexthop_ipaddr)

    # Set up the pool of IP addresses that remote VPN connections will assume.
    # In this example we make 100 addresses available (from .11 to .210) on
    # subnet  192.168.100.0/24
    vpn.set_l2tp_remote_access_client_ip_pool(start=client_ip_pool_start,
                                              end=client_ip_pool_end)

    # Set the IPsec authentication mode to 'pre-shared-secret'
    vpn.set_l2tp_remote_access_ipsec_auth_mode(mode=ipsec_auth_mode)

    # Set the 'pre-shared-secret' value
    func = vpn.set_l2tp_remote_access_ipsec_auth_pre_shared_secret
    func(secret=ipsec_auth_secret)

    # Set the L2TP remote access user authentication mode to 'local'
    vpn.set_l2tp_remote_access_user_auth_mode(l2tp_auth_mode)

    # Set the L2TP remote access user credentials ('username'/'password')
    vpn.set_l2tp_remote_access_user(name=uname1, pswd=upswd1)
    vpn.set_l2tp_remote_access_user(name=uname2, pswd=upswd2)
    vpn.set_l2tp_remote_access_user(name=uname3, pswd=upswd3)

    # Set 'primary' and 'secondary' DNS servers
    vpn.set_l2tp_remote_access_primary_dns_server(dns_srv1)
    vpn.set_l2tp_remote_access_secondary_dns_server(dns_srv2)

    # Set 'primary' and 'secondary' WINS servers
    vpn.set_l2tp_remote_access_primary_wins_server(wins_srv1)
    vpn.set_l2tp_remote_access_secondary_wins_server(wins_srv2)

    # Set Maximum Transmission Unit (MTU <128..16384>)
    vpn.set_l2tp_remote_access_mtu(mtu)

    print "\n"
    print (">>> VPN configuration to be applied to the '%s'" % (nodeName))
    print vpn.get_payload()
    time.sleep(rundelay)
    result = vrouter.set_vpn_cfg(vpn)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< VPN configuration was successfully created")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show VPN configuration on the '%s'" % (nodeName))
    time.sleep(rundelay)
    result = vrouter.get_vpn_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' VPN configuration:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
        print ("<<< VPN configuration was successfully read")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Delete VPN configuration from the '%s'" % (nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_vpn_cfg()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("VPN configuration successfully removed from '%s'" % (nodeName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show VPN configuration on the '%s'" % (nodeName))
    time.sleep(rundelay)
    result = vrouter.get_vpn_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' VPN configuration:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No VPN configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
Ejemplo n.º 19
0
def vr_demo_13():

    f = "cfg4.yml"
    d = {}
    if load_dict_from_file(f, d) is False:
        print ("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d["ctrlIpAddr"]
        ctrlPortNum = d["ctrlPortNum"]
        ctrlUname = d["ctrlUname"]
        ctrlPswd = d["ctrlPswd"]

        nodeName = d["nodeName"]
        nodeIpAddr = d["nodeIpAddr"]
        nodePortNum = d["nodePortNum"]
        nodeUname = d["nodeUname"]
        nodePswd = d["nodePswd"]
        rundelay = d["rundelay"]
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    print ("<<< OpenVPN configuration example: " "Site-to-Site Mode with Preshared Secret")
    print ("\n")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if status.eq(STATUS.NODE_CONFIGURED):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif status.eq(STATUS.DATA_NOT_FOUND):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if status.eq(STATUS.OK):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if status.eq(STATUS.NODE_CONNECTED):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print ("\n")
    print ("<<< Show OpenVPN interfaces configuration on the '%s'" % nodeName)
    result = vrouter.get_openvpn_interfaces_cfg()
    time.sleep(rundelay)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("'%s' OpenVPN interfaces configuration:" % nodeName)
        iflist = result.get_data()
        assert isinstance(iflist, list)
        for item in iflist:
            print json.dumps(item, indent=4, sort_keys=True)
    elif status.eq(STATUS.DATA_NOT_FOUND):
        print ("No OpenVPN interfaces configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    ifname = "vtun0"
    print (">>> Configure new '%s' OpenVPN tunnel interface on the '%s'" % (ifname, nodeName))
    time.sleep(rundelay)

    # Create OpenVPN interface
    vpnif = OpenVpnInterface(ifname)

    # Set the OpenVPN mode to 'site-to-site'
    mode = "site-to-site"
    vpnif.set_mode(mode)

    # Specify the location of the file containing the preshared secret
    secret_file = "/config/auth/secret"
    vpnif.set_shared_secret_key_file(secret_file)

    # Set the tunnel IP address for the local endpoint
    local_address = "192.168.200.1"
    vpnif.set_local_address(local_address)

    # Set the tunnel IP address of the remote endpoint
    remote_address = "192.168.200.2"
    vpnif.set_remote_address(remote_address)

    # Specify the physical IP address of the remote host
    remote_host = "87.65.43.21"
    vpnif.set_remote_host(remote_host)

    result = vrouter.set_openvpn_interface_cfg(vpnif)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("<<< '%s' interface configuration was successfully created" % ifname)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show '%s' interface configuration on the '%s'" % (ifname, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_openvpn_interface_cfg(ifname)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("'%s' interface configuration:" % ifname)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
        print ("<<< '%s' interface configuration was successfully read" % ifname)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    ip_prefix = "192.168.101.0/24"
    print (
        "<<< Create static route to access the remote subnet '%s' " "through the '%s' interface " % (ip_prefix, ifname)
    )
    time.sleep(rundelay)
    static_route = StaticRoute()
    static_route.set_interface_route(ip_prefix)
    static_route.set_interface_route_next_hop_interface(ip_prefix, ifname)
    result = vrouter.set_protocols_static_route_cfg(static_route)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("<<< Static route was successfully created")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show subnet '%s' static route configuration on the '%s'" % (ip_prefix, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_protocols_static_interface_route_cfg(ip_prefix)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("Static route configuration:")
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
        print ("<<< Static route configuration was successfully read")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Delete '%s' interface configuration from the '%s'" % (ifname, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_openvpn_interface_cfg(ifname)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("<<< '%s' interface configuration successfully " "removed from the '%s'" % (ifname, nodeName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show '%s' interface configuration on the '%s'" % (ifname, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_openvpn_interface_cfg(ifname)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % "Interface configuration still exists")
    elif status.eq(STATUS.DATA_NOT_FOUND):
        print ("No '%s' interface configuration found" % (ifname))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Delete '%s' subnet static route configuration from the '%s'" % (ip_prefix, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_protocols_static_interface_route_cfg(ip_prefix)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("<<< Static route configuration successfully removed " "from the '%s'" % (nodeName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show '%s' subnet static route configuration on the '%s'" % (ip_prefix, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_protocols_static_interface_route_cfg(ip_prefix)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % "Static route configuration still found")
    elif status.eq(STATUS.DATA_NOT_FOUND):
        print ("No static route configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if status.eq(STATUS.OK):
        print ("'%s' NETCONF node was successfully removed " "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 20
0
def vr_demo_12():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show VPN configuration on the '%s'" % nodeName)
    result = vrouter.get_vpn_cfg()
    time.sleep(rundelay)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' VPN configuration:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No VPN configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print (">>> Create new VPN configuration on the '%s'" % (nodeName))

    ca_cert_file = '/config/auth/ca.crt'
    srv_cert_file = '/config/auth/r1.crt'
    srv_key_file = '/config/auth/r1.key'
    crl_file = '/config/auth/r1.crl'
    print (" NOTE: For this demo to succeed the following files "
           "must exist on the '%s'\n"
           "       (empty files can be created for the sake of the demo):\n"
           "         %s\n"
           "         %s\n"
           "         %s\n"
           "         %s"
           % (nodeName, ca_cert_file, srv_cert_file, crl_file, srv_key_file))

    time.sleep(rundelay)

    # -------------------------------------------------------------------------
    # Encode VPN configuration options by using 'Vpn' object
    # -------------------------------------------------------------------------
    vpn = Vpn()

    # -------------------------------------------------------------------------
    # Create and configure Internet Key Exchange (IKE) group
    # -------------------------------------------------------------------------
    ike_grp_name = "IKE-1W"
    proposal_num = 1

    # Set the encryption cipher for proposal 1
    # (enumeration: 'aes128', 'aes256', '3des')
    encryption_cipher = 'aes256'
    vpn.set_ipsec_ike_group_proposal_encryption(ike_grp_name, proposal_num,
                                                encryption_cipher)

    # Set the hash algorithm for proposal 1
    # (enumeration: 'md5', 'sha1')
    hash_algorithm = 'sha1'
    vpn.set_ipsec_ike_group_proposal_hash(ike_grp_name, proposal_num,
                                          hash_algorithm)

    # Set the encryption cipher for proposal 2
    # (enumeration: 'aes128', 'aes256', '3des')
    proposal_num = 2
    encryption_cipher = 'aes128'
    vpn.set_ipsec_ike_group_proposal_encryption(ike_grp_name, proposal_num,
                                                encryption_cipher)

    # Set the hash algorithm for proposal 2
    # (enumeration: 'md5', 'sha1')
    hash_algorithm = 'sha1'
    vpn.set_ipsec_ike_group_proposal_hash(ike_grp_name, proposal_num,
                                          hash_algorithm)

    # Set the lifetime for the whole IKE group
    lifetime = 3600
    vpn.set_ipsec_ike_group_lifetime(ike_grp_name, lifetime)

    # -------------------------------------------------------------------------
    # Create and configure Encapsulating Security Payload (ESP) group
    # -------------------------------------------------------------------------
    esp_grp_name = "ESP-1W"

    # Set the encryption cipher for proposal 1
    # (enumeration: 'aes128', 'aes256', '3des')
    proposal_num = 1
    encryption_cipher = 'aes256'
    vpn.set_ipsec_esp_group_proposal_encryption(esp_grp_name, proposal_num,
                                                encryption_cipher)

    # Set the hash algorithm for proposal 1
    # (enumeration: 'md5', 'sha1')
    hash_algorithm = 'sha1'
    vpn.set_ipsec_esp_group_proposal_hash(esp_grp_name, proposal_num,
                                          hash_algorithm)

    # Set the encryption cipher for proposal 2
    # (enumeration: 'aes128', 'aes256', '3des')
    proposal_num = 2
    encryption_cipher = '3des'
    vpn.set_ipsec_esp_group_proposal_encryption(esp_grp_name, proposal_num,
                                                encryption_cipher)

    # Set the hash algorithm for proposal 2
    # (enumeration: 'md5', 'sha1')
    hash_algorithm = 'md5'
    vpn.set_ipsec_esp_group_proposal_hash(esp_grp_name, proposal_num,
                                          hash_algorithm)

    # Set the lifetime for the whole ESP group
    lifetime = 1800
    vpn.set_ipsec_esp_group_lifetime(esp_grp_name, lifetime)

    # -------------------------------------------------------------------------
    # Configure connection to a remote peer
    # -------------------------------------------------------------------------
    peer_node = "192.0.2.33"
    description = ("Site-to-Site VPN Configuration Example - "
                   "X.509 Certificate Authentication")
    vpn.set_ipsec_site_to_site_peer_description(peer_node, description)

    # Set authentication mode to 'x509'
    auth_mode = 'x509'
    vpn.set_ipsec_site_to_site_peer_auth_mode(peer_node, auth_mode)

    # Specify the 'distinguished name' of the certificate for the peer
    remote_id = "C=US, ST=CA, O=ABC Company, CN=east, [email protected]"
    vpn.set_ipsec_site_to_site_peer_auth_remote_id(peer_node, remote_id)

    # Specify the location of the CA certificate on the vRouter
    vpn.set_ipsec_site_to_site_peer_auth_ca_cert_file(peer_node, ca_cert_file)

    # Specify the location of the server certificate on the vRouter
    vpn.set_ipsec_site_to_site_peer_auth_srv_cert_file(peer_node,
                                                       srv_cert_file)

    # Specify the location of the server key file on the vRouter
    vpn.set_ipsec_site_to_site_peer_auth_srv_key_file(peer_node, srv_key_file)

    # Specify the password for the server key file
    srv_key_pswd = 'testpassword'
    vpn.set_ipsec_site_to_site_peer_auth_srv_key_pswd(peer_node, srv_key_pswd)

    # Specify the default ESP group for all tunnels
    esp_group_name = 'ESP-1W'
    vpn.set_ipsec_site_to_site_peer_default_esp_group(peer_node,
                                                      esp_group_name)

    # Specify the IKE group
    ike_group_name = 'IKE-1W'
    vpn.set_ipsec_site_to_site_peer_ike_group(peer_node, ike_group_name)

    # Identify the IP address on the vRouter to be used for this connection
    local_address = '192.0.2.1'
    vpn.set_ipsec_site_to_site_peer_local_address(peer_node, local_address)

    # Create a tunnel configuration and provide local and remote subnets
    # for this tunnel
    tunnel = 1
    local_prefix = '192.168.40.0/24'
    remote_prefix = '192.168.60.0/24'
    vpn.set_ipsec_site_to_site_peer_tunnel_local_prefix(peer_node, tunnel,
                                                        local_prefix)
    vpn.set_ipsec_site_to_site_peer_tunnel_remote_prefix(peer_node, tunnel,
                                                         remote_prefix)

    print "\n"
    print (">>> VPN configuration to be applied to the '%s'" % (nodeName))
    print vpn.get_payload()
    time.sleep(rundelay)

    result = vrouter.set_vpn_cfg(vpn)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< VPN configuration was successfully created")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show VPN configuration on the '%s'" % (nodeName))
    time.sleep(rundelay)
    result = vrouter.get_vpn_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' VPN configuration:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
        print ("<<< VPN configuration was successfully read")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    time.sleep(rundelay)

    print "\n"
    print ("<<< Delete VPN configuration on the '%s'" % (nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_vpn_cfg()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("VPN configuration successfully removed from '%s'" % (nodeName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show VPN configuration on the '%s'" % (nodeName))
    time.sleep(rundelay)
    result = vrouter.get_vpn_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' VPN configuration:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No VPN configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 21
0
def vr_demo_5():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show list of dataplane interfaces on the '%s'" % nodeName)
    time.sleep(rundelay)
    dpIfList = None
    result = vrouter.get_dataplane_interfaces_list()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Dataplane interfaces:"
        dpIfList = result.get_data()
        print json.dumps(dpIfList, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    if (dpIfList is not None):
        ifName = dpIfList[0]
        print("\n")
        print ("<<< Show '%s' dataplane interface configuration on the '%s'"
               % (ifName, nodeName))
        time.sleep(rundelay)
        result = vrouter.get_dataplane_interface_cfg(ifName)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("Dataplane interface '%s' config:" % ifName)
            cfg = result.get_data()
            data = json.loads(cfg)
            print json.dumps(data, indent=4)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.brief().lower())
            exit(0)

    print("\n")
    print ("<<< Show configuration of dataplane interfaces on the '%s'"
           % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_dataplane_interfaces_cfg()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Dataplane interfaces config:"
        dpIfCfg = result.get_data()
        print json.dumps(dpIfCfg, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 22
0
def vr_demo_4():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show firewalls configuration of the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_firewalls_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' firewall config:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No firewalls configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    fw_name = "FW-ACCEPT-SRC-172_22_17_108"
    firewall = Firewall(fw_name)
    # add a rule to the firewall instance
    rulenum = 33
    rule = Rule(rulenum)
    rule.add_action("accept")
    rule.add_source_address("172.22.17.108")
    firewall.add_rule(rule)
    print ("<<< Create new firewall instance '%s' on '%s'" %
           (fw_name, nodeName))
    print firewall.get_payload()
    time.sleep(rundelay)
    result = vrouter.add_modify_firewall_instance(firewall)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s' was successfully created" % fw_name)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    print("\n")
    print ("<<< Show content of the firewall instance '%s' on '%s'" %
           (fw_name, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_firewall_instance_cfg(fw_name)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s': " % fw_name)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show firewalls configuration on the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_firewalls_cfg()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' firewalls config:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print ("<<< Remove firewall instance '%s' from '%s'" %
           (fw_name, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_firewall_instance(firewall)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s' was successfully deleted" % fw_name)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show firewalls configuration on the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_firewalls_cfg()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' firewalls config:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 23
0
def vr_demo_2():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    yangModelName = "vyatta-security-firewall"
    yangModelVerson = "2014-11-07"
    print ("<<< Retrieve '%s' YANG model definition from the '%s'"
           % (yangModelName, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_schema(yangModelName, yangModelVerson)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "YANG model definition:"
        schema = result.get_data()
        print schema
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 24
0
def nc_demo_10():

    f = "cfg2.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller or NETCONF device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")
    print ("<<< Creating Controller instance")
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("'Controller':")
    print ctrl.to_json()

    print "\n"
    print ("<<< Show NETCONF nodes configured on the Controller")
    time.sleep(rundelay)
    result = ctrl.get_netconf_nodes_in_config()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Nodes configured:"
        nlist = result.get_data()
        for item in nlist:
            print "   '{}'".format(item)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured:
        print ("\n")
        print ("<<< '%s' is already configured on the Controller" % nodeName)
        print ("Unmounting '%s' from the Controller" % nodeName)
        time.sleep(rundelay)
        result = ctrl.delete_netconf_node(nodename=nodeName)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' NETCONF node was successfully removed "
                   "from the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.brief())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    print ("<<< Creating new '%s' NETCONF node" % nodeName)
    node = NetconfNode(ctrl, nodeName, nodeIpAddr, nodePortNum,
                       nodeUname, nodePswd)
    print ("'%s':" % nodeName)
    print node.to_json()

    print ("\n")
    print ("<<< Add '%s' NETCONF node to the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.add_netconf_node(node)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully added "
               "to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        print status.detailed()
        exit(0)

    print "\n"
    print ("<<< Show NETCONF nodes configured on the Controller")
    time.sleep(rundelay)
    result = ctrl.get_netconf_nodes_in_config()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Nodes configured:"
        nlist = result.get_data()
        for item in nlist:
            print "   '{}'".format(item)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print ("<<< Find the '%s' NETCONF node on the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        print ("'%s' node is configured" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print ("<<< Show connection status for all NETCONF nodes "
           "configured on the Controller")
    time.sleep(rundelay)
    result = ctrl.get_netconf_nodes_conn_status()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Nodes connection status:"
        nlist = result.get_data()
        for item in nlist:
            status = ""
            if (item['connected'] is True):
                status = "connected"
            else:
                status = "not connected"
            print "   '{}' is {}".format(item['node'], status)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print ("<<< Show connection status for the '%s' NETCONF node" % nodeName)
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("'%s' node is connected" % nodeName)
    elif (status.eq(STATUS.NODE_DISONNECTED)):
        print ("'%s' node is not connected" % nodeName)
    elif (status.eq(STATUS.NODE_NOT_FOUND)):
        print ("'%s' node is not found" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(node)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print ("<<< Show NETCONF nodes configured on the Controller")
    time.sleep(rundelay)
    result = ctrl.get_netconf_nodes_in_config()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "Nodes configured:"
        nlist = result.get_data()
        for item in nlist:
            print "   '{}'".format(item)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print "\n"
    print ("<<< Show connection status for the '%s' NETCONF node" % nodeName)
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if (status.eq(STATUS.NODE_CONNECTED)):
        print ("'%s' node is connected" % nodeName)
    elif (status.eq(STATUS.NODE_DISONNECTED)):
        print ("'%s' node is not connected" % nodeName)
    elif (status.eq(STATUS.NODE_NOT_FOUND)):
        print ("'%s' node is not found" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 25
0
def vr_demo_7():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        ifName = d['interfaceName']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print ("\n")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show firewalls configuration on the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_firewalls_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' firewalls config:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No firewalls configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    fwName1 = "ACCEPT-SRC-IPADDR"
    print (">>> Create new firewall instance '%s' on '%s'"
           % (fwName1, nodeName))
    firewall1 = Firewall(fwName1)
    # Add a rule to the firewall instance
    rulenum = 30
    rule = Rule(rulenum)
    rule.add_action("accept")
    rule.add_source_address("172.22.17.108")
    firewall1.add_rule(rule)
    print firewall1.get_payload()
    time.sleep(rundelay)
    result = vrouter.add_modify_firewall_instance(firewall1)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s' was successfully created" % fwName1)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    print "\n"
    fwName2 = "DROP-ICMP"
    print (">>> Create new firewall instance '%s' on '%s'"
           % (fwName2, nodeName))
    firewall2 = Firewall(fwName2)
    # Add a rule to the firewall instance
    rulenum = 40
    rule = Rule(rulenum)
    rule.add_action("drop")
    rule.add_icmp_typename("ping")
    firewall2.add_rule(rule)
    print firewall2.get_payload()
    time.sleep(rundelay)
    result = vrouter.add_modify_firewall_instance(firewall2)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s' was successfully created" % fwName2)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        exit(0)

    print("\n")
    print ("<<< Show firewalls configuration on the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_firewalls_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' firewalls config:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Apply firewall '%s' to inbound traffic "
           "and '%s' to outbound traffic on the '%s' "
           "dataplane interface" % (fwName1, fwName2, ifName))
    time.sleep(rundelay)
    result = vrouter.set_dataplane_interface_firewall(ifName, fwName1, fwName2)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instances were successfully applied "
               "to the '%s' dataplane interface" % (ifName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show '%s' dataplane interface configuration on the '%s'"
           % (ifName, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_dataplane_interface_cfg(ifName)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Interfaces '%s' config:" % ifName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Remove firewall settings from the '%s' dataplane interface"
           % (ifName))
    time.sleep(rundelay)
    result = vrouter.delete_dataplane_interface_firewall(ifName)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall settings successfully removed "
               "from '%s' dataplane interface" % ifName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show '%s' dataplane interface configuration on the '%s'"
           % (ifName, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_dataplane_interface_cfg(ifName)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Interfaces '%s' config:" % ifName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove firewall instance '%s' from '%s'"
           % (fwName1, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_firewall_instance(firewall1)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s' was successfully deleted" % fwName1)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove firewall instance '%s' from '%s'"
           % (fwName2, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_firewall_instance(firewall2)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Firewall instance '%s' was successfully deleted" % fwName2)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show firewalls configuration on the '%s'" % nodeName)
    time.sleep(rundelay)
    result = vrouter.get_firewalls_cfg()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' firewalls config:" % nodeName)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 26
0
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeId = "openflow:1"
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print "\n"
    print ("<<< Get info about '%s' node on the Controller" % nodeId)
    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    result = ctrl.get_node_info(nodeId)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' node info:" % nodeId)
        info = result.get_data()
        print json.dumps(info, indent=4)
    else:
        print ("\n")
        print ("!!!Failed, reason: %s" % status.brief().lower())
        exit(0)

    print "\n"
Ejemplo n.º 27
0
def of_demo_29():
    f = "cfg.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    description = (
        "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
        " This demo illustrates how to use Controller's notification \n"
        " subscription service for tracing dynamic changes in the\n"
        " network topology data tree maintained by the Controller.\n"
        "\n"
        " It is implied that core network services (Forwarding Rules\n"
        " Manager, Topology Manager, Switch Manager, Host Tracker)\n"
        " are functioning on the Controller\n"
        "\n"
        " This script creates an event listener on the Controller and\n"
        " establishes permanent connection to the events notification\n"
        " stream. Once a data change event in the topology tree (such\n"
        " as add/remove switch, host or link) is detected it will be\n"
        " reported to the screen.\n"
        "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
    )

    print "\n".strip()
    print description
    print "\n".strip()
    time.sleep(rundelay)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 29 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    # Identifier of the network topology to be traced
    # (name used by Controller for default topology instance)
    topo_id = 'flow:1'
    print "\n".strip()
    print ("<<< 'Controller': %s, Topology Identifier: '%s'" %
           (ctrlIpAddr, topo_id))
    time.sleep(rundelay)

    # Data store for the changes
    # Can be one of:
    # - CONFIGURATION: Logical data store representing configuration
    #                  state of the system and it's components.
    # - OPERATIONAL:   Logical data store representing operational
    #                  state of the system and it's components
    datastore = "OPERATIONAL"

    # Scope of the data changes
    # Can be one of:
    # - BASE:    Represents only a direct change of the node, such as
    #            replacement, addition or deletion of the node.
    # - ONE:     Represent a change (addition, replacement, deletion)
    #            of the node or one of its direct children.
    #            This scope is a superset of BASE.
    # - SUBTREE: Represents a change of the node or any of its child
    #            nodes, direct and nested.
    #            This scope is superset of ONE and BASE.
    scope = "SUBTREE"

    # Path to the network topology node in the YANG data tree
    path = ctrl.get_network_topology_yang_schema_path(topo_id)

    # Create listener on the Controller (if it does already exist Controller
    # just returns the stream name to subscribe to)
    result = ctrl.create_data_change_event_subscription(datastore, scope, path)
    status = result.get_status()
    if not status.eq(STATUS.OK):
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(1)

    stream_name = result.get_data()

    # Subscribe to the stream
    result = ctrl.subscribe_to_stream(stream_name)
    status = result.get_status()
    if not status.eq(STATUS.OK):
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(1)

    print "\n".strip()
    print " Successfully subscribed for data change notifications"
    print " Stream location:"
    stream_location = result.get_data()
    print "    %s" % stream_location
    print "\n".strip()
    print " Listening ... (CTRL-C to exit)"
    print "\n".strip()

    # Connect to the notification stream on the Controller
    # and start listening for the data change notifications
    # (report only events that we are really interested in)
    websock = create_connection(stream_location)
    try:
        while True:
            event = websock.recv()
            tcn = NetworkTopologyChangeNotification(event)

            timestamp = tcn.get_time()

            l = tcn.switches_added()
            if l and len(l):
                for i in l:
                    print " [%s] added switch: %s" % (timestamp, i)

            l = tcn.switches_removed()
            if l and len(l):
                for i in l:
                    print " [%s] removed switch: %s" % (timestamp, i)

            l = tcn.hosts_added()
            if l and len(l):
                for i in l:
                    print " [%s] added host: %s" % (timestamp, i)

            l = tcn.hosts_removed()
            if l and len(l):
                for i in l:
                    print " [%s] removed host: %s" % (timestamp, i)

            l = tcn.links_added()
            if l and len(l):
                for i in l:
                    print " [%s] added link: %s" % (timestamp, i)

            l = tcn.links_removed()
            if l and len(l):
                for i in l:
                    print " [%s] removed link: %s" % (timestamp, i)

    except(KeyboardInterrupt):
        print "Interrupted from keyboard, exit\n"

    websock.close()

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 28
0
def of_demo_30():

    f = "cfg.yml"
    d = {}
    if load_dict_from_file(f, d) is False:
        print ("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d["ctrlIpAddr"]
        ctrlPortNum = d["ctrlPortNum"]
        ctrlUname = d["ctrlUname"]
        ctrlPswd = d["ctrlPswd"]
        rundelay = d["rundelay"]
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    description = (
        "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
        " This demo illustrates how to use Controller's notification\n"
        " subscription service for tracing dynamic changes in the\n"
        " the Controller's inventory data store.\n"
        "\n"
        " It is implied that core network services (OpenFlow, NETCONF)\n"
        " are functioning on the Controller.\n"
        "\n"
        " This script creates an event listener on the Controller and\n"
        " establishes permanent connection to the events notification\n"
        " stream. Once a data change event in the inventory data store\n"
        " (such as add/remove node or flow entry) is detected\n"
        " it will be reported to the screen.\n"
        "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
    )

    print "\n".strip()
    print description
    print "\n".strip()
    time.sleep(rundelay)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 30 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print "\n".strip()
    print ("<<< 'Controller': %s" % (ctrlIpAddr))
    time.sleep(rundelay)

    # Data store for the changes
    # Can be one of:
    # - CONFIGURATION: Logical data store representing configuration
    #                  state of the system and it's components.
    # - OPERATIONAL:   Logical data store representing operational
    #                  state of the system and it's components
    datastore = "OPERATIONAL"

    # Scope of the data changes
    # Can be one of:
    # - BASE:    Represents only a direct change of the node, such as
    #            replacement, addition or deletion of the node.
    # - ONE:     Represent a change (addition, replacement, deletion)
    #            of the node or one of its direct children.
    #            This scope is a superset of BASE.
    # - SUBTREE: Represents a change of the node or any of its child
    #            nodes, direct and nested.
    #            This scope is superset of ONE and BASE.
    scope = "SUBTREE"

    # Path to the inventory data store in the YANG data tree
    path = ctrl.get_inventory_nodes_yang_schema_path()

    # Create listener on the Controller (if it does already exist Controller
    # just returns the stream name to subscribe to)
    result = ctrl.create_data_change_event_subscription(datastore, scope, path)
    status = result.get_status()
    if not status.eq(STATUS.OK):
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(1)

    stream_name = result.get_data()

    # Subscribe to the stream
    result = ctrl.subscribe_to_stream(stream_name)
    status = result.get_status()
    if not status.eq(STATUS.OK):
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(1)

    print "\n".strip()
    print " Successfully subscribed for data change notifications"
    print " Stream location:"
    stream_location = result.get_data()
    print "    %s" % stream_location
    print "\n".strip()
    print " Listening ... (CTRL-C to exit)"
    print "\n".strip()

    # Connect to the notification stream on the Controller
    # and start listening for the data change notifications
    # (report only events that we are really interested in)
    websock = create_connection(stream_location)
    try:
        while True:
            notification = websock.recv()
            icn = InventoryChangeNotification(notification)

            timestamp = icn.get_time()

            l = icn.nodes_added()
            if l and len(l):
                for i in l:
                    print " [%s] added node: %s" % (timestamp, i)

            l = icn.nodes_removed()
            if l and len(l):
                for i in l:
                    print " [%s] removed node: %s" % (timestamp, i)

            l = icn.flows_added()
            if l and len(l):
                for i in l:
                    print " [%s] added flow entry: %s" % (timestamp, i.to_string())

            l = icn.flows_removed()
            if l and len(l):
                for i in l:
                    print " [%s] removed flow entry: %s" % (timestamp, i.to_string())
    except (KeyboardInterrupt):
        print "Interrupted from keyboard, exit\n"

    websock.close()

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 29
0
def vr_demo_14():

    f = "cfg4.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']

        nodeName = d['nodeName']
        nodeIpAddr = d['nodeIpAddr']
        nodePortNum = d['nodePortNum']
        nodeUname = d['nodeUname']
        nodePswd = d['nodePswd']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    print("\n")
    print("<<< OpenVPN configuration example: Site-to-Site Mode with TLS")
    print("\n")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum,
                          nodeUname, nodePswd)
    print ("<<< 'Controller': %s, '%s': %s"
           % (ctrlIpAddr, nodeName, nodeIpAddr))

    print ("\n")
    time.sleep(rundelay)
    node_configured = False
    result = ctrl.check_node_config_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONFIGURED)):
        node_configured = True
        print ("<<< '%s' is configured on the Controller" % nodeName)
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        node_configured = False
    else:
        print ("\n")
        print "Failed to get configuration status for the '%s'" % nodeName
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    if node_configured is False:
        result = ctrl.add_netconf_node(vrouter)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< '%s' added to the Controller" % nodeName)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            exit(0)

    print ("\n")
    time.sleep(rundelay)
    result = ctrl.check_node_conn_status(nodeName)
    status = result.get_status()
    if(status.eq(STATUS.NODE_CONNECTED)):
        print ("<<< '%s' is connected to the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print ("<<< Show OpenVPN interfaces configuration on the '%s'" % nodeName)
    result = vrouter.get_openvpn_interfaces_cfg()
    time.sleep(rundelay)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print ("'%s' OpenVPN interfaces configuration:" % nodeName)
        iflist = result.get_data()
        assert(isinstance(iflist, list))
        for item in iflist:
            print json.dumps(item, indent=4, sort_keys=True)
    elif (status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No OpenVPN interfaces configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    ifname = 'vtun0'
    print (">>> Configure new '%s' OpenVPN tunnel interface on the '%s'"
           % (ifname, nodeName))
    time.sleep(rundelay)

    # Create OpenVPN interface
    vpnif = OpenVpnInterface(ifname)

    # Set the OpenVPN mode to 'site-to-site'
    mode = 'site-to-site'
    vpnif.set_mode(mode)

    # Set the local IP address of the VPN tunnel
    local_address = '192.168.200.1'
    vpnif.set_local_address(local_address)

    # Set the remote IP address of the VPN tunnel
    remote_address = '192.168.200.2'
    vpnif.set_remote_address(remote_address)

    # Specify the physical IP address of the remote host
    remote_host = '87.65.43.21'
    vpnif.set_remote_host(remote_host)

    # Set the TLS role of this endpoint
    tls_role = "passive"
    vpnif.set_tls_role(tls_role)

    # Specify the location of the CA certificate file
    vpnif.set_tls_ca_cert_file(path="/config/auth/ca.crt")

    # Specify the location of the host certificate file
    vpnif.set_tls_cert_file(path="/config/auth/V1.crt")

    # Specify the location of the CRL parameters file
    vpnif.set_tls_crl_file(path="/config/auth/crl.pem")

    # Specify the location of the DH file
    vpnif.set_tls_dh_file(path="/config/auth/dh1024.pem")

    # Specify the location of the host key file
    vpnif.set_tls_key_file(path="/config/auth/V1.key")

    # Apply configuration settings
    result = vrouter.set_openvpn_interface_cfg(vpnif)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< '%s' interface configuration was successfully created"
               % ifname)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show '%s' interface configuration on the '%s'"
           % (ifname, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_openvpn_interface_cfg(ifname)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' interface configuration:" % ifname)
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
        print ("<<< '%s' interface configuration was successfully read"
               % ifname)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    ip_prefix = '192.168.101.0/24'
    print ("<<< Create static route to access the remote subnet '%s' "
           "through the '%s' interface " % (ip_prefix, ifname))
    time.sleep(rundelay)
    static_route = StaticRoute()
    static_route.set_interface_route(ip_prefix)
    static_route.set_interface_route_next_hop_interface(ip_prefix, ifname)
    result = vrouter.set_protocols_static_route_cfg(static_route)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Static route was successfully created")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show subnet '%s' static route configuration on the '%s'"
           % (ip_prefix, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_protocols_static_interface_route_cfg(ip_prefix)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("Static route configuration:")
        cfg = result.get_data()
        data = json.loads(cfg)
        print json.dumps(data, indent=4, sort_keys=True)
        print ("<<< Static route configuration was successfully read")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Delete '%s' interface configuration from the '%s'"
           % (ifname, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_openvpn_interface_cfg(ifname)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< '%s' interface configuration successfully removed "
               "from the '%s'" % (ifname, nodeName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show '%s' interface configuration on the '%s'"
           % (ifname, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_openvpn_interface_cfg(ifname)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("\n")
        print ("!!!Demo terminated, reason: %s"
               % "Interface configuration still exists")
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No '%s' interface configuration found" % (ifname))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Delete '%s' subnet static route configuration from the '%s'"
           % (ip_prefix, nodeName))
    time.sleep(rundelay)
    result = vrouter.delete_protocols_static_interface_route_cfg(ip_prefix)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Static route configuration successfully removed "
               "from the '%s'" % (nodeName))
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print ("<<< Show '%s' subnet static route configuration on the '%s'"
           % (ip_prefix, nodeName))
    time.sleep(rundelay)
    result = vrouter.get_protocols_static_interface_route_cfg(ip_prefix)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("\n")
        print ("!!!Demo terminated, reason: %s"
               % "Static route configuration still found")
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        print ("No static route configuration found")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        print status.detailed()
        ctrl.delete_netconf_node(vrouter)
        exit(0)

    print "\n"
    print (">>> Remove '%s' NETCONF node from the Controller" % nodeName)
    time.sleep(rundelay)
    result = ctrl.delete_netconf_node(vrouter)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("'%s' NETCONF node was successfully removed "
               "from the Controller" % nodeName)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Ejemplo n.º 30
0
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage(sys.argv[0])
        elif opt in ("-i", "--identifier"):
            model_identifier = arg
        elif opt in ("-v", "--version"):
            model_version = arg
        else:
            print("Error: failed to parse option %s" % opt)
            usage(sys.argv[0])

    if(model_identifier is None) or (model_version is None):
        print("Error: incomplete command")
        usage(sys.argv[0])

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    print ("<<< 'Controller': %s" % (ctrlIpAddr))
    result = ctrl.get_schema("controller-config",
                             model_identifier, model_version)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print "YANG model definition:"
        schema = result.get_data()
        print schema.encode('utf-8', 'replace')
    else:
        print ("\n")
        print ("!!!Failed, reason: %s" % status.brief().lower())
        print ("%s" % status.detailed())
        exit(0)

    print ("\n")