Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bessctl/conf/perftest/nat.bess
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ Source() \
-> nat::NAT(ext_addrs=nat_config)

if bidirectional:
nat -> MACSwap() -> IPSwap() -> 1:nat:1 -> Sink()
nat:1 -> MACSwap() -> IPSwap() -> 1:nat:0 -> Sink()
else:
nat -> Sink()
nat:1 -> Sink()
4 changes: 2 additions & 2 deletions bessctl/conf/samples/nat.bess
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ packets = [gen_packet(scapy.UDP, '172.16.100.1', '10.0.0.1'),

# dynamic NAT configuration
nat::NAT(ext_addrs=[{'ext_addr': '192.168.0.1'}, {'ext_addr': '192.168.0.2'}])
Source() -> Rewrite(templates=packets) -> 0:nat:0 -> MACSwap() -> IPSwap() -> 1:nat:1 -> Sink()
Source() -> Rewrite(templates=packets) -> 0:nat:1 -> MACSwap() -> IPSwap() -> 1:nat:0 -> Sink()

# static NAT configuration
static_nat::StaticNAT(pairs=[
Expand All @@ -60,4 +60,4 @@ static_nat::StaticNAT(pairs=[
{'int_range': {'start': '192.168.0.0', 'end': '192.168.255.255'},
'ext_range': {'start': '66.77.0.0', 'end': '66.77.255.255'}},
])
Source() -> Rewrite(templates=packets) -> 0:static_nat:0 -> MACSwap() -> IPSwap() -> 1:static_nat:1 -> Sink()
Source() -> Rewrite(templates=packets) -> 0:static_nat:1 -> MACSwap() -> IPSwap() -> 1:static_nat:0 -> Sink()
8 changes: 4 additions & 4 deletions bessctl/module_tests/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def _swap_l4(l4):
pkt_orig = eth / ip_orig / l4_orig / l7

pkt_outs = self.run_module(module, 0, [pkt_orig], [0, 1])
self.assertEquals(len(pkt_outs[0]), 1)
pkt_natted = pkt_outs[0][0]
self.assertEquals(len(pkt_outs[1]), 1)
pkt_natted = pkt_outs[1][0]

# The NAT module can choose an arbitrary source port/id.
# We cannot test it, we have to read from the output.
Expand All @@ -81,9 +81,9 @@ def _swap_l4(l4):
pkt_reply = eth / ip_reply / l4_reply / l7

pkt_outs = self.run_module(module, 1, [pkt_reply], [0, 1])
self.assertEquals(len(pkt_outs[1]), 1)
self.assertEquals(len(pkt_outs[0]), 1)
self.assertSamePackets(eth / ip_unnatted / _swap_l4(l4_orig) / l7,
pkt_outs[1][0])
pkt_outs[0][0])

def test_nat_udp(self):
nat_config = [{'ext_addr': '192.168.1.1'}]
Expand Down
8 changes: 4 additions & 4 deletions bessctl/module_tests/placement_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_nat(self):
# Swap src/dst IP addresses / ports
ip = IPSwap()

Source() -> 0:nat:0 -> mac -> ip -> 1:nat:1 -> Sink()
Source() -> 0:nat:1 -> mac -> ip -> 1:nat:0 -> Sink()

self.assertFalse(bess.check_constraints())

Expand All @@ -74,7 +74,7 @@ def test_nat_queue(self):
# Swap src/dst IP addresses / ports
ip = IPSwap()

Source() -> 0:nat:0 -> Queue() -> ip -> 1:nat:1 -> Sink()
Source() -> 0:nat:1 -> Queue() -> ip -> 1:nat:0 -> Sink()

self.assertFalse(bess.check_constraints())

Expand All @@ -85,8 +85,8 @@ def test_nat_negative(self):
bess.add_worker(0, 0)
bess.add_worker(1, 1)
nat = NAT(ext_addrs=nat_config)
src0 -> 0: nat: 0 -> Sink()
src1 -> 1: nat: 1 -> Sink()
src0 -> 0: nat: 1 -> Sink()
src1 -> 1: nat: 0 -> Sink()
src0.attach_task(wid=0)
src1.attach_task(wid=1)

Expand Down
2 changes: 1 addition & 1 deletion core/modules/nat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ inline void Stamp(Ipv4 *ip, void *l4, const Endpoint &before,

template <NAT::Direction dir>
inline void NAT::DoProcessBatch(Context *ctx, bess::PacketBatch *batch) {
gate_idx_t ogate_idx = static_cast<gate_idx_t>(dir);
gate_idx_t ogate_idx = dir == kForward ? 1 : 0;
int cnt = batch->cnt();
uint64_t now = ctx->current_ns;

Expand Down
2 changes: 1 addition & 1 deletion core/modules/static_nat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static inline void UpdateChecksum(bess::utils::Ipv4 *ip, uint32_t incr) {

template <StaticNAT::Direction dir>
inline void StaticNAT::DoProcessBatch(Context *ctx, bess::PacketBatch *batch) {
gate_idx_t ogate_idx = static_cast<gate_idx_t>(dir);
gate_idx_t ogate_idx = dir == kForward ? 1 : 0;
int cnt = batch->cnt();

for (int i = 0; i < cnt; i++) {
Expand Down