Skip to content

Commit 21813a8

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

File tree

4 files changed

+238
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)