mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
Fixed cmake
Minor code cleanup
This commit is contained in:
parent
18cd80e35d
commit
6c611ea306
|
@ -28,10 +28,6 @@ endif(NOT DEFINED CMAKE_BUILD_TYPE)
|
|||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
#set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
#Ultrasparc64 users experiencing SIGBUS should try the following gcc options
|
||||
#(thanks to Robert Gibbon)
|
||||
#PLATOPTS_SPARC64=-mcpu=ultrasparc -pipe -fomit-frame-pointer -ffast-math -finline-functions -fweb -frename-registers -mapp-regs
|
||||
|
||||
# None
|
||||
set(CMAKE_C_FLAGS "-Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs")
|
||||
|
@ -51,6 +47,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
|||
|
||||
add_library(n2n n2n.c
|
||||
n2n_keyfile.c
|
||||
edge_utils.c
|
||||
wire.c
|
||||
minilzo.c
|
||||
twofish.c
|
||||
|
@ -73,9 +70,6 @@ if(N2N_OPTION_AES)
|
|||
target_link_libraries(n2n crypto)
|
||||
endif(N2N_OPTION_AES)
|
||||
|
||||
# For Solaris (or OpenSolaris?)
|
||||
#target_link_libraries(n2n socket nsl)
|
||||
|
||||
add_executable(edge edge.c)
|
||||
target_link_libraries(edge n2n)
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -64,7 +64,7 @@ APPS+=example_edge_embed
|
|||
|
||||
DOCS=edge.8.gz supernode.1.gz n2n_v2.7.gz
|
||||
|
||||
all: $(APPS) $(DOCS)
|
||||
all: $(APPS) $(DOCS) benchmark
|
||||
|
||||
edge: edge.c $(N2N_LIB) n2n_wire.h n2n.h Makefile
|
||||
$(CC) $(CFLAGS) edge.c $(N2N_LIB) $(LIBS_EDGE) -o edge
|
||||
|
|
139
benchmark.c
139
benchmark.c
|
@ -26,103 +26,106 @@
|
|||
#include <stdio.h>
|
||||
|
||||
uint8_t PKT_CONTENT[]={
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
|
||||
|
||||
/* Prototypes */
|
||||
static ssize_t do_encode_packet( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c );
|
||||
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
|
||||
n2n_trans_op_t transop_null;
|
||||
int main(int argc, char * argv[]) {
|
||||
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
|
||||
n2n_trans_op_t transop_null;
|
||||
|
||||
n2n_common_t cmn;
|
||||
n2n_PACKET_t pkt;
|
||||
n2n_community_t c;
|
||||
n2n_common_t cmn;
|
||||
n2n_PACKET_t pkt;
|
||||
n2n_community_t c;
|
||||
|
||||
struct timeval t1;
|
||||
struct timeval t2;
|
||||
struct timeval t1;
|
||||
struct timeval t2;
|
||||
|
||||
size_t i;
|
||||
size_t n;
|
||||
size_t idx;
|
||||
size_t rem;
|
||||
ssize_t nw;
|
||||
ssize_t tdiff;
|
||||
size_t i;
|
||||
size_t n;
|
||||
size_t idx;
|
||||
size_t rem;
|
||||
ssize_t nw;
|
||||
ssize_t tdiff;
|
||||
|
||||
transop_null_init( &transop_null );
|
||||
memset(c,0,sizeof(N2N_COMMUNITY_SIZE));
|
||||
transop_null_init( &transop_null );
|
||||
memset(c,0,sizeof(N2N_COMMUNITY_SIZE));
|
||||
|
||||
n=10000;
|
||||
memcpy( c, "abc123def456", 12 );
|
||||
n=10000;
|
||||
memcpy( c, "abc123def456", 12 );
|
||||
|
||||
gettimeofday( &t1, NULL );
|
||||
for(i=0; i<n; ++i)
|
||||
gettimeofday( &t1, NULL );
|
||||
for(i=0; i<n; ++i)
|
||||
{
|
||||
nw = do_encode_packet( pktbuf, N2N_PKT_BUF_SIZE, c);
|
||||
nw = do_encode_packet( pktbuf, N2N_PKT_BUF_SIZE, c);
|
||||
|
||||
nw += transop_null.fwd( &transop_null,
|
||||
pktbuf+nw, N2N_PKT_BUF_SIZE-nw,
|
||||
PKT_CONTENT, sizeof(PKT_CONTENT) );
|
||||
nw += transop_null.fwd( &transop_null,
|
||||
pktbuf+nw, N2N_PKT_BUF_SIZE-nw,
|
||||
PKT_CONTENT, sizeof(PKT_CONTENT) );
|
||||
|
||||
idx=0;
|
||||
rem=nw;
|
||||
idx=0;
|
||||
rem=nw;
|
||||
|
||||
decode_common( &cmn, pktbuf, &rem, &idx);
|
||||
decode_PACKET( &pkt, &cmn, pktbuf, &rem, &idx );
|
||||
decode_common( &cmn, pktbuf, &rem, &idx);
|
||||
decode_PACKET( &pkt, &cmn, pktbuf, &rem, &idx );
|
||||
|
||||
if ( 0 == (i%1000) )
|
||||
if ( 0 == (i%1000) )
|
||||
{
|
||||
fprintf(stderr,".");
|
||||
fprintf(stderr,".");
|
||||
}
|
||||
}
|
||||
gettimeofday( &t2, NULL );
|
||||
gettimeofday( &t2, NULL );
|
||||
|
||||
tdiff = ((t2.tv_sec - t1.tv_sec) * 1000000) + (t2.tv_usec - t1.tv_usec);
|
||||
tdiff = ((t2.tv_sec - t1.tv_sec) * 1000000) + (t2.tv_usec - t1.tv_usec);
|
||||
|
||||
fprintf( stderr, "\nrun %u times. (%u -> %u nsec each) %u.%06u -> %u.%06u.\n", i, tdiff, (tdiff *1000)/i, (uint32_t)t1.tv_sec, (uint32_t)t1.tv_usec, (uint32_t)t2.tv_sec, (uint32_t)t2.tv_usec );
|
||||
fprintf( stderr, "\nrun %u times. (%u -> %u nsec each) %u.%06u -> %u.%06u.\n",
|
||||
(unsigned int)i, (unsigned int)tdiff,
|
||||
(unsigned int)((tdiff *1000)/i),
|
||||
(uint32_t)t1.tv_sec, (uint32_t)t1.tv_usec,
|
||||
(uint32_t)t2.tv_sec, (uint32_t)t2.tv_usec );
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t do_encode_packet( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c )
|
||||
{
|
||||
n2n_mac_t destMac={0,1,2,3,4,5};
|
||||
n2n_common_t cmn;
|
||||
n2n_PACKET_t pkt;
|
||||
size_t idx;
|
||||
n2n_mac_t destMac={0,1,2,3,4,5};
|
||||
n2n_common_t cmn;
|
||||
n2n_PACKET_t pkt;
|
||||
size_t idx;
|
||||
|
||||
|
||||
memset( &cmn, 0, sizeof(cmn) );
|
||||
cmn.ttl = N2N_DEFAULT_TTL;
|
||||
cmn.pc = n2n_packet;
|
||||
cmn.flags=0; /* no options, not from supernode, no socket */
|
||||
memcpy( cmn.community, c, N2N_COMMUNITY_SIZE );
|
||||
memset( &cmn, 0, sizeof(cmn) );
|
||||
cmn.ttl = N2N_DEFAULT_TTL;
|
||||
cmn.pc = n2n_packet;
|
||||
cmn.flags=0; /* no options, not from supernode, no socket */
|
||||
memcpy( cmn.community, c, N2N_COMMUNITY_SIZE );
|
||||
|
||||
memset( &pkt, 0, sizeof(pkt) );
|
||||
memcpy( pkt.srcMac, destMac, N2N_MAC_SIZE);
|
||||
memcpy( pkt.dstMac, destMac, N2N_MAC_SIZE);
|
||||
memset( &pkt, 0, sizeof(pkt) );
|
||||
memcpy( pkt.srcMac, destMac, N2N_MAC_SIZE);
|
||||
memcpy( pkt.dstMac, destMac, N2N_MAC_SIZE);
|
||||
|
||||
pkt.sock.family=0; /* do not encode sock */
|
||||
pkt.sock.family=0; /* do not encode sock */
|
||||
|
||||
idx=0;
|
||||
encode_PACKET( pktbuf, &idx, &cmn, &pkt );
|
||||
traceEvent( TRACE_DEBUG, "encoded PACKET header of size=%u", (unsigned int)idx );
|
||||
idx=0;
|
||||
encode_PACKET( pktbuf, &idx, &cmn, &pkt );
|
||||
traceEvent( TRACE_DEBUG, "encoded PACKET header of size=%u", (unsigned int)idx );
|
||||
|
||||
return idx;
|
||||
return idx;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user