Пример #1
0
 
 rundelay = 3
 
 
 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) == True):
     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))
Пример #2
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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Пример #3
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_node_ids = []
    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 Table 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")

        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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Пример #4
0
def of_demo_27():

    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)

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

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)

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

    print("\n")
    print("<<< Get OpenFlow Network Topology information")
    time.sleep(rundelay)

    topology_ids = []
    topologies = []
    inventory = None

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

    result = ctrl.get_topology_ids()
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        topology_ids = result.get_data()
        assert (isinstance(topology_ids, list))
    else:
        print("\n")
        print("!!!Error, failed to obtain topology info, reason: %s" %
              status.brief().lower())
        exit(0)

    print "\n"
    print("<<< Network topologies")
    for topo_id in topology_ids:
        print "       '%s'" % topo_id

    of_topo_id = 'flow:1'
    for topo_id in topology_ids:
        if (topo_id != of_topo_id):
            continue
        result = ctrl.build_topology_object(topo_id)
        status = result.get_status()
        if (status.eq(STATUS.OK)):
            topo = result.get_data()
            topologies.append(topo)
            assert (isinstance(topo, Topology))
        else:
            print("\n")
            print("!!!Error, failed to parse '%s' topology info, reason: %s" %
                  (topo_id, status.brief().lower()))
            exit(0)

    for topo in topologies:
        if topo.get_id() != of_topo_id:
            continue
        time.sleep(rundelay)
        print "\n"
        print("<<< Information for '%s' network topology:") % topo.get_id()
        print "\n".strip()

        flows_cnt = 0
        sids = topo.get_switch_ids()
        for sid in sids:
            flows_cnt += inventory.get_openflow_node_flows_cnt(sid)

        print("        Number of flows              : %s" % flows_cnt)
        print("        Number of switches           : %s" %
              topo.get_switches_cnt())
        print("        Number of inter-switch links : %s" %
              topo.get_inter_switch_links_cnt())
        print("        Number of hosts              : %s" %
              topo.get_hosts_cnt())

        time.sleep(rundelay)
        print "\n"
        print("<<< OpenFlow switches in '%s' topology") % topo.get_id()
        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)
        switch_ids = topo.get_switch_ids()
        for switch_id in switch_ids:
            inv_node = inventory.get_openflow_node(switch_id)
            addr = inv_node.get_ip_address()
            node_id = inv_node.get_id()
            print "        {0:<15}  {1:<30}".format(addr, node_id)

        switches = topo.get_switches()
        for switch in switches:
            assert (isinstance(switch, Node))
            print "\n".strip()
            time.sleep(rundelay)
            print("<<< Neighborhood information for '%s' switch ports" %
                  switch.get_id())
            pnums = switch.get_port_numbers()
            for pnum in pnums:
                if pnum == 'LOCAL':
                    continue
                print "\n".strip()
                print "        Port '%s'" % pnum
                peer_list = topo.get_peer_list_for_node_port_(switch, pnum)
                if len(peer_list):
                    for item in peer_list:
                        assert (isinstance(item, Node))
                        if (item.is_switch()):
                            print("            Device Type : %s" % "switch")
                            print("            OpenFlow Id : %s" %
                                  item.get_openflow_id())
                        elif (item.is_host()):
                            print("            Device Type : %s" % "host")
                            mac_addr = item.get_mac_address()
                            print("            MAC Address : %s" % mac_addr)
                            ip_addr = item.get_ip_address_for_mac(mac_addr)
                            print("            IP Address  : %s" % ip_addr)
                else:
                    print "            None"

    time.sleep(rundelay)

    print("\n")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(">>> Demo End")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Пример #5
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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Пример #6
0
def of_demo_28():

    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)

    openflow_nodes = []

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

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

    print "\n"
    print("<<< Get OpenFlow Inventory 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"
    print("<<< OpenFlow switches")
    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)

    for node in openflow_nodes:
        assert (isinstance(node, OpenFlowCapableNode))
        time.sleep(rundelay)
        print "\n".strip()
        print "<<< Information for '%s' switch\n" % node.get_id()
        print "        IP Address      : %s" % node.get_ip_address()
        print "        Max tables      : %s" % node.get_max_tables_info()
        print "        Number of flows : %s" % node.get_flows_cnt()
        clist = node.get_capabilities()
        g = 2
        chunks = [clist[x:x + g] for x in xrange(0, len(clist), g)]
        s = 'Capabilities'
        print "        %s    :" % s,
        for i in range(0, len(chunks)):
            n = 0 if i == 0 else len(s) + 14
            print "%s%s" % (" " * n, ", ".join(chunks[i]))

        s1 = 'Table Id'
        s2 = 'Flows Cnt'
        print "\n".strip()
        print "        {0:<8}  {1:<10}".format(s1, s2)
        sym = '-'
        print "        {0:<8}  {1:<10}".format(sym * len(s1), sym * len(s2))
        flow_tables_cnt = node.get_flow_tables_cnt()
        for table_id in range(0, flow_tables_cnt + 1):
            cnt = node.get_flows_in_table_cnt(table_id)
            if (cnt != 0):
                print "        {0:<8}  {1:<10}".format(table_id, cnt)

        s1 = 'Port Num'
        s2 = 'OpenFlow Id'
        print "\n".strip()
        print "        {0:<8}  {1:<16}".format(s1, s2)
        print "        {0:<8}  {1:<30}".format(sym * 8, sym * 30)
        port_ids = node.get_port_ids()
        for port_id in port_ids:
            port_obj = node.get_port_obj(port_id)
            assert (isinstance(port_obj, OpenFlowPort))
            pnum = port_obj.get_port_number()
            print "        {0:<8}  {1:<30}".format(pnum, port_id)

    for node in openflow_nodes:
        assert (isinstance(node, OpenFlowCapableNode))
        time.sleep(rundelay)
        print "\n".strip()
        print "<<< Detailed information for '%s' switch\n" % node.get_id()
        print "        Manufacturer    : %s" % node.get_manufacturer_info()
        print "        Software        : %s" % node.get_software_info()
        print "        Hardware        : %s" % node.get_hardware_info()
        print "        Serial number   : %s" % node.get_serial_number()
        print "\n".strip()
        print "        OpenFlow Id     : %s" % node.get_id()
        print "        IP Address      : %s" % node.get_ip_address()
        print "        Description     : %s" % node.get_description()
        print "        Max buffers     : %s" % node.get_max_buffers_info()
        print "        Max tables      : %s" % node.get_max_tables_info()
        print "        Number of flows : %s" % node.get_flows_cnt()
        clist = node.get_capabilities()
        g = 2
        chunks = [clist[x:x + g] for x in xrange(0, len(clist), g)]
        s = 'Capabilities'
        print "        %s    :" % s,
        for i in range(0, len(chunks)):
            n = 0 if i == 0 else len(s) + 14
            print "%s%s" % (" " * n, ", ".join(chunks[i]))

        port_ids = node.get_port_ids()
        for port_id in port_ids:
            port_obj = node.get_port_obj(port_id)
            assert (isinstance(port_obj, OpenFlowPort))
            pnum = port_obj.get_port_number()
            pname = port_obj.get_port_name()
            pid = port_obj.get_port_id()
            mac = port_obj.get_mac_address()
            link_state = port_obj.get_link_state()
            fwd_state = port_obj.get_forwarding_state()
            pkts_rx = port_obj.get_packets_received()
            pkts_tx = port_obj.get_packets_transmitted()
            bytes_rx = port_obj.get_bytes_received()
            bytes_tx = port_obj.get_bytes_transmitted()
            print "\n".strip()
            print "        Port '{}'".format(pnum)
            print "            OpenFlow Id : {}".format(pid)
            print "            Name        : {}".format(pname)
            print "            MAC address : {}".format(mac)
            print "            Link state  : {}".format(link_state)
            print "            Oper state  : {}".format(fwd_state)
            print "            Pkts RX     : {}".format(pkts_rx)
            print "            Pkts TX     : {}".format(pkts_tx)
            print "            Bytes RX    : {}".format(bytes_rx)
            print "            Bytes TX    : {}".format(bytes_tx)

    print("\n")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(">>> Demo End")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Пример #7
0
def of_demo_28():

    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)

    openflow_node_ids = []
    openflow_nodes = []

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



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

    print "\n"
    print ("<<< Get OpenFlow Inventory 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"
    print ("<<< OpenFlow switches")
    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)

    for node in openflow_nodes:
        assert(isinstance(node, OpenFlowCapableNode))
        time.sleep(rundelay)
        print "\n".strip()
        print "<<< Information for '%s' switch\n" % node.get_id()
        print "        IP Address      : %s" % node.get_ip_address()
        print "        Max tables      : %s" % node.get_max_tables_info()
        print "        Number of flows : %s" % node.get_flows_cnt()
        clist = node.get_capabilities()
        g = 2
        chunks = [clist[x:x+g] for x in xrange(0, len(clist), g)]
        s = 'Capabilities'
        print "        %s    :" % s,
        for i in range(0, len(chunks)):
            n = 0 if i == 0 else len(s) + 14
            print "%s%s" % (" "*n, ", ".join(chunks[i]))

        s1 = 'Table Id'
        s2 = 'Flows Cnt'
        print "\n".strip()
        print "        {0:<8}  {1:<10}".format(s1, s2)
        sym = '-'
        print "        {0:<8}  {1:<10}".format(sym*len(s1), sym*len(s2))
        flow_tables_cnt = node.get_flow_tables_cnt()
        for table_id in range(0, flow_tables_cnt+1):
            cnt = node.get_flows_in_table_cnt(table_id)
            if (cnt != 0):
                print "        {0:<8}  {1:<10}".format(table_id, cnt)

        s1 = 'Port Num'
        s2 = 'OpenFlow Id'
        print "\n".strip()
        print "        {0:<8}  {1:<16}".format(s1, s2)
        print "        {0:<8}  {1:<30}".format(sym*8, sym*30)
        port_ids = node.get_port_ids()
        for port_id in port_ids:
            port_obj = node.get_port_obj(port_id)
            assert(isinstance(port_obj, OpenFlowPort))
            pnum = port_obj.get_port_number()
            print "        {0:<8}  {1:<30}".format(pnum, port_id)

    for node in openflow_nodes:
        assert(isinstance(node, OpenFlowCapableNode))
        time.sleep(rundelay)
        print "\n".strip()
        print "<<< Detailed information for '%s' switch\n" % node.get_id()
        print "        Manufacturer    : %s" % node.get_manufacturer_info()
        print "        Software        : %s" % node.get_software_info()
        print "        Hardware        : %s" % node.get_hardware_info()
        print "        Serial number   : %s" % node.get_serial_number()
        print "\n".strip()
        print "        OpenFlow Id     : %s" % node.get_id()
        print "        IP Address      : %s" % node.get_ip_address()
        print "        Description     : %s" % node.get_description()
        print "        Max buffers     : %s" % node.get_max_buffers_info()
        print "        Max tables      : %s" % node.get_max_tables_info()
        print "        Number of flows : %s" % node.get_flows_cnt()
        clist = node.get_capabilities()
        g = 2
        chunks = [clist[x:x+g] for x in xrange(0, len(clist), g)]
        s = 'Capabilities'
        print "        %s    :" % s,
        for i in range(0, len(chunks)):
            n = 0 if i == 0 else len(s) + 14
            print "%s%s" % (" "*n, ", ".join(chunks[i]))

        port_ids = node.get_port_ids()
        for port_id in port_ids:
            port_obj = node.get_port_obj(port_id)
            assert(isinstance(port_obj, OpenFlowPort))
            pnum = port_obj.get_port_number()
            pname = port_obj.get_port_name()
            pid = port_obj.get_port_id()
            mac = port_obj.get_mac_address()
            link_state = port_obj.get_link_state()
            fwd_state = port_obj.get_forwarding_state()
            pkts_rx = port_obj.get_packets_received()
            pkts_tx = port_obj.get_packets_transmitted()
            bytes_rx = port_obj.get_bytes_received()
            bytes_tx = port_obj.get_bytes_transmitted()
            print "\n".strip()
            print "        Port '{}'".format(pnum)
            print "            OpenFlow Id : {}".format(pid)
            print "            Name        : {}".format(pname)
            print "            MAC address : {}".format(mac)
            print "            Link state  : {}".format(link_state)
            print "            Oper state  : {}".format(fwd_state)
            print "            Pkts RX     : {}".format(pkts_rx)
            print "            Pkts TX     : {}".format(pkts_tx)
            print "            Bytes RX    : {}".format(bytes_rx)
            print "            Bytes TX    : {}".format(bytes_tx)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Пример #8
0
def of_demo_27():

    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)

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

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)

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

    print ("\n")
    print ("<<< Get OpenFlow Network Topology information")
    time.sleep(rundelay)

    topology_ids = []
    topologies = []
    inventory = None

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

    result = ctrl.get_topology_ids()
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        topology_ids = result.get_data()
        assert(isinstance(topology_ids, list))
    else:
        print ("\n")
        print ("!!!Error, failed to obtain topology info, reason: %s" %
               status.brief().lower())
        exit(0)

    print "\n"
    print ("<<< Network topologies")
    for topo_id in topology_ids:
        print "       '%s'" % topo_id

    of_topo_id = 'flow:1'
    for topo_id in topology_ids:
        if (topo_id != of_topo_id):
            continue
        result = ctrl.build_topology_object(topo_id)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            topo = result.get_data()
            topologies.append(topo)
            assert(isinstance(topo, Topology))
        else:
            print ("\n")
            print ("!!!Error, failed to parse '%s' topology info, reason: %s" %
                   (topo_id, status.brief().lower()))
            exit(0)

    for topo in topologies:
        if topo.get_id() != of_topo_id:
            continue
        time.sleep(rundelay)
        print "\n"
        print ("<<< Information for '%s' network topology:") % topo.get_id()
        print "\n".strip()

        flows_cnt = 0
        sids = topo.get_switch_ids()
        for sid in sids:
            flows_cnt += inventory.get_openflow_node_flows_cnt(sid)

        print ("        Number of flows              : %s" %
               flows_cnt)
        print ("        Number of switches           : %s" %
               topo.get_switches_cnt())
        print ("        Number of inter-switch links : %s" %
               topo.get_inter_switch_links_cnt())
        print ("        Number of hosts              : %s" %
               topo.get_hosts_cnt())

        time.sleep(rundelay)
        print "\n"
        print ("<<< OpenFlow switches in '%s' topology") % topo.get_id()
        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)
        switch_ids = topo.get_switch_ids()
        for switch_id in switch_ids:
            inv_node = inventory.get_openflow_node(switch_id)
            addr = inv_node.get_ip_address()
            node_id = inv_node.get_id()
            print "        {0:<15}  {1:<30}".format(addr, node_id)

        switches = topo.get_switches()
        for switch in switches:
            assert(isinstance(switch, Node))
            print "\n".strip()
            time.sleep(rundelay)
            print ("<<< Neighborhood information for '%s' switch ports" %
                   switch.get_id())
            pnums = switch.get_port_numbers()
            for pnum in pnums:
                if pnum == 'LOCAL':
                    continue
                print "\n".strip()
                print "        Port '%s'" % pnum
                peer_list = topo.get_peer_list_for_node_port_(switch, pnum)
                if len(peer_list):
                    for item in peer_list:
                        assert(isinstance(item, Node))
                        if(item.is_switch()):
                            print ("            Device Type : %s" %
                                   "switch")
                            print ("            OpenFlow Id : %s" %
                                   item.get_openflow_id())
                        elif (item.is_host()):
                            print ("            Device Type : %s" %
                                   "host")
                            mac_addr = item.get_mac_address()
                            print ("            MAC Address : %s" %
                                   mac_addr)
                            ip_addr = item.get_ip_address_for_mac(mac_addr)
                            print ("            IP Address  : %s" %
                                   ip_addr)
                else:
                    print "            None"

    time.sleep(rundelay)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")