Thu, May 13, 2021 at 12:51:26PM CEST, jtluka(a)redhat.com wrote:
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Devices/GeneveDevice.py | 65 ++++++++++++++++++++++++++++++++++++
lnst/Devices/__init__.py | 2 ++
2 files changed, 67 insertions(+)
create mode 100644 lnst/Devices/GeneveDevice.py
diff --git a/lnst/Devices/GeneveDevice.py b/lnst/Devices/GeneveDevice.py
new file mode 100644
index 00000000..cd35b19a
--- /dev/null
+++ b/lnst/Devices/GeneveDevice.py
@@ -0,0 +1,65 @@
+"""
+Defines the GeneveDevice class.
+
+Copyright 2017 Red Hat, Inc.
+Licensed under the GNU General Public License, version 2 as
+published by the Free Software Foundation; see COPYING for details.
+"""
+
+__author__ = """
+olichtne(a)redhat.com (Ondrej Lichtner)
+"""
I've accidentally copied old copyright and authorship. This can be fixed
while applying but I'm ok to resend another version.
J.
+
+import pyroute2
+import logging
+from lnst.Common.Logs import log_exc_traceback
+from lnst.Common.DeviceError import DeviceError, DeviceConfigError, DeviceNotFound
+from lnst.Common.IpAddress import ipaddress, Ip4Address
+from lnst.Devices.Device import Device
+from lnst.Devices.SoftDevice import SoftDevice
+
+class GeneveDevice(SoftDevice):
+ _name_template = "t_gnv"
+ _link_type = "geneve"
+ _mandatory_opts = ["id", "remote"]
+
+ @property
+ def id(self):
+ try:
+ return int(self._get_linkinfo_data_attr("IFLA_GENEVE_ID"))
+ except:
+ return None
+
+ @id.setter
+ def id(self, val):
+ if int(val) < 0 or int(val) > 16777215:
+ raise DeviceConfigError("Invalid value, must be 0-16777215.")
+
+ self._set_linkinfo_data_attr("IFLA_GENEVE_ID", int(val))
+ self._nl_link_sync("set")
+
+ @property
+ def remote(self):
+ # TODO: pyroute defines also IFLA_GENEVE_REMOTE6, this should be handled
+ try:
+ return
ipaddress(self._get_linkinfo_data_attr("IFLA_GENEVE_REMOTE"))
+ except:
+ return None
+
+ @remote.setter
+ def remote(self, val):
+ addr = ipaddress(val)
+ if isinstance(addr, Ip4Address):
+ self._set_linkinfo_data_attr("IFLA_GENEVE_REMOTE", str(addr))
+ else:
+ self._set_linkinfo_data_attr("IFLA_GENEVE_REMOTE6", str(addr))
+ self._nl_link_sync("set")
+
+ @property
+ def dst_port(self):
+ return int(self._get_linkinfo_data_attr("IFLA_GENEVE_PORT"))
+
+ @dst_port.setter
+ def dst_port(self, val):
+ self._set_linkinfo_data_attr("IFLA_GENEVE_PORT", int(val))
+ self._nl_link_sync("set")
diff --git a/lnst/Devices/__init__.py b/lnst/Devices/__init__.py
index fd41818b..52e4499e 100644
--- a/lnst/Devices/__init__.py
+++ b/lnst/Devices/__init__.py
@@ -7,6 +7,7 @@ from lnst.Devices.TeamDevice import TeamDevice
from lnst.Devices.MacvlanDevice import MacvlanDevice
from lnst.Devices.VlanDevice import VlanDevice
from lnst.Devices.VxlanDevice import VxlanDevice
+from lnst.Devices.GeneveDevice import GeneveDevice
from lnst.Devices.GreDevice import GreDevice
from lnst.Devices.Ip6GreDevice import Ip6GreDevice
from lnst.Devices.SitDevice import SitDevice
@@ -26,6 +27,7 @@ device_classes = [
("MacvlanDevice", MacvlanDevice),
("VlanDevice", VlanDevice),
("VxlanDevice", VxlanDevice),
+ ("GeneveDevice", GeneveDevice),
("GreDevice", GreDevice),
("Ip6GreDevice", Ip6GreDevice),
("SitDevice", SitDevice),
--
2.26.3