Exemplo n.º 1
0
static odp_packet_t make_odp_packet(uint16_t pkt_len)
{
	odp_packet_t odp_pkt;
	uint8_t      rand8a, rand8b, pkt_color, drop_eligible;

	rand8a        = random_8();
	rand8b        = random_8();
	pkt_color     = (rand8a < 224) ? 0 : ((rand8a < 248) ? 1 : 2);
	drop_eligible = (rand8b < 240) ? 1 : 0;
	odp_pkt       = odp_packet_alloc(odp_pool, pkt_len);
	if (odp_pkt == ODP_PACKET_INVALID) {
		printf("%s odp_packet_alloc failure *******\n", __func__);
		return 0;
	}

	odp_packet_color_set(odp_pkt, pkt_color);
	odp_packet_drop_eligible_set(odp_pkt, drop_eligible);
	odp_packet_shaper_len_adjust_set(odp_pkt, 24);
	return odp_pkt;
}
Exemplo n.º 2
0
static uint32_t pkt_service_class(void)
{
	uint32_t rand8;

       /* Make most of the traffic use service class 3 to increase the amount
	* of delayed traffic so as to stimulate more interesting behaviors.
	*/
	rand8 = random_8();
	switch (rand8) {
	case 0   ... 24:  return 0;
	case 25  ... 49:  return 1;
	case 50  ... 150: return 2;
	case 151 ... 255: return 3;
	default:          return 3;
	}
}
Exemplo n.º 3
0
int createSession(uint32_t *buf, uip_ipaddr_t *addr) {
    uint32_t i;

    Session_t *session = (Session_t *) (buf + 8);
    Session_t *s = (Session_t *) RES_SESSION_LIST; // Pointer auf Flashspeicher
    int index = getIndexOf(addr);

    // Ein neuer private Key für ECDH wird in jedem Fall generiert
    nvm_getVar(buf, RES_ECC_ORDER, LEN_ECC_ORDER);
    #if DEBUG
        printf("ECC_ORDER: ");
        for (i = 0; i < 8; i++) printf("%08X", uip_htonl(buf[i]));
        printf("\n");
    #endif
    do {
        random_x((uint8_t *) session->private_key, 32);
    } while (!ecc_is_valid_key(session->private_key, buf));

    // Falls schon ein Eintrag existiert wird die Session durch
    // setzten des neuen private Keys weiterentwickelt. Ansonsten
    // wird alles gesetzt.
    if (index >= 0) {
        nvm_setVar(session->private_key, (fpoint_t) s[index].private_key, 32);
        PRINTF("Session aktualisiert:\n");
        PRINTSESSION(index);
    } else {
        index = getIndexOf(NULL);;
        if (index < 0)
            return -1;

        uip_ipaddr_copy(&session->addr, addr);
        for (i = 0; i < 8; i++) {
            nvm_getVar(session->session + i, RES_ANSCHARS + (random_8() & 0x3F), 1);
        } // TODO session-id auf doppel prüfen
        session->epoch = 0;
        session->valid = 1;

        nvm_setVar(session, (fpoint_t) &s[index], sizeof(Session_t));
        PRINTF("Session erstellt:\n");
        PRINTSESSION(index);
        seq_num_r[index] = 1;
        seq_num_w[index] = 1;
    }

    return 0;
}
Exemplo n.º 4
0
void random_x(uint8_t *c, size_t len) {
    uint32_t i;
    for (i = 0; i < len; i++) c[i] = random_8();
}
Exemplo n.º 5
0
    virtual void handle_mov(UByte opcode, size_t word_size) {
        //
        // Modify immediate only
        //

        switch (opcode) {
        // [SKIP] Registers
        case 0x88:
        case 0x89:
        case 0x8A:
        case 0x8B:
        case 0x8C:
        case 0x8E:
        {
            UByte   next;

            _scanner.get(&next);
            skip_modrm(next, word_size);
            break;
        }
        // Immediate 8
        case 0xC6:
        {
            UByte   next;
            UByte   fault;

            _scanner.get(&next);
            skip_modrm(next, word_size);
            fault = random_8();
            _scanner.put(fault);

            System.Print("FI: MOV(%2X): Change IMM to %.2X\n",
                         opcode, fault);
            break;
        }
        // Immediate 16/32
        case 0xC7:
        {
            UByte   next;
            UInt    fault;

            _scanner.get(&next);
            skip_modrm(next, word_size);
            fault = random_word(word_size);
            _scanner.write(reinterpret_cast<const char*>(&fault),
                           word_size);

            System.Print("FI: MOV(%.2X): Change IMM to %.8lX\n",
                         opcode, fault);
            break;
        }
        // [SKIP] 'A' registers
        case 0xA0:
        case 0xA1:
        case 0xA2:
        case 0xA3:
        {
            skip_word(word_size);
            break;
        }
        // Immediate
        default:
        {
            if (0xB0 <= opcode && opcode <= 0xB7) {
                UByte fault = random_8();
                _scanner.put(fault);

                System.Print("FI: MOV(%2X): Change IMM to %.2X\n",
                             opcode, fault);
            }
            else if (0xB8 <= opcode && opcode <= 0xBF) {
                UInt fault = random_word(word_size);
                _scanner.write(reinterpret_cast<const char*>(&fault),
                               word_size);

                System.Print("FI: MOV(%2X): Change IMM to %.8lX\n",
                             opcode, fault);
            }
            else {
                System.Print(System.WARN, "Unknown opcode\n");
            }
        }
        }
    }
Exemplo n.º 6
0
static int traffic_generator(uint32_t pkts_to_send)
{
	odp_pool_param_t pool_params;
	odp_tm_queue_t   tm_queue;
	odp_packet_t     pkt;
	odp_bool_t       tm_is_idle;
	uint32_t         svc_class, queue_num, pkt_len, pkts_into_tm;
	uint32_t         pkts_from_tm, pkt_cnt, millisecs, odp_tm_enq_errs;
	int              rc;

	memset(&pool_params, 0, sizeof(odp_pool_param_t));
	pool_params.type           = ODP_POOL_PACKET;
	pool_params.pkt.num        = pkts_to_send + 10;
	pool_params.pkt.len        = 1600;
	pool_params.pkt.seg_len    = 0;
	pool_params.pkt.uarea_size = 0;

	odp_pool        = odp_pool_create("MyPktPool", &pool_params);
	odp_tm_enq_errs = 0;

	pkt_cnt = 0;
	while (pkt_cnt < pkts_to_send) {
		svc_class = pkt_service_class();
		queue_num = random_16() & (TM_QUEUES_PER_CLASS - 1);
		tm_queue  = queue_num_tbls[svc_class][queue_num + 1];
		pkt_len   = ((uint32_t)((random_8() & 0x7F) + 2)) * 32;
		pkt_len   = MIN(pkt_len, 1500);
		pkt       = make_odp_packet(pkt_len);

		pkt_cnt++;
		rc = odp_tm_enq(tm_queue, pkt);
		if (rc < 0) {
			odp_tm_enq_errs++;
			continue;
		}

		odp_atomic_inc_u32(&atomic_pkts_into_tm);
	}

	printf("%s odp_tm_enq_errs=%u\n", __func__, odp_tm_enq_errs);

       /* Wait until the main traffic mgmt worker thread is idle and has no
	* outstanding events (i.e. no timers, empty work queue, etc), but
	* not longer than 60 seconds.
	*/
	for (millisecs = 0; millisecs < 600000; millisecs++) {
		usleep(100);
		tm_is_idle = odp_tm_is_idle(odp_tm_test);
		if (tm_is_idle)
			break;
	}

	if (!tm_is_idle)
		printf("%s WARNING stopped waiting for the TM system "
		       "to be IDLE!\n", __func__);

	/* Wait for up to 2 seconds for pkts_from_tm to match pkts_into_tm. */
	for (millisecs = 0; millisecs < 2000; millisecs++) {
		usleep(1000);
		pkts_into_tm = odp_atomic_load_u32(&atomic_pkts_into_tm);
		pkts_from_tm = odp_atomic_load_u32(&atomic_pkts_from_tm);
		if (pkts_into_tm <= pkts_from_tm)
			break;
	}

	return 0;
}