Beispiel #1
0
 def _show_tg_names(self, start, amount, pid_input = DEFAULT_PROFILE_ID):
     tg_names = self.get_tg_names(pid_input)
     names = tg_names[start : start+amount]
     if not tg_names:
         print(format_text('There are no template groups!', 'bold'))
     elif not names:
             print(format_text('Invalid parameter combination!', 'bold'))
     else:
         if len(names) != len(tg_names):
             print(format_text('Showing only %s names out of %s.' % (len(names), len(tg_names)), 'bold'))
         NUM_OF_COLUMNS = 5
         while names:
             print('  '.join(map(lambda x: '%-20s' % x, names[:NUM_OF_COLUMNS])))
             del names[:NUM_OF_COLUMNS]
Beispiel #2
0
def simple():

    # create client
    #verbose_level = 'high'
    c = STLClient(verbose_level='error')
    passed = True

    try:
        # connect to server
        c.connect()

        my_ports = [0, 1]

        # prepare our ports
        c.reset(ports=my_ports)
        profile_file = os.path.join(stl_path.STL_PROFILES_PATH,
                                    'udp_1pkt_simple.py')

        try:
            profile = STLProfile.load(profile_file)
        except STLError as e:
            print(
                format_text(
                    "\nError while loading profile '{0}'\n".format(
                        profile_file), 'bold'))
            print(e.brief() + "\n")
            return

        print(profile.to_json())

        c.remove_all_streams(my_ports)

        c.add_streams(profile.get_streams(), ports=my_ports)

        c.start(ports=[0, 1], mult="5mpps", duration=10)

        # block until done
        c.wait_on_traffic(ports=[0, 1])

    except STLError as e:
        passed = False
        print(e)

    finally:
        c.disconnect()

    if passed:
        print("\nTest has passed :-)\n")
    else:
        print("\nTest has failed :-(\n")
Beispiel #3
0
    def do_sync_topo(self):
        '''
        Sync astf topology with current Emu server data.
        Requires resolved dgw mac address and ipv4 and ipv6 dgw resolved macs must not be different.
        '''
        emu_c, astf_c = self.emu_c, self.astf_c

        emu_topo = ASTFTopology()
        emu_ns_and_c = emu_c.get_all_ns_and_clients()
        empty_ip_val = ''

        for ns in emu_ns_and_c:
            # take only clients ns
            if ns['vport'] % 2:
                continue

            port = str(ns['vport'])
            vlans = filter(lambda x: x != 0, ns.get('tci', []))
            if len(vlans) > 1:
                raise TRexError(
                    'Cannot convert topo when namespace has more than 1 vlan')
            elif len(vlans) == 1:
                vlan = vlans[0]
            else:
                vlan = 0

            for c_i, c in enumerate(ns.get('clients', []), start=1):
                port_id = '%s.%s' % (port, c_i)
                src_mac = c['mac']  # mac is mandatory for client
                src_ipv4 = c.get('ipv4', empty_ip_val)
                src_ipv6 = c.get('ipv6', empty_ip_val)

                if src_ipv4 == '0.0.0.0' or src_ipv4 == empty_ip_val:
                    raise TRexError(
                        'Cannot sync: node with mac: "%s" has no ipv4 address'
                        % src_mac)

                if c.get('dgw') and c['dgw'].get('resolve'):
                    ipv4_dst = c['dgw'].get('rmac')
                else:
                    ipv4_dst = None

                if c.get('ipv6_dgw') and c['ipv6_dgw'].get('resolve'):
                    ipv6_dst = c['ipv6_dgw'].get('rmac')
                else:
                    ipv6_dst = None

                if ipv4_dst is None and ipv6_dst is None:
                    raise TRexError(
                        'Cannot sync: node with mac: "%s" has no resolved default gateway mac address'
                        % src_mac)

                if ipv4_dst is not None and ipv6_dst is not None and ipv4_dst != ipv6_dst:
                    raise TRexError(
                        'Cannot sync: node with mac: "%s" has different resolved default gateway mac address for ipv4 and ipv6'
                        % src_mac)

                emu_topo.add_vif(port_id=port_id,
                                 src_mac=src_mac,
                                 src_ipv4=src_ipv4,
                                 src_ipv6=src_ipv6,
                                 vlan=vlan)
                emu_topo.add_gw(
                    port_id=port_id,
                    src_start=src_ipv4,
                    src_end=src_ipv4,
                    dst=ipv4_dst if ipv4_dst is not None else ipv6_dst)

        astf_c.topo_clear()
        astf_c.topo_load(emu_topo)
        astf_c.topo_resolve()

        astf_c.logger.info(format_text("emu topo synced\n", 'green', 'bold'))