Beispiel #1
0
void nhdp_writer_add_addr(struct rfc5444_writer *wr, nhdp_addr_t *addr,
                          enum rfc5444_addrtlv_iana type, uint8_t value,
                          uint16_t metric_in, uint16_t metric_out)
{
    struct rfc5444_writer_address *wr_addr;
    struct netaddr n_addr;

    netaddr_from_nhdp_address(&n_addr, addr);

    switch (type) {
        case RFC5444_ADDRTLV_LOCAL_IF:
            /* Address is mandatory for every sub-msg (if message is splitted) */
            wr_addr = rfc5444_writer_add_address(wr, _nhdp_message_content_provider.creator,
                                                 &n_addr, true);
            break;

        case RFC5444_ADDRTLV_LINK_STATUS:
            /* Fall through */

        case RFC5444_ADDRTLV_OTHER_NEIGHB:
            /* Address only has to be included in one sub-msg (if message is splitted) */
            wr_addr = rfc5444_writer_add_address(wr, _nhdp_message_content_provider.creator,
                                                 &n_addr, false);
            break;

        default:
            /* Unknown type, extend switch if other types are allowed */
            return;
    }

    rfc5444_writer_add_addrtlv(wr, wr_addr, &_nhdp_addrtlvs[type],
                               &value, sizeof(uint8_t), false);

    /* Add LINK_METRIC TLV if necessary */
    if ((NHDP_METRIC == NHDP_LMT_DAT) && (metric_in != NHDP_METRIC_UNKNOWN)) {
        switch(type) {
            case RFC5444_ADDRTLV_LINK_STATUS:
                metric_in |= NHDP_KD_LM_INC;
                metric_in |= (metric_in == metric_out) ? NHDP_KD_LM_OUT : 0x00;
                break;
            case RFC5444_ADDRTLV_OTHER_NEIGHB:
                metric_in |= NHDP_KD_NM_INC;
                metric_in |= (metric_in == metric_out) ? NHDP_KD_NM_OUT : 0x00;
                break;
            default:
                /* Other types are not used and therefore no address tlv is added */
                return;
        }
        rfc5444_writer_add_addrtlv(wr, wr_addr, &_nhdp_addrtlvs[RFC5444_ADDRTLV_LINK_METRIC],
                                   &metric_in, sizeof(metric_in), true);
    }
}
Beispiel #2
0
static void addAddresses(struct rfc5444_writer *wr,
    struct rfc5444_writer_content_provider *provider) {
  uint8_t ip[4] = { 10,1, 0, 101 };
  struct rfc5444_writer_address *addr;
  char value0 =  0, value1 = 1;

  ip[0] = 10; ip[1] = 1; ip[2] = 0; ip[3] = 101;
  addr = rfc5444_writer_add_address(wr, provider->creator, ip, 32, false);
  rfc5444_writer_add_addrtlv(wr, addr, addrtlvs[1]._tlvtype, &value1, 1, false);

  ip[0] = 10; ip[1] = 1; ip[2] = 0; ip[3] = 102;
  addr = rfc5444_writer_add_address(wr, provider->creator, ip, 32, false);
  rfc5444_writer_add_addrtlv(wr, addr, addrtlvs[0]._tlvtype, &value0, 1, false);

  ip[0] = 10; ip[1] = 1; ip[2] = 0; ip[3] = 103;
  addr = rfc5444_writer_add_address(wr, provider->creator, ip, 32, false);
  rfc5444_writer_add_addrtlv(wr, addr, addrtlvs[1]._tlvtype, &value1, 1, false);

  ip[0] = 10; ip[1] = 11; ip[2] = 11; ip[3] = 11;
  addr = rfc5444_writer_add_address(wr, provider->creator, ip, 32, false);
  rfc5444_writer_add_addrtlv(wr, addr, addrtlvs[1]._tlvtype, &value1, 1, false);
}
Beispiel #3
0
static void addAddresses(struct rfc5444_writer *wr) {
  struct netaddr ip;
  struct rfc5444_writer_address *addr;
  char value0 =  0, value1 = 1;
  uint16_t metric;

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.11.1"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_LOCAL_IF], &value1, 1, false);

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.11.2"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_LOCAL_IF], &value1, 1, false);

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.11.3"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_LOCAL_IF], &value0, 1, false);

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.10.1"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_OTHERNEIGH], &value1, 1, false);
  metric = htons(0x2024);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC1], &metric, sizeof(metric), true);
  metric = htons(0x1013);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC2], &metric, sizeof(metric), true);

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.12.1"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_OTHERNEIGH], &value1, 1, false);
  metric = htons(0x202f);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC1], &metric, sizeof(metric), true);
  metric = htons(0x1013);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC2], &metric, sizeof(metric), true);

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.12.2"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_OTHERNEIGH], &value1, 1, false);
  metric = htons(0x202f);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC1], &metric, sizeof(metric), true);
  metric = htons(0x1013);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC2], &metric, sizeof(metric), true);

  CHECK_TRUE(0 == netaddr_from_string(&ip, "10.5.12.3"), "failed to initialize ip");
  addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_OTHERNEIGH], &value1, 1, false);
  metric = htons(0x202f);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC1], &metric, sizeof(metric), true);
  metric = htons(0x1013);
  rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs[IDX_METRIC2], &metric, sizeof(metric), true);
}
Beispiel #4
0
static void addAddresses(struct rfc5444_writer *wr) {
    struct netaddr ip; // = { { 10,1,0,101}, AF_INET, 32 };
    struct rfc5444_writer_address *addr;
    int value1 = 1;
    int i,j;

    CHECK_TRUE(0 == netaddr_from_string(&ip, "10.0.0.0"), "failed to initialize ip");

    for (i=0; i<100; i++) {
        for (j=0; j<100; j++) {
            ip._addr[2] = i;
            ip._addr[3] = j;
            //ip._addr[0] = 10; ip._addr[1] = 1; ip._addr[2] = 0; ip._addr[3] = 101;
            addr = rfc5444_writer_add_address(wr, cpr.creator, &ip, false);
            CHECK_TRUE(rfc5444_writer_add_addrtlv(wr, addr, &addrtlvs, &value1, sizeof(value1), false) == 0,
                       "Out of memory for address tlv");
            value1++;
        }
    }
}