Skip to content

Commit

Permalink
Introducing GRE tunneling support
Browse files Browse the repository at this point in the history
Currently YANET only supports the IPIP tunneling scheme for
packet delivery to service backends. However, there is no
native support for IPIP encapsulation on Windows platform
we want to support services on, so we had to implement GRE
tunnelling protocol.

This commit allows one to configure a tunneling mode, whether
IPIP or GRE, for each service inside balancer configuration
using lvs_method option set to TUN (for IPIP) or GRE respectively.

Commited by Steve Balayan (https://github.com/SteveBalayanAKAMedian)
  • Loading branch information
Timur Aitov authored and taitov committed Sep 21, 2023
1 parent fa29f25 commit 3e75227
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 18 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions autotests/units/001_one_port/065_balancer_gre/autotest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
steps:
- ipv4Update:
- "0.0.0.0/0 -> 200.0.0.1"
- "100.0.0.0/8 -> 100.0.0.5"
- ipv6Update: "::/0 -> fe80::1"
- cli:
- balancer real enable balancer0 10.0.0.1 tcp 80 2000::1 80
- balancer real enable balancer0 10.0.0.42 tcp 80 100.0.0.42 80
- balancer real enable balancer0 2001:dead:beef::1 tcp 80 2000::1 80
- balancer real enable balancer0 2001:dead:beef::2 tcp 80 100.0.0.6 80
- balancer real flush
- sleep: 1
- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 001-expect.pcap
- sleep: 1
- sendPackets:
- port: kni0
send: 002-send.pcap
expect: 002-expect.pcap
- sleep: 1
- sendPackets:
- port: kni0
send: 003-send.pcap
expect: 003-expect.pcap
- sleep: 1
- sendPackets:
- port: kni0
send: 004-send.pcap
expect: 004-expect.pcap
49 changes: 49 additions & 0 deletions autotests/units/001_one_port/065_balancer_gre/controlplane.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"modules": {
"lp0.100": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "100",
"macAddress": "00:11:22:33:44:55",
"nextModule": "acl0"
},
"lp0.200": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "200",
"macAddress": "00:11:22:33:44:55",
"nextModule": "acl0"
},
"acl0": {
"type": "acl",
"nextModules": [
"balancer0",
"route0"
]
},
"balancer0": {
"type": "balancer",
"source": "2000:51b::1",
"source_ipv4": "100.0.0.22",
"services": "services.conf",
"default_wlc_power": 10,
"nextModule": "route0"
},
"route0": {
"type": "route",
"interfaces": {
"kni0.100": {
"neighborIPv6Address": "fe80::1",
"neighborIPv4Address": "100.0.0.5",
"neighborMacAddress": "00:00:00:00:00:01",
"nextModule": "lp0.100"
},
"kni0.200": {
"neighborIPv4Address": "200.0.0.1",
"neighborMacAddress": "00:00:00:00:00:02",
"nextModule": "lp0.200"
}
}
}
}
}
80 changes: 80 additions & 0 deletions autotests/units/001_one_port/065_balancer_gre/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from scapy.all import *


def write_pcap(filename, *packetsList):
if len(packetsList) == 0:
PcapWriter(filename)._write_header(Ether())
return

PcapWriter(filename)

for packets in packetsList:
if type(packets) == list:
for packet in packets:
packet.time = 0
wrpcap(filename, [p for p in packet], append=True)
else:
packets.time = 0
wrpcap(filename, [p for p in packets], append=True)


write_pcap("001-send.pcap",
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IP(dst="10.0.0.1", src="1.1.0.1", ttl=64) / TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IP(dst="10.0.0.1", src="1.1.0.2", ttl=64) / TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IP(dst="10.0.0.1", src="1.1.0.3", ttl=64) / TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IP(dst="10.0.0.1", src="1.1.0.4", ttl=64) / TCP(dport=80, sport=12380),
)

write_pcap("001-expect.pcap",
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="2000::1", src="2000:51b::0101:0001:0:1", hlim=63, fl=0, nh=0x2f)/GRE(proto=0x0800)/IP(dst="10.0.0.1", src="1.1.0.1", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="2000::1", src="2000:51b::0101:0002:0:1", hlim=63, fl=0, nh=0x2f)/GRE(proto=0x0800)/IP(dst="10.0.0.1", src="1.1.0.2", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="2000::1", src="2000:51b::0101:0003:0:1", hlim=63, fl=0, nh=0x2f)/GRE(proto=0x0800)/IP(dst="10.0.0.1", src="1.1.0.3", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IPv6(dst="2000::1", src="2000:51b::0101:0004:0:1", hlim=63, fl=0, nh=0x2f)/GRE(proto=0x0800)/IP(dst="10.0.0.1", src="1.1.0.4", ttl=64)/TCP(dport=80, sport=12380),
)


write_pcap("002-send.pcap",
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IP(dst="10.0.0.42", src="1.1.0.1", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IP(dst="10.0.0.42", src="1.1.0.2", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IP(dst="10.0.0.42", src="1.1.0.3", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IP(dst="10.0.0.42", src="1.1.0.4", ttl=64)/TCP(dport=80, sport=12380),
)

write_pcap("002-expect.pcap",
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.42", src="100.0.0.22", ttl=63)/GRE(proto=0x0800)/IP(dst="10.0.0.42", src="1.1.0.1", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.42", src="100.0.0.22", ttl=63)/GRE(proto=0x0800)/IP(dst="10.0.0.42", src="1.1.0.2", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.42", src="100.0.0.22", ttl=63)/GRE(proto=0x0800)/IP(dst="10.0.0.42", src="1.1.0.3", ttl=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.42", src="100.0.0.22", ttl=63)/GRE(proto=0x0800)/IP(dst="10.0.0.42", src="1.1.0.4", ttl=64)/TCP(dport=80, sport=12380),
)

write_pcap("003-send.pcap",
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IPv6(dst="2001:dead:beef::1", src="2002::1", hlim=64) / TCP(dport=80, sport=12443),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IPv6(dst="2001:dead:beef::1", src="2002::2", hlim=64) / TCP(dport=80, sport=12443),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IPv6(dst="2001:dead:beef::1", src="2002::3", hlim=64) / TCP(dport=80, sport=12443),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02") / Dot1Q(vlan=200) / IPv6(dst="2001:dead:beef::1", src="2002::4", hlim=64) / TCP(dport=80, sport=12443)
)

write_pcap("003-expect.pcap",
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55") / Dot1Q(vlan=100) / IPv6(dst="2000::1", src="2000:51b::0001:0:1", hlim=63, fl=0, nh=0x2f) / GRE(proto=0x86DD) / IPv6(dst="2001:dead:beef::1", src="2002::1", hlim=64) / TCP(dport=80, sport=12443),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55") / Dot1Q(vlan=100) / IPv6(dst="2000::1", src="2000:51b::0002:0:1", hlim=63, fl=0, nh=0x2f) / GRE(proto=0x86DD) / IPv6(dst="2001:dead:beef::1", src="2002::2", hlim=64) / TCP(dport=80, sport=12443),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55") / Dot1Q(vlan=100) / IPv6(dst="2000::1", src="2000:51b::0003:0:1", hlim=63, fl=0, nh=0x2f) / GRE(proto=0x86DD) / IPv6(dst="2001:dead:beef::1", src="2002::3", hlim=64) / TCP(dport=80, sport=12443),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55") / Dot1Q(vlan=100) / IPv6(dst="2000::1", src="2000:51b::0004:0:1", hlim=63, fl=0, nh=0x2f) / GRE(proto=0x86DD) / IPv6(dst="2001:dead:beef::1", src="2002::4", hlim=64) / TCP(dport=80, sport=12443)
)


write_pcap("004-send.pcap",
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IPv6(dst="2001:dead:beef::2", src="2002::10", hlim=64)/TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IPv6(dst="2001:dead:beef::2", src="2002::11", hlim=64)/TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IPv6(dst="2001:dead:beef::2", src="2002::12", hlim=64)/TCP(dport=80, sport=12380),
Ether(dst="00:11:22:33:44:55", src="00:00:00:00:00:02")/Dot1Q(vlan=200)/IPv6(dst="2001:dead:beef::2", src="2002::13", hlim=64)/TCP(dport=80, sport=12380),
)

write_pcap("004-expect.pcap",
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.6", src="100.0.0.22", ttl=63)/ GRE(proto=0x86DD) /IPv6(dst="2001:dead:beef::2", src="2002::10", hlim=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.6", src="100.0.0.22", ttl=63)/ GRE(proto=0x86DD) /IPv6(dst="2001:dead:beef::2", src="2002::11", hlim=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.6", src="100.0.0.22", ttl=63)/ GRE(proto=0x86DD) /IPv6(dst="2001:dead:beef::2", src="2002::12", hlim=64)/TCP(dport=80, sport=12380),
Ether(dst="00:00:00:00:00:01", src="00:11:22:33:44:55")/Dot1Q(vlan=100)/IP(dst="100.0.0.6", src="100.0.0.22", ttl=63)/ GRE(proto=0x86DD) /IPv6(dst="2001:dead:beef::2", src="2002::13", hlim=64)/TCP(dport=80, sport=12380),
)
54 changes: 54 additions & 0 deletions autotests/units/001_one_port/065_balancer_gre/services.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"vip": "10.0.0.1",
"proto": "tcp",
"vport": "80",
"scheduler": "rr",
"lvs_method": "GRE",
"reals": [
{
"ip": "2000::1",
"port": "80"
}
]
},
{
"vip": "10.0.0.42",
"proto": "tcp",
"vport": "80",
"scheduler": "rr",
"lvs_method": "GRE",
"reals": [
{
"ip": "100.0.0.42",
"port": "80"
}
]
},
{
"vip": "2001:dead:beef::1",
"proto": "tcp",
"vport": "80",
"scheduler": "rr",
"lvs_method": "GRE",
"reals": [
{
"ip": "2000::1",
"port": "80"
}
]
},
{
"vip": "2001:dead:beef::2",
"proto": "tcp",
"vport": "80",
"scheduler": "rr",
"lvs_method": "GRE",
"reals": [
{
"ip": "100.0.0.6",
"port": "80"
}
]
}
]
31 changes: 31 additions & 0 deletions common/balancer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "type.h"

namespace balancer
{

enum class tunnel : uint8_t
{
ipip, // in services.conf it means lvs_method: TUN
gre,
};

constexpr const char* to_string(const tunnel& tunnel)
{
switch (tunnel)
{
case tunnel::ipip:
{
return "ipip";
}
case tunnel::gre:
{
return "gre";
}
}

return "unknown";
}

}
2 changes: 2 additions & 0 deletions common/controlplaneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "stream.h"
#include "type.h"
#include "balancer.h"
#include "scheduler.h"

namespace controlplane
Expand Down Expand Up @@ -308,6 +309,7 @@ using service_t = std::tuple<balancer_service_id_t,
std::optional<std::string>, ///< version
::balancer::scheduler,
::balancer::scheduler_params,
::balancer::tunnel,
uint8_t, ///< flags: mss_fix|ops
std::vector<real_t>>;

Expand Down
2 changes: 2 additions & 0 deletions common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "scheduler.h"
#include "type.h"
#include "acl.h"
#include "balancer.h"

namespace common::idp
{
Expand Down Expand Up @@ -259,6 +260,7 @@ namespace updateGlobalBase
uint8_t, ///< flags
tCounterId, ///< size 4
balancer::scheduler,
balancer::tunnel, // tunneling method (default ipip)
uint32_t, /// default_wlc_power
uint32_t, ///< real_start
uint32_t>; ///< real_size
Expand Down
16 changes: 11 additions & 5 deletions controlplane/src/balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,15 @@ void balancer_t::reload(const controlplane::base_t& base_prev,

for (const auto& [module_name, balancer] : base_prev.balancers)
{
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, flags, reals] : balancer.services)
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, tunnel, flags, reals] : balancer.services)
{
(void)service_id;
(void)version;
(void)scheduler;
(void)scheduler_params;
(void)reals;
(void)flags;
(void)tunnel;

service_counters.remove({module_name, {virtual_ip, proto, virtual_port}});

Expand All @@ -255,13 +256,14 @@ void balancer_t::reload(const controlplane::base_t& base_prev,
{
std::unordered_set<std::tuple<common::ip_address_t, uint16_t, uint8_t>> vip_vport_proto;

for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, flags, reals] : balancer.services)
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, tunnel, flags, reals] : balancer.services)
{
(void)service_id;
(void)version;
(void)scheduler;
(void)scheduler_params;
(void)flags;
(void)tunnel;

service_counters.insert({module_name, {virtual_ip, proto, virtual_port}});

Expand Down Expand Up @@ -600,10 +602,11 @@ void balancer_t::update_service(const balancer::generation_config_t& generation_
uint64_t services_reals_enabled_count = 0;
uint64_t services_reals_count = 0;

for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, flags, reals] : balancer.services)
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, tunnel, flags, reals] : balancer.services)
{
(void) flags;
(void) scheduler_params;
(void) tunnel;

if (service_id >= YANET_CONFIG_BALANCER_SERVICES_SIZE)
{
Expand Down Expand Up @@ -684,7 +687,7 @@ void balancer_t::compile(common::idp::updateGlobalBase::request& globalbase,

for (const auto& [module_name, balancer] : generation_config.config_balancers)
{
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, flags, reals] : balancer.services)
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, tunnel, flags, reals] : balancer.services)
{
(void) scheduler_params;
(void) version;
Expand Down Expand Up @@ -732,6 +735,7 @@ void balancer_t::compile(common::idp::updateGlobalBase::request& globalbase,
flags,
counter_ids[0],
scheduler,
tunnel,
balancer.default_wlc_power, //todo use scheduler_params.wlc_power when other services will be able to set it
(uint32_t)real_start,
(uint32_t)(req_reals.size() - real_start)});
Expand All @@ -753,12 +757,14 @@ void balancer_t::flush_reals(common::idp::updateGlobalBaseBalancer::request& bal
for (const auto& [module_name, balancer] : generation_config.config_balancers)
{

for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, flags, reals] : balancer.services)
for (const auto& [service_id, virtual_ip, proto, virtual_port, version, scheduler, scheduler_params, tunnel, flags, reals] : balancer.services)
{
(void)flags;
(void)scheduler;
(void)scheduler_params;
(void)version;
(void)tunnel;

if (service_id >= YANET_CONFIG_BALANCER_SERVICES_SIZE)
{
continue;
Expand Down
Loading

0 comments on commit 3e75227

Please sign in to comment.