#!/usr/bin/python ## ## Copyright (c) 2020 Intel Corporation ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. ## from rapid_log import RapidLog from prox_ctrl import prox_ctrl from rapid_machine import RapidMachine from math import ceil, log2 class RandomPortBits(object): """ Class to generate PROX bitmaps for random bit generation in source & dst UPD ports to emulate mutiple flows """ @staticmethod def get_bitmap(flow_number): number_of_random_bits = ceil(log2(flow_number)) if number_of_random_bits > 30: raise Exception("Not able to support that many flows") # throw exeption since we need the first bit to be 1 # Otherwise, the randomization could results in all 0's # and that might be an invalid UDP port and result in # packets begin discarded src_number_of_random_bits = number_of_random_bits // 2 dst_number_of_random_bits = (number_of_random_bits - src_number_of_random_bits) src_port_bitmap = '1000000000000000'.replace ('0','X', src_number_of_random_bits) dst_port_bitmap = '1000000000000000'.replace ('0','X', dst_number_of_random_bits) return [src_port_bitmap, dst_port_bitmap, 1<