Commit 0a24c63c authored by Jiachen,Chen's avatar Jiachen,Chen

Modified TestVariableLengthPacket

parent aae164df
......@@ -14,7 +14,7 @@
CLICK_DECLS
#define ARGS_DEBUG
#ifdef ARGS_DEBUG
#define DEBUG(...) _DEBUG(__VA_ARGS__, "dummy")
#define _DEBUG(fmt, ...) printf("[%s.%s():%d] " fmt "%.0s\n", \
......@@ -73,13 +73,14 @@ int TestArgs::configure(Vector<String>& conf, ErrorHandler* errh) {
printf("DST_ETH=%s, ", dst_ether_addr.unparse().c_str());
printf("DST_ETH buf=");
print_buf(dst_ether_addr.data(), 6); // this is already big-endian
printf("interval=%s, double_val=%f\n", interval.unparse().c_str(), interval.doubleval());
if (tmp_elem_p != nullptr) {
printf("elem->name: %s\n", tmp_elem_p->class_name());
if ((elem_p = dynamic_cast<TestArgsElemParam *>(tmp_elem_p)) != nullptr) {
if ((elem_p = dynamic_cast<TestArgsElemParam *> (tmp_elem_p)) != nullptr) {
printf("It is a TestArgsElemenParam\n");
elem_p->test_function();
}
}
......@@ -88,7 +89,7 @@ int TestArgs::configure(Vector<String>& conf, ErrorHandler* errh) {
}
void TestArgs::push(int port __attribute((__unused__)), Packet* p) {
void TestArgs::push(int port __attribute ((__unused__)), Packet* p) {
DEBUG("Got pkt: %p, forward to elem_p!", p);
if (elem_p != NULL) {
elem_p->push(0, p);
......
require(package "click_for_comnet");
elem::TestArgsElemParam;
elem2::TestCID;
// try to feed ELEM with elem2
test :: TestArgs(1, "string!", 192.168.1.1, SRC_ETH 01:02:03:04:05:06, DST_ETH 16:15:14:13:12:11, ELEM elem, INTERVAL 100ms);
TimedSource(INTERVAL 1, DATA "test", LIMIT 1, STOP true)
......
......@@ -37,6 +37,14 @@ static uint16_t get_cid(uint16_t host, uint16_t content) {
return (host << 12) | content;
}
//static bool is_content(uint16_t id) {
// return id & 0x8000 == 0x8000;
//}
//
//static uint16_t get_id(uint16_t id) {
// return id & 0x7FFF;
//}
int TestCID::initialize(ErrorHandler* errh __attribute ((__unused__))) {
uint16_t cid = 0xabcd;
......
/*
* File: TestVariableLengthPacket.cc
* Author: Jiachen Chen
*
* Created on April 30, 2019, 5:50 PM
*/
#include "TestVariableLengthPacket.hh"
#include <clicknet/ether.h>
#include <click/ipaddress.hh>
#include <click/packet.hh>
CLICK_DECLS
struct routing_packet {
uint8_t type;
uint16_t src;
uint8_t hop;
uint8_t length;
uint16_t addresses[];
} CLICK_SIZE_PACKED_ATTRIBUTE;
static void print_buf(void *content, size_t size) {
size_t i;
uint8_t *ptr = (uint8_t *) content;
for (i = 0; i < size; i++) {
printf("%02" PRIx8 " ", ptr[i]);
}
printf("\n");
}
TestVariableLengthPacket::TestVariableLengthPacket() : _init(0xbeef), _size(1) {
}
TestVariableLengthPacket::~TestVariableLengthPacket() = default;
int TestVariableLengthPacket::initialize(ErrorHandler* errh __attribute ((__unused__))) {
struct routing_packet* data;
size_t length = 3;
printf("sizeof (struct routing_packet)=%zd\n", sizeof (struct routing_packet)); // addresses has size 0
size_t size = sizeof (struct routing_packet) +length * sizeof (uint16_t);
data = reinterpret_cast<struct routing_packet *> (malloc(size));
data->length = length;
data->addresses[0] = htobe16(0xdead);
data->addresses[1] = htobe16(0xbeef);
data->addresses[2] = htobe16(0x2345);
// may sure that you don't exceed the boundary. otherwise you will overwrite other data
print_buf(data, size);
free(data);
// make a packet and push
WritablePacket *pkt = Packet::make(size);
data = reinterpret_cast<struct routing_packet *> (pkt->data());
data->length = length;
data->addresses[0] = htobe16(0xdead);
data->addresses[1] = htobe16(0xbeef);
data->addresses[2] = htobe16(0x2345);
checked_output_push(0, pkt);
return 0;
}
void TestVariableLengthPacket::push(int port __attribute ((__unused__)), Packet* p) {
struct routing_packet* data;
size_t length = _size++, i;
size_t size = sizeof (struct routing_packet) +length * sizeof (uint16_t);
WritablePacket *pkt = p->push(size);
data = reinterpret_cast<struct routing_packet *> (pkt->data());
data->length = length;
for (i = 0; i < length; i++) {
data->addresses[i] = htobe16(_init++);
}
checked_output_push(0, pkt);
}
CLICK_ENDDECLS
EXPORT_ELEMENT(TestVariableLengthPacket)
\ No newline at end of file
require(package "click_for_comnet");
TimedSource(INTERVAL 1, DATA \< EE >, LIMIT 10, STOP true)
-> Print("Before test", MAXLENGTH 64)
-> test :: TestVariableLengthPacket
-> Print("After test", MAXLENGTH 64)
-> Discard;
/*
* File: TestVariableLengthPacket.hh
* Author: Jiachen Chen
*
* Created on April 30, 2019, 5:49 PM
*/
#ifndef TESTVARIABLELENGTHPACKET_HH
#define TESTVARIABLELENGTHPACKET_HH
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
CLICK_DECLS
class TestVariableLengthPacket : public Element {
public:
TestVariableLengthPacket();
~TestVariableLengthPacket();
const char* class_name() const { return "TestVariableLengthPacket"; }
const char* processing() const { return PUSH; }
const char* port_count() const { return "1/1"; }
int initialize(ErrorHandler* errh) CLICK_COLD;
void push(int port, Packet* p);
private:
uint16_t _init;
size_t _size;
};
CLICK_ENDDECLS
#endif /* TESTVARIABLELENGTHPACKET_HH */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment