New test case: gen versus swap via gateway
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / testvRouter / create_interfaces_and_routes.pl
1 #!/bin/env perl
2
3 ##
4 ## Copyright (c) 2010-2017 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 # This script creates four sets of files: 2 sets for use case 0 and 1
20 # (which use the same configuration) and 2 for use case 2.
21 # Each use case is defined by 2 sets of configuration files.
22 # interface.txt contains the IP addresses of the DPDK fast path interfaces.
23 # route.x.y.txt contains the routing table for different configurations
24 # with x being number of routes and y number of next_hops.
25 # Those interface.txt and route.x.y.txt files should then be converted
26 # to fit the syntax of vRouter configuration files.
27
28 use strict;
29 my $max_nb_routes = 8192;
30 my $max_nb_next_hops = 1024;
31 my $max_nb_interfaces = 4;
32 my $nb_next_hops = 1;
33 my ($interface, $a1, $a2, $a3, $a4, $fh, $output_route);
34
35 # Create interface configuration for use case 0 and 1
36 my $interface_config = "interface.txt";
37 open($fh, '>', $interface_config) or die "Could not open file '$interface_config' $!";
38 print $fh "# interface IP address/prefix\n";
39 for ($interface = 0; $interface < $max_nb_interfaces; $interface++) {
40         print $fh ($interface+64).".0.0.240/24\n";      
41 }
42 close $fh;
43
44 # Create interface configuration for use case 2
45 my $interface_config = "interface_use_case_2.txt";
46 open($fh, '>', $interface_config) or die "Could not open file '$interface_config' $!";
47 print $fh "# interface IP address/prefix\n";
48 for ($interface = 0; $interface < $max_nb_interfaces; $interface++) {
49         print $fh ($interface * 8 + 1).".0.0.240/5\n";  
50 }
51 close $fh;
52
53 # Create routes configuration for use case 0 and 1
54 while ($nb_next_hops <= $max_nb_next_hops) {
55         my $nb_routes_per_interface = $nb_next_hops;
56         while ($nb_routes_per_interface <= $max_nb_routes) {
57                 $output_route = "route.".$nb_routes_per_interface.".".$nb_next_hops.".txt";
58                 open($fh, '>', $output_route) or die "Could not open file '$output_route' $!";
59                 print $fh "# destination/prefix;nex-hop\n";
60
61                 for (my $route_nb = 0; $route_nb < $nb_routes_per_interface; $route_nb++) {
62                         for ($interface = 0; $interface < $max_nb_interfaces; $interface++) {
63                                 $a1 = $interface * 8 + 1 + (($route_nb & 1) << 2) + ($route_nb & 2);
64                                 $a2 = (($route_nb & 4) << 5) + (($route_nb & 8) << 1) + (($route_nb & 0x10) >> 1) + (($route_nb & 0x20) >> 4) + (($route_nb & 0x40) >> 6);
65                                 $a3 = (($route_nb & 0x80)) + (($route_nb & 0x100) >> 2) + (($route_nb & 0x200) >> 5) + (($route_nb & 0x400) >> 7) + (($route_nb & 0x800) >> 10) + (($route_nb & 0x1000) >> 12);
66                                 $a4 = 0;
67                                 print $fh $a1.".".$a2.".".$a3.".".$a4."/24;";
68                                 print $fh ($interface+64).".0.".(($route_nb % $nb_next_hops) >> 7).".".(1 + (($route_nb % $nb_next_hops) & 0x7f)) ."\n";
69                         }
70                 }
71                 $nb_routes_per_interface = $nb_routes_per_interface * 2;
72         }
73         $nb_next_hops = $nb_next_hops * 2;              
74 }
75 close $fh;
76
77 # Create routes configuration for use case 2
78 $output_route = "route.1.1.use_case_2.txt";
79 open($fh, '>', $output_route) or die "Could not open file '$output_route' $!";
80 print $fh "# destination/prefix;nex-hop\n";
81
82 for ($interface = 0; $interface < $max_nb_interfaces; $interface++) {
83         $a1 = $interface + 64 ;
84         $a2 = 0;
85         $a3 = 0;
86         $a4 = 0;
87         print $fh $a1.".".$a2.".".$a3.".".$a4."/24;";
88         print $fh ($interface * 8 + 1).".0.0.1\n";
89 }
90 close $fh;