-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MPLS push module #590
base: master
Are you sure you want to change the base?
Add MPLS push module #590
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scapy.all as scapy | ||
|
||
eth = scapy.Ether(src='02:1e:67:9f:4d:ae', dst='06:16:3e:1b:72:32') | ||
ip = scapy.IP(src='192.168.0.1', dst='10.0.0.1') | ||
udp = scapy.UDP(sport=10001, dport=10002) | ||
test_packet = bytes(eth/ip/udp) | ||
|
||
mpls_push::MPLSPush() | ||
mpls_push.set(label=7, ttl=64, tc=0, is_bottom_of_stack=True) | ||
|
||
Source() -> Rewrite(templates=[test_packet]) -> mpls_push -> Sink() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "mpls_push.h" | ||
|
||
#include "../utils/endian.h" | ||
#include "../utils/ether.h" | ||
#include "../utils/mpls.h" | ||
|
||
using bess::utils::Ethernet; | ||
using bess::utils::be16_t; | ||
using bess::utils::Mpls; | ||
|
||
const Commands MPLSPush::cmds = {{"set", "MplsPushArg", | ||
MODULE_CMD_FUNC(&MPLSPush::CommandSet), | ||
Command::THREAD_UNSAFE}}; | ||
|
||
MPLSPush::MPLSPush() : label_(0), ttl_(64), tc_(0), is_bottom_of_stack_(true) {} | ||
|
||
|
||
CommandResponse MPLSPush::Init(const bess::pb::MplsPushArg &arg) { | ||
return CommandSet(arg); | ||
} | ||
|
||
void MPLSPush::ProcessBatch(bess::PacketBatch *batch) { | ||
int cnt = batch->cnt(); | ||
for (int i = 0; i < cnt; i++) { | ||
bess::Packet *pkt = batch->pkts()[i]; | ||
Ethernet *eth = pkt->head_data<Ethernet *>(); | ||
|
||
Ethernet::Address src_addr = eth->src_addr; | ||
Ethernet::Address dst_addr = eth->dst_addr; | ||
|
||
pkt->prepend(4); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All code south of here should be guarded by a check that this call to |
||
eth = pkt->head_data<Ethernet *>(); | ||
eth->src_addr = src_addr; | ||
eth->dst_addr = dst_addr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To the end of keeping the scope of this module narrow, might you just copy the original ethernet header here and change the ethertype? A sequence of |
||
eth->ether_type = be16_t(Ethernet::Type::kMpls); | ||
|
||
Mpls *mpls_hdr = reinterpret_cast<Mpls *>(eth + 1); | ||
mpls_hdr->SetEntry(label_, ttl_, tc_, is_bottom_of_stack_); | ||
} | ||
|
||
RunNextModule(batch); | ||
} | ||
|
||
CommandResponse MPLSPush::CommandSet(const bess::pb::MplsPushArg &arg) { | ||
label_ = arg.label(); | ||
ttl_ = arg.ttl(); | ||
is_bottom_of_stack_ = arg.is_bottom_of_stack(); | ||
tc_ = arg.tc(); | ||
return CommandSuccess(); | ||
} | ||
|
||
ADD_MODULE(MPLSPush, "mpls_push", "Push MPLS label") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef BESS_MODULES_MPLSPUSH_H_ | ||
#define BESS_MODULES_MPLSPUSH_H_ | ||
|
||
#include "../module.h" | ||
#include "../module_msg.pb.h" | ||
|
||
class MPLSPush final : public Module { | ||
public: | ||
static const gate_idx_t kNumIGates = 1; | ||
static const gate_idx_t kNumOGates = 1; | ||
|
||
static const Commands cmds; | ||
|
||
MPLSPush(); // constructor | ||
|
||
CommandResponse Init(const bess::pb::MplsPushArg &arg); | ||
|
||
void ProcessBatch(bess::PacketBatch *batch) override; | ||
|
||
CommandResponse CommandSet(const bess::pb::MplsPushArg &arg); | ||
|
||
private: | ||
uint32_t label_; | ||
uint8_t ttl_; | ||
uint8_t tc_; | ||
bool is_bottom_of_stack_; | ||
}; | ||
|
||
#endif // BESS_MODULES_MPLSPUSH_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, sorry. Ignore my comment below. I didn't notice these lines.