• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.load_dict_from_file函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pysdn.common.utils.load_dict_from_file函数的典型用法代码示例。如果您正苦于以下问题:Python load_dict_from_file函数的具体用法?Python load_dict_from_file怎么用?Python load_dict_from_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了load_dict_from_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: of_demo_3

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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
开发者ID:brocade,项目名称:pysdn,代码行数:60,代码来源:demo3.py


示例2: read_in_ovrly_cfg

def read_in_ovrly_cfg():
    f = "ovrly_mgr_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']
        ctrlTimeOut = d['ctrlTimeOut']

        hvsrIp_1 = d['hvsrIp_1']
        hvsrPortNum_1 = d['hvsrPortNum_1']
        hvsrName_1 = d['hvsrName_1']
        hvsrIp_2 = d['hvsrIp_2']
        hvsrPortNum_2 = d['hvsrPortNum_2']
        hvsrName_1 = d['hvsrName_1']

        vtepName_1 = d['vtepName_1']
        vtepName_2 = d['vtepName_2']

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

    return d
开发者ID:brocade,项目名称:pysdn,代码行数:31,代码来源:ovrly_mgr_script.py


示例3: nc_demo_2

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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
开发者ID:brocade,项目名称:pysdn,代码行数:51,代码来源:ctrl_demo2.py


示例4: nc_demo_5

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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
开发者ID:brocade,项目名称:pysdn,代码行数:49,代码来源:ctrl_demo5.py


示例5: nc_demo_3

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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
开发者ID:brocade,项目名称:pysdn,代码行数:49,代码来源:ctrl_demo3.py


示例6: setUp

 def setUp(self):
     f = "cfg1.yml"
     d = {}
     if not(load_dict_from_file(f, d)):
         print("Config file '%s' read error: " % f)
         exit()
     try:
         self.ctrlIpAddr = d['ctrlIpAddr']
         self.ctrlPortNum = d['ctrlPortNum']
         self.ctrlUname = d['ctrlUname']
         self.ctrlPswd = d['ctrlPswd']
         self.rundelay = d['rundelay']
     except:
         print ("Failed to get Controller device attributes")
         exit(0)
开发者ID:brocade,项目名称:pysdn,代码行数:15,代码来源:unit_test_controller.py


示例7: read_in_vr_cfg_file

def read_in_vr_cfg_file():
    f = "vr_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_1 = d['nodeName_1']
        nodeIpAddr_1 = d['nodeIpAddr_1']
        nodePortNum_1 = d['nodePortNum_1']
        nodeUname_1 = d['nodeUname_1']
        nodePswd_1 = d['nodePswd_1']

        nodeName_2 = d['nodeName_2']
        nodeIpAddr_2 = d['nodeIpAddr_2']
        nodePortNum_2 = d['nodePortNum_2']
        nodeUname_2 = d['nodeUname_2']
        nodePswd_2 = d['nodePswd_2']

        nodeName_3 = d['nodeName_3']
        nodeIpAddr_3 = d['nodeIpAddr_3']
        nodePortNum_3 = d['nodePortNum_3']
        nodeUname_3 = d['nodeUname_3']
        nodePswd_3 = d['nodePswd_3']

    except:
        logging.info ("Failed to get Controller and Node device attributes from Configuration file %s" % f)
        exit(0)

    return d
开发者ID:g2github,项目名称:pysdn,代码行数:36,代码来源:vr_cfg.py


示例8: of_demo_21

def of_demo_21():

    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 21 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    # --- Flow Match: Ethernet Type
    #                 IP DSCP
    #                 IP ECN
    #                 IPv6 Source Address
    #                 IPv6 Destination Address
    #                 IPv6 Flow Label
    #                 IPv6 Extension Header
    #                 TCP Source Port
    #                 TCP Destination Port
    #                 Metadata
    eth_type = ETH_TYPE_IPv6
    ip_dscp = IP_DSCP_CS6  # 'Class Selector' = 'Internet'
    ip_ecn = IP_ECN_CE     # 'Congestion Encountered'
    ipv6_src = "1234:5678:9ABC:DEF0:FDCD:A987:6543:210F/76"
    ipv6_dst = "2000:2abc:edff:fe00::3456/94"
    ipv6_flabel = 7
    ipv6_exthdr = 0        # 'no next header'
    ip_proto = IP_PROTO_TCP
    tcp_src_port = 1831
    tcp_dst_port = 1006
    metadata = "123456789"

    # --- Flow Actions: Output (CONTROLLER)
    output_port = "CONTROLLER"

    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
           (ctrlIpAddr, nodeName))

    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                IP DSCP (%s)\n"
           "                IP ECN (%s)\n"
           "                IPv6 Source Address (%s)\n"
           "                IPv6 Destination Address (%s)\n"
           "                IPv6 Flow Label (%s)\n"
           "                IPv6 Extension Header (%s)\n"
           "                TCP Source Port (%s)\n"
           "                TCP Destination Port (%s)\n"
           "                Metadata (%s)" %
           (hex(eth_type), ip_dscp, ip_ecn,
            ipv6_src, ipv6_dst, ipv6_flabel,
            ipv6_exthdr,
            tcp_src_port, tcp_dst_port, metadata))
    print ("        Action: Output (to %s)" % (output_port))

    time.sleep(rundelay)

    flow_entry = FlowEntry()
    table_id = 0
    flow_id = 27
    flow_entry.set_flow_table_id(table_id)
    flow_entry.set_flow_id(flow_id)
    flow_entry.set_flow_priority(flow_priority=1020)
    flow_entry.set_flow_cookie(cookie=2100)
    flow_entry.set_flow_hard_timeout(hard_timeout=1234)
    flow_entry.set_flow_idle_timeout(idle_timeout=3456)
    flow_entry.set_flow_strict(False)
    flow_entry.set_flow_install_hw(False)

    # --- Instruction: 'Apply-actions'
    #     Actions:     'Output'
    instruction = Instruction(instruction_order=0)
    action = OutputAction(order=0, port=output_port)
    instruction.add_apply_action(action)
    flow_entry.add_instruction(instruction)

    # --- Match Fields: Ethernet Type
    #                   IP DSCP
    #                   IP ECN
    #                   IPv6 Source Address
    #                   IPv6 Destination Address
    #                   IPv6 Flow Label
    #                   IPv6 Extension Header
#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:demo21.py


示例9: vr_demo_13

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)

#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:vr_demo13.py


示例10: vr_demo_1

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)

#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:vr_demo1.py


示例11: of_demo_31

def of_demo_31():
    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']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

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

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
           (ctrlIpAddr, nodeName))

    first_flow_id = 110
    # ---------------------------------------------------
    # First flow entry
    # ---------------------------------------------------
    table_id = 0
    flow_id = first_flow_id
    flow_name = "Set IPv4 ToS action"
    priority = 600
    cookie = 1000

    match_in_port = 109
    match_ip_eth_type = ETH_TYPE_IPv4
    match_ipv4_dst = "10.1.2.3/32"

    mod_nw_tos = 8

    act_out_port = 112

    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Input Port (%s)\n"
           "                Ethernet Type (%s)\n"
           "                IPv4 Destination Address (%s)" %
           (match_in_port,
            hex(match_ip_eth_type),
            match_ipv4_dst))
    print ("        Actions: Set IPv4 ToS (tos %s)\n"
           "                 Output (Port number %s)" %
           (mod_nw_tos, act_out_port))

    time.sleep(rundelay)

    # Allocate a placeholder for the Flow Entry
    flow_entry1 = FlowEntry()

    # Generic attributes of the Flow Entry
    flow_entry1.set_flow_table_id(table_id)
    flow_entry1.set_flow_name(flow_name)
    flow_entry1.set_flow_id(flow_id)
    flow_entry1.set_flow_cookie(cookie)
    flow_entry1.set_flow_priority(priority)
    flow_entry1.set_flow_hard_timeout(0)
    flow_entry1.set_flow_idle_timeout(0)

    # Instructions/Actions for the Flow Entry
    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = SetNwTosAction(action_order)
    action.set_tos(mod_nw_tos)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order)
    action.set_outport(act_out_port)
    instruction.add_apply_action(action)

    flow_entry1.add_instruction(instruction)

    # Match Fields for the Flow Entry
    match = Match()

    match.set_in_port(match_in_port)
    match.set_eth_type(match_ip_eth_type)
    match.set_ipv4_dst(match_ipv4_dst)

    flow_entry1.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry1.get_payload()
    time.sleep(rundelay)
#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:demo31.py


示例12: of_demo_42

def of_demo_42():
    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']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

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

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
           (ctrlIpAddr, nodeName))

    first_flow_id = 110
    # ---------------------------------------------------
    # First flow entry
    # ---------------------------------------------------
    table_id = 0
    flow_id = first_flow_id
    flow_name = "Modify MPLS TTL example1"
    priority = 900
    cookie = 1300

    match_in_port = 3
    match_eth_type = ETH_TYPE_MPLS_UCAST
    match_mpls_label = 567

    act_mod_mpls_ttl = 2
    act_out_port = 112

    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Input Port (%s)\n"
           "                Ethernet Type (%s)\n"
           "                MPLS Label (%s)" %
           (match_in_port,
            hex(match_eth_type),
            match_mpls_label))
    print ("        Actions: Set MPLS TTL (%s)\n"
           "                 Output (%s)" %
           (act_mod_mpls_ttl, act_out_port))

    time.sleep(rundelay)

    # Allocate a placeholder for the Flow Entry
    flow_entry1 = FlowEntry()

    # Generic attributes of the Flow Entry
    flow_entry1.set_flow_table_id(table_id)
    flow_entry1.set_flow_name(flow_name)
    flow_entry1.set_flow_id(flow_id)
    flow_entry1.set_flow_cookie(cookie)
    flow_entry1.set_flow_priority(priority)
    flow_entry1.set_flow_hard_timeout(0)
    flow_entry1.set_flow_idle_timeout(0)

    # Instructions/Actions for the Flow Entry
    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = SetMplsTTLAction(action_order)
    action.set_ttl(act_mod_mpls_ttl)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order)
    action.set_outport(act_out_port)
    instruction.add_apply_action(action)

    flow_entry1.add_instruction(instruction)

    # Match Fields for the Flow Entry
    match = Match()

    match.set_in_port(match_in_port)
    match.set_eth_type(match_eth_type)
    match.set_mpls_label(match_mpls_label)

    flow_entry1.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry1.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry1)
#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:demo42.py


示例13: vr_demo_2

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())
#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:vr_demo2.py


示例14: of_demo_34

def of_demo_34():

    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 34 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    print "\n".strip()
    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
           (ctrlIpAddr, nodeName))

    grp_ids_cfg = []
    grp_ids_oper = []

    print "\n".strip()
    print ("<<< Get OpenFlow Groups Information")
    time.sleep(rundelay)

    result = ofswitch.get_configured_group_ids()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        grp_ids_cfg = result.get_data()
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        grp_ids_cfg = []
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    result = ofswitch.get_operational_group_ids()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        grp_ids_oper = result.get_data()
    elif(status.eq(STATUS.DATA_NOT_FOUND)):
        grp_ids_oper = []
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    # Show current state of the Group Table in the Controller's
    # configuration and operational data stores
    print_groups(grp_ids_cfg, grp_ids_oper)

    # Create new group
    group_id = 13
    group_type = OFPGT_SELECT
    group_name = "Example of 'load balancing' group"
    weight1 = 60
    weight2 = 30
    weight3 = 10
    out_port1 = 110
    out_port2 = 111
    out_port3 = 112
    print "\n".strip()
    print ("<<< Create Group")
    print "\n".strip()
    print ("        Group Type : %s\n"
           "        Group ID   : %s\n"
           "        Group Name : \"%s\"" %
           (group_type.strip('group-').upper(),
            group_id, group_name))
    print ("        Buckets    :")
    print ("                     [0] weight : %s" %
           weight1)
    print ("                         actions: Output (%s)" %
           out_port1)
    print ("                     [1] weight : %s" %
           weight2)
    print ("                         actions: Output (%s)" %
           out_port2)
    print ("                     [2] weight : %s" %
           weight3)
    print ("                         actions: Output (%s)" %
           out_port3)
    time.sleep(rundelay)

    # Allocate a placeholder for the group entry
    group_entry = GroupEntry(group_id, group_type)
    group_entry.set_group_name(group_name)

#.........这里部分代码省略.........
开发者ID:brocade,项目名称:pysdn,代码行数:101,代码来源:demo34.py


示例15: of_demo_7

def of_demo_7():
    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 7 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    # --- Flow Match: Ethernet Source Address
    #                 Ethernet  Destination Address
    #                 IPv4 Source Address
    #                 IPv4 Destination Address
    #                 Input Port
    #     NOTE: Ethernet type must be 2048 (0x800) -> IPv4 protocol
    eth_type = ETH_TYPE_IPv4
    eth_src = "00:1a:1b:00:22:aa"
    eth_dst = "00:2b:00:60:ff:f1"
    ipv4_src = "44.44.44.1/24"
    ipv4_dst = "55.55.55.1/16"
    input_port = 13

    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
           (ctrlIpAddr, nodeName))

    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                Ethernet Source Address (%s)\n"
           "                Ethernet Destination Address (%s)\n"
           "                IPv4 Source Address (%s)\n"
           "                IPv4 Destination Address (%s)\n"
           "                Input Port (%s)" %
           (hex(eth_type), eth_src,
            eth_dst, ipv4_src, ipv4_dst,
            input_port))
    print ("        Action: Output (CONTROLLER)")

    time.sleep(rundelay)

    flow_entry = FlowEntry()
    table_id = 0
    flow_entry.set_flow_table_id(table_id)
    flow_id = 15
    flow_entry.set_flow_id(flow_id)
    flow_entry.set_flow_priority(flow_priority=1005)

    # --- Instruction: 'Apply-actions'
    #     Action:      'Output' to CONTROLLER
    instruction = Instruction(instruction_order=0)
    action = OutputAction(order=0, port="CONTROLLER", max_len=60)
    instruction.add_apply_action(action)
    flow_entry.add_instruction(instruction)
 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python validator.SchemaValidator类代码示例发布时间:2022-05-27
下一篇:
Python status.OperStatus类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap