Merge "docs: Update install and release docs for DPDK migration support"
[samplevnf.git] / VNFs / DPPD-PROX / flow_gen / bundle_maker.lua
1 --
2 -- Copyright (c) 2010-2017 Intel Corporation
3 --
4 -- Licensed under the Apache License, Version 2.0 (the "License");
5 -- you may not use this file except in compliance with the License.
6 -- You may obtain a copy of the License at
7 --
8 --     http://www.apache.org/licenses/LICENSE-2.0
9 --
10 -- Unless required by applicable law or agreed to in writing, software
11 -- distributed under the License is distributed on an "AS IS" BASIS,
12 -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- See the License for the specific language governing permissions and
14 -- limitations under the License.
15 --
16
17 function get_client_bundles(bundles)
18    local client_bundles = {};
19
20    for i,b in ipairs(bundles) do
21       client_bundles[i] = {bundle = b, imix_fraction = 1}
22    end
23
24    return client_bundles;
25 end
26
27 function get_server_streams(bundles)
28    local server_streams = {}
29    n_listen = 0
30    for i, bundle in ipairs(bundles) do
31       for j, stream in ipairs(bundle) do
32          n_listen = n_listen + 1
33          server_streams[n_listen] = stream
34       end
35    end
36    return server_streams;
37 end
38
39 function setup_bundles(first_ip_byte, speed_scaling)
40    bundles = dofile("cfg.lua")
41
42    local client_bundles = get_client_bundles(bundles);
43    local server_streams = get_server_streams(bundles);
44
45    for i,e in ipairs(client_bundles) do
46       for j,stream in ipairs(e.bundle) do
47          stream.clients.ip[1] = first_ip_byte
48          stream.clients.port_mask = 0xffff
49       end
50    end
51
52    for i,stream in ipairs(server_streams) do
53       stream.servers.ip[1] = first_ip_byte
54    end
55
56    local highest_bps = 0;
57    for i,e in ipairs(client_bundles) do
58       for j,s in ipairs(e.bundle) do
59          if (s.up_bps ~= 1250000000 and s.dn_bps ~= 1250000000) then
60             if (highest_bps < s.up_bps) then
61                highest_bps = s.up_bps
62             end
63             if (highest_bps < s.dn_bps) then
64                highest_bps = s.dn_bps
65             end
66          end
67       end
68    end
69
70    if (highest_bps == 0) then
71       highest_bps = 1250000000
72    end
73    max_ss = 1250000000/highest_bps
74
75    if (max_ss_and_quit == not nil and max_ss_and_quit == true) then
76       print("max ss=" .. max_ss .. "")
77       os.exit(0);
78    end
79
80    if (speed_scaling > max_ss) then
81       error("Scaling too high (maximum scaling is " .. max_ss .. ")")
82    end
83
84    for i,e in ipairs(client_bundles) do
85       for j,s in ipairs(e.bundle) do
86          if (s.up_bps ~= 1250000000 and s.dn_bps ~= 1250000000) then
87             s.up_bps = s.up_bps * speed_scaling;
88             s.dn_bps = s.dn_bps * speed_scaling;
89          end
90       end
91    end
92
93    return client_bundles, server_streams
94 end