Commit a28ad72f authored by Jiachen,Chen's avatar Jiachen,Chen

Added TestArgs

parent 64ccf67b
/*
* File: TestArgs.cc
* Author: Jiachen Chen
*
* Created on April 30, 2019, 3:10 AM
*/
#include "TestArgs.hh"
#include <click/string.hh>
#include <click/etheraddress.hh>
#include <click/ipaddress.hh>
#include <click/args.hh>
CLICK_DECLS
#define ARGS_DEBUG
#ifdef ARGS_DEBUG
#define DEBUG(...) _DEBUG(__VA_ARGS__, "dummy")
#define _DEBUG(fmt, ...) printf("[%s.%s():%d] " fmt "%.0s\n", \
class_name(), __func__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif
TestArgs::TestArgs() : elem_p(nullptr) {
}
TestArgs::~TestArgs() = default;
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");
}
int TestArgs::configure(Vector<String>& conf, ErrorHandler* errh) {
uint32_t int_val;
String str_val;
IPAddress ip_addr;
EtherAddress src_ether_addr, dst_ether_addr;
Element *tmp_elem_p;
if (Args(conf, this, errh)
.read_mp("INT_VAL", int_val)
.read_mp("STR_VAL", str_val)
.read_mp("IP_ADDR", ip_addr)
.read_p("SRC_ETH", src_ether_addr)
.read_p("DST_ETH", dst_ether_addr)
.read_p("ELEM", ElementArg(), tmp_elem_p)
.complete() < 0) {
return -1;
}
printf("intval=%" PRIu32 "\n", int_val);
printf("strval=%s\n", str_val.c_str());
printf("IP_addr=%s, ", ip_addr.unparse().c_str());
printf("IP buf=");
print_buf(ip_addr.data(), 4); // this is already big-endian
printf("SRC_ETH=%s, ", src_ether_addr.unparse().c_str());
printf("SRC_ETH buf=");
print_buf(src_ether_addr.data(), 6); // this is already big-endian
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
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) {
elem_p->test_function();
}
}
return 0;
}
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);
}
}
CLICK_ENDDECLS
EXPORT_ELEMENT(TestArgs)
\ No newline at end of file
require(package "click_for_comnet");
elem::TestArgsElemParam;
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);
TimedSource(INTERVAL 1, DATA "test", LIMIT 1, STOP true)
-> test;
elem
-> Print("From Elem")
-> Discard;
/*
* File: TestArgs.hh
* Author: Jiachen Chen
*
* Created on April 30, 2019, 3:10 AM
*/
#ifndef TESTARGS_HH
#define TESTARGS_HH
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
#include "TestArgsElemParam.hh"
CLICK_DECLS
class TestArgs : public Element {
public:
TestArgs() CLICK_COLD;
~TestArgs() CLICK_COLD;
const char* class_name() const { return "TestArgs"; }
const char* processing() const { return PUSH; }
const char* port_count() const { return "1/0"; }
int configure(Vector<String>& conf, ErrorHandler* errh) CLICK_COLD;
void push(int port, Packet* p);
private:
TestArgsElemParam *elem_p;
};
CLICK_ENDDECLS
#endif /* TESTARGS_HH */
/*
* File: TestArgsElemParam.cc
* Author: Jiachen Chen
*
* Created on April 30, 2019, 3:45 AM
*/
#include "TestArgsElemParam.hh"
CLICK_DECLS
#define ELEM_DEBUG
#ifdef ELEM_DEBUG
#define DEBUG(...) _DEBUG(__VA_ARGS__, "dummy")
#define _DEBUG(fmt, ...) printf("[%s.%s():%d] " fmt "%.0s\n", \
class_name(), __func__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif
TestArgsElemParam::TestArgsElemParam() = default;
TestArgsElemParam::~TestArgsElemParam() = default;
void TestArgsElemParam::push(int port, Packet* p) {
DEBUG("Got packet from %d, %p", port, p);
checked_output_push(0, p);
}
void TestArgsElemParam::test_function() {
DEBUG("This is a test function!!");
}
CLICK_ENDDECLS
EXPORT_ELEMENT(TestArgsElemParam)
\ No newline at end of file
/*
* File: TestArgsElemParam.hh
* Author: Jiachen Chen
*
* Created on April 30, 2019, 3:45 AM
*/
#ifndef TESTARGSELEMPARAM_HH
#define TESTARGSELEMPARAM_HH
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
CLICK_DECLS
class TestArgsElemParam : public Element {
public:
TestArgsElemParam();
~TestArgsElemParam();
const char* class_name() const { return "TestArgsElemParam"; }
const char* processing() const { return PUSH; }
const char* port_count() const { return "-1/1"; }
void push(int port, Packet* p);
void test_function();
private:
};
CLICK_ENDDECLS
#endif /* TESTARGSELEMPARAM_HH */
......@@ -10,6 +10,7 @@
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
#include <click/error.hh>
CLICK_DECLS
......
/*
* File: TestDataStructure.cc
* Author: Jiachen
* Author: Jiachen Chen
*
* Created on April 30, 2019, 2:55 AM
*/
......
/*
* File: TestDataStructure.hh
* Author: ubuntu
* Author: Jiachen Chen
*
* Created on April 30, 2019, 2:55 AM
*/
......@@ -9,6 +9,7 @@
#define TESTDATASTRUCTURE_HH
#include <click/config.h>
#include <click/glue.hh>
CLICK_DECLS
......
......@@ -13,8 +13,8 @@ CLICK_DECLS
#ifdef TEST_DEBUG
#define DEBUG(...) _DEBUG(__VA_ARGS__, "dummy")
#define _DEBUG(fmt, ...) printf("[%s():%d] " fmt "%.0s\n", \
__func__, __LINE__, __VA_ARGS__)
#define _DEBUG(fmt, ...) printf("[%s.%s():%d] " fmt "%.0s\n", \
class_name(), __func__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif
......
......@@ -10,6 +10,7 @@
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
#include <click/error.hh>
CLICK_DECLS
......
......@@ -10,6 +10,7 @@
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
#include <click/error.hh>
CLICK_DECLS
......
/*
* File: TestUseDataStructure.hh
* Author: ubuntu
* Author: Jiachen Chen
*
* Created on April 30, 2019, 2:57 AM
*/
......@@ -10,6 +10,7 @@
#include <click/config.h>
#include <click/element.hh>
#include <click/glue.hh>
#include "TestDataStructure.hh"
CLICK_DECLS
......
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