mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 02:38:03 +00:00 
			
		
		
		
	updated json port-test and cx-test scripts
This commit is contained in:
		
							
								
								
									
										237
									
								
								json/cx_test.pl
									
									
									
									
									
								
							
							
						
						
									
										237
									
								
								json/cx_test.pl
									
									
									
									
									
								
							| @@ -14,9 +14,10 @@ use HTTP::Request; | |||||||
| use LWP; | use LWP; | ||||||
| use LWP::UserAgent; | use LWP::UserAgent; | ||||||
| use Data::Dumper; | use Data::Dumper; | ||||||
|  | use Time::HiRes qw(usleep); | ||||||
| use JSON; | use JSON; | ||||||
| use lib '/home/lanforge/scripts'; | use lib '/home/lanforge/scripts'; | ||||||
| use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names); | use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); | ||||||
|  |  | ||||||
| package main; | package main; | ||||||
| # Default values for ye ole cmd-line args. | # Default values for ye ole cmd-line args. | ||||||
| @@ -51,39 +52,103 @@ $::HostUri = "http://$Host:$Port"; | |||||||
| my $uri = "/shelf/1"; | my $uri = "/shelf/1"; | ||||||
| my $rh = json_request($uri); | my $rh = json_request($uri); | ||||||
| my $ra_links = get_links_from($rh, 'resources'); | my $ra_links = get_links_from($rh, 'resources'); | ||||||
| my @links2= (); | my @ports_up= (); | ||||||
| my $ra_alias_links = []; |  | ||||||
| # TODO: make this a JsonUtils::list_ports() |  | ||||||
| for $uri (@$ra_links) { |  | ||||||
|    $uri =~ s{/resource}{/port}g; |  | ||||||
|    $uri .= "/list"; |  | ||||||
|    #logg("requesting $uri"); |  | ||||||
|    $rh = json_request($uri); |  | ||||||
|    #print Dumper($rh); |  | ||||||
|    push( @$ra_alias_links, @{get_port_names($rh, 'interfaces')}); |  | ||||||
|    push(@links2, @{get_links_from($rh, 'interfaces')}); |  | ||||||
|    #logg("\nfound: "); |  | ||||||
|    #logg(@links2); |  | ||||||
| } |  | ||||||
| #print Dumper($ra_alias_links); |  | ||||||
|  |  | ||||||
|  | # TODO: make this a JsonUtils::list_ports() | ||||||
|  | $uri = "/port/1/3/list?fields=alias,device,down,phantom,port"; | ||||||
|  | #logg("requesting $uri"); | ||||||
|  | $rh = json_request($uri); | ||||||
|  | flatten_list($rh, 'interfaces'); | ||||||
|  | for my $rh_p (keys %{$rh->{'flat_list'}}) { | ||||||
|  |    if (!$rh->{'flat_list'}->{$rh_p}->{'down'}) { | ||||||
|  |       push(@ports_up, $rh_p); | ||||||
|  |    } | ||||||
|  | } | ||||||
| # find first station | # find first station | ||||||
| my $rh_sta; | my $rh_sta; | ||||||
| for my $rh_alias_link (@$ra_alias_links) { | for my $rh_up (@ports_up) { | ||||||
|    #print Dumper($rh_alias_link); |    my $eid = $rh->{'flat_list'}->{$rh_up}->{'port'}; | ||||||
|    if ($rh_alias_link->{'alias'} =~/^sta\d+/) { |    my @hunks = split(/[.]/, $eid); | ||||||
|       $rh_sta=$rh_alias_link; |    if ($hunks[1]) { | ||||||
|       last; |       $rh_sta = $rh_up; | ||||||
|    } |    } | ||||||
| } | } | ||||||
| if (!defined $rh_sta) { | if (!defined $rh_sta) { | ||||||
|    die("Unable to find a virtual station. Is one up?"); |    die("Unable to find a virtual station. Is one up?"); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # delete old CXes and old endpoints | ||||||
|  | # TODO: collect_cx_names | ||||||
|  | my $rh_cxlist = json_request("/cx/list"); | ||||||
|  |  | ||||||
|  | my @cx_names = (); | ||||||
|  | for my $cx_name (sort keys %$rh_cxlist) { | ||||||
|  |    #print " cx_name[$cx_name]"; | ||||||
|  |    next if (ref $rh_cxlist->{$cx_name} ne "HASH"); | ||||||
|  |    next if (!defined $rh_cxlist->{$cx_name}->{"name"}); | ||||||
|  |    next if ($rh_cxlist->{$cx_name}->{"name"} eq "uri"); | ||||||
|  |    push(@cx_names, $rh_cxlist->{$cx_name}->{"name"}); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | print "\nRemoving cx: "; | ||||||
|  | $uri = "/cli-json/rm_cx"; | ||||||
|  | for my $cx_name (sort @cx_names) { | ||||||
|  |    print "$cx_name "; | ||||||
|  |    $rh = { | ||||||
|  |       "test_mgr" => "all", | ||||||
|  |       "cx_name" => $cx_name | ||||||
|  |    }; | ||||||
|  |    json_post($uri, $rh); | ||||||
|  | } | ||||||
|  | sleep 1; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | my $rh_endplist = json_request("/endp/list"); | ||||||
|  | print "\nRemoving endpoints: "; | ||||||
|  | flatten_list($rh_endplist, 'endpoint'); | ||||||
|  | #print Dumper($rh_endplist->{'flat_list'}); | ||||||
|  | #sleep 10; | ||||||
|  | my @endp_names = (); | ||||||
|  | for my $ep_name (keys %{$rh_endplist->{'flat_list'}}) { | ||||||
|  |    next if (!defined $ep_name); | ||||||
|  |    next if ($ep_name eq ""); | ||||||
|  |    next if ((ref $ep_name) eq "ARRAY"); | ||||||
|  |    next if (!defined $rh_endplist->{'flat_list'}->{$ep_name}->{"name"}); | ||||||
|  |    next if ($rh_endplist->{'flat_list'}->{$ep_name}->{"name"} eq ""); | ||||||
|  |    #print "epn:".Dumper($rh_endplist->{'flat_list'}->{$ep_name}->{"name"}); | ||||||
|  |    push(@endp_names, $ep_name); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | $uri = "/cli-json/rm_endp"; | ||||||
|  | for my $ep_name (@endp_names) { | ||||||
|  |    if (!defined $ep_name || $ep_name =~/^\s*$/ || (ref $ep_name) eq "ARRAY") { | ||||||
|  |       print " skipping ep_name[$ep_name]"; | ||||||
|  |       print Dumper(\$ep_name); | ||||||
|  |       next; | ||||||
|  |    } | ||||||
|  |    print "[$ep_name] "; | ||||||
|  |    #usleep(500000); | ||||||
|  |    $rh = { "endp_name" => $ep_name }; | ||||||
|  |    json_post($uri, $rh); | ||||||
|  |     | ||||||
|  | } | ||||||
|  |  | ||||||
|  | print "\nRefreshing..."; | ||||||
|  | my $h = {"endpoint"=>"all"}; | ||||||
|  | json_request("/cli-json/nc_show_endpoints", $h); | ||||||
|  | sleep 1; | ||||||
|  | $h = {"test_mgr"=>"all", "cross_connect"=>"all"}; | ||||||
|  | json_request("/cli-json/show_cxe", $h); | ||||||
|  |  | ||||||
| # assume resource 1, eth1 is present, and create an endpoint to it | # assume resource 1, eth1 is present, and create an endpoint to it | ||||||
| # -A and -B are expected convention for endpoint names | # -A and -B are expected convention for endpoint names | ||||||
|  |  | ||||||
|  | # create 10 endpoints | ||||||
|  | my $rh_ports = json_request("/port/1/3/list"); | ||||||
|  | flatten_list($rh_ports, 'interfaces'); | ||||||
|  |  | ||||||
| my $rh_endp_A = { | my $rh_endp_A = { | ||||||
|       'alias'           => 'udp_ex-A', |       'alias'           => 'udp_json', | ||||||
|       'shelf'           => 1, |       'shelf'           => 1, | ||||||
|       'resource'        => 1, |       'resource'        => 1, | ||||||
|       'port'            => 'b1000', # or eth1 |       'port'            => 'b1000', # or eth1 | ||||||
| @@ -96,15 +161,12 @@ my $rh_endp_A = { | |||||||
|       'payload_pattern' => 'increasing', |       'payload_pattern' => 'increasing', | ||||||
|       'multi_conn'      => 0 |       'multi_conn'      => 0 | ||||||
|    }; |    }; | ||||||
| json_post("/cli-json/add_endp", $rh_endp_A); |  | ||||||
|  |  | ||||||
| my $resourceB_uri = $rh_sta->{'uri'}; |  | ||||||
| my ($resourceB) = $resourceB_uri =~ m{/port/1/(\d+)/}; |  | ||||||
| my $rh_endp_B = { | my $rh_endp_B = { | ||||||
|       'alias'           => 'udp_ex-B', |       'alias'           => 'udp_json', | ||||||
|       'shelf'           => 1, |       'shelf'           => 1, | ||||||
|       'resource'        => $resourceB, |       'resource'        => 3, | ||||||
|       'port'            => $rh_sta->{'alias'}, |       'port'            => 'unset', | ||||||
|       'type'            => 'lf_udp', |       'type'            => 'lf_udp', | ||||||
|       'ip_port'         => -1, |       'ip_port'         => -1, | ||||||
|       'is_rate_bursty'  => 'NO', |       'is_rate_bursty'  => 'NO', | ||||||
| @@ -114,41 +176,116 @@ my $rh_endp_B = { | |||||||
|       'payload_pattern' => 'increasing', |       'payload_pattern' => 'increasing', | ||||||
|       'multi_conn'      => 0 |       'multi_conn'      => 0 | ||||||
|    }; |    }; | ||||||
| json_post("/cli-json/add_endp", $rh_endp_B); | my $rh_cx = { | ||||||
|  |    "alias" => 'udp_json', | ||||||
|  |    "test_mgr" => 'default_tm', | ||||||
|  |    'tx_endp' => '', | ||||||
|  |    'rx_endp' => '' | ||||||
|  | }; | ||||||
|  |  | ||||||
| sleep(2); | $h = {"endpoint"=>"all"}; | ||||||
| my $rh_cx ={ | json_request("/cli-json/nc_show_endpoints", $h); | ||||||
|    'alias'     => 'udp_ex', | $h = {"test_mgr"=>"all", "cross_connect"=>"all"}; | ||||||
|  | json_request("/cli-json/show_cxe", $h); | ||||||
|  | sleep 1; | ||||||
|  | print "\nConstructing new Endpoints: "; | ||||||
|  | my $num_ports = scalar keys(%{$rh_ports->{'flat_list'}}); | ||||||
|  | my $num_cx = 0; | ||||||
|  | for my $rh_p (values %{$rh_ports->{'flat_list'}}) { | ||||||
|  |  | ||||||
|  |    last if ($num_cx >= ($num_ports-1)); | ||||||
|  |    next if ($rh_p->{'alias'} !~ /^v*sta/); | ||||||
|  |  | ||||||
|  |    my $end_a_alias = "udp_json_$num_cx-A"; | ||||||
|  |    my $end_b_alias = "udp_json_$num_cx-B";  | ||||||
|  |    my $port_b = $rh_p->{'alias'}; | ||||||
|  |    print "$port_b "; | ||||||
|  |    $rh_endp_B->{'port'} = $port_b; | ||||||
|  |    $rh_endp_B->{'alias'} = $end_b_alias; | ||||||
|  |    $rh_endp_A->{'alias'} = $end_a_alias; | ||||||
|  |    $num_cx++; | ||||||
|  |  | ||||||
|  |    json_post("/cli-json/add_endp", $rh_endp_A); | ||||||
|  |    json_post("/cli-json/add_endp", $rh_endp_B); | ||||||
|  | } | ||||||
|  | print "\nRefreshing..."; | ||||||
|  | $h = {"endpoint"=>"all"}; | ||||||
|  | json_request("/cli-json/nc_show_endpoints", $h); | ||||||
|  | sleep 1; | ||||||
|  | print "\nConstructing new CX: "; | ||||||
|  | $num_cx = 0; | ||||||
|  | for my $rh_p (values %{$rh_ports->{'flat_list'}}) { | ||||||
|  |    last if ($num_cx >= ($num_ports-1)); | ||||||
|  |    next if ($rh_p->{'alias'} !~ /^v*sta/); | ||||||
|  |  | ||||||
|  |    my $end_a_alias = "udp_json_${num_cx}-A"; | ||||||
|  |    my $end_b_alias = "udp_json_${num_cx}-B";  | ||||||
|  |    my $port_b = $rh_p->{'alias'}; | ||||||
|  |    my $cx_alias = "udp_json_".$num_cx; | ||||||
|  |    $rh_cx->{'alias'} = $cx_alias;  | ||||||
|  |    $rh_cx->{'tx_endp'} = $end_a_alias; | ||||||
|  |    $rh_cx->{'rx_endp'} = $end_b_alias; | ||||||
|  |    json_post("/cli-json/add_cx", $rh_cx); | ||||||
|  |    print " $cx_alias"; | ||||||
|  |    $num_cx++; | ||||||
|  | } | ||||||
|  | print "\nRefreshing..."; | ||||||
|  | $h = {"endpoint"=>"all"}; | ||||||
|  | json_request("/cli-json/nc_show_endpoints", $h); | ||||||
|  |  | ||||||
|  | $rh_cxlist = json_request("/cx/list"); | ||||||
|  | @cx_names = (); | ||||||
|  | for my $cx_name (sort keys %$rh_cxlist) { | ||||||
|  |    next if (ref $rh_cxlist->{$cx_name} ne "HASH"); | ||||||
|  |    next if (!defined $rh_cxlist->{$cx_name}->{"name"}); | ||||||
|  |    push(@cx_names, $rh_cxlist->{$cx_name}->{"name"}); | ||||||
|  | } | ||||||
|  | for my $cx_alias (sort @cx_names) { | ||||||
|  |    my $rh_cx_t = { | ||||||
|       'test_mgr'  => 'default_tm', |       'test_mgr'  => 'default_tm', | ||||||
|    'tx_endp'   => 'udp_ex-A', |       'cx_name'   => $cx_alias, | ||||||
|    'rx_endp'   => 'udp_ex-B' |  | ||||||
| }; |  | ||||||
| json_post("/cli-json/add_cx", $rh_cx); |  | ||||||
| $rh_cx = { |  | ||||||
|    'test_mgr'  => 'default_tm', |  | ||||||
|    'cx_name'   => 'udp_ex', |  | ||||||
|       'milliseconds'=> 1000, |       'milliseconds'=> 1000, | ||||||
| }; |    }; | ||||||
| json_post("/cli-json/set_cx_report_timer", $rh_cx); |    json_post("/cli-json/set_cx_report_timer", $rh_cx_t); | ||||||
|  | } | ||||||
|  | print "\nRefreshing..."; | ||||||
|  | $h = {"endpoint"=>"all"}; | ||||||
|  | json_request("/cli-json/nc_show_endpoints", $h); | ||||||
|  | sleep 1; | ||||||
|  | $h = {"test_mgr"=>"all", "cross_connect"=>"all"}; | ||||||
|  | json_request("/cli-json/show_cxe", $h); | ||||||
|  |  | ||||||
| my $set_state = { | my $set_state = { | ||||||
|    'test_mgr'  => 'default_tm', |    'test_mgr'  => 'default_tm', | ||||||
|    'cx_name'   => 'udp_ex', |    'cx_name'   => 'udp_ex', | ||||||
|    'cx_state'  => 'RUNNING' |    'cx_state'  => 'RUNNING' | ||||||
| }; | }; | ||||||
| json_post("/cli-json/set_cx_state", $set_state); | @cx_names = (); | ||||||
|  | $rh_cxlist = json_request("/cx/list"); | ||||||
|  | for my $cx_name (sort keys %$rh_cxlist) { | ||||||
| my $rh_result; |    next if (ref $rh_cxlist->{$cx_name} ne "HASH"); | ||||||
| for(my $i = 0; $i < 60; $i++) { |    next if (!defined $rh_cxlist->{$cx_name}->{"name"}); | ||||||
|    $rh_result = json_request("/cx/udp_ex?fields=eid,state"); |    push(@cx_names, $rh_cxlist->{$cx_name}->{"name"}); | ||||||
|    print Dumper($rh_result); |  | ||||||
|    sleep(1); |  | ||||||
| } | } | ||||||
|  | print "\nStarting: "; | ||||||
|  | for my $cxname (@cx_names) { | ||||||
|  |    print " $cxname"; | ||||||
|  |    $set_state->{'cx_name'} = $cxname; | ||||||
|  |    json_post("/cli-json/set_cx_state", $set_state); | ||||||
|  | } | ||||||
|  | sleep 10; | ||||||
|  |  | ||||||
| $set_state = { | $set_state = { | ||||||
|    'test_mgr'  => 'default_tm', |    'test_mgr'  => 'default_tm', | ||||||
|    'cx_name'   => 'udp_ex', |    'cx_name'   => 'udp_ex', | ||||||
|    'cx_state'  => 'STOPPED' |    'cx_state'  => 'STOPPED' | ||||||
| }; | }; | ||||||
| json_post("/cli-json/set_cx_state", $set_state); | print "\nStopping: "; | ||||||
|  | for my $cxname (@cx_names) { | ||||||
|  |    $set_state->{'cx_name'} = $cxname; | ||||||
|  |    print " $cxname"; | ||||||
|  |    json_post("/cli-json/set_cx_state", $set_state); | ||||||
|  | } | ||||||
|  | print "...done\n"; | ||||||
|  |  | ||||||
| # | # | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ use LWP::UserAgent; | |||||||
| use Data::Dumper; | use Data::Dumper; | ||||||
| use JSON; | use JSON; | ||||||
| use lib '/home/lanforge/scripts'; | use lib '/home/lanforge/scripts'; | ||||||
| use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names); | use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); | ||||||
|  |  | ||||||
| package main; | package main; | ||||||
| # Default values for ye ole cmd-line args. | # Default values for ye ole cmd-line args. | ||||||
| @@ -51,35 +51,41 @@ my $rh = json_request($uri); | |||||||
| my $ra_links = get_links_from($rh, 'resources'); | my $ra_links = get_links_from($rh, 'resources'); | ||||||
| my @links2= (); | my @links2= (); | ||||||
| my $ra_alias_links = []; | my $ra_alias_links = []; | ||||||
|  |  | ||||||
| # TODO: make this a JsonUtils::list_ports() | # TODO: make this a JsonUtils::list_ports() | ||||||
| for $uri (@$ra_links) { | for $uri (@$ra_links) { | ||||||
|    $uri =~ s{/resource}{/port}g; |    $uri =~ s{/resource}{/port}g; | ||||||
|    $uri .= "/list"; |    $uri .= "/list?fields=_links,device,alias,port"; | ||||||
|    #logg("requesting $uri"); |    print "$uri\n"; | ||||||
|    $rh = json_request($uri); |    $rh = json_request($uri); | ||||||
|    #print Dumper($rh); |    if (defined $rh->{'interfaces'}) { | ||||||
|    push( @$ra_alias_links, @{get_port_names($rh, 'interfaces')}); |       flatten_list($rh, 'interfaces'); | ||||||
|  |       #push(@$ra_alias_links, keys(%{$rh->{'flat_list'}})); | ||||||
|  |       push( @$ra_alias_links, get_port_names($rh, 'interfaces')); | ||||||
|  |       #push(@links2, keys(%{$rh->{'flat_list'}})); | ||||||
|       push(@links2, @{get_links_from($rh, 'interfaces')}); |       push(@links2, @{get_links_from($rh, 'interfaces')}); | ||||||
|    #logg("\nfound: "); |    } | ||||||
|    #logg(@links2); |  | ||||||
| } | } | ||||||
| #print Dumper($ra_alias_links); |  | ||||||
|  |  | ||||||
| # destroy stations on resource 3, 7, 8 | # destroy stations on resource 3 | ||||||
| my @radios = (); | my @radios = (); | ||||||
| my @destroy_me = (); | my @destroy_me = (); | ||||||
| for my $rh_alias_link (@$ra_alias_links) { | for my $rh_alias_link (@$ra_alias_links) { | ||||||
|    push(@destroy_me, $rh_alias_link) |    for my $rh_link (@$rh_alias_link) { | ||||||
|       if (($rh_alias_link->{'uri'} =~m{^/port/1/[3]/}) |       if (  ($rh_link->{'uri'} =~m{^/port/1/[3]/}) | ||||||
|          && ($rh_alias_link->{'alias'} =~m{^v*sta})); |          && ($rh_link->{'device'} =~m{^sta})) { | ||||||
|    push(@radios, $rh_alias_link) |          push(@destroy_me, $rh_link); | ||||||
|       if (($rh_alias_link->{'uri'} =~m{^/port/1/[3]/}) |       } | ||||||
|          && ($rh_alias_link->{'alias'} =~m{^wiphy})); |  | ||||||
|  |       push(@radios, $rh_link) | ||||||
|  |          if (($rh_link->{'uri'} =~m{^/port/1/[3]/}) | ||||||
|  |             && ($rh_link->{'device'} =~m{^wiphy})); | ||||||
|  |    } | ||||||
| } | } | ||||||
| logg("\nDestroying these: "); | logg("\nDestroying these: "); | ||||||
| #print Dumper(@destroy_me); |  | ||||||
| for my $rh_target (@destroy_me) { | for my $rh_target (@destroy_me) { | ||||||
|    my $alias = $rh_target->{'alias'}; |    my $alias = $rh_target->{'device'}; | ||||||
|    my @hunks = split(/[\/]/, $rh_target->{'uri'}); |    my @hunks = split(/[\/]/, $rh_target->{'uri'}); | ||||||
|  |  | ||||||
|    # TODO: create JsonUtils::rm_vlan($eid, $alias) |    # TODO: create JsonUtils::rm_vlan($eid, $alias) | ||||||
| @@ -87,22 +93,31 @@ for my $rh_target (@destroy_me) { | |||||||
|    my $rh_data = { |    my $rh_data = { | ||||||
|       'shelf'=>1, |       'shelf'=>1, | ||||||
|       'resource'=>$hunks[3], |       'resource'=>$hunks[3], | ||||||
|       # 'port'=>'z'.$alias, # use this to force pre_exec check |       'port'=>$alias | ||||||
|       'port'=>$alias, |  | ||||||
|       'suppress_preexec_cli'=>'false', |  | ||||||
|       'suppress_preexec_method'=>'false', |  | ||||||
|       #'suppress_postexec_cli'=>'true', |  | ||||||
|       #'suppress_postexec_method'=>'true' |  | ||||||
|    }; |    }; | ||||||
|    logg(" $alias"); |    logg(" $alias"); | ||||||
|    my $rh_response =  json_post("/cli-json/rm_vlan", $rh_data); |    my $rh_response =  json_post("/cli-json/rm_vlan", $rh_data); | ||||||
|    usleep (25000); |    usleep (15000); | ||||||
| } | } | ||||||
| my $rh_update = { | my $rh_update = { | ||||||
|    'shelf'=>1, 'resource'=>'all', 'port'=>'all', 'flags'=>'0x1' |    'shelf'=>1, 'resource'=>3, 'port'=>'all', 'flags'=>'0x1' | ||||||
| }; | }; | ||||||
| logg(" updating "); | logg("\nRefreshing: "); | ||||||
| my $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | my $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | ||||||
|  | my $remaining = 1; | ||||||
|  | while ($remaining > 0) { | ||||||
|  |    $rh = json_request("/port/1/3/list"); | ||||||
|  |    flatten_list($rh, 'interfaces'); | ||||||
|  |    $remaining = 0; | ||||||
|  |    for my $name (keys %{$rh->{'flat_list'}}) { | ||||||
|  |       $remaining ++  | ||||||
|  |          if ($name =~ /^v*sta/); | ||||||
|  |    } | ||||||
|  |    print "Remaining stations: $remaining, "; | ||||||
|  |    sleep 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # this really should poll for ports to wait for them to disappear | # this really should poll for ports to wait for them to disappear | ||||||
| sleep 3; | sleep 3; | ||||||
| @@ -117,16 +132,19 @@ my $range; | |||||||
| my $num_sta = 160; | my $num_sta = 160; | ||||||
| my $radio_num; | my $radio_num; | ||||||
| my $radio_counter = 0; | my $radio_counter = 0; | ||||||
|  | $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | ||||||
|  |  | ||||||
| # add_sta + ht20 -ht40 -ht80 -create_admin_down | # add_sta + ht20 -ht40 -ht80 -create_admin_down | ||||||
| # flags=142609408&mode=8 | # flags=142609408&mode=8 | ||||||
|  |  | ||||||
|  | print "\nAdding stations...\n"; | ||||||
| for $rh_radio (@radios) { | for $rh_radio (@radios) { | ||||||
|    $radio_name = $rh_radio->{'alias'}; |    $radio_name = $rh_radio->{'alias'}; | ||||||
|    my @hunks = split(/[\/]/, $rh_radio->{'uri'}); |    my @hunks = split(/[\/]/, $rh_radio->{'uri'}); | ||||||
|    ($radio_num) = $radio_name =~ /wiphy(\d+)/; |    ($radio_num) = $radio_name =~ /wiphy(\d+)/; | ||||||
|    $resource = $hunks[3]; |    $resource = $hunks[3]; | ||||||
|    $range = ($resource * 1000) + ($radio_num * 100); |    $range = ($resource * 1000) + ($radio_num * 100); | ||||||
|    logg("\n/cli-json/add_sta = "); |    logg("\n/cli-json/add_sta on 1.$resource.$radio_name\n"); | ||||||
|    for (my $i = $range; $i < ($range+$num_sta); $i++) { |    for (my $i = $range; $i < ($range+$num_sta); $i++) { | ||||||
|       # TODO: create JsonUtils::add_sta($eid, $alias...) |       # TODO: create JsonUtils::add_sta($eid, $alias...) | ||||||
|       my $rh_data = { |       my $rh_data = { | ||||||
| @@ -135,29 +153,26 @@ for $rh_radio (@radios) { | |||||||
|          #'radio'=>'x'.$radio_name, # use to prompt radio not found error |          #'radio'=>'x'.$radio_name, # use to prompt radio not found error | ||||||
|          'radio'=>$radio_name, |          'radio'=>$radio_name, | ||||||
|          'sta_name'=>'sta'.$radio_counter, |          'sta_name'=>'sta'.$radio_counter, | ||||||
|          #'alias'=>'vsta'.$i, # deprecated, use set_port_alias |          #'alias'=>'vsta'.$i, # deprecated, use set_port + interest.set_alias | ||||||
|          #'flags'=>68862086144, # has port-down set |          #'flags'=>68862086144, # has port-down set | ||||||
|          'flags'=>142609408, |          'flags'=>142609408, | ||||||
|          'ssid'=>'idtest-1200-wpa2', |          'ssid'=>'idtest-1200-wpa2', | ||||||
|          'key'=>'idtest-1200-wpa2', |          'key'=>'idtest-1200-wpa2', | ||||||
|          'mac'=>'xx:xx:xx:xx:*:xx', |          'mac'=>'xx:xx:xx:xx:*:xx', | ||||||
|          'mode'=>0, |          'mode'=>0, | ||||||
|          'rate'=>'DEFAULT', |          'rate'=>'DEFAULT' | ||||||
|          'suppress_preexec_cli'=>'false', |  | ||||||
|          'suppress_preexec_method'=>'false', |  | ||||||
|          'suppress_postexec_cli'=>'true', |  | ||||||
|          'suppress_postexec_method'=>'true' |  | ||||||
|       }; |       }; | ||||||
|       #print Dumper($rh_data); |       logg(" sta$radio_counter"); | ||||||
|       logg("1/$resource/$radio_name -> sta$radio_counter"); |  | ||||||
|       my $rh_response = json_post("/cli-json/add_sta", $rh_data); |       my $rh_response = json_post("/cli-json/add_sta", $rh_data); | ||||||
|       usleep(25000); |       usleep(15000); | ||||||
|       $radio_counter +=1; |       $radio_counter +=1; | ||||||
|    } |    } | ||||||
|  |    $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | ||||||
|  |    sleep 1; | ||||||
| } | } | ||||||
| logg(" updating "); | logg("\nUpdating aliases "); | ||||||
| $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | ||||||
| sleep 2; | sleep 3; | ||||||
| $radio_counter = 0; | $radio_counter = 0; | ||||||
| for $rh_radio (@radios) { | for $rh_radio (@radios) { | ||||||
|    $radio_name = $rh_radio->{'alias'}; |    $radio_name = $rh_radio->{'alias'}; | ||||||
| @@ -166,54 +181,66 @@ for $rh_radio (@radios) { | |||||||
|    $resource = $hunks[3]; |    $resource = $hunks[3]; | ||||||
|    $range = ($resource * 10000) + ($radio_num * 1000); |    $range = ($resource * 10000) + ($radio_num * 1000); | ||||||
|  |  | ||||||
|    # set_port - port up, enable dhcp |  | ||||||
|    # current_flags=2147483648&interest=16386 |  | ||||||
|  |  | ||||||
|    for (my $i = $range; $i < ($range+$num_sta); $i++) { |    for (my $i = $range; $i < ($range+$num_sta); $i++) { | ||||||
|       print "sta$radio_counter = vsta$i [ $range .. ".($range+$num_sta)."] 1/$resource/$radio_num $radio_name \n"; |       print "sta$radio_counter:vsta$i  "; | ||||||
|  |       #my $eidname = "1.$resource.sta$radio_counter"; | ||||||
|  |  | ||||||
|  |       # set port up + dhcp + alias | ||||||
|       my $rh_data = { |       my $rh_data = { | ||||||
|          'suppress_preexec_cli'=>'false', |  | ||||||
|          'suppress_preexec_method'=>'false', |  | ||||||
|          'suppress_postexec_cli'=>'true', |  | ||||||
|          'suppress_postexec_method'=>'true', |  | ||||||
|          'shelf'=>1, |          'shelf'=>1, | ||||||
|          'resource'=>$resource, |          'resource'=>$resource, | ||||||
|          'port'=>'sta'.$radio_counter, |          'port'=>'sta'.$radio_counter, | ||||||
|  |          'current_flags'=>2147483648, | ||||||
|  |          'interest'=>20480, | ||||||
|          'alias'=>'vsta'.$i |          'alias'=>'vsta'.$i | ||||||
|       }; |       }; | ||||||
|       $rh_response = json_post("/cli-json/set_port", $rh_data); |  | ||||||
|       usleep(10000); |  | ||||||
|  |  | ||||||
|       # set port up + dhcp |  | ||||||
|       $rh_data = { |  | ||||||
|          'suppress_preexec_cli'=>'false', |  | ||||||
|          'suppress_preexec_method'=>'false', |  | ||||||
|          'suppress_postexec_cli'=>'true', |  | ||||||
|          'suppress_postexec_method'=>'true', |  | ||||||
|          'shelf'=>1, |  | ||||||
|          'resource'=>$resource, |  | ||||||
|          'port'=>'sta'.$radio_counter, |  | ||||||
|          'cmd_flags'=>0, |  | ||||||
|          'current_flags'=>2147483648, |  | ||||||
|          #'suppress_postexec'=>'true', |  | ||||||
|          'interest'=>16386 |  | ||||||
|       }; |  | ||||||
|       # TODO: create JsonUtils::set_dhcp($eid, $alias, $on_off) |  | ||||||
|       my $rh_response = json_post("/cli-json/set_port", $rh_data); |       my $rh_response = json_post("/cli-json/set_port", $rh_data); | ||||||
|       $radio_counter+=1; |       $radio_counter+=1; | ||||||
|       usleep(10000); |       usleep(10000); | ||||||
|    } |    } | ||||||
| } | } | ||||||
| logg(" updating "); | $radio_counter = 0; | ||||||
|  | for $rh_radio (@radios) { | ||||||
|  |    $radio_name = $rh_radio->{'alias'}; | ||||||
|  |    my @hunks = split(/[\/]/, $rh_radio->{'uri'}); | ||||||
|  |    ($radio_num) = $radio_name =~ /wiphy(\d+)/; | ||||||
|  |    $resource = $hunks[3]; | ||||||
|  |    $range = ($resource * 10000) + ($radio_num * 1000); | ||||||
|  |    for (my $i = $range; $i < ($range+$num_sta); $i++) { | ||||||
|  |       print "sta$radio_counter:vsta$i  "; | ||||||
|  |       #my $eidname = "1.$resource.sta$radio_counter"; | ||||||
|  |  | ||||||
|  |       # set port up + dhcp + alias | ||||||
|  |       my $rh_data = { | ||||||
|  |          'shelf'=>1, | ||||||
|  |          'resource'=>$resource, | ||||||
|  |          'port'=>'sta'.$radio_counter, | ||||||
|  |          'current_flags'=>0, | ||||||
|  |          'interest'=>8388608, | ||||||
|  |       }; | ||||||
|  |       my $rh_response = json_post("/cli-json/set_port", $rh_data); | ||||||
|  |       $radio_counter+=1; | ||||||
|  |       usleep(10000); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | logg("\nRefreshing after setting up... "); | ||||||
| $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | ||||||
| sleep 2; | sleep 1; | ||||||
| for $uri (@$ra_links) { | # wait on ports up | ||||||
|    $uri =~ s{/resource}{/port}g; | my $ports_still_down = 1; | ||||||
|    $uri .= "/list" | while ($ports_still_down > 0) { | ||||||
|       if ($uri !~ m{/list$}); |    $rh = json_request("/port/1/3/list?fields=_links,port,device,down"); | ||||||
|    $rh = json_request($uri); |    flatten_list($rh, 'interfaces'); | ||||||
|    push( @$ra_alias_links, @{get_port_names($rh, 'interfaces')}); |    $ports_still_down=0; | ||||||
|    push(@links2, @{get_links_from($rh, 'interfaces')}); |    for my $rh_p (values %{$rh->{'flat_list'}}) { | ||||||
|  |       next unless $rh_p->{'device'} =~ /^sta/; | ||||||
|  |       #print "$rh_p->{'device'} is $rh_p->{'down'} "; | ||||||
|  |       $ports_still_down++ | ||||||
|  |          if ($rh_p->{'down'}); | ||||||
|  |    } | ||||||
|  |    print "ports down: $ports_still_down "; | ||||||
|  |    $rh_response =  json_post("/cli-json/nc_show_ports", $rh_update); | ||||||
|  |    sleep 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| # ports down | # ports down | ||||||
| @@ -228,8 +255,8 @@ for my $port_uri (@links2) { | |||||||
|    my @hunks = split(/\./, $port); |    my @hunks = split(/\./, $port); | ||||||
|    my $resource = $hunks[1]; |    my $resource = $hunks[1]; | ||||||
|    my %post = ( |    my %post = ( | ||||||
|       'suppress_preexec_cli'=>'false', |       #'suppress_preexec_cli'=>'false', | ||||||
|       'suppress_preexec_method'=>'false', |       #'suppress_preexec_method'=>'false', | ||||||
|       #'suppress_postexec_cli'=>'false', |       #'suppress_postexec_cli'=>'false', | ||||||
|       #'suppress_postexec_method'=>'false', |       #'suppress_postexec_method'=>'false', | ||||||
|       "shelf" => 1, |       "shelf" => 1, | ||||||
| @@ -256,10 +283,10 @@ for my $port_uri (@links2) { | |||||||
|    my $resource = $hunks[1]; |    my $resource = $hunks[1]; | ||||||
|    # 'shelf=1&resource=2&port=vap2000&cmd_flags=0¤t_flags=0&interest=8388610' |    # 'shelf=1&resource=2&port=vap2000&cmd_flags=0¤t_flags=0&interest=8388610' | ||||||
|    my %post = ( |    my %post = ( | ||||||
|       'suppress_preexec_cli'=>'false', |       #'suppress_preexec_cli'=>'false', | ||||||
|       'suppress_preexec_method'=>'false', |       #'suppress_preexec_method'=>'false', | ||||||
|       'suppress_postexec_cli'=>'false', |       #'suppress_postexec_cli'=>'false', | ||||||
|       'suppress_postexec_method'=>'false', |       #'suppress_postexec_method'=>'false', | ||||||
|       "shelf" => 1, |       "shelf" => 1, | ||||||
|       "resource" => 0+$resource, |       "resource" => 0+$resource, | ||||||
|       "port" => $device, |       "port" => $device, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jed Reynolds
					Jed Reynolds