def main():
    logging.basicConfig()
    if len(sys.argv) == 2 and sys.argv[1] == '-v':
        logging.getLogger().setLevel(logging.INFO)
    if len(sys.argv) == 2 and sys.argv[1] == '-d':
        logging.getLogger().setLevel(logging.DEBUG)

    i = Ixia('ixia01')
    i.connect()
    i.discover()

    i.session.login('mw')
    pg = i.new_port_group()
    pg.create()
    pg.add_port(i.chassis.cards[0].ports[2])
    pg.add_port(i.chassis.cards[0].ports[3])
    pg.take_ownership()
    pg.destroy()

    i.disconnect()
Exemple #2
0
def main():
    logging.basicConfig()
    if len(sys.argv) == 2 and sys.argv[1] == '-v':
        logging.getLogger().setLevel(logging.INFO)
    if len(sys.argv) == 2 and sys.argv[1] == '-d':
        logging.getLogger().setLevel(logging.DEBUG)

    i = Ixia('ixia01')
    i.connect()
    i.discover()

    i.session.login('mw')
    pg = i.new_port_group()
    pg.create()
    pg.add_port(i.chassis.cards[0].ports[2])
    pg.add_port(i.chassis.cards[0].ports[3])
    pg.take_ownership()
    pg.destroy()

    i.disconnect()
Exemple #3
0
def main():
    logging.basicConfig()
    if len(sys.argv) == 2 and sys.argv[1] == '-v':
        logging.getLogger().setLevel(logging.INFO)
    if len(sys.argv) == 2 and sys.argv[1] == '-d':
        logging.getLogger().setLevel(logging.DEBUG)

    i = Ixia('ixia01')
    i.connect()
    i.discover()

    print '%8s | %8s | %s' % ('Port', 'Owner', 'Link State')
    print '---------+----------+-----------------'
    for card in i.chassis.cards:
        if card is None:
            continue
        for port in card.ports:
            print '%8s | %8s | %s' % (port, port.owner,
                                      link_state_str(port.link_state))

    i.disconnect()
def main():
    logging.basicConfig()
    if len(sys.argv) == 2 and sys.argv[1] == '-v':
        logging.getLogger().setLevel(logging.INFO)
    if len(sys.argv) == 2 and sys.argv[1] == '-d':
        logging.getLogger().setLevel(logging.DEBUG)

    i = Ixia('ixia01')
    i.connect()
    i.discover()

    print '%8s | %8s | %s' % ('Port', 'Owner', 'Link State')
    print '---------+----------+-----------------'
    for card in i.chassis.cards:
        if card is None:
            continue
        for port in card.ports:
            print '%8s | %8s | %s' % (port, port.owner,
                    link_state_str(port.link_state))

    i.disconnect()
Exemple #5
0
def main():
    usage = 'usage: %(prog)s <host> [options]'
    parser = argparse.ArgumentParser(usage=usage)
    parser.add_argument('host', help='be more verbose')
    parser.add_argument('-v',
                        action='store_true',
                        dest='verbose',
                        help='be more verbose')
    parser.add_argument('-d',
                        action='store_true',
                        dest='debug',
                        help='enable debug mode')
    parser.add_argument('-o',
                        '--ownership',
                        dest='ownership',
                        default='pyixia',
                        help='use ownership',
                        metavar='OWNER')
    parser.add_argument('-p',
                        '--ports',
                        dest='ports_list',
                        type=int,
                        help='connect to card port',
                        metavar='card port',
                        action='append',
                        nargs=2)
    parser.add_argument('-c',
                        '--commands',
                        dest='commands_string',
                        help='execute commands',
                        metavar='command',
                        choices=ALLOWED_COMMANDS,
                        action='append')
    parser.add_argument('-s',
                        '--statistics',
                        dest='statistics_list',
                        help='show statistics',
                        metavar='statistic_counter',
                        choices=ALLOWED_STATISTICS,
                        action='append')
    parser.add_argument('-g',
                        '--Settings',
                        dest='settings_list',
                        help='set port settings',
                        metavar='port_setting_argument',
                        choices=ALLOWED_SETTINGS,
                        action='append')
    parser.add_argument('-f',
                        '--file',
                        dest='file',
                        help='set file for settings',
                        metavar='settings_file')

    args = parser.parse_args()

    logging.basicConfig()
    if args.verbose:
        logging.getLogger('').setLevel(logging.INFO)
    if args.debug:
        logging.getLogger('').setLevel(logging.DEBUG)

    try:
        i = Ixia(args.host)
        i.connect()
        i.discover()

        i.session.login(args.ownership)
        pg = i.new_port_group()
        pg.create()

        ports_list = add_ports(i, pg, args.ports_list)
        if args.file:
            perform_file_settings(i, ports_list, args.file)

        if args.settings_list:
            set_settings(i, ports_list, args.settings_list)

        if args.commands_string:
            exec_commands(pg, args.commands_string)

        if args.statistics_list:
            get_statistics(i, ports_list, args.statistics_list)

        pg.destroy()
        i.disconnect()
    except socket.error as e:
        print e.strerror
Exemple #6
0
class ixiaStats(object):
    def __init__(self, chassis_ip):
        self.ip = chassis_ip
        self.ixia = Ixia(self.ip)

    def framesSent(self, card, port):
        assert type(card) == int
        assert type(port) == int

        if card <= 0 or port <= 0:
            assert False, 'Invalid number, card {0}, port {1}'.format(card, port)
        try:
            stats = self.ixia.chassis.cards[card - 1].ports[port - 1].stats.frames_sent
        except IndexError:
            assert False, 'Chassis is not connected and discovered! card/port number is out of accpetable range!'
        except:
            raise
        return stats

    def framesReceived(self, card, port):
        assert type(card) == int
        assert type(port) == int

        if card <= 0 or port <= 0:
            assert False, 'Invalid number, card {0}, port {1}'.format(card, port)
        try:
            stats = self.ixia.chassis.cards[card - 1].ports[port - 1].stats.frames_received
        except IndexError:
            assert False, 'Chassis is not connected and discovered or card/port number is out of accpetable range!'
        except:
            raise
        return stats

    def framesSentRate(self, card, port):
        stat_1 = self.framesSent(card, port)
        sleep(5)
        stat_2 = self.framesSent(card, port)
        return (stat_2 - stat_1)/5

    def framesReceivedRate(self, card, port):
        stat_1 = self.framesReceived(card, port)
        sleep(5)
        stat_2 = self.framesReceived(card, port)
        return (stat_2 - stat_1)/5

    @contextmanager
    def connect(self):
        try:
            self.ixia.connect()
            self.ixia.discover()
            yield
            self.ixia.disconnect()
        except:
            raise

    @classmethod
    def isclose(cls, a, b, rel_tol = 0.02, abs_tol = 0):
        '''
        Decide if a and b are relatively close
        rType: boolean
        '''
        return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)