Example #1
0
void itp_solver::undo_proxies (expr_ref_vector &r)
{
    app_ref e(m);
    // expand proxies
    for (unsigned i = 0, sz = r.size (); i < sz; ++i)
        if (is_proxy(r.get(i), e)) {
            SASSERT (m.is_or (e));
            r[i] = e->get_arg (1);
        }
}
Example #2
0
void abstract_actor::cleanup(std::uint32_t reason) {
    // log as 'actor'
    CPPA_LOGM_TRACE("cppa::actor", CPPA_ARG(m_id) << ", " << CPPA_ARG(reason)
                    << ", " << CPPA_ARG(m_is_proxy));
    CPPA_REQUIRE(reason != exit_reason::not_exited);
    // move everyhting out of the critical section before processing it
    decltype(m_links) mlinks;
    decltype(m_attachables) mattachables;
    { // lifetime scope of guard
        guard_type guard{m_mtx};
        if (m_exit_reason != exit_reason::not_exited) {
            // already exited
            return;
        }
        m_exit_reason = reason;
        mlinks = std::move(m_links);
        mattachables = std::move(m_attachables);
        // make sure lists are empty
        m_links.clear();
        m_attachables.clear();
    }
    CPPA_LOGC_INFO_IF(not is_proxy(), "cppa::actor", __func__,
                      "actor with ID " << m_id << " had " << mlinks.size()
                      << " links and " << mattachables.size()
                      << " attached functors; exit reason = " << reason
                      << ", class = " << detail::demangle(typeid(*this)));
    // send exit messages
    auto msg = make_any_tuple(exit_msg{address(), reason});
    CPPA_LOGM_DEBUG("cppa::actor", "send EXIT to " << mlinks.size() << " links");
    for (auto& aptr : mlinks) {
        aptr->enqueue({address(), aptr, message_id{}.with_high_priority()},
                      msg, m_host);
    }
    CPPA_LOGM_DEBUG("cppa::actor", "run " << mattachables.size()
                                   << " attachables");
    for (attachable_ptr& ptr : mattachables) {
        ptr->actor_exited(reason);
    }
}
Example #3
0
void itp_solver::undo_proxies_in_core (ptr_vector<expr> &r)
{
    app_ref e(m);
    expr_fast_mark1 bg;
    for (unsigned i = 0; i < m_first_assumption; ++i)
    { bg.mark(m_assumptions.get(i)); }

    // expand proxies
    unsigned j = 0;
    for (unsigned i = 0, sz = r.size(); i < sz; ++i) {
        // skip background assumptions
        if (bg.is_marked(r[i])) { continue; }

        // -- undo proxies, but only if they were introduced in check_sat
        if (m_is_proxied && is_proxy(r[i], e)) {
            SASSERT (m.is_or (e));
            r[j] = e->get_arg (1);
        } else if (i != j) { r[j] = r[i]; }
        j++;
    }
    r.shrink (j);
}
Example #4
0
bool
Node::is_local() const
{
  return !is_proxy();
}
Example #5
0
void itp_solver::get_itp_core (expr_ref_vector &core)
{
    scoped_watch _t_ (m_itp_watch);

    typedef obj_hashtable<expr> expr_set;
    expr_set B;
    for (unsigned i = m_first_assumption, sz = m_assumptions.size(); i < sz; ++i) {
        expr *a = m_assumptions.get (i);
        app_ref def(m);
        if (is_proxy(a, def)) { B.insert(def.get()); }
        B.insert (a);
    }

    proof_ref pr(m);
    pr = get_proof ();

    if (!m_new_unsat_core) {
        // old code
        farkas_learner learner_old;
        learner_old.set_split_literals(m_split_literals);

        learner_old.get_lemmas (pr, B, core);
        elim_proxies (core);
        simplify_bounds (core); // XXX potentially redundant
    } else {
        // new code
        unsat_core_learner learner(m);

        if (m_farkas_optimized) {
            if (true) // TODO: proper options
            {
                unsat_core_plugin_farkas_lemma_optimized* plugin_farkas_lemma_optimized = alloc(unsat_core_plugin_farkas_lemma_optimized, learner,m);
                learner.register_plugin(plugin_farkas_lemma_optimized);
            }
            else
            {
                unsat_core_plugin_farkas_lemma_bounded* plugin_farkas_lemma_bounded = alloc(unsat_core_plugin_farkas_lemma_bounded, learner,m);
                learner.register_plugin(plugin_farkas_lemma_bounded);
            }

        } else {
            unsat_core_plugin_farkas_lemma* plugin_farkas_lemma = alloc(unsat_core_plugin_farkas_lemma, learner, m_split_literals, m_farkas_a_const);
            learner.register_plugin(plugin_farkas_lemma);
        }

        if (m_minimize_unsat_core) {
            unsat_core_plugin_min_cut* plugin_min_cut = alloc(unsat_core_plugin_min_cut, learner, m);
            learner.register_plugin(plugin_min_cut);
        } else {
            unsat_core_plugin_lemma* plugin_lemma = alloc(unsat_core_plugin_lemma, learner);
            learner.register_plugin(plugin_lemma);
        }

        learner.compute_unsat_core(pr, B, core);

        elim_proxies (core);
        simplify_bounds (core); // XXX potentially redundant

//            // debug
//            expr_ref_vector core2(m);
//            unsat_core_learner learner2(m);
//
//            unsat_core_plugin_farkas_lemma* plugin_farkas_lemma2 = alloc(unsat_core_plugin_farkas_lemma, learner2, m_split_literals);
//            learner2.register_plugin(plugin_farkas_lemma2);
//            unsat_core_plugin_lemma* plugin_lemma2 = alloc(unsat_core_plugin_lemma, learner2);
//            learner2.register_plugin(plugin_lemma2);
//            learner2.compute_unsat_core(pr, B, core2);
//
//            elim_proxies (core2);
//            simplify_bounds (core2);
//
//            IF_VERBOSE(2,
//                       verbose_stream () << "Itp Core:\n"
//                       << mk_pp (mk_and (core), m) << "\n";);
//            IF_VERBOSE(2,
//                       verbose_stream () << "Itp Core2:\n"
//                       << mk_pp (mk_and (core2), m) << "\n";);
        //SASSERT(mk_and (core) == mk_and (core2));
    }

    IF_VERBOSE(2,
               verbose_stream () << "Itp Core:\n"
               << mk_pp (mk_and (core), m) << "\n";);
Example #6
0
static int
join_ok(Conn_t *conn)
{
  Reg_t *rtmp = NULL;   /* silence gcc 2.7.2.1 */
  Lecdb_t *ltmp; 
  const char *elanname;

  Debug_unit(&conn_unit, "Join_ok called");  
  dump_conn(conn);

  if (control_packet != NULL &&
      proper_request() == 1) {
/*    dump_control(control_packet);*/

    /* Do not accept control packets with lecid set to unknown value*/
    if (control_packet->lecid != 0) {
      Debug_unit(&conn_unit,"Lecid set");
      ltmp = leciddb_find(control_packet->lecid);
      if (!ltmp || memcmp(&ltmp->address, &control_packet->source_addr,
			  sizeof(AtmAddr_t)) != 0) {
	send_join_response(conn->fd, control_packet, conn->lecid,
			   (unsigned int)LE_STATUS_BAD_LECID);
	return 0;
      }
    }

    /* Is lan destination address present? */
    if (control_packet->source.tag != htons(LANE_DEST_NP)) {
      rtmp = regdb_find_mac(control_packet->source);

      /* Do not accept lan multicast address */
      if (is_multicast(&control_packet->source)) {
	Debug_unit(&conn_unit,"Destination lan address is multicast");
	send_join_response(conn->fd, control_packet, conn->lecid,
			   ((unsigned int)LE_STATUS_BAD_DEST));
	return 0;
      }

      /* Duplicate registered Lan-destination, duplicate mac-address */
      if (rtmp && memcmp(&rtmp->atm_address,&control_packet->source_addr, 
			 sizeof(AtmAddr_t)) != 0) {
	Debug_unit(&conn_unit,"Duplicate Destination lan, duplicate mac");
	send_join_response(conn->fd, control_packet, conn->lecid,
			   ((unsigned int)LE_STATUS_DUPLICATE_REG));
	return 0;
      }
    }

    /* Duplicate atm-address */
    if ((ltmp =leciddb_find_atm(control_packet->source_addr)) != NULL &&
	ltmp->lecid != conn->lecid) {
      Debug_unit(&conn_unit,"Duplicate atmaddress");
      send_join_response(conn->fd, control_packet, conn->lecid,
			 ((unsigned int)LE_STATUS_DUPLICATE_ADDR));
      return 0;
    }
    /* If we have elan-name, check it agaist the one in join request */
    elanname = get_var_str(&conn_unit, "ELANNAME");
    if (elanname) {
      Debug_unit(&conn_unit, "Compare %s with %s",elanname, 
		 control_packet->elan_name);
      if ((strlen(elanname) != control_packet->elan_name_size) ||
	  strncmp(elanname, control_packet->elan_name, 
		  control_packet->elan_name_size)) {
	/* Don't match */
	Debug_unit(&conn_unit, "Invalid elan-name set");
	send_join_response(conn->fd, control_packet, conn->lecid,
			   ((unsigned int)LE_STATUS_NO_CONFIG));
	return 0;
      }
    }
    Debug_unit(&conn_unit,"Control_packet OK.");
    /* Control_packet OK. */
    if (leciddb_find(conn->lecid) == NULL) {
      leciddb_add(conn->lecid,
		  control_packet->source_addr, conn->fd);
    }
    if (control_packet->source.tag != htons(LANE_DEST_NP) && !rtmp) {
/*      dump_addr(&control_packet->source); */
      regdb_add(control_packet->source_addr, 
		control_packet->source);
    }
    /* Send join response */
    if ((conn->proxy == BL_TRUE || is_proxy() == BL_TRUE) &&
	proxydb_find(conn->lecid) == NULL) {
      proxydb_add((const Conn_t *)conn, conn->fd);
    }
    timer_ack(&conn_unit, conn->timer);
    send_join_response(conn->fd, control_packet, conn->lecid,
		       (unsigned short)LE_STATUS_SUCCESS);
    return 1;
  } 

  return 0;
}
Example #7
0
/*
 * Handle new connections or data arrival
 * data points to Conn_t
 */
static int
data_handler(const Event_t *event, void *funcdata)
{
  Conn_t *tmp, *newconn;
  int fd, nbytes;
  static char buffer[BUFSIZE];
  LaneControl_t *ctmp;
  struct sockaddr_atmsvc addr;

  assert(event->data != NULL);
  tmp = (Conn_t *)event->data;
  dump_conn(tmp);
  if (tmp->type == CT_MAIN) {
    nbytes = sizeof(addr);
    memset(&addr,0, nbytes);
    fd = accept(tmp->fd, (struct sockaddr *)&addr, &nbytes);
    if (fd <0) {
      dump_error(&conn_unit, "accept");
      if (errno == ENETRESET) {
	Debug_unit(&conn_unit,"Restart. Sleeping 10 secs...");
	sleep(10);
	event_put(&conn_unit, CE_RESTART, NULL);
      } else if (errno == EUNATCH) {
	Debug_unit(&conn_unit,"Exiting...");
	event_put(&conn_unit, CE_EXIT, NULL);
      }
      return -1;
    }
    newconn = conn_add(CT_SVC_CD, fd,0);
    newconn->state = call_state(CE_SVC_OPEN, 0, newconn);
  }
  else {
    /* tmp->fd or tmp->sfd ?*/
    nbytes = read(tmp->active_fd, buffer, BUFSIZE);
    if (nbytes < 0) {
      dump_error(&conn_unit, "read");
      if (errno == EUNATCH)
	event_put(&conn_unit, CE_EXIT, NULL);
      if (errno == ENETRESET) {
	Debug_unit(&conn_unit, "Restart. Sleeping 10 secs...");
	sleep(10);
	event_put(&conn_unit, CE_RESTART, NULL);
      }
    } else if (nbytes == 0) {
      /* EOF */
      Debug_unit(&conn_unit, "EOF");
      tmp->state = call_state(CE_SVC_CLOSE, 0, tmp);
    } else {
      buffer[nbytes] = '\0';
      Debug_unit(&conn_unit, "Data: %2.2x %2.2x %2.2x", 
		 0xff&buffer[0],0xff&buffer[1],0xff&buffer[2]);
      ctmp = (LaneControl_t *)buffer;
      if (is_control(ctmp) == 1) {
	control_packet = (LaneControl_t*)buffer;
	dump_control(ctmp);
	tmp->proxy = is_proxy();
	tmp->state = call_state(CE_DATA, ctmp->opcode, tmp);
      } else
	Debug_unit(&conn_unit,"Not a control_packet, discarding...");
    }
  }
  mem_free(&conn_unit, event);
  return 1;
}