Commit 7f0d4b6a authored by Jiachen,Chen's avatar Jiachen,Chen

Added TestCID

parent ba7d3671
/*
* File: TestCID.cc
* Author: Jiachen CHen
*
* Created on April 30, 2019, 1:48 AM
*/
#include "TestCID.hh"
#include <assert.h>
#include <inttypes.h>
CLICK_DECLS
TestCID::TestCID() = default;
TestCID::~TestCID() = 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");
}
static uint16_t get_cid_host(uint16_t cid) {
return (cid >> 12) & 0xF;
}
static uint16_t get_cid_content(uint16_t cid) {
return cid & 0xFFF;
}
static uint16_t get_cid(uint16_t host, uint16_t content) {
assert(host <= 0xF && content <= 0xFFF);
return (host << 12) | content;
}
int TestCID::initialize(ErrorHandler* errh __attribute ((__unused__))) {
uint16_t cid = 0xabcd;
printf("cid=0x%" PRIx16 ", host=0x%" PRIx16 ", content=0x%" PRIx16 "\n",
cid, get_cid_host(cid), get_cid_content(cid));
printf("buf=");
print_buf(&cid, sizeof (cid));
uint16_t cid2 = get_cid(0xb, 0xeef);
printf("cid2=0x%" PRIx16 ", host=0x%" PRIx16 ", content=0x%" PRIx16 "\n",
cid2, get_cid_host(cid2), get_cid_content(cid2));
printf("buf=");
print_buf(&cid2, sizeof (cid2));
return 0;
}
CLICK_ENDDECLS
EXPORT_ELEMENT(TestCID)
require(package "click_for_comnet");
test :: TestCID;
DriverManager(stop);
/*
* File: TestCID.hh
* Author: Jiachen Chen
*
* Created on April 30, 2019, 1:48 AM
*/
#ifndef TESTCID_HH
#define TESTCID_HH
#include <click/config.h>
#include <click/element.hh>
#include <click/error.hh>
CLICK_DECLS
class TestCID : public Element {
public:
TestCID();
~TestCID();
const char *class_name() const { return "TestCID"; }
int initialize(ErrorHandler *errh);
private:
};
CLICK_ENDDECLS
#endif /* TESTCID_HH */
......@@ -8,6 +8,7 @@
#include "TestLittleEndian.hh"
#include <endian.h>
#include <inttypes.h>
CLICK_DECLS
TestLittleEndian::TestLittleEndian() = default;
......@@ -17,21 +18,32 @@ 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("%02" PRIx8 " ", ptr[i]);
}
printf("\n");
}
int TestLittleEndian::initialize(ErrorHandler* errh __attribute ((__unused__))) {
uint32_t i;
uint32_t i, net, host;
i = 0x12345678;
i = 0xdeadbeef;
printf("i=0x%" PRIx32 "\n", i);
printf("in memory: ");
print_buf(&i, sizeof(i));
i = htobe32(0x12345678);
print_buf(&i, sizeof(i));
net = htobe32(i);
printf("net=0x%" PRIx32 "\n", net);
printf("in memory: ");
print_buf(&net, sizeof(net));
host = be32toh(net);
printf("host=0x%" PRIx32 "\n", host);
printf("in memory: ");
print_buf(&host, sizeof(host));
return 0;
}
CLICK_ENDDECLS
EXPORT_ELEMENT(TestLittleEndian)
\ No newline at end of file
......@@ -4,13 +4,15 @@
*
* Created on April 30, 2019, 12:20 AM
*/
#ifndef TESTLITTLEENDIAN_HH
#define TESTLITTLEENDIAN_HH
#include <click/config.h>
#include <click/element.hh>
#include <click/error.hh>
#ifndef TESTLITTLEENDIAN_HH
#define TESTLITTLEENDIAN_HH
CLICK_DECLS
class TestLittleEndian : public Element {
public:
......@@ -24,5 +26,7 @@ private:
};
CLICK_ENDDECLS
#endif /* TESTLITTLEENDIAN_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