Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
click_for_comnet2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jiachen,Chen
click_for_comnet2
Commits
7f0d4b6a
Commit
7f0d4b6a
authored
Apr 30, 2019
by
Jiachen,Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TestCID
parent
ba7d3671
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
8 deletions
+121
-8
TestCID.cc
TestCID.cc
+59
-0
TestCID.click
TestCID.click
+5
-0
TestCID.hh
TestCID.hh
+33
-0
TestLittleEndian.cc
TestLittleEndian.cc
+17
-5
TestLittleEndian.hh
TestLittleEndian.hh
+7
-3
No files found.
TestCID.cc
0 → 100644
View file @
7f0d4b6a
/*
* 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
)
TestCID.click
0 → 100644
View file @
7f0d4b6a
require(package "click_for_comnet");
test :: TestCID;
DriverManager(stop);
TestCID.hh
0 → 100644
View file @
7f0d4b6a
/*
* 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 */
TestLittleEndian.cc
View file @
7f0d4b6a
...
...
@@ -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
TestLittleEndian.hh
View file @
7f0d4b6a
...
...
@@ -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 */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment