Skip to content

Commit

Permalink
refs #27: Add stub for IPsec unit test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Feb 28, 2016
1 parent 4f9e131 commit 35b97f1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
8 changes: 0 additions & 8 deletions elements/ipsec/IPsecAES_kernel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@

#include <cuda.h>
#include <stdint.h>

#include "util_sa_entry.hh"

namespace nba {
enum {
CUDA_THREADS_PER_AES_BLK = 256,
MAX_ALIGNMENT_SIZE = 64,
IP_ALIGNMENT_SIZE = 2 // Adjust start offset of ip header by shifting 2byte
};

extern void *ipsec_aes_encryption_get_cuda_kernel();

//#define PER_PKT_INFO

}
#endif /* __NBA_ELEMENT_IPSEC_IPSECAES_KERNEL_HH__ */
6 changes: 0 additions & 6 deletions elements/ipsec/IPsecAuthHMACSHA1_kernel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
//----- not used in NBA currently. copied from the old NBA.
namespace nba {

enum {
CUDA_THREADS_PER_HSHA1_BLK = 32,
IP_ALIGNMENT_SIZE = 2 // Adjust start offset of ip header by shifting 2byte
};
//-----

extern void *ipsec_hsha1_encryption_get_cuda_kernel();

}
Expand Down
10 changes: 7 additions & 3 deletions elements/ipsec/IPsecESPencap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ int IPsecESPencap::process(int input_port, Packet *pkt)
if (likely(sa_item != sa_table.end())) {
sa_entry = sa_item->second;
anno_set(&pkt->anno, NBA_ANNO_IPSEC_FLOW_ID, sa_entry->entry_idx);
assert(sa_entry->entry_idx < 1024u);
} else {
pkt->kill();
return 0;
// FIXME: this is to encrypt all traffic regardless sa_entry lookup results.
// (just for worst-case performance tests)
unsigned f = (tunnel_counter ++) % num_tunnels;
sa_entry = sa_table_linear[f];
anno_set(&pkt->anno, NBA_ANNO_IPSEC_FLOW_ID, f);
//unsigned f = (tunnel_counter ++) % num_tunnels;
//sa_entry = sa_table_linear[f];
//anno_set(&pkt->anno, NBA_ANNO_IPSEC_FLOW_ID, f);
//assert(f < 1024u);
}

int ip_len = ntohs(iph->tot_len);
Expand Down
38 changes: 38 additions & 0 deletions tests/test_ipsec.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#ifdef USE_CUDA
#include <cuda_runtime.h>
#endif
#include <nba/framework/datablock.hh>
#include <nba/framework/datablock_shared.hh>
#include <nba/element/annotation.hh>
#include <nba/element/packet.hh>
#include <nba/element/packetbatch.hh>
#include <nba/framework/test_utils.hh>
#include <gtest/gtest.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rte_mbuf.h>
#include "../elements/ipsec/util_esp.hh"
#include "../elements/ipsec/util_ipsec_key.hh"
#include "../elements/ipsec/util_sa_entry.hh"
#include "../elements/ipsec/IPsecAES_kernel.hh"
#include "../elements/ipsec/IPsecAuthHMACSHA1_kernel.hh"
#include "../elements/ipsec/IPsecDatablocks.hh"
#if 0
#require <lib/datablock.o>
#require <lib/test_utils.o>
#require "../elements/ipsec/IPsecAES_kernel.o"
#require "../elements/ipsec/IPsecAuthHMACSHA1_kernel.o"
#require "../elements/ipsec/IPsecDatablocks.o"
#endif

using namespace std;
using namespace nba;

TEST(IPsecTest, Loading) {
EXPECT_TRUE(1);
}

// vim: ts=8 sts=4 sw=4 et
9 changes: 4 additions & 5 deletions tests/test_ipv4route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,10 @@ TEST_P(IPLookupCUDAMatchTest, SingleBatchWithDatablock) {

// We skip postprocessing since it has no actual elements here.
batch->tracker.has_results = true;

EXPECT_NE(0, output_buffer[0]);
EXPECT_NE(0, output_buffer[1]);
EXPECT_EQ(cpu_results[0], output_buffer[0]);
EXPECT_EQ(cpu_results[1], output_buffer[1]);
for (unsigned o = 0; o < out_count; o++) {
EXPECT_NE(0, output_buffer[o]);
EXPECT_EQ(cpu_results[o], output_buffer[o]);
}

free(datablocks[0]);
free(datablocks[1]);
Expand Down

0 comments on commit 35b97f1

Please sign in to comment.