mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-11-03 20:27:54 +00:00 
			
		
		
		
	create_l3.py: remove stations, only create one cx
driver.py, drivermetadata.xml: include --mgr argument for CloudShell dataplane test
This commit is contained in:
		@@ -13,6 +13,7 @@ import sys
 | 
			
		||||
import os
 | 
			
		||||
import importlib
 | 
			
		||||
import paramiko
 | 
			
		||||
from scp import SCPClient
 | 
			
		||||
 | 
			
		||||
# command = "./lanforge-scripts/py-scripts/update_dependencies.py"
 | 
			
		||||
# print("running:[{}]".format(command))
 | 
			
		||||
@@ -221,28 +222,79 @@ class LanforgeResourceDriver (ResourceDriverInterface):
 | 
			
		||||
            drop_A="0",
 | 
			
		||||
            drop_B="0"
 | 
			
		||||
        )
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        output = self.send_command(context, cmd)
 | 
			
		||||
        print(output)
 | 
			
		||||
        return output
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
    def create_l3(self, context, name, min_rate_a, min_rate_b, endp_a, endp_b):
 | 
			
		||||
 | 
			
		||||
        # args = {
 | 
			
		||||
        #     "host": context.resource.address,
 | 
			
		||||
        #     "name_prefix": name,
 | 
			
		||||
        #     "min_rate_a": min_rate_a,
 | 
			
		||||
        #     "min_rate_b": min_rate_b,
 | 
			
		||||
        #     "endp_a": endp_a,
 | 
			
		||||
        #     "endp_b": endp_b
 | 
			
		||||
        # }
 | 
			
		||||
        
 | 
			
		||||
        cmd = f"/home/lanforge/lanforge-scripts/py-scripts/create_l3.py --host \"localhost\" --endp_a \"{endp_a}\" --endp_b \"{endp_b}\" --min_rate_a \"{min_rate_a}\" --min_rate_b \"{min_rate_b}\""
 | 
			
		||||
        cmd = f"/home/lanforge/lanforge-scripts/py-scripts/create_l3.py --endp_a \"{endp_a}\" --endp_b \"{endp_b}\" --min_rate_a \"{min_rate_a}\" --min_rate_b \"{min_rate_b}\""
 | 
			
		||||
 | 
			
		||||
        output = self.send_command(context, cmd)
 | 
			
		||||
        print(output)
 | 
			
		||||
        return output
 | 
			
		||||
 | 
			
		||||
    def pull_reports(self, hostname="", port=22,
 | 
			
		||||
                     username="lanforge", password="lanforge",
 | 
			
		||||
                     report_location="/home/lanforge/html_reports/",
 | 
			
		||||
                     report_dir="./"):
 | 
			
		||||
        
 | 
			
		||||
        ssh = paramiko.SSHClient()
 | 
			
		||||
        ssh.load_system_host_keys()
 | 
			
		||||
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 | 
			
		||||
        ssh.connect(hostname="juicer", username=username, password=password, port=port, allow_agent=False, look_for_keys=False)
 | 
			
		||||
 | 
			
		||||
        with SCPClient(ssh.get_transport()) as scp:
 | 
			
		||||
            scp.get(remote_path=report_location, local_path=report_dir, recursive=True)
 | 
			
		||||
            scp.close()
 | 
			
		||||
        
 | 
			
		||||
    def dataplane_test(self, context, instance_name, upstream, station, duration, download_speed, upload_speed, traffic_types, local_lf_report_dir, output_report_dir, mgr):
 | 
			
		||||
 | 
			
		||||
        cmd = '''/home/lanforge/lanforge-scripts/py-scripts/lf_dataplane_test.py --mgr {mgr} --port 8080 --lf_user lanforge --lf_password lanforge \
 | 
			
		||||
                --instance_name {instance_name} --config_name test_con \
 | 
			
		||||
                --upstream {upstream} --station {station} --duration {duration}\
 | 
			
		||||
                --download_speed {download_speed} --upload_speed {upload_speed} \
 | 
			
		||||
                --raw_line 'pkts: 256;1024' \
 | 
			
		||||
                --raw_line 'directions: DUT Transmit' \
 | 
			
		||||
                --raw_line 'traffic_types: {traffic_types}' \
 | 
			
		||||
                --test_rig juicer --pull_report \
 | 
			
		||||
                --local_lf_report_dir {local_lf_report_dir}'''.format(
 | 
			
		||||
                    instance_name=instance_name,
 | 
			
		||||
                    mgr=mgr,
 | 
			
		||||
                    upstream=upstream,
 | 
			
		||||
                    station=station,
 | 
			
		||||
                    duration=duration,
 | 
			
		||||
                    download_speed=download_speed,
 | 
			
		||||
                    upload_speed=upload_speed,
 | 
			
		||||
                    traffic_types=traffic_types,
 | 
			
		||||
                    local_lf_report_dir=local_lf_report_dir
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
        output = self.send_command(context, cmd)
 | 
			
		||||
        print(output)
 | 
			
		||||
        
 | 
			
		||||
        resource = LanforgeResource.create_from_context(context)
 | 
			
		||||
        session = CloudShellAPISession(host=context.connectivity.server_address,
 | 
			
		||||
                                       token_id=context.connectivity.admin_auth_token,
 | 
			
		||||
                                       domain=context.reservation.domain)
 | 
			
		||||
        terminal_ip = context.resource.address
 | 
			
		||||
        resource_model_name = resource.cloudshell_model_name
 | 
			
		||||
        terminal_pass = session.DecryptPassword(context.resource.attributes[f'{resource_model_name}.Password']).Value
 | 
			
		||||
        terminal_user = context.resource.attributes[f'{resource_model_name}.User']
 | 
			
		||||
        # session.AttachFileToReservation(context.reservation.reservation_id, f"C:/Users/Administrator/{output_report_dir}", "C:/Users/Administrator/AppData/Local/Temp", True)
 | 
			
		||||
        self.pull_reports(hostname=context.resource.address, port=22,
 | 
			
		||||
                          username=terminal_user, password=terminal_pass,
 | 
			
		||||
                          report_location=f"/home/lanforge/html-reports",
 | 
			
		||||
                          report_dir=f"C:/Users/Administrator/{output_report_dir}")
 | 
			
		||||
        return output
 | 
			
		||||
 | 
			
		||||
    def scenario(self, context, load):
 | 
			
		||||
        cmd = f"/home/lanforge/lanforge-scripts/py-scripts/scenario.py --load {load}"
 | 
			
		||||
 | 
			
		||||
        output = self.send_command(context, cmd)
 | 
			
		||||
        print(output)
 | 
			
		||||
        return output
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    # setup for mock-debug environment
 | 
			
		||||
@@ -267,6 +319,7 @@ if __name__ == "__main__":
 | 
			
		||||
    # print driver.run_custom_command(context, custom_command="sh run", cancellation_context=cancellation_context)
 | 
			
		||||
    # result = driver.example_command_with_api(context)
 | 
			
		||||
 | 
			
		||||
    driver.create_l3(context, "my_fire", "69000", "41000", "eth1", "eth2")
 | 
			
		||||
    driver.create_wanlink(context, name="my_wanlin", latency="49", rate="6000")
 | 
			
		||||
    # driver.create_l3(context, "my_fire", "69000", "41000", "eth1", "eth2")
 | 
			
		||||
    # driver.create_wanlink(context, name="my_wanlin", latency="49", rate="6000")
 | 
			
		||||
    driver.dataplane_test(context, "instance", "upstream", "station", "duration")
 | 
			
		||||
    print("done")
 | 
			
		||||
 
 | 
			
		||||
@@ -7,12 +7,72 @@
 | 
			
		||||
		<Command Description="" 
 | 
			
		||||
			 DisplayName="Orchestration Restore" 
 | 
			
		||||
			 Name="orchestration_restore" />
 | 
			
		||||
	  <Command Description="Send Command to Resource"
 | 
			
		||||
		   DisplayName="Scenario"
 | 
			
		||||
		   Name="send_command">
 | 
			
		||||
	    <Parameters>
 | 
			
		||||
	      <Parameter Name="cmd"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="The command to send"/>
 | 
			
		||||
	    </Parameters>
 | 
			
		||||
	  </Command>
 | 
			
		||||
	  <Command Description="Pull Reports from LANforge"
 | 
			
		||||
		   DisplayName="Pull Reports"
 | 
			
		||||
		   Name="pull_reports">
 | 
			
		||||
	    <Parameters>
 | 
			
		||||
	      <Parameter Name="hostname"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="hostname"/>
 | 
			
		||||
	      <Parameter Name="port"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="port"/>
 | 
			
		||||
	      <Parameter Name="username"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="username"/>
 | 
			
		||||
	      <Parameter Name="password"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="password"/>
 | 
			
		||||
	      <Parameter Name="report_location"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="report location"/>
 | 
			
		||||
	      <Parameter Name="report_dir"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="report dir"/>
 | 
			
		||||
	    </Parameters>
 | 
			
		||||
	  </Command>
 | 
			
		||||
	</Category>
 | 
			
		||||
	<Category Name="Example Commands">
 | 
			
		||||
		<Command Description="Example Command from Demo"
 | 
			
		||||
			 DisplayName="Example Command"
 | 
			
		||||
			 Name="example_command"/>
 | 
			
		||||
	</Category>
 | 
			
		||||
	<Category Name="Scenario">
 | 
			
		||||
	  <Command Description="Load or start a scenario"
 | 
			
		||||
		   DisplayName="Scenario"
 | 
			
		||||
		   Name="scenario">
 | 
			
		||||
	    <Parameters>
 | 
			
		||||
	      <Parameter Name="load"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="BLANK"
 | 
			
		||||
			 Description="The name of the database to load"/>
 | 
			
		||||
	    </Parameters>
 | 
			
		||||
	  </Command>
 | 
			
		||||
	</Category>
 | 
			
		||||
	<Category Name="ICE">
 | 
			
		||||
		<Command Description="Create a virtual wanlink with custom impairments."
 | 
			
		||||
			 DisplayName="Create Wanlink"
 | 
			
		||||
@@ -68,6 +128,62 @@
 | 
			
		||||
			 Description="Upstream port"/>
 | 
			
		||||
	    </Parameters>
 | 
			
		||||
	  </Command>
 | 
			
		||||
	  <Command Description="Initialize a dataplane test"
 | 
			
		||||
		   DisplayName="Dataplane Test"
 | 
			
		||||
		   Name="dataplane_test">
 | 
			
		||||
	    <Parameters>
 | 
			
		||||
	      <Parameter Name="instance_name"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="dataplane-instance"
 | 
			
		||||
			 Description="The name for the dataplane test"/>
 | 
			
		||||
	      <Parameter Name="upstream"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="1.1.eth1"
 | 
			
		||||
			 Description="The upstream port"/>
 | 
			
		||||
	      <Parameter Name="station"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="1.1.eth2"
 | 
			
		||||
			 Description="The downstream port"/>
 | 
			
		||||
	      <Parameter Name="duration"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="15s"
 | 
			
		||||
			 Description="The duration of the test (append 's' for seconds)"/>
 | 
			
		||||
	      <Parameter Name="download_speed"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="10Mbps"
 | 
			
		||||
			 Description="The rate of upstream port (append Mbps/Bps)"/>
 | 
			
		||||
	      <Parameter Name="upload_speed"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="0"
 | 
			
		||||
			 Description="The rate of downstream port (append Mbps/Bps)"/>
 | 
			
		||||
	      <Parameter Name="traffic_types"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="UDP"
 | 
			
		||||
			 Description="The type of traffic (TCP/UDP)"/>
 | 
			
		||||
	      <Parameter Name="local_lf_report_dir"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="tmp/my_report/"
 | 
			
		||||
			 Description="The LANforge directory to save generated reports"/>   
 | 
			
		||||
	      <Parameter Name="output_report_dir"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue=""
 | 
			
		||||
			 Description="The server directory to save generated reports"/>   
 | 
			
		||||
	      <Parameter Name="mgr"
 | 
			
		||||
			 Type="String"
 | 
			
		||||
			 Mandatory="False"
 | 
			
		||||
			 DefaultValue="localhost"
 | 
			
		||||
			 Description="The IP address to run the test on"/>   
 | 
			
		||||
	    </Parameters>
 | 
			
		||||
	  </Command>
 | 
			
		||||
	</Category>
 | 
			
		||||
    </Layout>
 | 
			
		||||
</Driver>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,3 +2,4 @@ mock
 | 
			
		||||
cloudshell-shell-core>=5.0.3,<6.0.0
 | 
			
		||||
cloudshell-automation-api
 | 
			
		||||
paramiko
 | 
			
		||||
scp
 | 
			
		||||
 
 | 
			
		||||
@@ -45,10 +45,10 @@ class CreateL3(Realm):
 | 
			
		||||
        self.endp_a = endp_a
 | 
			
		||||
        self.mode = mode
 | 
			
		||||
        self.name_prefix = name_prefix
 | 
			
		||||
        self.station_profile = self.new_station_profile()
 | 
			
		||||
        # self.station_profile = self.new_station_profile()
 | 
			
		||||
        # self.station_profile.lfclient_url = self.lfclient_url
 | 
			
		||||
        # self.station_list= LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=2, padding_number_=10000, radio='wiphy0') #Make radio a user defined variable from terminal.
 | 
			
		||||
        self.cx_profile = self.new_l3_cx_profile()
 | 
			
		||||
        self.station_profile.lfclient_url = self.lfclient_url
 | 
			
		||||
        self.station_list= LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=2, padding_number_=10000, radio='wiphy0') #Make radio a user defined variable from terminal.
 | 
			
		||||
        self.cx_profile.host = self.host
 | 
			
		||||
        self.cx_profile.port = self.port
 | 
			
		||||
        self.cx_profile.name_prefix = self.name_prefix
 | 
			
		||||
@@ -71,7 +71,7 @@ class CreateL3(Realm):
 | 
			
		||||
 | 
			
		||||
def main(args):
 | 
			
		||||
 | 
			
		||||
    num_sta = 1
 | 
			
		||||
    num_sta = 0
 | 
			
		||||
    # if (args.num_stations is not None) and (int(args.num_stations) > 0):
 | 
			
		||||
    #     num_sta = int(args.num_stations)
 | 
			
		||||
 | 
			
		||||
@@ -103,7 +103,7 @@ if __name__ == "__main__":
 | 
			
		||||
        ''')
 | 
			
		||||
    parser.add_argument('--min_rate_a', help='--min_rate_a bps rate minimum for side_a', default=56000)
 | 
			
		||||
    parser.add_argument('--min_rate_b', help='--min_rate_b bps rate minimum for side_b', default=56000)
 | 
			
		||||
    parser.add_argument('--endp_a', help='--endp_a station list', default=["eth1"], action="append", required=True)
 | 
			
		||||
    parser.add_argument('--endp_a', help='--endp_a station list', default=[], action="append", required=True)
 | 
			
		||||
    parser.add_argument('--endp_b', help='--upstream port', default="eth2", required=True)
 | 
			
		||||
    parser.add_argument('--mode', help='Used to force mode of stations', default=0)
 | 
			
		||||
    parser.add_argument('--ap', help='Used to force a connection to a particular AP')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user