Skip to content

Commit

Permalink
Create pull_request.yml (#12)
Browse files Browse the repository at this point in the history
* Create pull_request.yml
* Apply clang-format
  • Loading branch information
krsna1729 committed Nov 14, 2019
1 parent 345d06d commit 8f746cf
Show file tree
Hide file tree
Showing 13 changed files with 1,040 additions and 1,069 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Pull Request

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: geertvdc/setup-hub@master
- name: Dependencies
run: |
sudo apt-get -y install jq clang-format-8
sudo cp $(which clang-format-8) /bin/clang-format
- name: Checkout PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
hub pr checkout $(jq -r ".number" "$GITHUB_EVENT_PATH")
- name: Clang Format
run: |
SRC=$(git ls-tree --full-tree -r HEAD | grep -e "\.\(c\|h\|cc\|hh\|hpp\|cpp\)\$" | cut -f 2)
wget https://raw.githubusercontent.com/NetSys/bess/master/core/.clang-format
clang-format -style=file -i $SRC
rm .clang-format
- name: Commit and push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git remote set-url origin https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git
git config --global user.email "actions@github"
git config --global user.name "Github Actions"
hub commit -a -m "Apply clang-format" && hub push || echo "Nothing to commit"
133 changes: 61 additions & 72 deletions core/modules/gtpu_decap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,93 +18,82 @@
#include "utils/gtp.h"
#include <rte_jhash.h>
/*----------------------------------------------------------------------------------*/
using bess::utils::Ipv4;
using bess::utils::Udp;
using bess::utils::Gtpv1;
using bess::utils::be32_t;
using bess::utils::Gtpv1;
using bess::utils::Ipv4;
using bess::utils::ToIpv4Address;
using bess::utils::Udp;

enum {DEFAULT_GATE = 0, FORWARD_GATE};
enum { DEFAULT_GATE = 0, FORWARD_GATE };
/*----------------------------------------------------------------------------------*/
void
GtpuDecap::ProcessBatch(Context *ctx, bess::PacketBatch *batch)
{
int cnt = batch->cnt();
int hits = 0;
uint64_t key[bess::PacketBatch::kMaxBurst];
void *key_ptr[bess::PacketBatch::kMaxBurst];
struct session_info *data[bess::PacketBatch::kMaxBurst];
uint64_t hit_mask = 0ULL;
void GtpuDecap::ProcessBatch(Context *ctx, bess::PacketBatch *batch) {
int cnt = batch->cnt();
int hits = 0;
uint64_t key[bess::PacketBatch::kMaxBurst];
void *key_ptr[bess::PacketBatch::kMaxBurst];
struct session_info *data[bess::PacketBatch::kMaxBurst];
uint64_t hit_mask = 0ULL;

for (int i = 0; i < cnt; i++) {
bess::Packet *p = batch->pkts()[i];
/* assuming that this module comes right after EthernetTrim */
/* pkt_len can be used as the length of IP datagram */
/* Trim iph->ihl<<2 + sizeof(Udp) + size of Gtpv1 header */
Ipv4 *iph = p->head_data<Ipv4 *>();
Gtpv1 *gtph = (Gtpv1 *)((uint8_t *)iph + (iph->header_length<<2) + sizeof(Udp));
batch->pkts()[i]->adj((iph->header_length<<2) +
sizeof(Udp) +
gtph->header_length());
for (int i = 0; i < cnt; i++) {
bess::Packet *p = batch->pkts()[i];
/* assuming that this module comes right after EthernetTrim */
/* pkt_len can be used as the length of IP datagram */
/* Trim iph->ihl<<2 + sizeof(Udp) + size of Gtpv1 header */
Ipv4 *iph = p->head_data<Ipv4 *>();
Gtpv1 *gtph =
(Gtpv1 *)((uint8_t *)iph + (iph->header_length << 2) + sizeof(Udp));
batch->pkts()[i]->adj((iph->header_length << 2) + sizeof(Udp) +
gtph->header_length());

iph = p->head_data<Ipv4 *>();
be32_t daddr = iph->dst;
be32_t saddr = iph->src;
DLOG(INFO) << "ip->saddr: " << ToIpv4Address(saddr)
<< ", ip->daddr: " << ToIpv4Address(daddr)
<< std::endl;
key[i] = SESS_ID(saddr.raw_value(), DEFAULT_BEARER);
key_ptr[i] = &key[i];
}
iph = p->head_data<Ipv4 *>();
be32_t daddr = iph->dst;
be32_t saddr = iph->src;
DLOG(INFO) << "ip->saddr: " << ToIpv4Address(saddr)
<< ", ip->daddr: " << ToIpv4Address(daddr) << std::endl;
key[i] = SESS_ID(saddr.raw_value(), DEFAULT_BEARER);
key_ptr[i] = &key[i];
}

if ((hits = rte_hash_lookup_bulk_data(session_map,
(const void **)&key_ptr,
cnt,
&hit_mask,
(void **)data)) <= 0) {
DLOG(INFO) << "Failed to look-up" << std::endl;
/* Since default module is sink, the packets go right in the dump */
/* RunNextModule() sends batch to DEFAULT GATE */
RunNextModule(ctx, batch);
return;
}
if ((hits = rte_hash_lookup_bulk_data(session_map, (const void **)&key_ptr,
cnt, &hit_mask, (void **)data)) <= 0) {
DLOG(INFO) << "Failed to look-up" << std::endl;
/* Since default module is sink, the packets go right in the dump */
/* RunNextModule() sends batch to DEFAULT GATE */
RunNextModule(ctx, batch);
return;
}

for (int i = 0; i < cnt; i++) {
bess::Packet *p = batch->pkts()[i];
for (int i = 0; i < cnt; i++) {
bess::Packet *p = batch->pkts()[i];

if (!ISSET_BIT(hit_mask, i)) {
EmitPacket(ctx, p, DEFAULT_GATE);
std::cerr << "Fetch failed for ip->daddr: "
<< ToIpv4Address(be32_t(UE_ADDR(key[i])))
<< std::endl;
continue;
}
EmitPacket(ctx, p, FORWARD_GATE);
}
if (!ISSET_BIT(hit_mask, i)) {
EmitPacket(ctx, p, DEFAULT_GATE);
std::cerr << "Fetch failed for ip->daddr: "
<< ToIpv4Address(be32_t(UE_ADDR(key[i]))) << std::endl;
continue;
}
EmitPacket(ctx, p, FORWARD_GATE);
}

DLOG(INFO) << "rte_hash_lookup_bulk_data output: (cnts: "
<< cnt << ", hits: " << hits << ", hit_mask: " << hit_mask
<< ")" << std::endl;
DLOG(INFO) << "rte_hash_lookup_bulk_data output: (cnts: " << cnt
<< ", hits: " << hits << ", hit_mask: " << hit_mask << ")"
<< std::endl;
}
/*----------------------------------------------------------------------------------*/
CommandResponse
GtpuDecap::Init(const bess::pb::GtpuDecapArg &arg) {

std::string ename = arg.ename();
CommandResponse GtpuDecap::Init(const bess::pb::GtpuDecapArg &arg) {
std::string ename = arg.ename();

if (ename.c_str()[0] == '\0')
return CommandFailure(EINVAL,
"Invalid input name!");
if (ename.c_str()[0] == '\0')
return CommandFailure(EINVAL, "Invalid input name!");

std::string hashtable_name = "session_map" + ename;
std::cerr << "Fetching rte_hash: " << hashtable_name << std::endl;
std::string hashtable_name = "session_map" + ename;
std::cerr << "Fetching rte_hash: " << hashtable_name << std::endl;

session_map = rte_hash_find_existing(hashtable_name.c_str());
if (session_map == NULL)
return CommandFailure(ENOMEM,
"Unable to find rte_hash table: %s\n",
"session_map");
return CommandSuccess();
session_map = rte_hash_find_existing(hashtable_name.c_str());
if (session_map == NULL)
return CommandFailure(ENOMEM, "Unable to find rte_hash table: %s\n",
"session_map");
return CommandSuccess();
}
/*----------------------------------------------------------------------------------*/
ADD_MODULE(GtpuDecap, "gtpu_decap", "first version of gtpu decap module")
18 changes: 8 additions & 10 deletions core/modules/gtpu_decap.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
#ifndef BESS_MODULES_GTPUDECAP_H_
#define BESS_MODULES_GTPUDECAP_H_
/*----------------------------------------------------------------------------------*/
#include <rte_hash.h>
#include "../module.h"
#include "../pb/module_msg.pb.h"
#include "../utils/gtp_common.h"
#include <rte_hash.h>
/*----------------------------------------------------------------------------------*/
class GtpuDecap final : public Module {
public:
GtpuDecap() {
max_allowed_workers_ = Worker::kMaxWorkers;
}

/* Gates: (0) Default, (1) Forward */
static const gate_idx_t kNumOGates = 2;
GtpuDecap() { max_allowed_workers_ = Worker::kMaxWorkers; }

/* Gates: (0) Default, (1) Forward */
static const gate_idx_t kNumOGates = 2;

CommandResponse Init(const bess::pb::GtpuDecapArg &arg);
void ProcessBatch(Context *ctx, bess::PacketBatch *batch) override;
CommandResponse Init(const bess::pb::GtpuDecapArg &arg);
void ProcessBatch(Context *ctx, bess::PacketBatch *batch) override;

private:
struct rte_hash *session_map = NULL;
struct rte_hash *session_map = NULL;
};
/*----------------------------------------------------------------------------------*/
#endif // BESS_MODULES_GTPUDECAP_H_
119 changes: 55 additions & 64 deletions core/modules/gtpu_echo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,88 +19,79 @@
/* for eth header */
#include "utils/ether.h"
/*----------------------------------------------------------------------------------*/
using bess::utils::be16_t;
using bess::utils::be32_t;
using bess::utils::Ethernet;
using bess::utils::Ipv4;
using bess::utils::Gtpv1;
using bess::utils::Udp;
using bess::utils::be32_t;
using bess::utils::be16_t;
using bess::utils::Ipv4;
using bess::utils::ToIpv4Address;
using bess::utils::Udp;

enum {DEFAULT_GATE = 0, FORWARD_GATE};
enum { DEFAULT_GATE = 0, FORWARD_GATE };
/*----------------------------------------------------------------------------------*/
bool
GtpuEcho::process_echo_request(bess::Packet *p)
{
Ethernet *eth = p->head_data<Ethernet *>();
Ipv4 *iph = (Ipv4 *)((unsigned char *)eth + sizeof(Ethernet));
Udp *udp = (Udp *)((unsigned char *)iph + (iph->header_length<<2));
Gtpv1 *gtph = (Gtpv1 *)((unsigned char *)udp + sizeof(Udp));
struct gtpu_recovery_ie_t *recovery_ie = NULL;
bool GtpuEcho::process_echo_request(bess::Packet *p) {
Ethernet *eth = p->head_data<Ethernet *>();
Ipv4 *iph = (Ipv4 *)((unsigned char *)eth + sizeof(Ethernet));
Udp *udp = (Udp *)((unsigned char *)iph + (iph->header_length << 2));
Gtpv1 *gtph = (Gtpv1 *)((unsigned char *)udp + sizeof(Udp));
struct gtpu_recovery_ie_t *recovery_ie = NULL;

/* re-use space (if available) left in Ethernet padding for recovery_ie */
if (p->total_len() - (sizeof(Ethernet) + iph->length.value() + sizeof(struct gtpu_recovery_ie_t))) {
recovery_ie = (struct gtpu_recovery_ie_t *)((char *)gtph +
sizeof(Gtpv1) +
gtph->length.value());
} else {
/* otherwise prepend payload to the frame */
recovery_ie = (struct gtpu_recovery_ie_t *)p->append(sizeof(struct gtpu_recovery_ie_t));
if (recovery_ie == NULL) {
std::cerr << "Couldn't append " << sizeof(struct gtpu_recovery_ie_t)
<< " bytes to mbuf" << std::endl;
return false;
}
}
/* re-use space (if available) left in Ethernet padding for recovery_ie */
if (p->total_len() - (sizeof(Ethernet) + iph->length.value() +
sizeof(struct gtpu_recovery_ie_t))) {
recovery_ie = (struct gtpu_recovery_ie_t *)((char *)gtph + sizeof(Gtpv1) +
gtph->length.value());
} else {
/* otherwise prepend payload to the frame */
recovery_ie = (struct gtpu_recovery_ie_t *)p->append(
sizeof(struct gtpu_recovery_ie_t));
if (recovery_ie == NULL) {
std::cerr << "Couldn't append " << sizeof(struct gtpu_recovery_ie_t)
<< " bytes to mbuf" << std::endl;
return false;
}
}

gtph->type = GTPU_ECHO_RESPONSE;
gtph->length = be16_t(gtph->length.value() +
sizeof(struct gtpu_recovery_ie_t));
recovery_ie->type = GTPU_ECHO_RECOVERY;
recovery_ie->restart_cntr = 0;
gtph->type = GTPU_ECHO_RESPONSE;
gtph->length =
be16_t(gtph->length.value() + sizeof(struct gtpu_recovery_ie_t));
recovery_ie->type = GTPU_ECHO_RECOVERY;
recovery_ie->restart_cntr = 0;

/* Swap src and dest IP addresses */
std::swap(iph->src, iph->dst);
iph->length = be16_t(iph->length.value() + sizeof(struct gtpu_recovery_ie_t));
/* Reset checksum. This will be computed by next module in line */
iph->checksum = 0;
/* Swap src and dest IP addresses */
std::swap(iph->src, iph->dst);
iph->length = be16_t(iph->length.value() + sizeof(struct gtpu_recovery_ie_t));
/* Reset checksum. This will be computed by next module in line */
iph->checksum = 0;

/* Swap src and dst UDP ports */
std::swap(udp->src_port, udp->dst_port);
udp->length = be16_t(udp->length.value() + sizeof(struct gtpu_recovery_ie_t));
/* Reset checksum. This will be computed by next module in line */
udp->checksum = 0;
return true;
/* Swap src and dst UDP ports */
std::swap(udp->src_port, udp->dst_port);
udp->length = be16_t(udp->length.value() + sizeof(struct gtpu_recovery_ie_t));
/* Reset checksum. This will be computed by next module in line */
udp->checksum = 0;
return true;
}
/*----------------------------------------------------------------------------------*/
void
GtpuEcho::ProcessBatch(Context *ctx, bess::PacketBatch *batch)
{
int cnt = batch->cnt();
for (int i = 0; i < cnt; i++) {
bess::Packet *p = batch->pkts()[i];
void GtpuEcho::ProcessBatch(Context *ctx, bess::PacketBatch *batch) {
int cnt = batch->cnt();
for (int i = 0; i < cnt; i++) {
bess::Packet *p = batch->pkts()[i];

EmitPacket(ctx, p, (process_echo_request(p)) ?
FORWARD_GATE : DEFAULT_GATE);
}
EmitPacket(ctx, p, (process_echo_request(p)) ? FORWARD_GATE : DEFAULT_GATE);
}
}
/*----------------------------------------------------------------------------------*/
void
GtpuEcho::DeInit()
{
/* do nothing */
void GtpuEcho::DeInit() {
/* do nothing */
}
/*----------------------------------------------------------------------------------*/
CommandResponse
GtpuEcho::Init(const bess::pb::GtpuEchoArg &arg) {

s1u_sgw_ip = arg.s1u_sgw_ip();
CommandResponse GtpuEcho::Init(const bess::pb::GtpuEchoArg &arg) {
s1u_sgw_ip = arg.s1u_sgw_ip();

if (s1u_sgw_ip == 0)
return CommandFailure(EINVAL,
"Invalid S1U SGW IP address!");
if (s1u_sgw_ip == 0)
return CommandFailure(EINVAL, "Invalid S1U SGW IP address!");

return CommandSuccess();
return CommandSuccess();
}
/*----------------------------------------------------------------------------------*/
ADD_MODULE(GtpuEcho, "gtpu_echo", "first version of gtpu echo module")
Loading

0 comments on commit 8f746cf

Please sign in to comment.