+ // basic validation of input
+ if(windowSize_ <= 0){
+ ss << "Illegal value for window size = " << windowSize_ << " when adding policy " << std::endl;
+ error_string = ss.str();
+ return false;
+ }
+ if(threshold_ < 0){
+ ss << "Illegal value for trigger threshold = " << threshold_ << " when adding policy " << std::endl;
+ error_string = ss.str();
+ return false;
+ }
+
+ if(blockRate_ < 0 || blockRate_ > 100){
+ ss << "Illegal value for blocking rate = " << blockRate_ << " when adding policy " << std::endl;
+ error_string = ss.str();
+ return false;
+ }
+ if (id < 0){
+ ss << "Illegal value for class id = " << id << " when adding policy " << std::endl;
+ error_string = ss.str();
+ return false;
+ }
+
+
+ // create the policy
+ try{
+ policy_list.insert(std::pair<int, protector_policy> (id, protector_policy(enforce, windowSize_, threshold_, blockRate_)));
+ }
+ catch(std::exception &e){
+ ss <<"Error : " << __FILE__ << "," << __LINE__ << ": " << "Error creating policy. Reason = " << e.what() << std::endl;
+ error_string = ss.str();
+ mdclog_write(MDCLOG_ERR, "%s\n", error_string.c_str());
+ return false;
+ }
+
+ mdclog_write(MDCLOG_DEBUG, "Added new policy with id %d with enforce=%d, window size = %d, threshold = %d, blocking rate = %f\n", id, enforce, windowSize_, threshold_, blockRate_);