Skip to content

Commit

Permalink
Merge pull request #38 from AnnikaH/master
Browse files Browse the repository at this point in the history
Support for TCP load balancer (microLB) configuration and improvements to assignment processing
  • Loading branch information
AnnikaH authored Nov 22, 2017
2 parents 9d3ac18 + 5babfd3 commit cb03d06
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 79 deletions.
377 changes: 306 additions & 71 deletions NaCl.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cpp_resolve_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def resolve_member_value_from_element_cpp(element, member_list, ctx):
") does not have any named attributes")

if element.base_type == BASE_TYPE_UNTYPED_INIT:
val = element.get_member_value(member_list)
val = element.get_member_value(member_list, ctx)
if val is None:
sys.exit("line " + get_line_and_column(ctx) + " Could not identify " + element.name + "." + ".".join(member_list))

Expand Down
39 changes: 39 additions & 0 deletions cpp_template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{{#has_vlans}}
#include <net/vlan>
{{/has_vlans}}
{{#has_load_balancers}}
#include <microLB>
{{/has_load_balancers}}

using namespace net;

Expand All @@ -23,6 +26,9 @@ std::shared_ptr<Conntrack> nacl_ct_obj;
{{#has_nats}}
std::unique_ptr<nat::NAPT> nacl_natty_obj;
{{/has_nats}}
{{#has_load_balancers}}
static microLB::Balancer* nacl_lb_obj = nullptr;
{{/has_load_balancers}}
{{#has_functions}}

namespace custom_made_classes_from_nacl {
Expand Down Expand Up @@ -181,4 +187,37 @@ void register_plugin_nacl() {
{{/snats}}
{{/has_snats}}
{{/has_nats}}
{{#has_load_balancers}}

// Load balancers
{{#load_balancers}}

{{servers_iface_name}}.tcp().set_MSL(15s);
nacl_lb_obj = new microLB::Balancer({{clients_iface_name}}, {{port}}, {{servers_iface_name}});
{{#pool}}

Socket socket_{{index}}{ {{address}}, {{port}} };
nacl_lb_obj->nodes.add_node({{servers_iface_name}}, socket_{{index}}, nacl_lb_obj->get_pool_signal());
{{/pool}}

/*
Name: {{name}}
Layer: {{layer}}

Clients iface: {{clients_iface_name}}
Clients port: {{port}}
Clients wait queue limit: {{wait_queue_limit}}
Clients session limit: {{session_limit}}

Servers iface: {{servers_iface_name}}
Servers algorithm: {{algorithm}}
Servers pool:
{{#pool}}

Node address: {{address}}
Node port: {{port}}
{{/pool}}
{{/load_balancers}}
*/
{{/has_load_balancers}}
}
7 changes: 7 additions & 0 deletions examples/assignments.nacl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ my_map: {
e1: 10
}

my_map.e2.e2-3: 50

my_map.e2: {
e2-1: 30,
e2-2: 40
}

vlan1.address: 20.20.20.10
vlan1.netmask: 255.255.255.0

Expand Down
37 changes: 37 additions & 0 deletions examples/lb.nacl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Iface outside {
address: 10.20.17.71,
netmask: 255.255.255.0,
gateway: 10.20.17.1,
index: 0
}

Iface inside {
address: 10.20.17.72,
netmask: 255.255.255.0,
gateway: 10.20.17.1,
index: 1
}

Load_balancer lb {
layer: tcp,
clients: {
iface: outside,
port: 80,
wait_queue_limit: 1000,
session_limit: 1000
},
servers: {
iface: inside,
algorithm: round_robin,
pool: [
{
address: 10.20.17.81,
port: 80
},
{
address: 10.20.17.82,
port: 80
}
]
}
}
54 changes: 54 additions & 0 deletions examples/lb_with_uplink.nacl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Iface uplink {
address: 10.0.0.42,
netmask: 255.255.255.0,
gateway: 10.0.0.1,
index: 0
}

Iface outside {
address: 10.0.0.43,
netmask: 255.255.255.0,
gateway: 10.0.0.1,
index: 1
}

Iface inside {
address: 10.0.0.44,
netmask: 255.255.255.0,
gateway: 10.0.0.1,
index: 2
}

Load_balancer lb {
servers: {
algorithm: round_robin,
pool: [
{
address: 10.0.0.1,
port: 6001
},
{
address: 10.0.0.1,
port: 6002
},
{
address: 10.0.0.1,
port: 6003
},
{
address: 10.0.0.1,
port: 6004
}
]
}
}

lb.layer: tcp
lb.clients: {
iface: outside,
port: 80,
wait_queue_limit: 1000,
session_limit: 1000
}

lb.servers.iface: inside
49 changes: 49 additions & 0 deletions goldenfiles/lb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
#include <net/inet4>
#include <net/ip4/cidr.hpp>
#include <plugins/nacl.hpp>
#include <microLB>

using namespace net;

static microLB::Balancer* nacl_lb_obj = nullptr;
void register_plugin_nacl() {
INFO("NaCl", "Registering NaCl plugin");

auto& outside = Inet4::stack<0>();
outside.network_config(IP4::addr{10,20,17,71}, IP4::addr{255,255,255,0}, IP4::addr{10,20,17,1});
auto& inside = Inet4::stack<1>();
inside.network_config(IP4::addr{10,20,17,72}, IP4::addr{255,255,255,0}, IP4::addr{10,20,17,1});


// Load balancers

inside.tcp().set_MSL(15s);
nacl_lb_obj = new microLB::Balancer(outside, 80, inside);

Socket socket_0{ IP4::addr{10,20,17,81}, 80 };
nacl_lb_obj->nodes.add_node(inside, socket_0, nacl_lb_obj->get_pool_signal());

Socket socket_1{ IP4::addr{10,20,17,82}, 80 };
nacl_lb_obj->nodes.add_node(inside, socket_1, nacl_lb_obj->get_pool_signal());

/*
Name: lb
Layer: tcp
Clients iface: outside
Clients port: 80
Clients wait queue limit: 1000
Clients session limit: 1000
Servers iface: inside
Servers algorithm: round_robin
Servers pool:
Node address: IP4::addr{10,20,17,81}
Node port: 80
Node address: IP4::addr{10,20,17,82}
Node port: 80
*/
}
63 changes: 63 additions & 0 deletions goldenfiles/lb_with_uplink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <net/inet4>
#include <net/ip4/cidr.hpp>
#include <plugins/nacl.hpp>
#include <microLB>

using namespace net;

static microLB::Balancer* nacl_lb_obj = nullptr;
void register_plugin_nacl() {
INFO("NaCl", "Registering NaCl plugin");

auto& inside = Inet4::stack<2>();
inside.network_config(IP4::addr{10,0,0,44}, IP4::addr{255,255,255,0}, IP4::addr{10,0,0,1});
auto& outside = Inet4::stack<1>();
outside.network_config(IP4::addr{10,0,0,43}, IP4::addr{255,255,255,0}, IP4::addr{10,0,0,1});
auto& uplink = Inet4::stack<0>();
uplink.network_config(IP4::addr{10,0,0,42}, IP4::addr{255,255,255,0}, IP4::addr{10,0,0,1});


// Load balancers

inside.tcp().set_MSL(15s);
nacl_lb_obj = new microLB::Balancer(outside, 80, inside);

Socket socket_0{ IP4::addr{10,0,0,1}, 6001 };
nacl_lb_obj->nodes.add_node(inside, socket_0, nacl_lb_obj->get_pool_signal());

Socket socket_1{ IP4::addr{10,0,0,1}, 6002 };
nacl_lb_obj->nodes.add_node(inside, socket_1, nacl_lb_obj->get_pool_signal());

Socket socket_2{ IP4::addr{10,0,0,1}, 6003 };
nacl_lb_obj->nodes.add_node(inside, socket_2, nacl_lb_obj->get_pool_signal());

Socket socket_3{ IP4::addr{10,0,0,1}, 6004 };
nacl_lb_obj->nodes.add_node(inside, socket_3, nacl_lb_obj->get_pool_signal());

/*
Name: lb
Layer: tcp
Clients iface: outside
Clients port: 80
Clients wait queue limit: 1000
Clients session limit: 1000
Servers iface: inside
Servers algorithm: round_robin
Servers pool:
Node address: IP4::addr{10,0,0,1}
Node port: 6001
Node address: IP4::addr{10,0,0,1}
Node port: 6002
Node address: IP4::addr{10,0,0,1}
Node port: 6003
Node address: IP4::addr{10,0,0,1}
Node port: 6004
*/
}
Loading

0 comments on commit cb03d06

Please sign in to comment.