Ejemplo n.º 1
0
void simple_cokriging_markI(
    const sugarbox_grid_t & grid,
    const cont_property_array_t & input_prop,
    const cont_property_array_t & secondary_data,
    mean_t primary_mean,
    mean_t secondary_mean,
    double secondary_variance,
    double correlation_coef,
    const neighbourhood_param_t & neighbourhood_params,
    const covariance_param_t & primary_cov_params,
    cont_property_array_t & output_prop)
{
    if (input_prop.size() != output_prop.size())
        throw hpgl_exception("simple_cokriging", boost::format("Input data size: %s. Output data size: %s. Must be equal.") % input_prop.size() % output_prop.size());

    print_algo_name("Simple Colocated Cokriging Markov Model I");
    print_params(neighbourhood_params);
    print_params(primary_cov_params);
    print_param("Primary mean", primary_mean);
    print_param("Secondary mean", secondary_mean);
    print_param("Secondary variance", secondary_variance);
    print_param("Correllation coef", correlation_coef);

    cov_model_t cov(primary_cov_params);

    cross_cov_model_mark_i_t<cov_model_t> cross_cov(correlation_coef, secondary_variance, &cov);

    int data_size = input_prop.size();

    neighbour_lookup_t<sugarbox_grid_t, cov_model_t> n_lookup(&grid, &cov, neighbourhood_params);

    progress_reporter_t report(data_size);

    report.start(data_size);

    // for each node
    for (node_index_t i = 0; i < data_size; ++i)
    {
        // 		calc value
        cont_value_t result = -500;
        if (input_prop.is_informed(i))
        {
            result = input_prop[i];
        }
        else
        {
            cont_value_t secondary_value = secondary_data.is_informed(i) ? secondary_data[i] : secondary_mean;
            if (!calc_value(i, input_prop, secondary_value, primary_mean, secondary_mean,
                            secondary_variance, cov, cross_cov, n_lookup, result))
            {
                result = primary_mean + secondary_value - secondary_mean;
            }
        }
        // 		set value at node
        output_prop.set_at(i, result);
        report.next_lap();
    }
}
Ejemplo n.º 2
0
bool nl_bridge::is_mac_in_l2_cache(rtnl_neigh *n) {
  assert(n);

  std::unique_ptr<rtnl_neigh, decltype(&rtnl_neigh_put)> n_lookup(
      NEIGH_CAST(nl_cache_search(l2_cache.get(), OBJ_CAST(n))), rtnl_neigh_put);

  if (n_lookup) {
    VLOG(2) << __FUNCTION__ << ": found existing l2_cache entry "
            << OBJ_CAST(n_lookup.get());
    return true;
  }

  return false;
}
Ejemplo n.º 3
0
int nl_bridge::fdb_timeout(rtnl_link *br_link, uint16_t vid,
                           const rofl::caddress_ll &mac) {
  int rv = 0;

  std::unique_ptr<rtnl_neigh, decltype(&rtnl_neigh_put)> n(rtnl_neigh_alloc(),
                                                           rtnl_neigh_put);

  std::unique_ptr<nl_addr, decltype(&nl_addr_put)> h_src(
      nl_addr_build(AF_LLC, mac.somem(), mac.memlen()), nl_addr_put);

  rtnl_neigh_set_ifindex(n.get(), rtnl_link_get_ifindex(br_link));
  rtnl_neigh_set_master(n.get(), rtnl_link_get_master(br_link));
  rtnl_neigh_set_family(n.get(), AF_BRIDGE);
  rtnl_neigh_set_vlan(n.get(), vid);
  rtnl_neigh_set_lladdr(n.get(), h_src.get());
  rtnl_neigh_set_flags(n.get(), NTF_MASTER | NTF_EXT_LEARNED);
  rtnl_neigh_set_state(n.get(), NUD_REACHABLE);

  // find entry in local l2_cache
  std::unique_ptr<rtnl_neigh, decltype(&rtnl_neigh_put)> n_lookup(
      NEIGH_CAST(nl_cache_search(l2_cache.get(), OBJ_CAST(n.get()))),
      rtnl_neigh_put);

  if (n_lookup) {
    // * remove l2 entry from kernel
    nl_msg *msg = nullptr;
    rtnl_neigh_build_delete_request(n.get(), NLM_F_REQUEST, &msg);
    assert(msg);

    // send the message and create new fdb entry
    if (nl->send_nl_msg(msg) < 0) {
      LOG(ERROR) << __FUNCTION__ << ": failed to send netlink message";
      return -EINVAL;
    }

    // XXX TODO maybe delete after NL event and not yet here
    nl_cache_remove(OBJ_CAST(n_lookup.get()));
  }

  return rv;
}
Ejemplo n.º 4
0
void nl_bridge::remove_neigh_from_fdb(rtnl_neigh *neigh) {
  assert(sw);
  nl_addr *addr = rtnl_neigh_get_lladdr(neigh);

  if (nl_addr_cmp(rtnl_link_get_addr(bridge), addr) == 0) {
    // ignore ll addr of bridge on slave
    return;
  }

  // lookup l2_cache as well
  std::unique_ptr<rtnl_neigh, decltype(&rtnl_neigh_put)> n_lookup(
      NEIGH_CAST(nl_cache_search(l2_cache.get(), OBJ_CAST(neigh))),
      rtnl_neigh_put);

  if (n_lookup) {
    nl_cache_remove(OBJ_CAST(n_lookup.get()));
  }

  const uint32_t port = nl->get_port_id(rtnl_neigh_get_ifindex(neigh));
  rofl::caddress_ll mac((uint8_t *)nl_addr_get_binary_addr(addr),
                        nl_addr_get_len(addr));

  sw->l2_addr_remove(port, rtnl_neigh_get_vlan(neigh), mac);
}