Example #1
0
// domains than flows
// THIS THE MOST FUCKING COMPLEX FUNCTION IN THIS MODEL
int GCN::flows_throught_domains_streaming(float time)
{
    map<int, Domain*>::iterator domain_map_iter;

    for(domain_map_iter = domain_map.begin(); domain_map_iter != domain_map.end(); ++domain_map_iter)
    {
        Domain* domain;
        int domain_id = domain_map_iter->first;
        domain = domain_map_iter->second;

        map<int, Flow*>::iterator flow_map_iter;
        int domain_for_flow_type;
        for(flow_map_iter = flow_map.begin(); flow_map_iter != flow_map.end(); ++flow_map_iter)
        {
            Flow* flow;
            int flow_id = flow_map_iter->first;
            flow = flow_map_iter->second;
            domain_for_flow_type = flow->get_domain_type_for_this_flow(domain_id);

            if(domain_for_flow_type == 0) // start domain for this flow
            {
                float start_rate = flow->start_rate_generator();
                float overload = domain->add_load(flow_id, start_rate); // change domain load... overload may be NULL
                flow->change_state(domain_id,start_rate - overload,overload,0.0f); // change flow state at this domain
                //change domains vuln host number
                if(flow->is_malware())
                {
                    Malware* malware;
                    malware = malware_map[flow->get_flow_malware_id()];
                    domain->change_inf_hosts_number(flow->get_flow_malware_id(),start_rate,
                                                    malware->get_copy_size(),malware->get_infection_speed());
                }
            }
            else if (domain_for_flow_type == 1) // transit domain for this flow
            {
                int prev_domain_id = flow->get_prev_domain_in_flow_path(domain_id);
                Link* link = this->get_link(prev_domain_id,domain_id);
                Domain* prev_domain = domain_map[prev_domain_id];
                float flow_rate_in_prev_domain = prev_domain->get_flow_res(flow_id); // see how muck ress this flow took in prev domain

                float transfer_rate; // next stage to calc transfer rate for this flow
                float link_bandwidth = link->get_bandwidth(); // general link bandwidth
                int link_id = link->get_link_id(); // link id
                float tick_link_bandwidth = tick_link_state_map[link_id]; // current tick link bandwidth
                if(flow_rate_in_prev_domain > (link_bandwidth - tick_link_bandwidth))
                    transfer_rate = link_bandwidth - tick_link_bandwidth; // we cant transfer more then link allowed
                else
                    transfer_rate = flow_rate_in_prev_domain;

                //change domains (curr and prev) load
                prev_domain->sub_load(flow_id,transfer_rate);
                domain->add_load(flow_id,transfer_rate);

                //change domains vuln host number
                if(flow->is_malware())
                {
                    Malware* malware;
                    malware = malware_map[flow->get_flow_malware_id()];
                    domain->change_inf_hosts_number(flow->get_flow_malware_id(),transfer_rate,
                                                    malware->get_copy_size(),malware->get_infection_speed());
                }

                //change tick link state
                tick_link_state_map[link_id] += transfer_rate;
            }
            else if (domain_for_flow_type == 2) // last domain for this flow
            {

                int prev_domain_id = flow->get_prev_domain_in_flow_path(domain_id);
                Link* link = this->get_link(prev_domain_id,domain_id);

                Domain* prev_domain = domain_map[prev_domain_id];
                float flow_rate_in_prev_domain = prev_domain->get_flow_res(flow_id); // see how muck ress this flow took in prev domain

                float transfer_rate; // next stage to calc transfer rate for this flow
                float link_bandwidth = link->get_bandwidth(); // general link bandwidth
                int link_id = link->get_link_id(); // link id
                float tick_link_bandwidth = tick_link_state_map[link_id]; // current tick link bandwidth
                if(flow_rate_in_prev_domain > (link_bandwidth - tick_link_bandwidth))
                    transfer_rate = link_bandwidth - tick_link_bandwidth; // we cant transfer more then link allowed
                else
                    transfer_rate = flow_rate_in_prev_domain;

                //change domains (curr and prev) load
                prev_domain->sub_load(flow_id,transfer_rate); // NO ADD LOAD - becouse of consume

                //change domains vuln host number
                if(flow->is_malware())
                {
                    Malware* malware;
                    malware = malware_map[flow->get_flow_malware_id()];
                    domain->change_inf_hosts_number(flow->get_flow_malware_id(),transfer_rate,
                                                    malware->get_copy_size(),malware->get_infection_speed());
                }

                //change tick link state
                tick_link_state_map[link_id] += transfer_rate;
            }
        }
    }

    return 0;
}