Skip to content

Commit 3fdf636

Browse files
committed
[feature] Openwrt: Add support for mwan3
1 parent a16a91f commit 3fdf636

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed

netjsonconfig/backends/openwrt/converters/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .general import General
33
from .interfaces import Interfaces
44
from .led import Led
5+
from .mwan3 import Mwan3
56
from .ntp import Ntp
67
from .openvpn import OpenVpn
78
from .radios import Radios
@@ -24,4 +25,5 @@
2425
'Switch',
2526
'WireguardPeers',
2627
'Wireless',
28+
'Mwan3',
2729
]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from collections import OrderedDict
2+
3+
from ..schema import schema
4+
from .base import OpenWrtConverter
5+
6+
7+
class Mwan3(OpenWrtConverter):
8+
netjson_key = 'mwan3'
9+
intermediate_key = 'mwan3'
10+
_uci_types = ['interface']
11+
_schema = schema['properties']['mwan3']
12+
13+
def to_intermediate_loop(self, block, result, index=None):
14+
interfaces = self.__intermediate_interfaces(block.pop('interfaces', {}))
15+
result.setdefault('mwan3', [])
16+
result['mwan3'] = interfaces
17+
return result
18+
19+
def __intermediate_interfaces(self, interfaces):
20+
"""
21+
converts NetJSON interface to
22+
UCI intermediate data structure
23+
"""
24+
result = []
25+
for interface in interfaces:
26+
resultdict = OrderedDict(
27+
(
28+
('.name', self._get_uci_name(interface.pop('name'))),
29+
('.type', 'interface'),
30+
)
31+
)
32+
resultdict.update(interface)
33+
result.append(resultdict)
34+
return result
35+
36+
def to_netjson_loop(self, block, result, index):
37+
result['mwan3'] = self.__netjson_mwan3(block)
38+
return result
39+
40+
def __netjson_mwan3(self, mwan3):
41+
del mwan3['.type']
42+
_name = mwan3.pop('.name')
43+
if _name != 'mwan3':
44+
mwan3['id'] = _name
45+
return self.type_cast(mwan3)

netjsonconfig/backends/openwrt/openwrt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class OpenWrt(BaseBackend):
2525
converters.Wireless,
2626
converters.OpenVpn,
2727
converters.WireguardPeers,
28+
converters.Mwan3,
2829
converters.Default,
2930
]
3031
parser = OpenWrtParser

netjsonconfig/backends/openwrt/schema.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,197 @@
928928
},
929929
},
930930
},
931+
"mwan3": {
932+
"type": "object",
933+
"title": "Mwan3",
934+
"additionalProperties": True,
935+
"propertyOrder": 11,
936+
"properties": {
937+
"interfaces": {
938+
"type": "array",
939+
"title": "Interfaces",
940+
"propertyOrder": 1,
941+
"items": {
942+
"type": "object",
943+
"title": "Interface",
944+
"additionalProperties": True,
945+
"required": [
946+
"name",
947+
"track_ip",
948+
],
949+
"properties": {
950+
"name": {
951+
"type": "string",
952+
"title": "Name",
953+
"description": "the OpenWrt interface name",
954+
"propertyOrder": 1,
955+
},
956+
"enabled": {
957+
"type": "boolean",
958+
"title": "Enabled",
959+
"description": "specifies wether mwan3 should run on this interface",
960+
"default": False,
961+
"format": "checkbox",
962+
"propertyOrder": 2,
963+
},
964+
"track_method": {
965+
"type": "string",
966+
"title": "Tracking method",
967+
"description": "Tracking method for mwan3track",
968+
"enum": ["ping", "arping", "httping", "nping-*"],
969+
"default": "ping",
970+
"propertyOrder": 3,
971+
},
972+
"track_ip": {
973+
"title": "Tracking IPs",
974+
"description": "List of IPs to ping to test the interface. If this list "
975+
"is empty then the interface is always considered up",
976+
"type": "array",
977+
"uniqueItems": True,
978+
"additionalItems": True,
979+
"items": {
980+
"type": "string",
981+
"title": "ipv4 address",
982+
"minLength": 7,
983+
"maxLength": 15,
984+
"format": "ipv4",
985+
},
986+
"propertyOrder": 4,
987+
},
988+
"reliability": {
989+
"type": "integer",
990+
"title": "Reliability",
991+
"description": "Number of track_ip hosts that must reply for the test to"
992+
" be considered successful. Ensure there are at least this"
993+
" many track_ip hosts defined or the interface will always"
994+
" be considered down",
995+
"default": 1,
996+
"propertyOrder": 5,
997+
},
998+
"count": {
999+
"type": "integer",
1000+
"title": "Count",
1001+
"description": "Number of checks to send to each host with each test",
1002+
"default": 1,
1003+
"propertyOrder": 6,
1004+
},
1005+
"timeout": {
1006+
"type": "integer",
1007+
"title": "Timeout",
1008+
"description": "Number of seconds to wait for an echo-reply after an "
1009+
"echo-request",
1010+
"default": 4,
1011+
"propertyOrder": 7,
1012+
},
1013+
"interval": {
1014+
"type": "integer",
1015+
"title": "Interval",
1016+
"description": "Number of seconds between each test",
1017+
"default": 10,
1018+
"propertyOrder": 8,
1019+
},
1020+
"failure_interval": {
1021+
"type": "integer",
1022+
"title": "Failure interval",
1023+
"description": "Number of seconds between each test during teardown on "
1024+
"failure detection",
1025+
"propertyOrder": 9,
1026+
},
1027+
"recovery_interval": {
1028+
"type": "integer",
1029+
"title": "Recovery interval",
1030+
"description": "Number of seconds between each test during tearup on "
1031+
"recovery detection",
1032+
"propertyOrder": 10,
1033+
},
1034+
"keep_failure_interval": {
1035+
"type": "boolean",
1036+
"title": "Keep failure interval",
1037+
"description": "In the event of an error, keep the number of seconds "
1038+
"between each test during teardown (failure detection)",
1039+
"default": False,
1040+
"format": "checkbox",
1041+
"propertyOrder": 11,
1042+
},
1043+
"up": {
1044+
"type": "integer",
1045+
"title": "Up",
1046+
"description": "Number of successful tests to consider link as alive",
1047+
"default": 5,
1048+
"propertyOrder": 12,
1049+
},
1050+
"down": {
1051+
"type": "integer",
1052+
"title": "Down",
1053+
"description": "Number of failed tests to consider link as dead",
1054+
"default": 5,
1055+
"propertyOrder": 13,
1056+
},
1057+
"family": {
1058+
"type": "string",
1059+
"title": "Family",
1060+
"description": "",
1061+
"enum": [
1062+
"ipv4",
1063+
"ipv6",
1064+
],
1065+
"default": "ipv4",
1066+
"propertyOrder": 14,
1067+
},
1068+
"max_ttl": {
1069+
"type": "integer",
1070+
"title": "Time to live",
1071+
"description": "Time to live (TTL) or hop limit. Only valid if tracking "
1072+
"method is ping.",
1073+
"default": 60,
1074+
"propertyOrder": 15,
1075+
},
1076+
"initial_state": {
1077+
"type": "string",
1078+
"title": "Initial state",
1079+
"description": "If the value is offline, then traffic goes via this "
1080+
"interface only if mwan3track checked the connection "
1081+
"first. If the value is online, then the mwan3track "
1082+
"test is not waited for. The interface is marked as "
1083+
"online at once.",
1084+
"enum": [
1085+
"online",
1086+
"offline",
1087+
],
1088+
"default": "online",
1089+
"propertyOrder": 16,
1090+
},
1091+
"size": {
1092+
"type": "integer",
1093+
"title": "Size",
1094+
"description": "Size of ping packets to use in bytes. Only valid if "
1095+
"tracking method is ping.",
1096+
"default": 56,
1097+
"propertyOrder": 17,
1098+
},
1099+
"flush_conntrack": {
1100+
"title": "Flush connection tracking",
1101+
"description": "specifies upon which events the connections table should"
1102+
" be flushed",
1103+
"type": "array",
1104+
"uniqueItems": True,
1105+
"additionalItems": True,
1106+
"items": {
1107+
"type": "string",
1108+
"enum": [
1109+
"ifup",
1110+
"ifdown",
1111+
"connected",
1112+
"disconnected",
1113+
],
1114+
},
1115+
"propertyOrder": 18,
1116+
},
1117+
},
1118+
},
1119+
}
1120+
},
1121+
},
9311122
},
9321123
},
9331124
)

0 commit comments

Comments
 (0)