Skip to content
Open
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
7 changes: 4 additions & 3 deletions doc/trex_port_service_mode.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The *modes*:

1. *On* : All the packets are forwarded to rx to be processed by Client or Capture.
2. *Off* - Only latency packets are forwarded. Before v2.66 non TCP UDP were forward to rx in software mode after v2.66 (including) only in filter mode those packets are forwarded for more flexibility.
3. *Filter* [bgp, no_tcp_udp, emu, transport, mdns, dhcp, all] - In this case specific packets are forwarded to rx. An example can be BGP packets for BIRD. It is relevant only for software mode, `--software`
3. *Filter* [bgp, bfd, no_tcp_udp, emu, transport, mdns, dhcp, all] - In this case specific packets are forwarded to rx. An example can be BGP packets for BIRD. It is relevant only for software mode, `--software`
Using filter mode you would be able to run TCP/UDP traffic in high rate while keeping the routing protocols function. The performance would be as good as "off", the only penalty comes from the software mode that requires all packets to be processed in the rx side.

[NOTE]
Expand All @@ -35,8 +35,8 @@ Service mode can be useful when writing Python plugins for emulation (example: I
----

trex>service --help
usage: service [-h] [-p PORTS [PORTS ...] | -a] [--bgp] [--dhcp] [--mdns]
[--emu] [--tran] [--no-tcp-udp] [--all] [--off]
usage: service [-h] [-p PORTS [PORTS ...] | -a] [--bgp] [--bfd] [--dhcp]
[--mdns] [--emu] [--tran] [--no-tcp-udp] [--all] [--off]

Configures port for service mode. In service mode ports will reply to ARP,
PING and etc.
Expand All @@ -49,6 +49,7 @@ optional arguments:
ports

--bgp filter mode with bgp packets forward to rx
--bfd filter mode with bfd packets forward to rx
--dhcp filter mode with dhcpv4/dhcpv6 packets forward to rx
--mdns filter mode with mDNS packets forward to rx
--emu filter mode for all emu services rx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def lookup (self, pkt):

# NA in response to our NS
if ICMPv6ND_NA in scapy_pkt:
return self.services.get((scapy_pkt[IPv6].dst, scapy_pkt[IPv6].src, tuple(vlans)), [] )
return self.services.get((scapy_pkt[IPv6].dst, scapy_pkt[ICMPv6ND_NA].tgt, tuple(vlans)), [] )

# NS from neighbor to verify ourselves
if ICMPv6ND_NS in scapy_pkt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
DHCP_MASK = 4
TRANSPORT_MASK = 8
MDNS_MASK = 16
BFD_MASK = 32
ALL_MASK = 255 # all bits are on


Expand Down Expand Up @@ -2236,6 +2237,7 @@ def set_service_mode_base (self, ports = None, enabled = True, filtered = False,
DHCP_MASK = 4
TRANSPORT = 8
MDNS = 16
BFD_MASK = 32
ALL_MASK = 255

:raises:
Expand Down Expand Up @@ -2992,7 +2994,7 @@ def _get_service_params(self, opts):
3 arguments: enable, filtered & mask to use in set_service_mode
"""

filtered = opts.allow_no_tcp_udp or opts.allow_bgp or opts.allow_all or opts.allow_emu or opts.allow_dhcp or opts.allow_transport
filtered = opts.allow_no_tcp_udp or opts.allow_bgp or opts.allow_all or opts.allow_emu or opts.allow_dhcp or opts.allow_transport or opts.allow_bfd

mask = 0
if filtered:
Expand All @@ -3010,6 +3012,8 @@ def _get_service_params(self, opts):
mask |= NO_TCP_UDP_MASK
if opts.allow_transport:
mask |= TRANSPORT_MASK
if opts.allow_bfd:
mask |= BFD_MASK

else:
mask = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,13 @@ class OPTIONS_DB_ARGS:
'dest': 'allow_bgp',
'help': 'filter mode with bgp packets forward to rx'})

SERVICE_BFD_FILTERED = ArgumentPack(
['--bfd'],
{'action': 'store_true',
'default': False,
'dest': 'allow_bfd',
'help': 'filter mode with bfd packets forward to rx'})

SERVICE_TRAN_FILTERED = ArgumentPack(
['--tran'],
{'action': 'store_true',
Expand Down Expand Up @@ -2123,6 +2130,7 @@ class OPTIONS_DB_GROUPS:
NON_MUTEX,
[
SERVICE_BGP_FILTERED,
SERVICE_BFD_FILTERED,
SERVICE_DHCP_FILTERED,
SERVICE_MDNS_FILTERED,
SERVICE_EMU_FILTERED,
Expand Down
14 changes: 14 additions & 0 deletions src/44bsd/flow_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@ void CFlowTable::check_service_filter(CSimplePacketParser & parser, tcp_rx_pkt_a
}
}

if (m_service_filtered_mask & TrexPort::BFD) {
if ( parser.m_protocol == IPPROTO_UDP ) {
UDPHeader *l4_header = (UDPHeader *)parser.m_l4;
uint16_t src_port = l4_header->getSourcePort();
uint16_t dst_port = l4_header->getDestPort();
if ( (( src_port == BFDc_PORT || dst_port == BFDc_PORT )) ||
(( src_port == BFDe_PORT || dst_port == BFDe_PORT )) ||
(( src_port == mBFDc_PORT || dst_port == mBFDc_PORT ))) {
action = tREDIRECT_RX_CORE;
return;
}
}
}

if ( (m_service_filtered_mask & TrexPort::TRANSPORT) &&
((parser.m_protocol == IPPROTO_UDP) || (parser.m_protocol == IPPROTO_TCP)) ) {
UDPHeader *l4_header = (UDPHeader *)parser.m_l4;
Expand Down
3 changes: 3 additions & 0 deletions src/common/Network/Packet/TcpHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ limitations under the License.
#define DHCPv4_PORT 67
#define DHCPv6_PORT 546
#define MDNS_PORT 5353
#define BFDc_PORT 3784
#define BFDe_PORT 3785
#define mBFDc_PORT 4784
class TCPUDPHeaderBase
{
public:
Expand Down
3 changes: 2 additions & 1 deletion src/stx/common/trex_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class TrexPort {
BGP = 1 << 1,
DHCP = 1 << 2, /* both for v4 and v6 */
TRANSPORT = 1 << 3, /* TCP & UDP with source (port& 0xff00 == 0xff00) generated by EMU */
MDNS = 1 << 4 /* mDNS - multicast DNS - EMU */
MDNS = 1 << 4, /* mDNS - multicast DNS - EMU */
BFD = 1 << 5 /* all BFD ports */
};

TrexPort(uint8_t port_id);
Expand Down
2 changes: 1 addition & 1 deletion src/stx/common/trex_stack_linux_based.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ void CLinuxIfNode::conf_ip6_internal(bool enabled, const string &ip6_buf) {
char buf[INET6_ADDRSTRLEN];
if ( enabled ) {
run_in_ns("sysctl net.ipv6.conf." + m_if_name + "-L.disable_ipv6=0", "Could not enable ipv6 for veth");
run_in_ns("ip -6 route add default dev " + m_if_name + "-L", "Could not set interface as default route");
run_in_ns("ip -6 route replace default dev " + m_if_name + "-L", "Could not set interface as default route");
if ( ip6_buf.size() ) {
inet_ntop(AF_INET6, ip6_buf.c_str(), buf, INET6_ADDRSTRLEN);
string ip6_str(buf);
Expand Down
13 changes: 13 additions & 0 deletions src/stx/stl/trex_stl_dp_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ COLD_FUNC bool TrexStatelessDpCore::check_service_filter(bool &drop) {
}
}

if ( (m_service_mask & TrexPort::BFD) && (proto == IPPROTO_UDP) ) {
UDPHeader *l4_header = (UDPHeader *)m_parser->get_l4();
uint16_t src_port = l4_header->getSourcePort();
uint16_t dst_port = l4_header->getDestPort();

if ( (( src_port == BFDc_PORT || dst_port == BFDc_PORT )) ||
(( src_port == BFDe_PORT || dst_port == BFDe_PORT )) ||
(( src_port == mBFDc_PORT || dst_port == mBFDc_PORT ))) {
drop = false;
return true;
}
}

if ( (m_service_mask & TrexPort::TRANSPORT) && ((proto == IPPROTO_UDP)
|| (proto == IPPROTO_TCP)) ) {
UDPHeader *l4_header = (UDPHeader *)m_parser->get_l4();
Expand Down