summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-geneve.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-11-24 20:33:25 +0100
committerChristian Poessinger <christian@poessinger.com>2019-11-24 20:33:25 +0100
commit525af4f27dc2aa7e226f2bba46b4b1736bbc014f (patch)
tree8068edf769df8f680246ebd0e5e1e6e625ff3ed2 /src/conf_mode/interfaces-geneve.py
parent24b23d41146eddd8fb0609ad4ae85d27e7c6ec6a (diff)
parent5238f0970219639e988bc31beb7db27b43f94e6e (diff)
downloadvyos-1x-525af4f27dc2aa7e226f2bba46b4b1736bbc014f.tar.gz
vyos-1x-525af4f27dc2aa7e226f2bba46b4b1736bbc014f.zip
Merge branch 'current' of github.com:vyos/vyos-1x into equuleus
* 'current' of github.com:vyos/vyos-1x: bridge: T1673: re-use "base" variable bridge: T1673: add missing VLAN bridge member migration geneve: T1799: add misssing "vni" to default_config_data vxlan: T1636: add misssing "vni" to default_config_data geneve: T1799: set minimum MTU size 1500 bytes geneve: T1799: add IPv4 routing parameters geneve: T1799: support bridging geneve: T1799: add Generic Network Virtualization Encapsulation
Diffstat (limited to 'src/conf_mode/interfaces-geneve.py')
-rwxr-xr-xsrc/conf_mode/interfaces-geneve.py166
1 files changed, 166 insertions, 0 deletions
diff --git a/src/conf_mode/interfaces-geneve.py b/src/conf_mode/interfaces-geneve.py
new file mode 100755
index 000000000..ba684b553
--- /dev/null
+++ b/src/conf_mode/interfaces-geneve.py
@@ -0,0 +1,166 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2019 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+from sys import exit
+from copy import deepcopy
+
+from vyos.configdict import list_diff
+from vyos.config import Config
+from vyos.ifconfig import GeneveIf, Interface
+from vyos.interfaces import get_type_of_interface
+from vyos import ConfigError
+from netifaces import interfaces
+
+default_config_data = {
+ 'address': [],
+ 'deleted': False,
+ 'description': '',
+ 'disable': False,
+ 'intf': '',
+ 'ip_arp_cache_tmo': 30,
+ 'ip_proxy_arp': 0,
+ 'mtu': 1500,
+ 'remote': '',
+ 'vni': ''
+}
+
+def get_config():
+ geneve = deepcopy(default_config_data)
+ conf = Config()
+
+ # determine tagNode instance
+ try:
+ geneve['intf'] = os.environ['VYOS_TAGNODE_VALUE']
+ except KeyError as E:
+ print("Interface not specified")
+
+ # Check if interface has been removed
+ if not conf.exists('interfaces geneve ' + geneve['intf']):
+ geneve['deleted'] = True
+ return geneve
+
+ # set new configuration level
+ conf.set_level('interfaces geneve ' + geneve['intf'])
+
+ # retrieve configured interface addresses
+ if conf.exists('address'):
+ geneve['address'] = conf.return_values('address')
+
+ # retrieve interface description
+ if conf.exists('description'):
+ geneve['description'] = conf.return_value('description')
+
+ # Disable this interface
+ if conf.exists('disable'):
+ geneve['disable'] = True
+
+ # ARP cache entry timeout in seconds
+ if conf.exists('ip arp-cache-timeout'):
+ geneve['ip_arp_cache_tmo'] = int(conf.return_value('ip arp-cache-timeout'))
+
+ # Enable proxy-arp on this interface
+ if conf.exists('ip enable-proxy-arp'):
+ geneve['ip_proxy_arp'] = 1
+
+ # Maximum Transmission Unit (MTU)
+ if conf.exists('mtu'):
+ geneve['mtu'] = int(conf.return_value('mtu'))
+
+ # Remote address of GENEVE tunnel
+ if conf.exists('remote'):
+ geneve['remote'] = conf.return_value('remote')
+
+ # Virtual Network Identifier
+ if conf.exists('vni'):
+ geneve['vni'] = conf.return_value('vni')
+
+ return geneve
+
+
+def verify(geneve):
+ if geneve['deleted']:
+ # bail out early
+ return None
+
+ if not geneve['remote']:
+ raise ConfigError('GENEVE remote must be configured')
+
+ if not geneve['vni']:
+ raise ConfigError('GENEVE VNI must be configured')
+
+ return None
+
+
+def generate(geneve):
+ return None
+
+
+def apply(geneve):
+ # Check if GENEVE interface already exists
+ if geneve['intf'] in interfaces():
+ v = GeneveIf(geneve['intf'])
+ # GENEVE is super picky and the tunnel always needs to be recreated,
+ # thus we can simply always delete it first.
+ v.remove()
+
+ if not geneve['deleted']:
+ # GENEVE interface needs to be created on-block
+ # instead of passing a ton of arguments, I just use a dict
+ # that is managed by vyos.ifconfig
+ conf = deepcopy(GeneveIf.get_config())
+
+ # Assign GENEVE instance configuration parameters to config dict
+ conf['vni'] = geneve['vni']
+ conf['remote'] = geneve['remote']
+
+ # Finally create the new interface
+ v = GeneveIf(geneve['intf'], config=conf)
+ # update interface description used e.g. by SNMP
+ v.set_alias(geneve['description'])
+ # Maximum Transfer Unit (MTU)
+ v.set_mtu(geneve['mtu'])
+
+ # configure ARP cache timeout in milliseconds
+ v.set_arp_cache_tmo(geneve['ip_arp_cache_tmo'])
+ # Enable proxy-arp on this interface
+ v.set_proxy_arp(geneve['ip_proxy_arp'])
+
+ # Configure interface address(es) - no need to implicitly delete the
+ # old addresses as they have already been removed by deleting the
+ # interface above
+ for addr in geneve['address']:
+ v.add_addr(addr)
+
+ # As the bond interface is always disabled first when changing
+ # parameters we will only re-enable the interface if it is not
+ # administratively disabled
+ if not geneve['disable']:
+ v.set_state('up')
+
+ return None
+
+
+if __name__ == '__main__':
+ try:
+ c = get_config()
+ verify(c)
+ generate(c)
+ apply(c)
+ except ConfigError as e:
+ print(e)
+ exit(1)