Skip to content

Commit

Permalink
Virtual Router Implementation (#129)
Browse files Browse the repository at this point in the history
This is the implementation of virtual routers using Linux network namespaces, iptables, Linux bridges and veth interfaces.

Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
  • Loading branch information
gabrik committed Jul 17, 2019
1 parent 110b2fb commit 7f59014
Show file tree
Hide file tree
Showing 13 changed files with 1,028 additions and 47 deletions.
4 changes: 2 additions & 2 deletions fos-plugins/linux/linux_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ class Linux(OSPlugin):

def execute_command(self, command, blocking=False, external=False):
if isinstance(blocking, str):
root = bool(distutils.util.strtobool(blocking))
blocking = bool(distutils.util.strtobool(blocking))
if isinstance(external, str):
root = bool(distutils.util.strtobool(external))
external = bool(distutils.util.strtobool(external))
try:
self.logger.info('execute_command()', 'OS Plugin executing command {}'.format(command))
r = ''
Expand Down
2 changes: 2 additions & 0 deletions fos-plugins/linuxbridge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ else
sudo cp ../linuxbridge/linuxbridge_plugin /etc/fos/plugins/linuxbridge/
sudo cp ../linuxbridge/README.md /etc/fos/plugins/linuxbridge/
sudo ln -sf /etc/fos/plugins/linuxbridge/linuxbridge_plugin /usr/bin/fos_linuxbridge
sudo cp ../linuxbridge/get_face_address /etc/fos/plugins/linuxbridge/get_face_address
sudo ln -sf /etc/fos/plugins/linuxbridge/get_face_address /usr/bin/fos_get_address
endif
sudo cp /etc/fos/plugins/linuxbridge/fos_linuxbridge.service /lib/systemd/system/
sudo sh -c "echo $(UUID) | xargs -i jq '.configuration.nodeid = \"{}\"' /etc/fos/plugins/linuxbridge/linuxbridge_plugin.json > /tmp/linuxbridge_plugin.tmp && mv /tmp/linuxbridge_plugin.tmp /etc/fos/plugins/linuxbridge/linuxbridge_plugin.json"
Expand Down
53 changes: 53 additions & 0 deletions fos-plugins/linuxbridge/get_face_address
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

# Copyright (c) 2014,2018 ADLINK Technology Inc.
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors: Gabriele Baldoni, ADLINK Technology Inc. - LinuxBridge plugin

import sys
import netifaces
import socket


def get_net_size(netmask):
binary_str = ''
for octet in netmask:
binary_str += bin(int(octet))[2:].zfill(8)
return str(len(binary_str.rstrip('0')))

def ip_mask_to_cird(ip, mask):

try:
socket.inet_aton(ip)
socket.inet_aton(mask)
except:
return "0.0.0.0/0"

ip = ip.split('.')
mask = mask.split('.')
net_start = [str(int(ip[x])) for x in range(0, 4)]
return '.'.join(net_start) + '/' + get_net_size(mask)

def main(face):
try:
addr = netifaces.ifaddresses(face)[2][0]['addr']
mask = netifaces.ifaddresses(face)[2][0]['netmask']
addr = ip_mask_to_cird(addr, mask)

except:
addr = '0.0.0.0/0'
print(addr)


if __name__ == '__main__':
main(sys.argv[1])
339 changes: 338 additions & 1 deletion fos-plugins/linuxbridge/linuxbridge_plugin

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions fos-plugins/linuxbridge/templates/vnet_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@

sudo ip netns add fosns-{{ net_id }}
sudo ip link add br-{{ net_id }} type bridge

sudo ip netns exec fosns-{{ net_id }} ip link add br-{{ net_id }}-ns type bridge

sudo ip link add l-{{ net_id }}-i type veth peer name l-{{ net_id }}-e
sudo ip link set l-{{ net_id }}-e netns fosns-{{ net_id }}
sudo ip link set l-{{ net_id }}-i master br-{{ net_id }}
sudo ip link set l-{{ net_id }}-i up


sudo ip netns exec fosns-{{ net_id }} ip link set br-{{ net_id }}-ns up
sudo ip netns exec fosns-{{ net_id }} ip link set l-{{ net_id }}-e master br-{{ net_id }}-ns
sudo ip netns exec fosns-{{ net_id }} ip link set l-{{ net_id }}-e up

sudo ip link add name vxl-{{ net_id }} type vxlan id {{ group_id }} group {{ mcast_group_address }} dstport 4789 dev {{ wan }}
sudo ip link set dev vxl-{{ net_id }} master br-{{ net_id }}
sudo ip link set up dev br-{{ net_id }}
Expand Down
1 change: 1 addition & 0 deletions fos-plugins/linuxbridge/templates/vnet_destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sudo ip link set br-{{ net_id }} down
sudo ip link set vxl-{{ net_id }} down
sudo ip link del br-{{ net_id }}
sudo ip link del vxl-{{ net_id }}
sudo ip link del l-{{ net_id }}-i
sudo ip netns del fosns-{{ net_id }}


238 changes: 200 additions & 38 deletions src/agent/fos-agent/fos_agent.ml

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/api/python/api/fog05/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def remove_network(self, net_uuid):
self.connector.glob.desired.remove_network(
self.sysid, self.tenantid, net_uuid)


def add_connection_point(self, cp_descriptor):
cp_descriptor.update({'status': 'add'})
cp_id = cp_descriptor.get('uuid')
Expand Down Expand Up @@ -373,6 +374,33 @@ def disconnect_cp(self, cp_uuid):
return cp_uuid
raise ValueError('Error connecting: {}'.format(res['error']))

def add_router(self, nodeid, manifest):
router_id = manifest.get('uuid')
self.connector.glob.desired.add_node_network_router(
self.sysid, self.tenantid, nodeid, router_id, manifest)
router_info = self.connector.glob.actual.get_node_network_router(
self.sysid, self.tenantid, nodeid, router_id)
while router_info is None:
router_info = self.connector.glob.actual.get_node_network_router(
self.sysid, self.tenantid, nodeid, router_id)
return router_info


def remove_router(self, node_id, router_id):
self.connector.glob.desired.remove_node_network_router(
self.sysid, self.tenantid, node_id, router_id)

def add_router_port(self, nodeid, router_id, port_type, vnet_id=None, ip_address=None):
if port_type.upper() not in ['EXTERNAL', 'INTERNAL']:
raise ValueError("port_type can be only one of : INTERNAL, EXTERNAL")

port_type = port_type.upper()
return self.connector.glob.actual.add_port_to_router(self.sysid, self.tenantid, nodeid, router_id, port_type, vnet_id, ip_address)

def remove_router_port(self, nodeid, router_id, vnet_id):
return self.connector.glob.actual.remove_port_from_router(self.sysid, self.tenantid, nodeid, router_id, vnet_id)



def create_floating_ip(self, nodeid):
return self.connector.glob.actual.add_node_floatingip(self.sysid, self.tenantid, nodeid)
Expand Down
Loading

0 comments on commit 7f59014

Please sign in to comment.